Commit c7d2c6b1 authored by Florian's avatar Florian

Merge branch 'bug-onStartCommand' into develop

parents 00a68468 58d6b179
......@@ -156,6 +156,9 @@ public class SettingsFragment extends PreferenceFragment {
final Preference prefLocRad = findPreference(ConfigConstants.SETTING_LOCATION_RADIUS);
prefLocRad.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
if(newValue.toString().trim().equals("")){
return false;
}
String prefLocRadStr = String.format(getString(R.string.settings_location_radius_title), String.valueOf(newValue));
prefLocRad.setTitle(prefLocRadStr);
//Log.d("MyApp", "Pref " + preference.getKey() + " " + newValue.toString());
......@@ -167,6 +170,9 @@ public class SettingsFragment extends PreferenceFragment {
final Preference prefPulseDur = findPreference(ConfigConstants.SETTING_PULSE_DURATION);
prefPulseDur.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
if(newValue.toString().trim().equals("")){
return false;
}
String prefPulseDurStr = String.format(getString(R.string.settings_pulse_duration_title), String.valueOf(newValue));
prefPulseDur.setTitle(prefPulseDurStr);
return true;
......@@ -176,6 +182,9 @@ public class SettingsFragment extends PreferenceFragment {
final Preference prefPauseDur = findPreference(ConfigConstants.SETTING_PAUSE_DURATION);
prefPauseDur.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
if(newValue.toString().trim().equals("")){
return false;
}
String prefPauseDurStr = String.format(getString(R.string.settings_pause_duration_title), String.valueOf(newValue));
prefPauseDur.setTitle(prefPauseDurStr);
return true;
......@@ -185,6 +194,9 @@ public class SettingsFragment extends PreferenceFragment {
final Preference prefBandwidth = findPreference(ConfigConstants.SETTING_BANDWIDTH);
prefBandwidth.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
if(newValue.toString().trim().equals("")){
return false;
}
String prefBandwidthStr = String.format(getString(R.string.settings_bandwidth_title), String.valueOf(newValue));
prefBandwidth.setTitle(prefBandwidthStr);
return true;
......@@ -194,6 +206,9 @@ public class SettingsFragment extends PreferenceFragment {
final Preference prefBlockingDuration = findPreference(ConfigConstants.SETTING_BLOCKING_DURATION);
prefBlockingDuration.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
if(newValue.toString().trim().equals("")){
return false;
}
if(Integer.valueOf((String)newValue)==1) {
String prefBlockingDurationStr = String.format(getString(R.string.settings_blocking_duration_singular), String.valueOf(newValue));
prefBlockingDuration.setTitle(prefBlockingDurationStr);
......
......@@ -23,11 +23,14 @@ import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.util.Log;
import android.widget.ImageButton;
import android.widget.Toast;
import java.util.concurrent.Executors;
......@@ -57,7 +60,20 @@ public class SoniService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (ServiceConstants.ACTION.STARTFOREGROUND_ACTION.equals(intent.getAction())) {
if(intent == null){
Intent service = new Intent(getApplicationContext(), SoniService.class);
service.setAction(ServiceConstants.ACTION.STOPFOREGROUND_ACTION);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor ed = sp.edit();
ed.putString(ConfigConstants.PREFERENCES_APP_STATE, StateEnum.ON_HOLD.toString());
ed.apply();
SoniService.IS_SERVICE_RUNNING = false;
stopForeground(true);
stopSelf();
}else if (ServiceConstants.ACTION.STARTFOREGROUND_ACTION.equals(intent.getAction())) {
//Log.i(LOG_TAG, "Received Start Foreground Intent ");
showNotification();
SoniService.IS_SERVICE_RUNNING = true;
......
This diff is collapsed.
......@@ -31,7 +31,7 @@
android:selectAllOnFocus="true"
android:singleLine="true"
android:inputType="number"
android:title="Location radius (metre)" />
android:title="@string/settings_title_location_radius" />
<CheckBoxPreference
android:defaultValue="true"
android:key="cbprefGpsUse"
......@@ -67,21 +67,21 @@
android:selectAllOnFocus="true"
android:singleLine="true"
android:inputType="number"
android:title="Pulse duration (ms)" />
android:title="@string/settings_title_pulse_duration" />
<EditTextPreference
android:defaultValue="0"
android:key="etprefPauseDuration"
android:selectAllOnFocus="true"
android:singleLine="true"
android:inputType="number"
android:title="Pause duration (ms)" />
android:title="@string/settings_title_pause_duration" />
<EditTextPreference
android:defaultValue="10"
android:key="etprefBandwidth"
android:selectAllOnFocus="true"
android:singleLine="true"
android:inputType="number"
android:title="Bandwidth" />
android:title="@string/settings_title_bandwidth" />
<EditTextPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
......@@ -90,7 +90,7 @@
android:key="etprefSpoofDuration"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="Blocking duration in minutes" />
android:title="@string/settings_title_blocking_duration" />
</PreferenceCategory>
<PreferenceCategory android:title="Expert settings - RESET">
<Preference
......
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