Commit f055eb9a authored by akwizgran's avatar akwizgran

Added button to stop service.

parent 4fe0b14b
......@@ -4,6 +4,8 @@ public interface Constants {
String ACTION_START = "org.briarproject.snooze.ACTION_START";
String ACTION_STOP = "org.briarproject.snooze.ACTION_STOP";
String ACTION_ALARM = "org.briarproject.snooze.ACTION_ALARM";
String EXTRA_FOREGROUND_SERVICE = "org.briarproject.snooze.EXTRA_FOREGROUND_SERVICE";
......
......@@ -71,12 +71,12 @@ public class LogFragment extends Fragment implements LogListener {
});
}
public void onClickClearLogButton() {
private void onClickClearLogButton() {
log.clear();
outputTextView.setText("");
}
public void onClickCopyLogButton() {
private void onClickCopyLogButton() {
ClipboardManager cp = (ClipboardManager) getContext().getSystemService(CLIPBOARD_SERVICE);
String text = outputTextView.getText().toString();
cp.setPrimaryClip(ClipData.newPlainText(getString(R.string.app_name), text));
......
......@@ -19,6 +19,7 @@ import android.widget.TextView;
import org.briarproject.snooze.alarm.AlarmType;
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_FOREGROUND_SERVICE;
......@@ -92,10 +93,16 @@ public class SettingsFragment extends Fragment {
onClickApplySettingsButton();
}
});
layout.findViewById(R.id.stopServiceButton).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
onClickStopServiceButton();
}
});
return layout;
}
public void onClickApplySettingsButton() {
private void onClickApplySettingsButton() {
View layout = getView();
boolean foreground =
((Switch) layout.findViewById(R.id.foregroundServiceSwitch)).isChecked();
......@@ -115,4 +122,10 @@ public class SettingsFragment extends Fragment {
i.putExtra(EXTRA_ALARM_TYPE, alarmType.name());
getContext().startService(i);
}
private void onClickStopServiceButton() {
Intent i = new Intent(getContext(), SnoozeService.class);
i.setAction(ACTION_STOP);
getContext().startService(i);
}
}
......@@ -8,6 +8,7 @@ import android.os.Binder;
import android.os.IBinder;
import android.os.PowerManager;
import android.support.v7.app.NotificationCompat;
import android.widget.Toast;
import org.briarproject.snooze.alarm.Alarm;
import org.briarproject.snooze.alarm.AlarmFactory;
......@@ -17,9 +18,11 @@ import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.net.wifi.WifiManager.WIFI_MODE_FULL;
import static android.os.PowerManager.PARTIAL_WAKE_LOCK;
import static android.widget.Toast.LENGTH_SHORT;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.briarproject.snooze.Constants.ACTION_ALARM;
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_FOREGROUND_SERVICE;
......@@ -75,6 +78,10 @@ public class SnoozeService extends Service {
else if (!newWifiLock && wifiLock != null) releaseWifiLock();
startNetworkThread();
setAlarm(newAlarmType);
Toast.makeText(this, R.string.service_started, LENGTH_SHORT).show();
} else if (ACTION_STOP.equals(i.getAction())) {
stopSelf();
Toast.makeText(this, R.string.service_stopped, LENGTH_SHORT).show();
} else if (ACTION_ALARM.equals(i.getAction())) {
AlarmType alarmType = AlarmType.valueOf(i.getStringExtra(EXTRA_ALARM_TYPE));
log.log("Alarm " + alarmType);
......
......@@ -4,8 +4,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
android:orientation="vertical"
android:padding="8dp"
tools:context="org.briarproject.snooze.LogFragment">
<ScrollView
......@@ -29,14 +29,14 @@
<Button
android:id="@+id/clearLogButton"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/clear_log"/>
<Button
android:id="@+id/copyLogButton"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/copy_log"/>
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="8dp"
tools:context="org.briarproject.snooze.SettingsFragment">
<LinearLayout
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp"
tools:context="org.briarproject.snooze.SettingsFragment">
<Switch
android:id="@+id/foregroundServiceSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/use_foreground_service"/>
<Switch
android:id="@+id/wakeLockSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/use_permanent_wake_lock"/>
<Switch
android:id="@+id/wifiLockSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/use_wifi_lock"/>
android:layout_height="0dp"
android:layout_weight="1"
android:padding="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="4dp">
android:orientation="vertical">
<TextView
android:layout_width="0dp"
<Switch
android:id="@+id/foregroundServiceSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="6"
android:text="@string/alarm_interval"/>
android:layout_marginBottom="8dp"
android:text="@string/use_foreground_service"/>
<SeekBar
android:id="@+id/alarmIntervalSeekBar"
android:layout_width="0dp"
<Switch
android:id="@+id/wakeLockSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="7"
android:max="14"/>
android:layout_marginBottom="8dp"
android:text="@string/use_permanent_wake_lock"/>
<TextView
android:id="@+id/alarmIntervalTextView"
android:layout_width="0dp"
<Switch
android:id="@+id/wifiLockSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
tools:text="1 min"/>
android:layout_marginBottom="8dp"
android:text="@string/use_wifi_lock"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="4dp">
<TextView
android:layout_width="0dp"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="6"
android:text="@string/keepalive_interval"/>
<SeekBar
android:id="@+id/keepaliveIntervalSeekBar"
android:layout_width="0dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:layout_marginBottom="8dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="6"
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"/>
<TextView
android:id="@+id/alarmIntervalTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
tools:text="1 min"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="7"
android:max="14"/>
<TextView
android:id="@+id/keepaliveIntervalTextView"
android:layout_width="0dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:layout_marginBottom="8dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="6"
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"/>
<TextView
android:id="@+id/keepaliveIntervalTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
tools:text="1 min"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
tools:text="1 min"/>
android:gravity="center_vertical"
android:orientation="horizontal"
android:layout_marginBottom="8dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/alarm_type"/>
<Spinner
android:id="@+id/alarmTypeSpinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<Spinner
android:id="@+id/alarmTypeSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/applySettingsButton"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/apply_settings"/>
<Button
android:id="@+id/stopServiceButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/stop_service"/>
</LinearLayout>
</ScrollView>
\ No newline at end of file
</LinearLayout>
\ No newline at end of file
......@@ -2,10 +2,15 @@
<string name="app_name">Snooze</string>
<string name="ongoing_notification_title">Snooze is running</string>
<string name="ongoing_notification_text">Touch to open</string>
<string name="settings">Settings</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>
<string name="alarm_interval">Alarm interval</string>
<string name="keepalive_interval">Keepalive interval</string>
<string name="interval">%d min</string>
<string name="alarm_type">Alarm type</string>
<string-array name="alarm_types">
<item>No alarm</item>
<item>Java Timer</item>
......@@ -14,11 +19,12 @@
<item>Android wakeup alarm</item>
</string-array>
<string name="apply_settings">Apply settings</string>
<string name="service_started">Service started</string>
<string name="stop_service">Stop service</string>
<string name="service_stopped">Service stopped</string>
<string name="log">Log</string>
<string name="clear_log">Clear log</string>
<string name="copy_log">Copy log</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="alarm_interval">Alarm interval</string>
<string name="keepalive_interval">Keepalive interval</string>
<string name="interval">%d min</string>
</resources>
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