diff options
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java | 11 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java (renamed from app/src/main/java/de/danoeh/antennapod/dialog/TimeDialog.java) | 131 | ||||
-rw-r--r-- | app/src/main/res/layout-v14/time_dialog.xml | 33 | ||||
-rw-r--r-- | app/src/main/res/layout/time_dialog.xml | 31 |
4 files changed, 143 insertions, 63 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java index 40a0d1801..e34b4dc67 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -31,7 +31,7 @@ import de.danoeh.antennapod.core.util.StorageUtils; import de.danoeh.antennapod.core.util.playback.MediaPlayerError; import de.danoeh.antennapod.core.util.playback.Playable; import de.danoeh.antennapod.core.util.playback.PlaybackController; -import de.danoeh.antennapod.dialog.TimeDialog; +import de.danoeh.antennapod.dialog.SleepTimerDialog; /** * Provides general features which are both needed for playing audio and video @@ -323,13 +323,10 @@ public abstract class MediaplayerActivity extends ActionBarActivity break; case R.id.set_sleeptimer_item: if (controller.serviceAvailable()) { - TimeDialog td = new TimeDialog(this, - R.string.set_sleeptimer_label, - R.string.set_sleeptimer_label) { - + SleepTimerDialog td = new SleepTimerDialog(this, 0, 0) { @Override - public void onTimeEntered(long millis) { - controller.setSleepTimer(millis); + public void onTimerSet(long millis, boolean shakeToReset, boolean vibrate) { + controller.setSleepTimer(millis, shakeToReset, vibrate); } }; td.show(); diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/TimeDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java index 5c4d4c430..a699706a8 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/TimeDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java @@ -2,6 +2,7 @@ package de.danoeh.antennapod.dialog; import android.app.Dialog; import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; @@ -9,100 +10,80 @@ import android.util.Log; import android.view.View; import android.view.Window; import android.view.inputmethod.InputMethodManager; -import android.widget.*; -import de.danoeh.antennapod.core.BuildConfig; -import de.danoeh.antennapod.R; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.EditText; +import android.widget.Spinner; +import android.widget.Toast; import java.util.concurrent.TimeUnit; -public abstract class TimeDialog extends Dialog { - private static final String TAG = "TimeDialog"; +import de.danoeh.antennapod.R; + +public abstract class SleepTimerDialog extends Dialog { + + private static final String TAG = SleepTimerDialog.class.getSimpleName(); private static final int DEFAULT_SPINNER_POSITION = 1; private Context context; + private String PREF_NAME = "SleepTimerDialog"; + private String PREF_VALUE = "LastValue"; + private String PREF_TIME_UNIT = "LastTimeUnit"; + private String PREF_VIBRATE = "Vibrate"; + private String PREF_SHAKE_TO_RESET = "ShakeToReset"; + private SharedPreferences prefs; private EditText etxtTime; private Spinner spTimeUnit; + private CheckBox cbShakeToReset; + private CheckBox cbVibrate; private Button butConfirm; private Button butCancel; - private TimeUnit[] units = {TimeUnit.SECONDS, TimeUnit.MINUTES, - TimeUnit.HOURS}; + private TimeUnit[] units = { TimeUnit.SECONDS, TimeUnit.MINUTES, TimeUnit.HOURS }; - public TimeDialog(Context context, int titleTextId, int leftButtonTextId) { + public SleepTimerDialog(Context context, int titleTextId, int leftButtonTextId) { super(context); this.context = context; + prefs = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); - String[] spinnerContent = new String[]{context.getString(R.string.time_seconds), + String[] spinnerContent = new String[] { + context.getString(R.string.time_seconds), context.getString(R.string.time_minutes), - context.getString(R.string.time_hours)}; + context.getString(R.string.time_hours) }; setContentView(R.layout.time_dialog); etxtTime = (EditText) findViewById(R.id.etxtTime); spTimeUnit = (Spinner) findViewById(R.id.spTimeUnit); + cbShakeToReset = (CheckBox) findViewById(R.id.cbShakeToReset); + cbVibrate = (CheckBox) findViewById(R.id.cbVibrate); butConfirm = (Button) findViewById(R.id.butConfirm); butCancel = (Button) findViewById(R.id.butCancel); - butConfirm.setText(R.string.set_sleeptimer_label); - butCancel.setText(R.string.cancel_label); setTitle(R.string.set_sleeptimer_label); - ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>( - this.getContext(), android.R.layout.simple_spinner_item, - spinnerContent); - spinnerAdapter - .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - spTimeUnit.setAdapter(spinnerAdapter); - spTimeUnit.setSelection(DEFAULT_SPINNER_POSITION); - butCancel.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View v) { - dismiss(); - } - }); - butConfirm.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - try { - long input = readTimeMillis(); - onTimeEntered(input); - dismiss(); - } catch (NumberFormatException e) { - e.printStackTrace(); - Toast toast = Toast.makeText(context, - R.string.time_dialog_invalid_input, - Toast.LENGTH_LONG); - toast.show(); - } - } - }); + etxtTime.setText(prefs.getString(PREF_VALUE, "15")); etxtTime.addTextChangedListener(new TextWatcher() { - @Override public void afterTextChanged(Editable s) { checkInputLength(s.length()); } @Override - public void beforeTextChanged(CharSequence s, int start, int count, - int after) { - + public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override - public void onTextChanged(CharSequence s, int start, int before, - int count) { - + public void onTextChanged(CharSequence s, int start, int before, int count) { } }); - checkInputLength(etxtTime.getText().length()); etxtTime.postDelayed(new Runnable() { @Override public void run() { @@ -111,23 +92,54 @@ public abstract class TimeDialog extends Dialog { } }, 100); + ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(this.getContext(), + android.R.layout.simple_spinner_item, spinnerContent); + spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spTimeUnit.setAdapter(spinnerAdapter); + int selection = prefs.getInt(PREF_TIME_UNIT, DEFAULT_SPINNER_POSITION); + spTimeUnit.setSelection(selection); + cbShakeToReset.setChecked(prefs.getBoolean(PREF_SHAKE_TO_RESET, true)); + cbVibrate.setChecked(prefs.getBoolean(PREF_VIBRATE, true)); + butConfirm.setText(R.string.set_sleeptimer_label); + butConfirm.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + try { + savePreferences(); + long input = readTimeMillis(); + onTimerSet(input, cbShakeToReset.isChecked(), cbVibrate.isChecked()); + dismiss(); + } catch (NumberFormatException e) { + e.printStackTrace(); + Toast toast = Toast.makeText(context, R.string.time_dialog_invalid_input, + Toast.LENGTH_LONG); + toast.show(); + } + } + }); + + butCancel.setText(R.string.cancel_label); + butCancel.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + dismiss(); + } + }); } private void checkInputLength(int length) { if (length > 0) { - if (BuildConfig.DEBUG) - Log.d(TAG, "Length is larger than 0, enabling confirm button"); + Log.d(TAG, "Length is larger than 0, enabling confirm button"); butConfirm.setEnabled(true); } else { - if (BuildConfig.DEBUG) - Log.d(TAG, "Length is smaller than 0, disabling confirm button"); + Log.d(TAG, "Length is smaller than 0, disabling confirm button"); butConfirm.setEnabled(false); } } - public abstract void onTimeEntered(long millis); + public abstract void onTimerSet(long millis, boolean shakeToReset, boolean vibrate); private long readTimeMillis() { TimeUnit selectedUnit = units[spTimeUnit.getSelectedItemPosition()]; @@ -135,4 +147,13 @@ public abstract class TimeDialog extends Dialog { return selectedUnit.toMillis(value); } + private void savePreferences() { + prefs.edit() + .putString(PREF_VALUE, etxtTime.getText().toString()) + .putInt(PREF_TIME_UNIT, spTimeUnit.getSelectedItemPosition()) + .putBoolean(PREF_SHAKE_TO_RESET, cbShakeToReset.isChecked()) + .putBoolean(PREF_VIBRATE, cbVibrate.isChecked()) + .apply(); + } + } diff --git a/app/src/main/res/layout-v14/time_dialog.xml b/app/src/main/res/layout-v14/time_dialog.xml index 7fd4309d5..aefb82b8b 100644 --- a/app/src/main/res/layout-v14/time_dialog.xml +++ b/app/src/main/res/layout-v14/time_dialog.xml @@ -2,7 +2,7 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" - android:orientation="vertical" > + android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" @@ -31,6 +31,37 @@ android:layout_marginTop="8dp" /> </LinearLayout> + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center"> + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="vertical"> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="8dp" + android:textSize="16sp" + android:text="@string/timer_about_to_expire_label"/> + + <CheckBox android:id="@+id/cbShakeToReset" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/shake_to_reset_label"/> + + <CheckBox android:id="@+id/cbVibrate" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/timer_vibration_label"/> + + </LinearLayout> + + </LinearLayout> + <RelativeLayout android:id="@+id/footer" android:layout_width="fill_parent" diff --git a/app/src/main/res/layout/time_dialog.xml b/app/src/main/res/layout/time_dialog.xml index a42f87781..e387a1689 100644 --- a/app/src/main/res/layout/time_dialog.xml +++ b/app/src/main/res/layout/time_dialog.xml @@ -33,6 +33,37 @@ </LinearLayout> <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center"> + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="vertical"> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="8dp" + android:textSize="16sp" + android:text="@string/timer_about_to_expire_label"/> + + <CheckBox android:id="@+id/cbShakeToReset" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/shake_to_reset_label"/> + + <CheckBox android:id="@+id/cbVibrate" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/timer_vibration_label"/> + + </LinearLayout> + + </LinearLayout> + + <LinearLayout style="@android:style/ButtonBar" android:layout_width="match_parent" android:layout_height="wrap_content" |