Commit 081955c1 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Video advanced options Dialog

parent a74f8206
......@@ -37,15 +37,6 @@
android:background="?attr/advanced_options_divider"
tools:ignore="PxUsage" />
<TextView
android:id="@+id/add_subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/background_item"
android:text="@string/subtitle_label"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:id="@+id/equalizer"
android:layout_width="match_parent"
......
......@@ -2,24 +2,134 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.8"
android:background="@color/black"
android:paddingTop="?attr/actionBarSize"
tools:context="org.videolan.vlc.gui.video.AdvancedOptionsFragment">
android:padding="20dp"
tools:context="org.videolan.vlc.gui.video.AdvOptionsDialog">
<!-- TODO: Update blank fragment layout -->
<ImageView
android:id="@+id/playback_speed_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/ic_speed_normal_w"/>
<TextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:id="@+id/playback_speed_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test" />
android:layout_alignParentTop="true"
android:layout_alignBottom="@+id/playback_speed_seek"
android:layout_toRightOf="@+id/playback_speed_icon"
android:text="@string/playback_speed"
android:gravity="center_vertical"/>
<TextView
android:id="@+id/tv2"
android:id="@+id/playback_speed_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/playback_speed_title"
android:text="1.00x"
android:gravity="bottom"
android:layout_alignBottom="@+id/seek_beginning"
android:layout_below="@+id/playback_speed_title"/>
<SeekBar
android:id="@+id/playback_speed_seek"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:layout_below="@+id/tv1"
android:textColor="@color/white"
android:text="test 2" />
android:layout_marginLeft="10dp"
android:maxHeight="@dimen/seekbar_height"
android:minHeight="@dimen/seekbar_height"
android:max="200"
android:progress="100"
android:indeterminate="false"
android:layout_toRightOf="@+id/playback_speed_title"
android:layout_toLeftOf="@+id/playback_speed_reset"
android:progressDrawable="@drawable/po_seekbar"
android:thumb="@drawable/seekbar_thumb"/>
<TextView
android:id="@+id/seek_beginning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/playback_speed_seek"
android:layout_alignLeft="@+id/playback_speed_seek"
android:text="0.25" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/playback_speed_seek"
android:layout_toRightOf="@+id/seek_beginning"
android:layout_toLeftOf="@+id/seek_end"
android:gravity="center_horizontal"
android:text="1.00" />
<TextView
android:id="@+id/seek_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/playback_speed_seek"
android:layout_alignRight="@+id/playback_speed_seek"
android:text="4.00" />
<Button
android:id="@+id/playback_speed_reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="1x"/>
<!-- Sleep Timer-->
<ImageView
android:id="@+id/sleep_timer_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_below="@+id/playback_speed_value"
android:layout_marginTop="10dp"
android:src="@drawable/ic_sleep_normal_w"/>
<TextView
android:id="@+id/sleep_timer_title"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:gravity="center_vertical"
android:layout_below="@+id/playback_speed_value"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/sleep_timer_icon"
android:text="@string/sleep_title" />
<TextView
android:id="@+id/sleep_timer_value"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:gravity="center_vertical"
android:layout_below="@+id/playback_speed_value"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/sleep_timer_title"
android:layout_alignLeft="@+id/seek_beginning"
android:text="none_set"
android:clickable="true"/>
<TextView
android:id="@+id/sleep_timer_cancel"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_below="@+id/playback_speed_value"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/sleep_timer_value"
android:text="@string/sleep_cancel"
android:clickable="true"/>
<!-- Jump to position -->
<ImageView
android:id="@+id/jump_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_below="@+id/playback_speed_value"
android:layout_toLeftOf="@+id/jump_title"
android:layout_marginTop="10dp"
android:src="@drawable/ic_jumpto_normal_w" />
<TextView
android:id="@+id/jump_title"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:gravity="center_vertical"
android:layout_below="@+id/playback_speed_value"
android:layout_marginTop="10dp"
android:layout_alignRight="@+id/playback_speed_reset"
android:text="@string/jump_to_time" />
</RelativeLayout>
......@@ -76,10 +76,4 @@
</RelativeLayout>
<!--<fragment-->
<!--android:name="org.videolan.vlc.gui.video.AdvancedOptionsFragment"-->
<!--android:layout_width="600dp"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_alignParentRight="true"/>-->
</RelativeLayout>
\ No newline at end of file
......@@ -19,6 +19,7 @@
*****************************************************************************/
package org.videolan.vlc;
import java.util.Calendar;
import java.util.Locale;
import org.videolan.vlc.gui.audio.AudioUtil;
......@@ -40,6 +41,8 @@ public class VLCApplication extends Application {
public final static String INCOMING_CALL_INTENT = "org.videolan.vlc.IncomingCallIntent";
public final static String CALL_ENDED_INTENT = "org.videolan.vlc.CallEndedIntent";
public static Calendar sPlayerSleepTime = null;
@Override
public void onCreate() {
super.onCreate();
......
......@@ -111,56 +111,15 @@ public class CommonDialogs {
}
}
TextView add_subtitle = (TextView)dialog.findViewById(R.id.add_subtitle);
LinearLayout equalizer = (LinearLayout)dialog.findViewById(R.id.equalizer);
if(t == MenuType.Video) {
add_subtitle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("org.openintents.action.PICK_FILE");
File file = new File(android.os.Environment.getExternalStorageDirectory().getPath());
intent.setData(Uri.fromFile(file));
// Set fancy title and button (optional)
intent.putExtra("org.openintents.extra.TITLE", context.getString(R.string.subtitle_select));
intent.putExtra("org.openintents.extra.BUTTON_TEXT", context.getString(R.string.open));
if (context
.getPackageManager()
.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY).size() > 0) {
((Activity)context).startActivityForResult(intent, INTENT_SPECIFIC);
} else {
// OI intent not found, trying anything
Intent intent2 = new Intent(Intent.ACTION_GET_CONTENT);
intent2.setType("*/*");
intent2.addCategory(Intent.CATEGORY_OPENABLE);
try {
((Activity)context).startActivityForResult(intent2, INTENT_GENERIC);
} catch(ActivityNotFoundException e) {
Log.i(TAG, "No file picker found on system");
Toast.makeText(context,
R.string.no_file_picker_found,
Toast.LENGTH_SHORT).show();
}
}
dialog.dismiss();
}
});
equalizer.setVisibility(View.GONE);
} else {
final MainActivity activity = (MainActivity)context;
equalizer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
activity.showSecondaryFragment("equalizer");
dialog.dismiss();
}
});
add_subtitle.setVisibility(View.GONE);
}
final MainActivity activity = (MainActivity)context;
equalizer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
activity.showSecondaryFragment("equalizer");
dialog.dismiss();
}
});
// show dialog
dialog.show();
......
/**
* **************************************************************************
* TimePickerDialogFragment.java
* ****************************************************************************
* Copyright © 2011-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;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.text.format.DateFormat;
import android.widget.TimePicker;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.LibVlcUtil;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.video.AdvOptionsDialog;
import java.util.Calendar;
public class TimePickerDialogFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
public static final int ACTION_SLEEP = 0;
public static final int ACTION_JUMP = 1;
boolean setTime = !LibVlcUtil.isICSOrLater() || LibVlcUtil.isLolliPopOrLater();
int action =-1;
public TimePickerDialogFragment(){}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
action = getArguments().getInt("action");
boolean is24 = true;
int hour = 0;
int minute = 0;
if (action == ACTION_SLEEP) {
// Use the current time as the default values for the picker
final Calendar c = VLCApplication.sPlayerSleepTime != null ?
VLCApplication.sPlayerSleepTime : Calendar.getInstance();
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE);
is24 = DateFormat.is24HourFormat(getActivity());
}
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute, is24);
}
@Override
public void onStart() {
super.onStart();
getDialog().setCancelable(true);
}
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
if (!setTime){ //workaround for weird ICS&JB bug
setTime = true;
return;
}
Calendar currentTime = Calendar.getInstance();
Calendar sleepTime = Calendar.getInstance();
sleepTime.set(Calendar.HOUR_OF_DAY, hourOfDay);
sleepTime.set(Calendar.MINUTE, minute);
sleepTime.set(Calendar.SECOND, 0);
switch(action){
case ACTION_SLEEP:
if (sleepTime.before(currentTime))
sleepTime.roll(Calendar.DATE, true);
AdvOptionsDialog.setSleep(view.getContext(), sleepTime);
break;
case ACTION_JUMP:
long time = (long)((hourOfDay*60+minute)*60000);
LibVLC.getExistingInstance().setTime(time);
break;
}
}
}
......@@ -45,7 +45,6 @@ public class TimeSleep extends ExpandableLayout {
private final WheelView mHourWheel;
private final WheelView mMinWheel;
private static Calendar mTime = null;
public TimeSleep(Context context, AttributeSet attrs) {
super(context, attrs);
......@@ -65,9 +64,9 @@ public class TimeSleep extends ExpandableLayout {
okButton.setOnClickListener(mOnOkListener);
cancelButton.setOnClickListener(mOnCancelListener);
if (mTime != null && mTime.before(Calendar.getInstance()))
mTime = null;
Calendar c = mTime != null ? mTime : Calendar.getInstance();
if (VLCApplication.sPlayerSleepTime != null && VLCApplication.sPlayerSleepTime.before(Calendar.getInstance()))
VLCApplication.sPlayerSleepTime = null;
Calendar c = VLCApplication.sPlayerSleepTime != null ? VLCApplication.sPlayerSleepTime : Calendar.getInstance();
mHourWheel.setCurrentItem(c.get(Calendar.HOUR_OF_DAY));
mMinWheel.setCurrentItem(c.get(Calendar.MINUTE));
setText();
......@@ -98,7 +97,7 @@ public class TimeSleep extends ExpandableLayout {
};
private void setText() {
setText(mTime != null ? DateFormat.getTimeFormat(getContext()).format(mTime.getTime()) : null);
setText(VLCApplication.sPlayerSleepTime != null ? DateFormat.getTimeFormat(getContext()).format(VLCApplication.sPlayerSleepTime.getTime()) : null);
}
public static void setSleep(Context context, Calendar time) {
......@@ -114,7 +113,7 @@ public class TimeSleep extends ExpandableLayout {
alarmMgr.cancel(sleepPendingIntent);
Log.i(TAG, "Sleep cancelled");
}
mTime = time;
VLCApplication.sPlayerSleepTime = time;
}
public static void cancelSleep(Context context) {
......
/**
* **************************************************************************
* AdvOptionsDialog.java
* ****************************************************************************
* Copyright © 2011-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.video;
import android.app.AlarmManager;
import android.app.Dialog;
import android.app.PendingIntent;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.DialogFragment;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.TimePicker;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.LibVlcUtil;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.TimePickerDialogFragment;
import org.videolan.vlc.util.Strings;
import java.util.Calendar;
public class AdvOptionsDialog extends DialogFragment{
public final static String TAG = "VLC/AdvOptionsDialog";
public static final int SPEED_TEXT = 0;
public static final int SLEEP_TEXT = 1;
public static final int TOGGLE_CANCEL = 2;
public static final int DIALOG_LISTENER = 3;
public static final int RESET_RETRY = 4;
private TextView mSpeedTv;
private SeekBar mSeek;
private Button mReset;
private ImageView mSleepIcon;
private TextView mSleepTitle;
private TextView mSleepTime;
private TextView mSleepCancel;
private ImageView mJumpIcon;
private TextView mJumpTitle;
private static AdvOptionsDialog sInstance;
public AdvOptionsDialog() {}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sInstance = this;
setStyle(STYLE_NO_FRAME, R.style.Base_Theme_AppCompat_Dialog);
if (VLCApplication.sPlayerSleepTime != null && VLCApplication.sPlayerSleepTime.before(Calendar.getInstance()))
VLCApplication.sPlayerSleepTime = null;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_advanced_options, container, false);
mSeek = (SeekBar) root.findViewById(R.id.playback_speed_seek);
mSpeedTv = (TextView) root.findViewById(R.id.playback_speed_value);
mReset = (Button) root.findViewById(R.id.playback_speed_reset);
mSeek.setOnSeekBarChangeListener(mSeekBarListener);
mReset.setOnClickListener(mResetListener);
mSleepIcon = (ImageView) root.findViewById(R.id.sleep_timer_icon);
mSleepTitle = (TextView) root.findViewById(R.id.sleep_timer_title);
mSleepTime = (TextView) root.findViewById(R.id.sleep_timer_value);
mSleepCancel = (TextView) root.findViewById(R.id.sleep_timer_cancel);
mSleepIcon.setOnClickListener(mSleepListener);
mSleepTitle.setOnClickListener(mSleepListener);
mSleepTime.setOnClickListener(mSleepListener);
mSleepCancel.setOnClickListener(mSleepCancelListener);
mJumpIcon = (ImageView) root.findViewById(R.id.jump_icon);
mJumpTitle = (TextView) root.findViewById(R.id.jump_title);
mJumpIcon.setOnClickListener(mJumpListener);
mJumpTitle.setOnClickListener(mJumpListener);
getDialog().setCancelable(true);
mHandler.sendEmptyMessage(TOGGLE_CANCEL);
return root;
}
private SeekBar.OnSeekBarChangeListener mSeekBarListener = new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
float rate = (float) Math.pow(4, ((double) progress / (double) 100) - 1);
mHandler.obtainMessage(SPEED_TEXT, Strings.formatRateString(rate)).sendToTarget();
LibVLC.getExistingInstance().setRate(rate);
}
public void onStartTrackingTouch(SeekBar seekBar) {}
public void onStopTrackingTouch(SeekBar seekBar) {}
};
private View.OnClickListener mResetListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
mSeek.setProgress(100);
LibVLC.getExistingInstance().setRate(1);
}
};
View.OnClickListener mSleepListener = new View.OnClickListener(){
@Override
public void onClick(View v) {
showTimePicker(TimePickerDialogFragment.ACTION_SLEEP);
}
};
View.OnClickListener mSleepCancelListener = new View.OnClickListener(){
@Override
public void onClick(View v) {
setSleep(v.getContext(), null);
mHandler.sendEmptyMessage(TOGGLE_CANCEL);
}
};
View.OnClickListener mJumpListener = new View.OnClickListener(){
@Override
public void onClick(View v) {
showTimePicker(TimePickerDialogFragment.ACTION_JUMP);
}
};
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);
}
public static void setSleep(Context context, Calendar time) {
AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(VLCApplication.SLEEP_INTENT);
PendingIntent sleepPendingIntent = PendingIntent.getBroadcast(VLCApplication.getAppContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
if (time != null) {
alarmMgr.set(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), sleepPendingIntent);
}
else {
alarmMgr.cancel(sleepPendingIntent);
}
VLCApplication.sPlayerSleepTime = time;
}
private final static Handler mHandler = new Handler(){
public boolean retry = true;
@Override
public void handleMessage(Message msg) {