Skip to content

Commit

Permalink
Merge branch 'fat-tire-misc_small_fixes'
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Jan 11, 2018
2 parents 111e9e7 + e21f837 commit 78d6196
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 108 deletions.
145 changes: 76 additions & 69 deletions src/main/java/org/havenapp/main/SettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void,Object,Void> {

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) {
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/org/havenapp/main/service/MonitorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/havenapp/main/service/WebServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> content = new HashMap<String, String>();
Map<String, String> content = new HashMap<>();
Method method = session.getMethod();
if (Method.PUT.equals(method) || Method.POST.equals(method)) try {
session.parseBody(content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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"));

}

Expand Down
4 changes: 2 additions & 2 deletions src/main/res/layout/activity_monitor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
/>
<Button
Expand Down
3 changes: 1 addition & 2 deletions src/main/res/layout/camera_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_height="match_parent">

<FrameLayout android:id="@+id/preview"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:layout_width="1dp"
android:layout_height="1dp">
</FrameLayout>
Expand All @@ -14,7 +14,6 @@
android:id="@+id/new_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/preview"
/>


Expand Down
9 changes: 5 additions & 4 deletions src/main/res/layout/custom_slide_notify.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:background="@color/colorPrimaryDark"
>
android:background="@color/colorPrimaryDark">

<TextView
android:id="@+id/custom_slide_big_text"
Expand All @@ -18,11 +18,12 @@
android:textStyle="bold"
android:textSize="28sp"/>

<EditText
<android.support.v7.widget.AppCompatEditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textColor="@color/White"
android:backgroundTint="@color/colorPrimaryLight"
app:backgroundTint="@color/colorPrimaryLight"
android:hint="@string/sms_hint"
android:gravity="center"
android:inputType="phone"
Expand All @@ -39,7 +40,7 @@
android:layout_marginRight="40dp"

android:textStyle="bold"
android:textSize="16dp"/>
android:textSize="16sp"/>

<Button
android:layout_width="120dp"
Expand Down
4 changes: 3 additions & 1 deletion src/main/res/layout/event_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@
android:gravity="center_vertical"
android:orientation="vertical"
android:visibility="gone"
android:paddingLeft="4dp" />
android:paddingLeft="4dp"
android:paddingRight="4dp" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_margin_half"
android:paddingRight="4dp"
android:paddingLeft="4dp">

<TextView
Expand Down

0 comments on commit 78d6196

Please sign in to comment.