-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nlathia
committed
Jun 8, 2015
0 parents
commit 4fa27bd
Showing
25 changed files
with
1,010 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.DS_Store | ||
|
||
bin/ | ||
|
||
gen/ | ||
|
||
libs/ | ||
|
||
.settings/ | ||
|
||
.classpath | ||
|
||
.project | ||
|
||
proguard-project.txt | ||
|
||
project.properties | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.test" | ||
android:versionCode="1" | ||
android:versionName="1.0" > | ||
|
||
<uses-sdk | ||
android:minSdkVersion="9" | ||
android:targetSdkVersion="25" /> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
|
||
<application | ||
android:name="com.emotionsense.demo.data.DemoApplication" | ||
android:allowBackup="true" | ||
android:icon="@drawable/ic_launcher" | ||
android:label="@string/app_name" | ||
android:theme="@style/AppTheme" > | ||
<activity | ||
android:name="com.emotionsense.demo.data.MainActivity" | ||
android:label="@string/app_name" > | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:paddingBottom="@dimen/activity_vertical_margin" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
tools:context="com.emotionsense.demo.data.MainActivity" > | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/hello_world" /> | ||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
tools:context="com.example.test.MainActivity" > | ||
|
||
<item | ||
android:id="@+id/action_settings" | ||
android:orderInCategory="100" | ||
android:title="@string/action_settings" | ||
app:showAsAction="never"/> | ||
|
||
</menu> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<resources> | ||
|
||
<!-- | ||
Base application theme for API 11+. This theme completely replaces | ||
AppBaseTheme from res/values/styles.xml on API 11+ devices. | ||
--> | ||
<style name="AppBaseTheme" parent="Theme.AppCompat.Light"> | ||
<!-- API 11 theme customizations can go here. --> | ||
</style> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<resources> | ||
|
||
<!-- | ||
Base application theme for API 14+. This theme completely replaces | ||
AppBaseTheme from BOTH res/values/styles.xml and | ||
res/values-v11/styles.xml on API 14+ devices. | ||
--> | ||
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | ||
<!-- API 14 theme customizations can go here. --> | ||
</style> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<resources> | ||
|
||
<!-- | ||
Example customization of dimensions originally defined in res/values/dimens.xml | ||
(such as screen margins) for screens with more than 820dp of available width. This | ||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). | ||
--> | ||
<dimen name="activity_horizontal_margin">64dp</dimen> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<resources> | ||
|
||
<!-- Default screen margins, per the Android Design guidelines. --> | ||
<dimen name="activity_horizontal_margin">16dp</dimen> | ||
<dimen name="activity_vertical_margin">16dp</dimen> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<string name="app_name">test</string> | ||
<string name="hello_world">Hello world!</string> | ||
<string name="action_settings">Settings</string> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<resources> | ||
|
||
<!-- | ||
Base application theme, dependent on API level. This theme is replaced | ||
by AppBaseTheme from res/values-vXX/styles.xml on newer devices. | ||
--> | ||
<style name="AppBaseTheme" parent="Theme.AppCompat.Light"> | ||
<!-- | ||
Theme customizations available in newer API levels can go in | ||
res/values-vXX/styles.xml, while customizations related to | ||
backward-compatibility can go here. | ||
--> | ||
</style> | ||
|
||
<!-- Application theme. --> | ||
<style name="AppTheme" parent="AppBaseTheme"> | ||
<!-- All customizations that are NOT specific to a particular API-level can go here. --> | ||
</style> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.emotionsense.demo.data; | ||
|
||
import android.app.Application; | ||
|
||
public class DemoApplication extends Application | ||
{ | ||
private static DemoApplication instance; | ||
|
||
public DemoApplication() | ||
{ | ||
super(); | ||
instance = this; | ||
} | ||
|
||
public static Application getContext() | ||
{ | ||
return instance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.emotionsense.demo.data; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
|
||
import com.emotionsense.demo.data.loggers.StoreOnlyEncryptedFiles; | ||
import com.example.test.R; | ||
import com.ubhave.datahandler.loggertypes.AbstractDataLogger; | ||
import com.ubhave.sensormanager.ESException; | ||
import com.ubhave.sensormanager.ESSensorManager; | ||
import com.ubhave.sensormanager.SensorDataListener; | ||
import com.ubhave.sensormanager.data.SensorData; | ||
import com.ubhave.sensormanager.sensors.SensorUtils; | ||
|
||
public class MainActivity extends Activity implements SensorDataListener | ||
{ | ||
private final static String LOG_TAG = "MainActivity"; | ||
|
||
private ESSensorManager sensorManager; | ||
private AbstractDataLogger logger; | ||
private int subscriptionId; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) | ||
{ | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
try | ||
{ | ||
logger = StoreOnlyEncryptedFiles.getInstance(); | ||
sensorManager = ESSensorManager.getSensorManager(this); | ||
} | ||
catch (Exception e) | ||
{ | ||
Log.d(LOG_TAG, e.getLocalizedMessage()); | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onPause() | ||
{ | ||
super.onPause(); | ||
try | ||
{ | ||
sensorManager.unsubscribeFromSensorData(subscriptionId); | ||
Log.d(LOG_TAG, "Unsubscribed from proximity sensor subscription: "+subscriptionId); | ||
} | ||
catch (ESException e) | ||
{ | ||
Log.d(LOG_TAG, e.getLocalizedMessage()); | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onResume() | ||
{ | ||
super.onResume(); | ||
try | ||
{ | ||
subscriptionId = sensorManager.subscribeToSensorData(SensorUtils.SENSOR_TYPE_PROXIMITY, this); | ||
Log.d(LOG_TAG, "Subscribed to proximity sensor with id: "+subscriptionId); | ||
} | ||
catch (ESException e) | ||
{ | ||
Log.d(LOG_TAG, e.getLocalizedMessage()); | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onDataSensed(SensorData data) | ||
{ | ||
try | ||
{ | ||
Log.d(LOG_TAG, "Received proximity data."); | ||
logger.logSensorData(data); | ||
} | ||
catch (Exception e) | ||
{ | ||
Log.d(LOG_TAG, e.getLocalizedMessage()); | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onCrossingLowBatteryThreshold(boolean isBelowThreshold) | ||
{} | ||
} |
104 changes: 104 additions & 0 deletions
104
src/com/emotionsense/demo/data/loggers/AsyncEncryptedDatabase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package com.emotionsense.demo.data.loggers; | ||
|
||
import java.util.HashMap; | ||
|
||
import android.content.Context; | ||
|
||
import com.emotionsense.demo.data.DemoApplication; | ||
import com.ubhave.datahandler.config.DataStorageConfig; | ||
import com.ubhave.datahandler.except.DataHandlerException; | ||
import com.ubhave.datahandler.loggertypes.AbstractAsyncTransferLogger; | ||
import com.ubhave.datahandler.loggertypes.AbstractDataLogger; | ||
import com.ubhave.sensormanager.ESException; | ||
|
||
public class AsyncEncryptedDatabase extends AbstractAsyncTransferLogger | ||
{ | ||
private static AsyncEncryptedDatabase instance; | ||
|
||
public static AbstractDataLogger getInstance() throws ESException, DataHandlerException | ||
{ | ||
if (instance == null) | ||
{ | ||
instance = new AsyncEncryptedDatabase(DemoApplication.getContext()); | ||
} | ||
return instance; | ||
} | ||
|
||
protected AsyncEncryptedDatabase(final Context context) throws DataHandlerException, ESException | ||
{ | ||
super(context, DataStorageConfig.STORAGE_TYPE_DB); | ||
} | ||
|
||
@Override | ||
protected String getDataPostURL() | ||
{ | ||
return RemoteServerDetails.FILE_POST_URL; | ||
} | ||
|
||
@Override | ||
protected String getPostKey() | ||
{ | ||
return RemoteServerDetails.DATA_KEY; | ||
} | ||
|
||
@Override | ||
protected String getSuccessfulPostResponse() | ||
{ | ||
return RemoteServerDetails.RESPONSE_ON_SUCCESS; | ||
} | ||
|
||
@Override | ||
protected HashMap<String, String> getPostParameters() | ||
{ | ||
// Note: no additional parameters used in demo. | ||
return null; | ||
} | ||
|
||
@Override | ||
protected long getDataLifeMillis() | ||
{ | ||
// Note: all data that is more than 1 hour old will be transferred | ||
return 1000L * 60 * 60 * 1; | ||
} | ||
|
||
@Override | ||
protected long getTransferAlarmLengthMillis() | ||
{ | ||
// Note: transfer alarm will fire every 2 hours | ||
return 1000L * 60 * 60 * 2; | ||
} | ||
|
||
@Override | ||
protected String getStorageName() | ||
{ | ||
return "Demo-Encrypted-Async-Database"; | ||
} | ||
|
||
@Override | ||
protected String getUniqueUserId() | ||
{ | ||
// Note: this should not be a static string | ||
return "test-user-id"; | ||
} | ||
|
||
@Override | ||
protected String getDeviceId() | ||
{ | ||
// Note: this should not be a static string | ||
return "test-device-id"; | ||
} | ||
|
||
@Override | ||
protected boolean shouldPrintLogMessages() | ||
{ | ||
// Note: return false to turn off Log.d messages | ||
return true; | ||
} | ||
|
||
@Override | ||
protected String getEncryptionPassword() | ||
{ | ||
// Note: return non-null password to encrypt data | ||
return "password"; | ||
} | ||
} |
Oops, something went wrong.