Commit 11873b8a authored by Shannon Stork's avatar Shannon Stork

Allow user to enter ip address and port number

parent f6987c44
......@@ -8,6 +8,10 @@ public interface Constants {
String ACTION_ALARM = "org.briarproject.snooze.ACTION_ALARM";
String EXTRA_IP_ADDRESS = "org.briarproject.snooze.EXTRA_IP_ADDRESS";
String EXTRA_PORT_NUMBER = "org.briarproject.snooze.EXTRA_PORT_NUMBER";
String EXTRA_FOREGROUND_SERVICE = "org.briarproject.snooze.EXTRA_FOREGROUND_SERVICE";
String EXTRA_WAKE_LOCK = "org.briarproject.snooze.EXTRA_WAKE_LOCK";
......
......@@ -10,6 +10,7 @@ import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Spinner;
......@@ -22,6 +23,8 @@ import static org.briarproject.snooze.Constants.ACTION_START;
import static org.briarproject.snooze.Constants.ACTION_STOP;
import static org.briarproject.snooze.Constants.EXTRA_ALARM_INTERVAL_MS;
import static org.briarproject.snooze.Constants.EXTRA_ALARM_TYPE;
import static org.briarproject.snooze.Constants.EXTRA_IP_ADDRESS;
import static org.briarproject.snooze.Constants.EXTRA_PORT_NUMBER;
import static org.briarproject.snooze.Constants.EXTRA_FOREGROUND_SERVICE;
import static org.briarproject.snooze.Constants.EXTRA_KEEPALIVE_BYTES;
import static org.briarproject.snooze.Constants.EXTRA_KEEPALIVE_INTERVAL_MS;
......@@ -122,6 +125,8 @@ public class SettingsFragment extends Fragment {
private void onClickApplySettingsButton() {
View layout = getView();
String ipAddress = ((EditText) layout.findViewById(R.id.ipEntry)).getText().toString();
int portNumber = Integer.parseInt(((EditText) layout.findViewById(R.id.portEntry)).getText().toString());
boolean foreground =
((Switch) layout.findViewById(R.id.foregroundServiceSwitch)).isChecked();
boolean wakeLock = ((Switch) layout.findViewById(R.id.wakeLockSwitch)).isChecked();
......@@ -134,6 +139,8 @@ public class SettingsFragment extends Fragment {
((SeekBar) layout.findViewById(R.id.keepaliveBytesSeekBar)).getProgress() + 1;
Intent i = new Intent(getContext(), SnoozeService.class);
i.setAction(ACTION_START);
i.putExtra(EXTRA_IP_ADDRESS, ipAddress);
i.putExtra(EXTRA_PORT_NUMBER, portNumber);
i.putExtra(EXTRA_FOREGROUND_SERVICE, foreground);
i.putExtra(EXTRA_WAKE_LOCK, wakeLock);
i.putExtra(EXTRA_WIFI_LOCK, wifiLock);
......
......@@ -25,6 +25,8 @@ import static org.briarproject.snooze.Constants.ACTION_START;
import static org.briarproject.snooze.Constants.ACTION_STOP;
import static org.briarproject.snooze.Constants.EXTRA_ALARM_INTERVAL_MS;
import static org.briarproject.snooze.Constants.EXTRA_ALARM_TYPE;
import static org.briarproject.snooze.Constants.EXTRA_IP_ADDRESS;
import static org.briarproject.snooze.Constants.EXTRA_PORT_NUMBER;
import static org.briarproject.snooze.Constants.EXTRA_FOREGROUND_SERVICE;
import static org.briarproject.snooze.Constants.EXTRA_KEEPALIVE_BYTES;
import static org.briarproject.snooze.Constants.EXTRA_KEEPALIVE_INTERVAL_MS;
......@@ -45,6 +47,8 @@ public class SnoozeService extends Service {
private NetworkClient networkClient = null;
private Alarm alarm = null;
private int alarmIntervalMs, keepaliveIntervalMs, keepaliveBytes;
private String host;
private int port;
private volatile Logger log = null;
......@@ -64,6 +68,8 @@ public class SnoozeService extends Service {
@Override
public int onStartCommand(Intent i, int flags, int startId) {
if (ACTION_START.equals(i.getAction())) {
host = i.getStringExtra(EXTRA_IP_ADDRESS);
port = i.getIntExtra(EXTRA_PORT_NUMBER, 9999);
boolean newForeground = i.getBooleanExtra(EXTRA_FOREGROUND_SERVICE, false);
boolean newWakeLock = i.getBooleanExtra(EXTRA_WAKE_LOCK, false);
boolean newWifiLock = i.getBooleanExtra(EXTRA_WIFI_LOCK, false);
......@@ -171,8 +177,6 @@ public class SnoozeService extends Service {
private void startNetworkThread() {
if (networkClient != null) networkClient.closeConnection();
String host = getString(R.string.host);
int port = getResources().getInteger(R.integer.port);
networkClient = new NetworkClient(host, port, keepaliveIntervalMs, keepaliveBytes,
getApplicationContext());
networkClient.start();
......
......@@ -19,132 +19,176 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="6"
android:text="@string/use_ip_address" />
<EditText
android:id="@+id/ipEntry"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="16"
android:max="14" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="6"
android:text="@string/use_port_number" />
<EditText
android:id="@+id/portEntry"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="16"
android:max="14" />
</LinearLayout>
<Switch
android:id="@+id/foregroundServiceSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="@string/use_foreground_service"/>
android:text="@string/use_foreground_service" />
<Switch
android:id="@+id/wakeLockSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="@string/use_permanent_wake_lock"/>
android:text="@string/use_permanent_wake_lock" />
<Switch
android:id="@+id/wifiLockSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="@string/use_wifi_lock"/>
android:text="@string/use_wifi_lock" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:layout_marginBottom="8dp">
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="6"
android:text="@string/alarm_interval"/>
android:text="@string/alarm_interval" />
<SeekBar
android:id="@+id/alarmIntervalSeekBar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="7"
android:max="14"/>
android:max="14" />
<TextView
android:id="@+id/alarmIntervalTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
tools:text="1 min"/>
tools:text="1 min" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:layout_marginBottom="8dp">
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="6"
android:text="@string/keepalive_interval"/>
android:text="@string/keepalive_interval" />
<SeekBar
android:id="@+id/keepaliveIntervalSeekBar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="7"
android:max="14"/>
android:max="14" />
<TextView
android:id="@+id/keepaliveIntervalTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
tools:text="1 min"/>
tools:text="1 min" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:layout_marginBottom="8dp">
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="6"
android:text="@string/keepalive_bytes"/>
android:text="@string/keepalive_bytes" />
<SeekBar
android:id="@+id/keepaliveBytesSeekBar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="7"
android:max="99"/>
android:max="99" />
<TextView
android:id="@+id/keepaliveBytesTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
tools:text="1"/>
tools:text="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:layout_marginBottom="8dp">
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/alarm_type"/>
android:text="@string/alarm_type" />
<Spinner
android:id="@+id/alarmTypeSpinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"/>
android:layout_weight="2" />
</LinearLayout>
</LinearLayout>
......
......@@ -4,6 +4,10 @@
<string name="ongoing_notification_text">Touch to open</string>
<string name="settings">Settings</string>
<string name="ip_address">IP address</string>
<string name="port">Port number</string>
<string name="use_ip_address">IP address</string>
<string name="use_port_number">Port number</string>
<string name="use_foreground_service">Foreground service</string>
<string name="use_permanent_wake_lock">Permanent wake lock</string>
<string name="use_wifi_lock">Wi-Fi lock</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment