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
improve layout and UX of Setting screen (part 1)
n8fr8ae64ba006768
diff --git a/src/main/java/info/guardianproject/phoneypot/PreferenceManager.java b/src/main/java/info/guardianproject/phoneypot/PreferenceManager.javaindex d41b54c..e3b48c8 100644--- a/src/main/java/info/guardianproject/phoneypot/PreferenceManager.java+++ b/src/main/java/info/guardianproject/phoneypot/PreferenceManager.java@@ -104,7 +104,7 @@ public class PreferenceManager {}public String getAccelerometerSensitivity() {- return appSharedPrefs.getString(ACCELEROMETER_SENSITIVITY, "");+ return appSharedPrefs.getString(ACCELEROMETER_SENSITIVITY, MEDIUM);}public void activateCamera(boolean active) {@@ -131,7 +131,7 @@ public class PreferenceManager {}public String getCameraSensitivity() {- return appSharedPrefs.getString(CAMERA_SENSITIVITY, "");+ return appSharedPrefs.getString(CAMERA_SENSITIVITY, MEDIUM);}public void activateFlash(boolean active) {@@ -158,7 +158,7 @@ public class PreferenceManager {}public String getMicrophoneSensitivity() {- return appSharedPrefs.getString(MICROPHONE_SENSITIVITY, "");+ return appSharedPrefs.getString(MICROPHONE_SENSITIVITY, MEDIUM);}public void activateSms(boolean active) {@@ -265,6 +265,6 @@ public class PreferenceManager {public int getAudioLength (){- return 10000; //30 seconds+ return 15000; //30 seconds}}diff --git a/src/main/java/info/guardianproject/phoneypot/SettingsActivity.java b/src/main/java/info/guardianproject/phoneypot/SettingsActivity.javaindex c988f3d..733e1d8 100644--- a/src/main/java/info/guardianproject/phoneypot/SettingsActivity.java+++ b/src/main/java/info/guardianproject/phoneypot/SettingsActivity.java@@ -24,10 +24,13 @@ import android.text.TextUtils;import android.util.Log;import android.view.Menu;import android.view.MenuItem;+import android.view.View;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.EditText;import android.widget.CompoundButton.OnCheckedChangeListener;+import android.widget.NumberPicker;+import android.widget.RadioButton;import android.widget.Spinner;import org.w3c.dom.Text;@@ -48,6 +51,8 @@ public class SettingsActivity extends AppCompatActivity {Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);setSupportActionBar(toolbar);+ setTitle("PhoneyPot Settings");+preferences = new PreferenceManager(this.getApplicationContext());/*@@ -62,40 +67,14 @@ public class SettingsActivity extends AppCompatActivity {final CheckBox smsCheck = (CheckBox) this.findViewById(R.id.sms_check);final CheckBox remoteAccessCheck = (CheckBox) this.findViewById(R.id.remote_access_check);- /*- * Detecting if the device has a front camera- * and configuring the spinner of camera selection- * properly- */- final Spinner selectCameraSpinner = (Spinner) this.findViewById(R.id.camera_spinner);- PackageManager pm = getPackageManager();- boolean frontCam;-- frontCam = pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT);- if (!frontCam) {- selectCameraSpinner.setEnabled(false);- }-- /*- * Detecting if the device has the flash- * and configuring properly the check box- */-- final Spinner accelerometerSensitivity = (Spinner)- this.findViewById(R.id.accelerometer_sensitivity_spinner);- final Spinner cameraSensitivity = (Spinner)- this.findViewById(R.id.camera_sensitivity_spinner);- final Spinner microphoneSensitivity = (Spinner)- this.findViewById(R.id.microphone_sensitivity_spinner);-final EditText phoneNumber = (EditText)this.findViewById(R.id.phone_number);final EditText remoteAccessOnion = (EditText)this.findViewById(R.id.remote_access_onion);- final EditText timerDelay = (EditText)+ final NumberPicker timerDelay = (NumberPicker)this.findViewById(R.id.timer_delay);smsCheck.setOnCheckedChangeListener(new OnCheckedChangeListener() {@@ -116,54 +95,19 @@ public class SettingsActivity extends AppCompatActivity {}});- /**- * Loads preferences and sets view- */- if (preferences.getAccelerometerActivation()) {- String sensitivity = preferences.getAccelerometerSensitivity();- if (sensitivity.equals(PreferenceManager.LOW))- accelerometerSensitivity.setSelection(0);- else if (sensitivity.equals(PreferenceManager.MEDIUM))- accelerometerSensitivity.setSelection(1);- else if (sensitivity.equals(PreferenceManager.HIGH))- accelerometerSensitivity.setSelection(2);- else if (sensitivity.equals(PreferenceManager.OFF))- accelerometerSensitivity.setSelection(3);- }if (preferences.getCameraActivation()) {- String sensitivity = preferences.getCameraSensitivity();- if (sensitivity.equals(PreferenceManager.LOW))- cameraSensitivity.setSelection(0);- else if (sensitivity.equals(PreferenceManager.MEDIUM))- cameraSensitivity.setSelection(1);- else if (sensitivity.equals(PreferenceManager.HIGH))- cameraSensitivity.setSelection(2);- else if (sensitivity.equals(PreferenceManager.OFF))- cameraSensitivity.setSelection(3);String camera = preferences.getCamera();if (camera.equals(PreferenceManager.FRONT))- selectCameraSpinner.setSelection(0);+ ((RadioButton)findViewById(R.id.radio_camera_front)).setChecked(true);else if (camera.equals(PreferenceManager.BACK))- selectCameraSpinner.setSelection(1);+ ((RadioButton)findViewById(R.id.radio_camera_back)).setChecked(true);else if (camera.equals(PreferenceManager.OFF))- selectCameraSpinner.setSelection(2);+ ((RadioButton)findViewById(R.id.radio_camera_none)).setChecked(true);}- if (preferences.getMicrophoneActivation()) {- String sensitivity = preferences.getMicrophoneSensitivity();- if (sensitivity.equals(PreferenceManager.LOW))- microphoneSensitivity.setSelection(0);- else if (sensitivity.equals(PreferenceManager.MEDIUM))- microphoneSensitivity.setSelection(1);- else if (sensitivity.equals(PreferenceManager.HIGH))- microphoneSensitivity.setSelection(2);- else if (sensitivity.equals(PreferenceManager.OFF))- microphoneSensitivity.setSelection(3);- }-if (preferences.getSmsActivation()) {smsCheck.setChecked(true);phoneNumber.setText(preferences.getSmsNumber());@@ -176,7 +120,9 @@ public class SettingsActivity extends AppCompatActivity {}- timerDelay.setText(preferences.getTimerDelay()+"");+ timerDelay.setMaxValue(600);+ timerDelay.setMinValue(0);+ timerDelay.setValue(preferences.getTimerDelay());askForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, 1);@@ -220,37 +166,22 @@ public class SettingsActivity extends AppCompatActivity {private void save (){- Spinner accelerometerSensitivity = (Spinner)- this.findViewById(R.id.accelerometer_sensitivity_spinner);- Spinner cameraSensitivity = (Spinner)- this.findViewById(R.id.camera_sensitivity_spinner);- Spinner microphoneSensitivity = (Spinner)- this.findViewById(R.id.microphone_sensitivity_spinner);EditText phoneNumber = (EditText)this.findViewById(R.id.phone_number);- EditText timerDelay = (EditText)+ NumberPicker timerDelay = (NumberPicker)this.findViewById(R.id.timer_delay);- Spinner selectCameraSpinner = (Spinner) this.findViewById(R.id.camera_spinner);CheckBox smsCheck = (CheckBox) this.findViewById(R.id.sms_check);CheckBox remoteAccessCheck = (CheckBox) this.findViewById(R.id.remote_access_check);preferences.activateAccelerometer(true);- preferences.setAccelerometerSensitivity(- (String)accelerometerSensitivity.getSelectedItem());preferences.activateCamera(true);- preferences.setCamera(- (String)selectCameraSpinner.getSelectedItem());- preferences.setCameraSensitivity(- (String)cameraSensitivity.getSelectedItem());preferences.activateMicrophone(true);- preferences.setMicrophoneSensitivity(- (String)microphoneSensitivity.getSelectedItem());if (smsCheck.isChecked() && !phoneNumber.getText().toString().equals("")) {Log.i("StartActivity", "Send message alert is active");@@ -263,7 +194,7 @@ public class SettingsActivity extends AppCompatActivity {preferences.activateRemoteAccess(remoteAccessCheck.isChecked());- preferences.setTimerDelay(Integer.parseInt(timerDelay.getText().toString()));+ preferences.setTimerDelay(timerDelay.getValue());setResult(RESULT_OK);@@ -315,5 +246,27 @@ public class SettingsActivity extends AppCompatActivity {}}+ public void onRadioButtonClicked(View view) {+ // Is the button now checked?+ boolean checked = ((RadioButton) view).isChecked();++ // Check which radio button was clicked+ switch(view.getId()) {+ case R.id.radio_camera_back:+ if (checked)+ preferences.setCamera(PreferenceManager.BACK);+ break;+ case R.id.radio_camera_front:+ if (checked)+ preferences.setCamera(PreferenceManager.FRONT);+ break;+ case R.id.radio_camera_none:+ if (checked)+ preferences.setCamera(PreferenceManager.OFF);+ break;++ }+ }+}diff --git a/src/main/java/info/guardianproject/phoneypot/sensors/motion/Preview.java b/src/main/java/info/guardianproject/phoneypot/sensors/motion/Preview.javaindex 498e871..252c2d0 100644--- a/src/main/java/info/guardianproject/phoneypot/sensors/motion/Preview.java+++ b/src/main/java/info/guardianproject/phoneypot/sensors/motion/Preview.java@@ -179,6 +179,10 @@ public class Preview extends SurfaceView implements SurfaceHolder.Callback {camera = Camera.open();cameraFacing = Camera.CameraInfo.CAMERA_FACING_BACK;}+ else+ {+ camera = null;+ }if (camera != null) {final Camera.Parameters parameters = camera.getParameters();diff --git a/src/main/res/layout/activity_settings.xml b/src/main/res/layout/activity_settings.xmlindex c9cbaba..ee157c0 100644--- a/src/main/res/layout/activity_settings.xml+++ b/src/main/res/layout/activity_settings.xml@@ -12,124 +12,125 @@android:background="?attr/colorPrimary"android:theme="@style/AppTheme.AppBarOverlay"/>app:popupTheme="@style/AppTheme.PopupOverlay" />-+<ScrollView+ android:layout_width="match_parent"+ android:layout_height="match_parent"><LinearLayoutandroid:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"android:padding="6sp">-- <TextView+ <TextView+ android:id="@+id/camera_prompt"+ android:text="@string/camera_prompt"+ android:layout_alignParentLeft="true"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:paddingTop="10dp"+ />+ <!--+ <Spinner+ android:id="@+id/camera_spinner"+ android:layout_alignParentRight="true"+ android:prompt="@string/camera_prompt"+ android:entries="@array/select_camera"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:layout_centerHorizontal="true"+ />-->+ <RadioGroup+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:orientation="horizontal">+ <RadioButton android:id="@+id/radio_camera_front"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:text="@string/camera_front"+ android:onClick="onRadioButtonClicked"+ android:layout_margin="6dp"+ />+ <RadioButton android:id="@+id/radio_camera_back"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:text="@string/camera_back"+ android:onClick="onRadioButtonClicked"+ android:layout_margin="6dp"+ />+ <RadioButton android:id="@+id/radio_camera_none"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:text="@string/camera_none"+ android:onClick="onRadioButtonClicked"+ android:layout_margin="6dp"/>+ </RadioGroup>++ <LinearLayout+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:orientation="horizontal"+ android:paddingTop="10dp"++ >++ <TextViewandroid:id="@+id/accelerometer_prompt"android:text="@string/accelerometer_prompt"android:layout_alignParentLeft="true"- android:layout_width="wrap_content"+ android:layout_width="200dp"android:layout_height="wrap_content"- android:paddingTop="10dp"/>+ <Button+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:text="@string/action_configure"+ />+</LinearLayout>- <Spinner- android:id="@+id/accelerometer_sensitivity_spinner"+ <LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"- android:layout_alignParentRight="true"- android:layout_centerHorizontal="true"- android:entries="@array/select_sensitivity"- android:prompt="@string/accelerometer_prompt" />+ android:orientation="horizontal"+ android:paddingTop="10dp"- <TextView- android:id="@+id/camera_prompt"- android:text="@string/camera_prompt"- android:layout_alignParentLeft="true"- android:layout_width="wrap_content"- android:layout_height="wrap_content"- android:paddingTop="10dp"- />- <Spinner- android:id="@+id/camera_spinner"- android:layout_alignParentRight="true"- android:prompt="@string/camera_prompt"- android:entries="@array/select_camera"- android:layout_width="wrap_content"- android:layout_height="wrap_content"- android:layout_centerHorizontal="true"- />- <TextView- android:id="@+id/camera_sensitivity_prompt"- android:text="@string/camera_sensitivity"- android:layout_alignParentLeft="true"- android:layout_width="wrap_content"- android:layout_height="wrap_content"- android:paddingTop="10dp"- android:layout_below="@id/camera_prompt"- />- <Spinner- android:id="@+id/camera_sensitivity_spinner"- android:layout_alignParentRight="true"- android:layout_below="@id/camera_sensitivity_prompt"- android:prompt="@string/accelerometer_prompt"- android:entries="@array/select_sensitivity"- android:layout_width="wrap_content"- android:layout_height="wrap_content"- android:layout_centerHorizontal="true"- />-- <TextView+ >+++ <TextViewandroid:id="@+id/microphone_prompt"android:text="@string/microphone_sensitivity"android:layout_alignParentLeft="true"- android:layout_width="wrap_content"+ android:layout_width="200dp"android:layout_height="wrap_content"- android:paddingTop="10dp"/>- <Spinner- android:id="@+id/microphone_sensitivity_spinner"- android:layout_alignParentRight="true"- android:prompt="@string/microphone_sensitivity"- android:entries="@array/select_sensitivity"- android:layout_width="wrap_content"- android:layout_height="wrap_content"- android:layout_centerHorizontal="true"- />-+ <Button+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:text="@string/action_configure"+ />+</LinearLayout>- <CheckBox- android:id="@+id/sms_check"- android:text="@string/sms_label"- android:layout_width="wrap_content"- android:layout_height="wrap_content"- android:layout_centerHorizontal="true"- tools:context=".SettingsActivity" />- <EditText- android:id="@+id/phone_number"- android:hint="@string/sms_hint"- android:inputType="phone"- android:layout_centerHorizontal="true"- android:layout_width="fill_parent"- android:layout_height="wrap_content"- android:paddingTop="10dp"- />+ <LinearLayout+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:orientation="horizontal"+ ><TextViewandroid:id="@+id/timer_label"android:text="@string/timer_delay_label"- android:layout_alignParentLeft="true"- android:layout_width="wrap_content"+ android:layout_width="200dp"android:layout_height="wrap_content"- android:paddingTop="10dp"/>- <EditText+ <NumberPickerandroid:id="@+id/timer_delay"- android:inputType="numberDecimal"- android:layout_centerHorizontal="true"- android:layout_width="fill_parent"+ android:layout_width="wrap_content"android:layout_height="wrap_content"- android:paddingTop="10dp"/>+ </LinearLayout><CheckBoxandroid:id="@+id/remote_access_check"android:text="@string/remote_access_label"@@ -144,6 +145,23 @@android:layout_height="wrap_content"android:layout_centerHorizontal="true"tools:context=".SettingsActivity" />+ <CheckBox+ android:id="@+id/sms_check"+ android:text="@string/sms_label"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:layout_centerHorizontal="true"+ tools:context=".SettingsActivity" />+ <EditText+ android:id="@+id/phone_number"+ android:hint="@string/sms_hint"+ android:inputType="phone"+ android:layout_centerHorizontal="true"+ android:layout_width="fill_parent"+ android:layout_height="wrap_content"+ android:paddingTop="10dp"+ /></LinearLayout>+ </ScrollView></LinearLayout>\ No newline at end of filediff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xmlindex a8ec66e..a581c98 100644--- a/src/main/res/values/strings.xml+++ b/src/main/res/values/strings.xml@@ -10,15 +10,15 @@<string name="title_activity_start">PhoneyPot</string><string name="accelerometer_prompt">- Set movement & vibration sensitivity+ Movement Sensitivity</string><string name="microphone_sensitivity">- Set microphone sensitivity+ Sound Sensitivity</string><string name="camera_sensitivity">- Set camera motion sensitivity+ Camera Motion sensitivity</string><string name="timer_delay_label">@@ -30,7 +30,7 @@</string><string name="camera_label">- Use the camera to detect motion+ Select Camera</string><string name="flash_label">@@ -38,7 +38,7 @@</string><string name="sms_label">- Send an SMS as alert+ Send an SMS alert when detection occurs</string><string name="sms_hint">@@ -98,4 +98,10 @@<string name="remote_access_label">Enable remote access via Tor Onion Service</string><string name="remote_access_hint">(onion service address will be displayed here)</string>++ <string name="camera_front">Front</string>+ <string name="camera_back">Back</string>+ <string name="camera_none">None</string>++ <string name="action_configure">Configure</string></resources>\ No newline at end of file