diff --git a/src/main/java/org/havenapp/main/SettingsFragment.java b/src/main/java/org/havenapp/main/SettingsFragment.java index fe65600b..7a539990 100644 --- a/src/main/java/org/havenapp/main/SettingsFragment.java +++ b/src/main/java/org/havenapp/main/SettingsFragment.java @@ -19,10 +19,7 @@ import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceFragmentCompat; import android.support.v7.preference.SwitchPreferenceCompat; -import android.telephony.SmsManager; import android.text.TextUtils; -import android.view.Menu; -import android.view.MenuInflater; import android.view.MenuItem; import android.widget.Toast; @@ -34,8 +31,6 @@ import org.havenapp.main.ui.MicrophoneConfigureActivity; import java.io.File; -import java.util.ArrayList; -import java.util.StringTokenizer; import info.guardianproject.netcipher.proxy.OrbotHelper; @@ -228,75 +223,87 @@ public void onPause() { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - if (PreferenceManager.CAMERA.equals(key)) { - switch (Integer.parseInt(((ListPreference) findPreference(PreferenceManager.CAMERA)).getValue())) { - case 0: - preferences.setCamera(PreferenceManager.FRONT); - findPreference(PreferenceManager.CAMERA).setSummary(PreferenceManager.FRONT); - break; - case 1: - preferences.setCamera(PreferenceManager.BACK); - findPreference(PreferenceManager.CAMERA).setSummary(PreferenceManager.BACK); - break; - case 2: - preferences.setCamera(PreferenceManager.NONE); - findPreference(PreferenceManager.CAMERA).setSummary(PreferenceManager.NONE); - break; + switch (key) { + case PreferenceManager.CAMERA: + switch (Integer.parseInt(((ListPreference) findPreference(PreferenceManager.CAMERA)).getValue())) { + case 0: + preferences.setCamera(PreferenceManager.FRONT); + findPreference(PreferenceManager.CAMERA).setSummary(PreferenceManager.FRONT); + break; + case 1: + preferences.setCamera(PreferenceManager.BACK); + findPreference(PreferenceManager.CAMERA).setSummary(PreferenceManager.BACK); + break; + case 2: + preferences.setCamera(PreferenceManager.NONE); + findPreference(PreferenceManager.CAMERA).setSummary(PreferenceManager.NONE); + break; - } - } else if (PreferenceManager.SMS_ACTIVE.equals(key)) { - - setPhoneNumber(); - } else if (PreferenceManager.REMOTE_ACCESS_ACTIVE.equals(key)) { - boolean remoteAccessActive = ((SwitchPreferenceCompat) findPreference(PreferenceManager.REMOTE_ACCESS_ACTIVE)).isChecked(); - if (remoteAccessActive) { - checkRemoteAccessOnion(); - app.startServer(); - } else { - app.stopServer(); - } - } else if (PreferenceManager.REGISTER_SIGNAL.equals(key)) { - String signalNum = ((EditTextPreference) findPreference(PreferenceManager.REGISTER_SIGNAL)).getText(); + } + break; + case PreferenceManager.SMS_ACTIVE: - if (checkValidString(signalNum)) { - signalNum = "+" + signalNum.trim().replaceAll("[^0-9]", ""); + setPhoneNumber(); + break; + case PreferenceManager.REMOTE_ACCESS_ACTIVE: + boolean remoteAccessActive = ((SwitchPreferenceCompat) findPreference(PreferenceManager.REMOTE_ACCESS_ACTIVE)).isChecked(); + if (remoteAccessActive) { + checkRemoteAccessOnion(); + app.startServer(); + } else { + app.stopServer(); + } + break; + case PreferenceManager.REGISTER_SIGNAL: + String signalNum = ((EditTextPreference) findPreference(PreferenceManager.REGISTER_SIGNAL)).getText(); - preferences.setSignalUsername(signalNum); - findPreference(PreferenceManager.REGISTER_SIGNAL).setSummary(signalNum); + if (checkValidString(signalNum)) { + signalNum = "+" + signalNum.trim().replaceAll("[^0-9]", ""); - resetSignal(preferences.getSignalUsername()); - activateSignal(preferences.getSignalUsername(), null); - } else { - preferences.setSignalUsername(""); - findPreference(PreferenceManager.REGISTER_SIGNAL).setSummary(R.string.register_signal_desc); - } - } else if (PreferenceManager.VERIFY_SIGNAL.equals(key)) { - String text = ((EditTextPreference) findPreference(PreferenceManager.VERIFY_SIGNAL)).getText(); - activateSignal(preferences.getSignalUsername(), text); - } else if (PreferenceManager.SMS_NUMBER.equals(key)) { - boolean smsActive = ((SwitchPreferenceCompat) findPreference(PreferenceManager.SMS_ACTIVE)).isChecked(); - if (smsActive && TextUtils.isEmpty(preferences.getSignalUsername())) { - askForPermission(Manifest.permission.SEND_SMS, 6); - askForPermission(Manifest.permission.READ_PHONE_STATE, 6); + preferences.setSignalUsername(signalNum); + findPreference(PreferenceManager.REGISTER_SIGNAL).setSummary(signalNum); + + resetSignal(preferences.getSignalUsername()); + activateSignal(preferences.getSignalUsername(), null); + } else { + preferences.setSignalUsername(""); + findPreference(PreferenceManager.REGISTER_SIGNAL).setSummary(R.string.register_signal_desc); + } + break; + case PreferenceManager.VERIFY_SIGNAL: { + String text = ((EditTextPreference) findPreference(PreferenceManager.VERIFY_SIGNAL)).getText(); + activateSignal(preferences.getSignalUsername(), text); + break; } - setPhoneNumber(); - } else if (PreferenceManager.REMOTE_ACCESS_ONION.equals(key)) { - String text = ((EditTextPreference) findPreference(PreferenceManager.REMOTE_ACCESS_ONION)).getText(); - if (checkValidString(text)) { - preferences.setRemoteAccessOnion(text.trim()); - findPreference(PreferenceManager.REMOTE_ACCESS_ONION).setSummary(preferences.getRemoteAccessOnion().trim() + ":" + WebServer.LOCAL_PORT); - } else { - preferences.setRemoteAccessOnion(text); - findPreference(PreferenceManager.REMOTE_ACCESS_ONION).setSummary(R.string.remote_access_hint); + case PreferenceManager.SMS_NUMBER: + boolean smsActive = ((SwitchPreferenceCompat) findPreference(PreferenceManager.SMS_ACTIVE)).isChecked(); + if (smsActive && TextUtils.isEmpty(preferences.getSignalUsername())) { + askForPermission(Manifest.permission.SEND_SMS, 6); + askForPermission(Manifest.permission.READ_PHONE_STATE, 6); + } + setPhoneNumber(); + break; + case PreferenceManager.REMOTE_ACCESS_ONION: { + String text = ((EditTextPreference) findPreference(PreferenceManager.REMOTE_ACCESS_ONION)).getText(); + if (checkValidString(text)) { + preferences.setRemoteAccessOnion(text.trim()); + findPreference(PreferenceManager.REMOTE_ACCESS_ONION).setSummary(preferences.getRemoteAccessOnion().trim() + ":" + WebServer.LOCAL_PORT); + } else { + preferences.setRemoteAccessOnion(text); + findPreference(PreferenceManager.REMOTE_ACCESS_ONION).setSummary(R.string.remote_access_hint); + } + break; } - } else if (PreferenceManager.REMOTE_ACCESS_CRED.equals(key)) { - String text = ((EditTextPreference) findPreference(PreferenceManager.REMOTE_ACCESS_CRED)).getText(); - if (checkValidString(text)) { - preferences.setRemoteAccessCredential(text.trim()); - findPreference(PreferenceManager.REMOTE_ACCESS_CRED).setSummary(R.string.bullets); - } else { - preferences.setRemoteAccessCredential(text); - findPreference(PreferenceManager.REMOTE_ACCESS_CRED).setSummary(R.string.remote_access_credential_hint); + case PreferenceManager.REMOTE_ACCESS_CRED: { + String text = ((EditTextPreference) findPreference(PreferenceManager.REMOTE_ACCESS_CRED)).getText(); + if (checkValidString(text)) { + preferences.setRemoteAccessCredential(text.trim()); + findPreference(PreferenceManager.REMOTE_ACCESS_CRED).setSummary(R.string.bullets); + } else { + preferences.setRemoteAccessCredential(text); + findPreference(PreferenceManager.REMOTE_ACCESS_CRED).setSummary(R.string.remote_access_credential_hint); + } + break; } } } @@ -400,4 +407,4 @@ public void onTimeSet(TimePickerDialog view, int hourOfDay, int minute, int seco int delaySeconds = second + minute * 60 + hourOfDay * 60 * 60; preferences.setTimerDelay(delaySeconds); } -} \ No newline at end of file +} diff --git a/src/main/java/org/havenapp/main/sensors/MicrophoneMonitor.java b/src/main/java/org/havenapp/main/sensors/MicrophoneMonitor.java index ae023f44..48538b54 100644 --- a/src/main/java/org/havenapp/main/sensors/MicrophoneMonitor.java +++ b/src/main/java/org/havenapp/main/sensors/MicrophoneMonitor.java @@ -77,7 +77,7 @@ public MicrophoneMonitor(Context context) try { //maybe it is a threshold value? mNoiseThreshold = Double.parseDouble(prefs.getMicrophoneSensitivity()); - } catch (Exception e) { + } catch (Exception ignored) { } break; } diff --git a/src/main/java/org/havenapp/main/sensors/media/MicSamplerTask.java b/src/main/java/org/havenapp/main/sensors/media/MicSamplerTask.java index 85e9e6ee..ba01ae9b 100644 --- a/src/main/java/org/havenapp/main/sensors/media/MicSamplerTask.java +++ b/src/main/java/org/havenapp/main/sensors/media/MicSamplerTask.java @@ -10,21 +10,21 @@ package org.havenapp.main.sensors.media; -import java.io.IOException; - import android.os.AsyncTask; import android.util.Log; +import java.io.IOException; + public class MicSamplerTask extends AsyncTask { - + private MicListener listener = null; private AudioCodec volumeMeter = new AudioCodec(); private boolean sampling = true; private boolean paused = false; - - public static interface MicListener { - public void onSignalReceived(short[] signal); - public void onMicError(); + + public interface MicListener { + void onSignalReceived(short[] signal); + void onMicError(); } public void setMicListener(MicListener listener) { diff --git a/src/main/java/org/havenapp/main/service/MonitorService.java b/src/main/java/org/havenapp/main/service/MonitorService.java index 28ab3fa7..f83def5a 100644 --- a/src/main/java/org/havenapp/main/service/MonitorService.java +++ b/src/main/java/org/havenapp/main/service/MonitorService.java @@ -59,21 +59,11 @@ public class MonitorService extends Service { private final static String channelId = "monitor_id"; private final static CharSequence channelName = "Haven notifications"; private final static String channelDescription= "Important messages from Haven"; - - /** - * True only if service has been alerted by the accelerometer - */ - private boolean already_alerted; /** * Object used to retrieve shared preferences */ private PreferenceManager mPrefs = null; - - /** - * Incrementing alert id - */ - private int mNotificationAlertId = 7007; /** * Sensor Monitors diff --git a/src/main/java/org/havenapp/main/service/WebServer.java b/src/main/java/org/havenapp/main/service/WebServer.java index a1da863a..870edcf5 100644 --- a/src/main/java/org/havenapp/main/service/WebServer.java +++ b/src/main/java/org/havenapp/main/service/WebServer.java @@ -58,7 +58,7 @@ public Response serve(IHTTPSession session) { { // We have to use session.parseBody() to obtain POST data. // See https://github.com/NanoHttpd/nanohttpd/issues/427 - Map content = new HashMap(); + Map content = new HashMap<>(); Method method = session.getMethod(); if (Method.PUT.equals(method) || Method.POST.equals(method)) try { session.parseBody(content); diff --git a/src/main/java/org/havenapp/main/ui/MicrophoneConfigureActivity.java b/src/main/java/org/havenapp/main/ui/MicrophoneConfigureActivity.java index c78661f1..287b7c52 100644 --- a/src/main/java/org/havenapp/main/ui/MicrophoneConfigureActivity.java +++ b/src/main/java/org/havenapp/main/ui/MicrophoneConfigureActivity.java @@ -11,7 +11,6 @@ import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; -import android.view.Menu; import android.view.MenuItem; import android.widget.TextView; @@ -140,15 +139,6 @@ public void clearScreen(Canvas canvas) { canvas.drawColor(Color.WHITE, PorterDuff.Mode.CLEAR); } }; - /** - mWaveform.progressTouch = new SimpleWaveform.ProgressTouch() { - @Override - public void progressTouch(int progress, MotionEvent event) { - Log.d("", "you touch at: " + progress); - mWaveform.firstPartNum = progress; - mWaveform.refresh(); - } - };**/ //show... mWaveform.refresh(); } @@ -248,7 +238,7 @@ public void onSignalReceived(short[] signal) { } mWaveform.refresh(); - mTextLevel.setText(getString(R.string.current_noise_base) + ' ' + ((int)averageDB)+"db"); + mTextLevel.setText(getString(R.string.current_noise_base).concat(" ").concat(Integer.toString((int) averageDB)).concat("db")); } diff --git a/src/main/res/layout/activity_monitor.xml b/src/main/res/layout/activity_monitor.xml index ccb3f83d..4bda4ce5 100644 --- a/src/main/res/layout/activity_monitor.xml +++ b/src/main/res/layout/activity_monitor.xml @@ -42,7 +42,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" - android:textSize="78dp" + android:textSize="78sp" android:text="1:00" android:textStyle="bold" android:textColor="@color/White" @@ -57,7 +57,7 @@ android:background="@drawable/round_drawable_accent" android:id="@+id/btnStartNow" android:layout_margin="10dp" - android:textSize="25dp" + android:textSize="25sp" android:padding="6dp" />