[Android] Sleep Timer: New UI and behaviour
Alexandre Perraud
git at videolan.org
Thu Jul 9 18:14:21 CEST 2015
vlc-ports/android | branch: master | Alexandre Perraud <4leyx4ndre at gmail.com> | Thu Jul 9 17:28:16 2015 +0200| [6c1a0c2687fe7caa86b45191c65aad30922b4bff] | committer: Geoffrey Métais
Sleep Timer: New UI and behaviour
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=6c1a0c2687fe7caa86b45191c65aad30922b4bff
---
vlc-android/res/values/strings.xml | 1 +
.../videolan/vlc/gui/dialogs/AdvOptionsDialog.java | 26 +++----
.../videolan/vlc/gui/dialogs/PickTimeFragment.java | 4 +-
.../videolan/vlc/gui/dialogs/SleepTimerDialog.java | 76 ++++++++++++++++++++
4 files changed, 90 insertions(+), 17 deletions(-)
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 3011335..1887ff9 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -143,6 +143,7 @@
<string name="tools">Tools</string>
<string name="playback_speed">Playback speed</string>
<string name="sleep_title">Sleep timer</string>
+ <string name="sleep_in">Sleep in</string>
<string name="sleep_cancel">Cancel sleep timer</string>
<string name="jump_to_time">Jump to Time</string>
<string name="subtitle_label">Add subtitle file</string>
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java
index 1981d2e..f488f24 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java
@@ -61,7 +61,8 @@ import org.videolan.vlc.util.WeakHandler;
import java.util.Calendar;
import static org.videolan.vlc.gui.dialogs.PickTimeFragment.ACTION_AUDIO_DELAY;
-import static org.videolan.vlc.gui.dialogs.PickTimeFragment.ACTION_JUMP_TO_TIME;
+import static org.videolan.vlc.gui.dialogs.PickTimeFragmentTemp.ACTION_JUMP_TO_TIME;
+import static org.videolan.vlc.gui.dialogs.PickTimeFragmentTemp.ACTION_SLEEP_TIMER;
import static org.videolan.vlc.gui.dialogs.PickTimeFragment.ACTION_SPU_DELAY;
public class AdvOptionsDialog extends DialogFragment implements View.OnClickListener, PlaybackService.Client.Callback {
@@ -270,9 +271,12 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
case PickTimeFragment.ACTION_SPU_DELAY:
newFragment = new SubsDelayDialog();
break;
- case PickTimeFragment.ACTION_JUMP_TO_TIME:
+ case PickTimeFragmentTemp.ACTION_JUMP_TO_TIME:
newFragment = new JumpToTimeDialog();
break;
+ case PickTimeFragmentTemp.ACTION_SLEEP_TIMER:
+ newFragment = new SleepTimerDialog();
+ break;
default:
return;
}
@@ -286,9 +290,12 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
if (mDelayController != null)
mDelayController.showSubsDelaySetting();
break;
- case PickTimeFragment.ACTION_JUMP_TO_TIME:
+ case PickTimeFragmentTemp.ACTION_JUMP_TO_TIME:
newFragment = new JumpToTimeDialog();
break;
+ case PickTimeFragmentTemp.ACTION_SLEEP_TIMER:
+ newFragment = new SleepTimerDialog();
+ break;
default:
return;
}
@@ -307,17 +314,6 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
}
};
- private void showTimePicker(int action) {
- DialogFragment newFragment = new TimePickerDialogFragment();
- Bundle args = new Bundle();
- args.putInt("action", action);
- newFragment.setArguments(args);
- newFragment.show(getActivity().getSupportFragmentManager(), "timePicker");
- mHandler.sendEmptyMessage(RESET_RETRY);
- mHandler.sendMessageDelayed(mHandler.obtainMessage(DIALOG_LISTENER, newFragment), 100);
- dismiss();
- }
-
public static void setSleep(Calendar time) {
AlarmManager alarmMgr = (AlarmManager) VLCApplication.getAppContext().getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(VLCApplication.SLEEP_INTENT);
@@ -397,7 +393,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
break;
case R.id.sleep_timer_title:
case R.id.sleep_timer_value:
- showTimePicker(TimePickerDialogFragment.ACTION_SLEEP);
+ showTimePickerFragment(ACTION_SLEEP_TIMER);
break;
case R.id.sleep_timer_cancel:
setSleep(null);
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/PickTimeFragment.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/PickTimeFragment.java
index 45dc1da..41c049e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/PickTimeFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/PickTimeFragment.java
@@ -50,8 +50,8 @@ public abstract class PickTimeFragment extends DialogFragment implements DialogI
public final static String TAG = "VLC/PickTimeFragment";
public static final int ACTION_JUMP_TO_TIME = 0;
- public static final int ACTION_SPU_DELAY = 1;
- public static final int ACTION_AUDIO_DELAY = 2;
+ public static final int ACTION_SPU_DELAY = 2;
+ public static final int ACTION_AUDIO_DELAY = 3;
protected int mTextColor;
protected boolean mLiveAction = true;
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/SleepTimerDialog.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/SleepTimerDialog.java
new file mode 100644
index 0000000..06d2166
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/SleepTimerDialog.java
@@ -0,0 +1,76 @@
+/*
+ * *************************************************************************
+ * SleepTimerDialog.java
+ * **************************************************************************
+ * Copyright © 2015 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * ***************************************************************************
+ */
+
+package org.videolan.vlc.gui.dialogs;
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import org.videolan.vlc.R;
+
+import java.util.Calendar;
+
+public class SleepTimerDialog extends PickTimeFragmentTemp {
+
+ protected static long ONE_DAY_IN_MILLIS = 24 * 60 * 60 * 1000;
+
+ public SleepTimerDialog() {
+ super();
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View view = super.onCreateView(inflater, container, savedInstanceState);
+ mMaxTimeSize = 4;
+ return view;
+ }
+
+
+ protected void executeAction() {
+ long hours = !mHours.equals("") ? Long.parseLong(mHours) * HOURS_IN_MICROS : 0l;
+ long minutes = !mMinutes.equals("") ? Long.parseLong(mMinutes) * MINUTES_IN_MICROS : 0l;
+ long interval = (hours + minutes) / MILLIS_IN_MICROS; //Interval in ms
+
+ if (interval < ONE_DAY_IN_MILLIS) {
+ Calendar sleepTime = Calendar.getInstance();
+ sleepTime.setTimeInMillis(Calendar.getInstance().getTimeInMillis() + interval);
+ sleepTime.set(Calendar.SECOND, 0);
+ AdvOptionsDialog.setSleep(sleepTime);
+ }
+
+ dismiss();
+ }
+
+ @Override
+ protected int getTitle() {
+ return R.string.sleep_in;
+ }
+
+ @Override
+ protected int getIcon() {
+ return R.attr.ic_sleep_normal_style;
+ }
+
+}
\ No newline at end of file
More information about the Android
mailing list