From 69e968b64cd67f9a51ae3f5fe950fcf8e4021994 Mon Sep 17 00:00:00 2001 From: nlathia Date: Wed, 1 Jul 2015 15:33:34 +0100 Subject: [PATCH] Add sensor type to pull thread --- .../emotionsense/demo/data/MainActivity.java | 43 ++++++++----------- .../demo/data/SenseOnceThread.java | 5 ++- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/com/emotionsense/demo/data/MainActivity.java b/src/com/emotionsense/demo/data/MainActivity.java index 4d3d483..a4722a0 100644 --- a/src/com/emotionsense/demo/data/MainActivity.java +++ b/src/com/emotionsense/demo/data/MainActivity.java @@ -21,9 +21,11 @@ public class MainActivity extends Activity private AbstractDataLogger logger; private ESSensorManager sensorManager; - private SubscribeThread[] subscribeThread; + private SubscribeThread[] subscribeThreads; + private SenseOnceThread[] pullThreads; - private final int[] pullSensors = { }; + private final int[] pushSensors = {}; + private final int[] pullSensors = {}; @Override protected void onCreate(Bundle savedInstanceState) @@ -37,8 +39,19 @@ protected void onCreate(Bundle savedInstanceState) sensorManager = ESSensorManager.getSensorManager(this); // Use this thread to collect a single sample of pull sensor data - SenseOnceThread sensingThread = new SenseOnceThread(this, sensorManager, logger); - sensingThread.start(); + pullThreads = new SenseOnceThread[pullSensors.length]; + for (int i = 0; i < pullSensors.length; i++) + { + pullThreads[i] = new SenseOnceThread(this, sensorManager, logger, pullSensors[i]); + pullThreads[i].start(); + } + + subscribeThreads = new SubscribeThread[pushSensors.length]; + for (int i = 0; i < pushSensors.length; i++) + { + subscribeThreads[i] = new SubscribeThread(this, sensorManager, logger, pushSensors[i]); + subscribeThreads[i].start(); + } } catch (Exception e) { @@ -48,28 +61,6 @@ protected void onCreate(Bundle savedInstanceState) } } - @Override - protected void onDestroy() - { - super.onDestroy(); - for (SubscribeThread thread : subscribeThread) - { - thread.stopSensing(); - } - } - - @Override - protected void onResume() - { - super.onResume(); - subscribeThread = new SubscribeThread[pullSensors.length]; - for (int i = 0; i < pullSensors.length; i++) - { - subscribeThread[i] = new SubscribeThread(this, sensorManager, logger, pullSensors[i]); - subscribeThread[i].start(); - } - } - public void onSearchClicked(final View view) { try diff --git a/src/com/emotionsense/demo/data/SenseOnceThread.java b/src/com/emotionsense/demo/data/SenseOnceThread.java index 832843f..5400484 100644 --- a/src/com/emotionsense/demo/data/SenseOnceThread.java +++ b/src/com/emotionsense/demo/data/SenseOnceThread.java @@ -12,16 +12,17 @@ public class SenseOnceThread extends Thread { - private final int sensorType = SensorUtils.SENSOR_TYPE_STEP_COUNTER; + private final int sensorType; private final Activity resultScreen; private final ESSensorManager sensorManager; private final AbstractDataLogger logger; - public SenseOnceThread(final Activity resultScreen, final ESSensorManager sensorManager, AbstractDataLogger logger) + public SenseOnceThread(final Activity resultScreen, final ESSensorManager sensorManager, AbstractDataLogger logger, int sensorType) { this.resultScreen = resultScreen; this.sensorManager = sensorManager; this.logger = logger; + this.sensorType = sensorType; } private void toast(final String message)