Skip to content

armgit / haven

Public Imported from GitHub
0

Haven is for people who need a way to protect their personal spaces and possessions without compromising their own privacy, through an Android app and on-device sensors

Added alert label in accelerometer fragment. Changed accelerometer threshold.

Luca Bonatoc256b10dc7b8
diff --git a/res/layout/accelerometer_fragment.xml b/res/layout/accelerometer_fragment.xml
index f25e4ee..ec5efc7 100644
--- a/res/layout/accelerometer_fragment.xml
+++ b/res/layout/accelerometer_fragment.xml
@@ -4,34 +4,44 @@
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
-
- <TextView
+
+ <TextView
android:id="@+id/accelerometer_text"
android:layout_centerHorizontal="true"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="SHAKE DETECTED"
+ android:textColor="#FFFFFF"
+ android:textSize="22dp"
+ android:textStyle="bold"
+ android:typeface="sans"
+ android:background="#820600"
+ android:layout_marginTop="10dp"
+ android:gravity="center"
+ android:paddingTop="2dp"
+ android:paddingBottom="2dp"
/>
-
- <TextView
+
+ <TextView
android:id="@+id/magnetic_field_text"
android:layout_below="@id/accelerometer_text"
android:layout_centerHorizontal="true"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
/>
-
- <TextView
+
+ <TextView
android:id="@+id/orientation_text"
android:layout_below="@id/magnetic_field_text"
android:layout_centerHorizontal="true"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
/>
-
- <FrameLayout android:id="@+id/opengl"
- android:layout_below="@id/orientation_text"
- android:layout_centerHorizontal="true"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- </FrameLayout>
-</RelativeLayout>
\ No newline at end of file
+
+ <FrameLayout android:id="@+id/opengl"
+ android:layout_below="@id/orientation_text"
+ android:layout_centerHorizontal="true"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+ </FrameLayout>
+</RelativeLayout>
diff --git a/src/me/ziccard/secureit/fragment/AccelerometerFragment.java b/src/me/ziccard/secureit/fragment/AccelerometerFragment.java
index cddf14c..9e74668 100644
--- a/src/me/ziccard/secureit/fragment/AccelerometerFragment.java
+++ b/src/me/ziccard/secureit/fragment/AccelerometerFragment.java
@@ -64,12 +64,15 @@ public class AccelerometerFragment extends Fragment implements SensorEventListen
/**
* Shake threshold
*/
- private static int SHAKE_THRESHOLD = 3000;
+ private static int SHAKE_THRESHOLD = 2300;
/**
* Text showing accelerometer values
*/
private TextView accelerometerText;
+ private int maxAlertPeriod = 30;
+ private int remainingAlertPeriod = 0;
+ private boolean alert = false;
public void onAccuracyChanged(Sensor sensor, int accuracy) {
@@ -86,8 +89,13 @@ public class AccelerometerFragment extends Fragment implements SensorEventListen
lastUpdate = curTime;
accel_values = event.values.clone();
-
- accelerometerText.setText("X: "+accel_values[0]+", Y: "+accel_values[1]+" Z: "+accel_values[2]);
+
+ if (alert && remainingAlertPeriod > 0) {
+ remainingAlertPeriod = remainingAlertPeriod - 1;
+ } else {
+ accelerometerText.setVisibility(View.INVISIBLE);
+ alert = false;
+ }
view.renderer.setPosition(-accel_values[0], accel_values[1], accel_values[2]);
@@ -100,11 +108,18 @@ public class AccelerometerFragment extends Fragment implements SensorEventListen
/*
* Send Alert
*/
+
+ alert = true;
+ remainingAlertPeriod = maxAlertPeriod;
+ accelerometerText.setVisibility(View.VISIBLE);
+
Message message = new Message();
message.what = BluetoothService.ACCELEROMETER_MESSAGE;
try {
+ if (serviceMessenger != null) {
serviceMessenger.send(message);
+ }
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -133,14 +148,14 @@ public class AccelerometerFragment extends Fragment implements SensorEventListen
* Set sensitivity value
*/
if (prefs.getAccelerometerSensitivity().equals("Medium")) {
- SHAKE_THRESHOLD = 4000;
- Log.i("AccelerometerFragment", "Sensitivity set to 4000");
+ SHAKE_THRESHOLD = 2700;
+ Log.i("AccelerometerFragment", "Sensitivity set to 2700");
} else if (prefs.getAccelerometerSensitivity().equals("Low")) {
- SHAKE_THRESHOLD = 5000;
- Log.i("AccelerometerFragment", "Sensitivity set to 5000");
+ SHAKE_THRESHOLD = 3100;
+ Log.i("AccelerometerFragment", "Sensitivity set to 3100");
} else {
- SHAKE_THRESHOLD = 3000;
- Log.i("AccelerometerFragment", "Sensitivity set to 3000");
+ SHAKE_THRESHOLD = 2300;
+ Log.i("AccelerometerFragment", "Sensitivity set to 2300");
}
getActivity().bindService(new Intent(getActivity(),