First commit
This commit is contained in:
		
							
								
								
									
										142
									
								
								Privacy/DemoCollab.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										142
									
								
								Privacy/DemoCollab.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,142 @@
 | 
				
			|||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * The collaborative version of the "DemoFilterTime" privacy mechanism.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.*;
 | 
				
			||||||
 | 
					import java.io.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import android.content.Context;
 | 
				
			||||||
 | 
					import android.util.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@SuppressWarnings("unchecked")
 | 
				
			||||||
 | 
					public class DemoCollab {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private Context context;
 | 
				
			||||||
 | 
					  private int pref;
 | 
				
			||||||
 | 
					  private List <Object> state;
 | 
				
			||||||
 | 
					  private List<Map<String, String>> peers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public void onStart (Context c, int i, ObjectInputStream ois) throws Exception {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@onStart: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Get application context.
 | 
				
			||||||
 | 
					    context = c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Get privacy preferences.
 | 
				
			||||||
 | 
					    pref = i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Restore state.
 | 
				
			||||||
 | 
					    if (ois != null) {
 | 
				
			||||||
 | 
					      Log.wtf(TAG, "Restoring state...");
 | 
				
			||||||
 | 
					      state = (List<Object>) ois.readObject();
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      Log.wtf(TAG, "Initializing state...");
 | 
				
			||||||
 | 
					      state = new ArrayList<>();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    peers = new ArrayList<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public void onStop () {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@onStop: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public void onPreferenceChanged (int i) {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@onPreferenceChanged: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "" + i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pref = i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public boolean saveState (ObjectOutputStream oos) {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@saveState: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // s.writeObject(state);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public int processData (ObjectInputStream ois, ObjectOutputStream oos) throws Exception {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@processData: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Get list of data.
 | 
				
			||||||
 | 
					    List <Object> list = (List<Object>) ois.readObject();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Edit each data entry of the data list.
 | 
				
			||||||
 | 
					    for (Object o : list) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      Map data = (Map) o;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      data.put("device", data.get("device"));
 | 
				
			||||||
 | 
					      data.put("task", data.get("task"));
 | 
				
			||||||
 | 
					      data.put("sensor", data.get("sensor"));
 | 
				
			||||||
 | 
					      data.put("values", data.get("values"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      float min = -1;
 | 
				
			||||||
 | 
					      float max = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      Random r = new Random();
 | 
				
			||||||
 | 
					      float d = min + (max - min) * r.nextFloat();  // -1 < d < 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      long var = (long) (((float) pref / 10) * d * 3600000000000L);   // (pref/10) * random * (1hr)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      data.put("timestamp", (Long) data.get("timestamp") + var);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    oos.writeObject(list);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // If a peer is present...
 | 
				
			||||||
 | 
					    if(!peers.isEmpty()) {
 | 
				
			||||||
 | 
					      // Collaborate!
 | 
				
			||||||
 | 
					      return Integer.parseInt(peers.get(0).get("id"));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * Collaborative stuff.
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  /**/
 | 
				
			||||||
 | 
					  public void onPeersChanged (List<Map<String, String>> peers) {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@onPeersChanged: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    this.peers = peers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, peers.toString());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public boolean aggregateData (ObjectInputStream ois, ObjectOutputStream oos) throws Exception {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@aggregateData: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Read input stream.
 | 
				
			||||||
 | 
					    List <Object> data = (List<Object>) ois.readObject();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Write to output stream.
 | 
				
			||||||
 | 
					    oos.writeObject(data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  /**/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										111
									
								
								Privacy/DemoFilterLocation.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										111
									
								
								Privacy/DemoFilterLocation.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,111 @@
 | 
				
			|||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * A simple implementation which adds noise to the location component of the
 | 
				
			||||||
 | 
					 * data that is produced by the "DemoLocation" sensing task.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.*;
 | 
				
			||||||
 | 
					import java.io.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import android.content.Context;
 | 
				
			||||||
 | 
					import android.util.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@SuppressWarnings("unchecked")
 | 
				
			||||||
 | 
					public class DemoFilterLocation {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private static Context context;
 | 
				
			||||||
 | 
					  private static int pref;
 | 
				
			||||||
 | 
					  private static List <Object> state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public void onStart (Context c, int i, ObjectInputStream ois) throws Exception {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@onStart: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Get application context.
 | 
				
			||||||
 | 
					    context = c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Get privacy preferences.
 | 
				
			||||||
 | 
					    pref = i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Restore state.
 | 
				
			||||||
 | 
					    if (ois != null) {
 | 
				
			||||||
 | 
					      Log.wtf(TAG, "Restoring state...");
 | 
				
			||||||
 | 
					      state = (List<Object>) ois.readObject();
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      Log.wtf(TAG, "Initializing state...");
 | 
				
			||||||
 | 
					      state = new ArrayList<>();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public void onStop () {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@onStop: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public void onPreferenceChanged (int i) {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@onPreferenceChanged: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "" + i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pref = i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public boolean saveState (ObjectOutputStream oos) throws Exception {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@saveState: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // s.writeObject(state);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public int processData (ObjectInputStream ois, ObjectOutputStream oos) throws Exception {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@processData: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Get list of data.
 | 
				
			||||||
 | 
					    List <Object> list = (List<Object>) ois.readObject();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Edit each data entry of the data list.
 | 
				
			||||||
 | 
					    for (Object o : list) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      Map data = (Map) o;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      data.put("device", data.get("device"));
 | 
				
			||||||
 | 
					      data.put("task", data.get("task"));
 | 
				
			||||||
 | 
					      data.put("sensor", data.get("sensor"));
 | 
				
			||||||
 | 
					      data.put("timestamp", data.get("timestamp"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      double[] location = (double[]) data.get("values");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      double x0 = location[0];   // lat
 | 
				
			||||||
 | 
					      double y0 = location[1];   // lng
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      double r = (double) pref * 10 / 111300;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      double w = r * Math.sqrt(Math.random());
 | 
				
			||||||
 | 
					      double t = 2 * Math.PI * Math.random();
 | 
				
			||||||
 | 
					      double x = w * Math.cos(t);
 | 
				
			||||||
 | 
					      double y = w * Math.sin(t);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      double x1 = x / Math.cos(y0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      double values[] = {x1 + x0, y + y0};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      data.put("values", values);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    oos.writeObject(list);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										104
									
								
								Privacy/DemoFilterTime.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										104
									
								
								Privacy/DemoFilterTime.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,104 @@
 | 
				
			|||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * A simple implementation which adds noise to the time component of the
 | 
				
			||||||
 | 
					 * data that is produced by any sensing task.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.*;
 | 
				
			||||||
 | 
					import java.io.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import android.content.Context;
 | 
				
			||||||
 | 
					import android.util.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@SuppressWarnings("unchecked")
 | 
				
			||||||
 | 
					public class DemoFilterTime {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private static Context context;
 | 
				
			||||||
 | 
					  private static int pref;
 | 
				
			||||||
 | 
					  private static List <Object> state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public void onStart (Context c, int i, ObjectInputStream ois) throws Exception {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@onStart: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Get application context.
 | 
				
			||||||
 | 
					    context = c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Get privacy preferences.
 | 
				
			||||||
 | 
					    pref = i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Restore state.
 | 
				
			||||||
 | 
					    if (ois != null) {
 | 
				
			||||||
 | 
					      Log.wtf(TAG, "Restoring state...");
 | 
				
			||||||
 | 
					      state = (List<Object>) ois.readObject();
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      Log.wtf(TAG, "Initializing state...");
 | 
				
			||||||
 | 
					      state = new ArrayList<>();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public void onStop () {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@onStop: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public void onPreferenceChanged (int i) {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@onPreferenceChanged: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "" + i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pref = i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public boolean saveState (ObjectOutputStream oos) throws Exception {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@saveState: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // s.writeObject(state);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public int processData (ObjectInputStream ois, ObjectOutputStream oos) throws Exception {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@processData: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Get list of data.
 | 
				
			||||||
 | 
					    List <Object> list = (List<Object>) ois.readObject();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Edit each data entry of the data list.
 | 
				
			||||||
 | 
					    for (Object o : list) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      Map data = (Map) o;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      data.put("device", data.get("device"));
 | 
				
			||||||
 | 
					      data.put("task", data.get("task"));
 | 
				
			||||||
 | 
					      data.put("sensor", data.get("sensor"));
 | 
				
			||||||
 | 
					      data.put("values", data.get("values"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      float min = -1;
 | 
				
			||||||
 | 
					      float max = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      Random r = new Random();
 | 
				
			||||||
 | 
					      float d = min + (max - min) * r.nextFloat();  // -1 < d < 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      long var = (long) (((float) pref / 10) * d * 3600000000000L);   // (pref/10) * random * (1hr)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      data.put("timestamp", (Long) data.get("timestamp") + var);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    oos.writeObject(list);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										168
									
								
								Sensing/DemoLocation.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										168
									
								
								Sensing/DemoLocation.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,168 @@
 | 
				
			|||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * A simple sensing task that logs the location the device has remained at for
 | 
				
			||||||
 | 
					 * a defined period of time.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.*;
 | 
				
			||||||
 | 
					import java.util.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import android.content.*;
 | 
				
			||||||
 | 
					import android.hardware.Sensor;
 | 
				
			||||||
 | 
					import android.location.*;
 | 
				
			||||||
 | 
					import android.os.*;
 | 
				
			||||||
 | 
					import android.util.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class DemoLocation implements LocationListener  {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Context context;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  List<Object> data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  LocationManager locMgr;
 | 
				
			||||||
 | 
					  LocationListener locLnr;
 | 
				
			||||||
 | 
					  Location lastLoc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Timer and total time definition.
 | 
				
			||||||
 | 
					  CountDownTimer timer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  int hours 	= 0;
 | 
				
			||||||
 | 
					  int minutes = 0;
 | 
				
			||||||
 | 
					  int seconds = 5;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Convert the above to milliseconds.
 | 
				
			||||||
 | 
					  int timeTotal = (hours * 3600 + minutes * 60 + seconds) * 1000;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public void onStart(Context c, ObjectInputStream s) throws Exception {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@onStart: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    context = c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    data = new ArrayList<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    timer = new CountDownTimer(timeTotal, 1000) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      public void onTick(long arg0) {
 | 
				
			||||||
 | 
					        String TAG =  getClass().getName() + "@onTick: ";
 | 
				
			||||||
 | 
					        // Log.wtf(TAG, arg0 / 1000 + " seconds remaining...");
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // Log the current location.
 | 
				
			||||||
 | 
					      public void onFinish() {
 | 
				
			||||||
 | 
					        String TAG =  getClass().getName() + "@onFinish: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Log.wtf(TAG, lastLoc.toString());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // add location to data
 | 
				
			||||||
 | 
					        Map<String, Object> newData = new HashMap<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        double[] values = new double[2];
 | 
				
			||||||
 | 
					        values[0] = lastLoc.getLatitude();
 | 
				
			||||||
 | 
					        values[1] = lastLoc.getLongitude();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        newData.put("sensor", Sensor.TYPE_ALL);
 | 
				
			||||||
 | 
					        // newData.put("timestamp", lastLoc.getTime() * 1000000);
 | 
				
			||||||
 | 
					        newData.put("timestamp", System.currentTimeMillis() * 1000000L);
 | 
				
			||||||
 | 
					        newData.put("values", values);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        data.add(newData);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Monitor location changes.
 | 
				
			||||||
 | 
					    locMgr = (LocationManager) context.getSystemService(context.LOCATION_SERVICE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Criteria criteria = new Criteria();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    String provider = locMgr.getBestProvider(criteria, true);
 | 
				
			||||||
 | 
					    if(provider == null) {
 | 
				
			||||||
 | 
					      provider = locMgr.getBestProvider(criteria, false);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    locMgr.requestLocationUpdates(provider, 1000, 1, this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Location loc = locMgr.getLastKnownLocation(provider);
 | 
				
			||||||
 | 
					    if (loc != null) {
 | 
				
			||||||
 | 
					      Log.wtf(TAG, provider + " provider selected.");
 | 
				
			||||||
 | 
					      onLocationChanged(loc);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else {
 | 
				
			||||||
 | 
					      Log.wtf(TAG, "Location not available.");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public boolean saveState(ObjectOutputStream s) {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@saveState: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public List<Object> getData() {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@getData: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    List<Object> tmp = data;
 | 
				
			||||||
 | 
					    data = new ArrayList<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return tmp;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public void onStop() {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@onStop: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Stop the timer.
 | 
				
			||||||
 | 
					    if(timer != null) {
 | 
				
			||||||
 | 
					      timer.cancel();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //  Release the location listener.
 | 
				
			||||||
 | 
					    if(locMgr != null) {
 | 
				
			||||||
 | 
					      locMgr.removeUpdates(locLnr = this);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  /**/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Called when the location has changed.
 | 
				
			||||||
 | 
					  @Override
 | 
				
			||||||
 | 
					  public void onLocationChanged(Location loc) {
 | 
				
			||||||
 | 
					    String TAG =  getClass().getName() + "@onLocationChanged: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Log.wtf(TAG, loc.toString());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    lastLoc = loc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (timer != null) {
 | 
				
			||||||
 | 
					      timer.cancel();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    timer.start();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @Override
 | 
				
			||||||
 | 
					  public void onProviderDisabled(String arg0) {
 | 
				
			||||||
 | 
					    // TODO Auto-generated method stub
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @Override
 | 
				
			||||||
 | 
					  public void onProviderEnabled(String arg0) {
 | 
				
			||||||
 | 
					    // TODO Auto-generated method stub
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @Override
 | 
				
			||||||
 | 
					  public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
 | 
				
			||||||
 | 
					    // TODO Auto-generated method stub
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										169
									
								
								Sensing/DemoOrientation.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										169
									
								
								Sensing/DemoOrientation.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,169 @@
 | 
				
			|||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * A simple sensing task that identifies the orientation of the device's screen
 | 
				
			||||||
 | 
					 * and reports the accelerometer's values whenever the screen faces:
 | 
				
			||||||
 | 
					 * - TOP
 | 
				
			||||||
 | 
					 * - BOTTOM
 | 
				
			||||||
 | 
					 * - LEFT
 | 
				
			||||||
 | 
					 * - RIGHT
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.*;
 | 
				
			||||||
 | 
					import java.io.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import android.content.Context;
 | 
				
			||||||
 | 
					import android.hardware.*;
 | 
				
			||||||
 | 
					import android.util.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class DemoOrientation implements SensorEventListener {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private static Context context;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private static int state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						List<Object> data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private static SensorManager sensorManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Save the last measurement outcome (do not report multiple TOPs).
 | 
				
			||||||
 | 
						private static String face;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public void onStart(Context c, ObjectInputStream s) throws Exception {
 | 
				
			||||||
 | 
							String TAG =  getClass().getName() + "@onStart: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							context = c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Save a counter to debug the overall functionality of the framework.
 | 
				
			||||||
 | 
							if (s != null) {
 | 
				
			||||||
 | 
								state = (Integer) s.readObject();
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								state = 1;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							data = new ArrayList<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Monitor the accelerometer of the device.
 | 
				
			||||||
 | 
							sensorManager = (SensorManager) context.getSystemService(context.SENSOR_SERVICE);
 | 
				
			||||||
 | 
							Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
 | 
				
			||||||
 | 
							sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public boolean saveState(ObjectOutputStream s) throws Exception {
 | 
				
			||||||
 | 
							String TAG =  getClass().getName() + "@saveState: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							s.writeObject(state);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public List<Object> getData() {
 | 
				
			||||||
 | 
							String TAG =  getClass().getName() + "@getData: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							List<Object> l = data;
 | 
				
			||||||
 | 
							data = new ArrayList<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return l;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public void onStop() {
 | 
				
			||||||
 | 
							String TAG =  getClass().getName() + "@onStop: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							sensorManager.unregisterListener(this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Override
 | 
				
			||||||
 | 
						public void onAccuracyChanged(Sensor arg0, int arg1) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Called when sensor values have changed.
 | 
				
			||||||
 | 
						@Override
 | 
				
			||||||
 | 
						public void onSensorChanged(SensorEvent event) {
 | 
				
			||||||
 | 
							String TAG =  getClass().getName() + "@onSensorChanged: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
 | 
				
			||||||
 | 
								float x = event.values[0];
 | 
				
			||||||
 | 
								float y = event.values[1];
 | 
				
			||||||
 | 
								float z = event.values[2];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Map<String, Object> newData = new HashMap<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								double[] values = new double[3];
 | 
				
			||||||
 | 
								values[0] = (double) event.values[0];
 | 
				
			||||||
 | 
								values[1] = (double) event.values[1];
 | 
				
			||||||
 | 
								values[2] = (double) event.values[2];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								newData.put("sensor", event.sensor.getType());
 | 
				
			||||||
 | 
								// newData.put("timestamp", event.timestamp);
 | 
				
			||||||
 | 
								newData.put("timestamp", System.currentTimeMillis() * 1000000L);
 | 
				
			||||||
 | 
								newData.put("values", values);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// LEFT
 | 
				
			||||||
 | 
								if(x > 9 && y > 0 && y < 1 && z > 0 && z < 1) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if(!"LEFT".equals(face)) {
 | 
				
			||||||
 | 
										Log.wtf(TAG, Integer.toString(state+1) + ". LEFT");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										data.add(newData);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										state++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									face = "LEFT";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// RIGHT
 | 
				
			||||||
 | 
								} else if(x < -9 && y > 0 && y < 1 && z > 0 && z < 1) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if(!"RIGHT".equals(face)) {
 | 
				
			||||||
 | 
										Log.wtf(TAG, Integer.toString(state+1) + ". RIGHT");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										data.add(newData);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										state++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									face = "RIGHT";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// UP
 | 
				
			||||||
 | 
								} else if(z > 9.5) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if(!"UP".equals(face)) {
 | 
				
			||||||
 | 
										Log.wtf(TAG, Integer.toString(state+1) + ". UP");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										data.add(newData);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										state++;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									face = "UP";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// DOWN
 | 
				
			||||||
 | 
								} else if(z < -9.5) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if(!"DOWN".equals(face)) {
 | 
				
			||||||
 | 
										Log.wtf(TAG, Integer.toString(state+1) + ". DOWN");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										data.add(newData);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										state++;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									face = "DOWN";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										119
									
								
								Sensing/DemoTest.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										119
									
								
								Sensing/DemoTest.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,119 @@
 | 
				
			|||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * A dummy sensing task that logs the values of the accelerometer sensor of the
 | 
				
			||||||
 | 
					 * device and reports the 100th value.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.*;
 | 
				
			||||||
 | 
					import java.io.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import android.content.Context;
 | 
				
			||||||
 | 
					import android.hardware.*;
 | 
				
			||||||
 | 
					import android.util.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class DemoTest implements SensorEventListener {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private static Context context;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private static int state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						List<Object> data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private static SensorManager sensorManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private static String face;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public void onStart(Context c, ObjectInputStream s) throws Exception {
 | 
				
			||||||
 | 
							String TAG =  getClass().getName() + "@onStart: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							context = c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (s != null) {
 | 
				
			||||||
 | 
								state = (Integer) s.readObject();
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								state = 1;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							data = new ArrayList<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							sensorManager = (SensorManager) context.getSystemService(context.SENSOR_SERVICE);
 | 
				
			||||||
 | 
							Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
 | 
				
			||||||
 | 
							sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public boolean saveState(ObjectOutputStream s) throws Exception {
 | 
				
			||||||
 | 
							String TAG =  getClass().getName() + "@saveState: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							s.writeObject(state);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public List<Object> getData() {
 | 
				
			||||||
 | 
							String TAG =  getClass().getName() + "@getData: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							List<Object> l = data;
 | 
				
			||||||
 | 
							data = new ArrayList<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return l;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public void onStop() {
 | 
				
			||||||
 | 
							String TAG =  getClass().getName() + "@onStop: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							sensorManager.unregisterListener(this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Override
 | 
				
			||||||
 | 
						public void onAccuracyChanged(Sensor arg0, int arg1) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Called when sensor values have changed.
 | 
				
			||||||
 | 
						@Override
 | 
				
			||||||
 | 
						public void onSensorChanged(SensorEvent event) {
 | 
				
			||||||
 | 
							String TAG =  getClass().getName() + "@onSensorChanged: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Log.wtf(TAG, "...");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// We are interested only for the accelerometer values.
 | 
				
			||||||
 | 
							if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Map<String, Object> newData = new HashMap<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								double[] values = new double[3];
 | 
				
			||||||
 | 
								values[0] = (double) event.values[0];
 | 
				
			||||||
 | 
								values[1] = (double) event.values[1];
 | 
				
			||||||
 | 
								values[2] = (double) event.values[2];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// Log only the 100th measurement.
 | 
				
			||||||
 | 
								if (state % 100 == 0) {
 | 
				
			||||||
 | 
									Log.wtf(TAG, Integer.toString(state) + ". DATA");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									newData.put("sensor", event.sensor.getType());
 | 
				
			||||||
 | 
									// newData.put("timestamp", event.timestamp);
 | 
				
			||||||
 | 
									newData.put("timestamp", System.currentTimeMillis() * 1000000L);
 | 
				
			||||||
 | 
									newData.put("values", values);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									data.add(newData);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								state++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user