Commit 86e912f2 authored by Alexandre Perraud's avatar Alexandre Perraud

Playback Speed : redesign and simplify code

parent f5fac202
......@@ -20,6 +20,7 @@
android:orientation="horizontal">
<ImageView
android:id="@+id/playback_speed_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="?attr/ic_speed_normal_style" />
......@@ -34,17 +35,23 @@
</LinearLayout>
<ImageView
android:id="@+id/playback_speed_reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:nextFocusDown="@+id/playback_speed_seek"
android:layout_alignParentRight="true"
android:src="@drawable/ic_speed_reset" />
</RelativeLayout>
<SeekBar
android:id="@+id/playback_speed_seek"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:indeterminate="false"
android:max="200"
android:maxHeight="@dimen/seekbar_height"
android:minHeight="@dimen/seekbar_height"
android:nextFocusUp="@+id/playback_speed_reset"
android:progress="100"
android:progressDrawable="@drawable/po_seekbar"
android:splitTrack="false"
android:thumb="@drawable/seekbar_thumb" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
......@@ -53,7 +60,9 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/playback_speed_value"
android:layout_alignParentLeft="true"
android:gravity="bottom"
android:paddingLeft="@dimen/half_default_margin"
android:text="0.25" />
......@@ -69,25 +78,11 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/playback_speed_value"
android:layout_alignParentRight="true"
android:paddingRight="@dimen/half_default_margin"
android:text="4.00" />
</RelativeLayout>
<SeekBar
android:id="@+id/playback_speed_seek"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:indeterminate="false"
android:max="200"
android:maxHeight="@dimen/seekbar_height"
android:minHeight="@dimen/seekbar_height"
android:nextFocusUp="@+id/playback_speed_reset"
android:progress="100"
android:progressDrawable="@drawable/po_seekbar"
android:splitTrack="false"
android:thumb="@drawable/seekbar_thumb" />
</LinearLayout>
......@@ -40,28 +40,16 @@
<!-- Playback speed -->
<LinearLayout
<TextView
android:id="@+id/playback_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:clickable="true"
android:layout_marginLeft="@dimen/adv_options_margin"
android:orientation="vertical">
<ImageView
android:id="@+id/playback_speed_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:src="?attr/ic_speed_normal_style" />
<TextView
android:id="@+id/playback_speed_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</LinearLayout>
android:drawableTop="?attr/ic_speed_normal_style"
android:focusable="true"
android:gravity="center_horizontal" />
<!-- Play as Audio -->
......
......@@ -56,14 +56,13 @@ import java.util.Calendar;
import static org.videolan.vlc.gui.dialogs.PickTimeFragment.ACTION_JUMP_TO_TIME;
import static org.videolan.vlc.gui.dialogs.PickTimeFragment.ACTION_SLEEP_TIMER;
public class AdvOptionsDialog extends DialogFragment implements View.OnClickListener, PlaybackService.Client.Callback {
public class AdvOptionsDialog extends DialogFragment implements View.OnClickListener, View.OnLongClickListener, PlaybackService.Client.Callback {
public final static String TAG = "VLC/AdvOptionsDialog";
public static final String MODE_KEY = "mode";
public static final int MODE_VIDEO = 0;
public static final int MODE_AUDIO = 1;
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;
......@@ -78,8 +77,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
private ImageView mPlayAsAudio;
private TextView mEqualizer;
private ImageView mPlaybackSpeedIcon;
private TextView mPlaybackSpeedValue;
private TextView mPlaybackSpeed;
private ImageView mSleepIcon;
private TextView mSleepValue;
......@@ -136,10 +134,10 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
getDialog().setCanceledOnTouchOutside(true);
mPlaybackSpeedValue = (TextView) root.findViewById(R.id.playback_speed_value);
mPlaybackSpeedValue.setOnFocusChangeListener(mFocusListener);
mPlaybackSpeedIcon = (ImageView) root.findViewById(R.id.playback_speed_icon);
mPlaybackSpeedIcon.setOnClickListener(this);
mPlaybackSpeed = (TextView) root.findViewById(R.id.playback_speed);
mPlaybackSpeed.setOnFocusChangeListener(mFocusListener);
mPlaybackSpeed.setOnClickListener(this);
mPlaybackSpeed.setOnLongClickListener(this);
mSleepValue = (TextView) root.findViewById(R.id.sleep_value);
mSleepIcon = (ImageView) root.findViewById(R.id.sleep_icon);
......@@ -264,7 +262,19 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
VLCApplication.sPlayerSleepTime = time;
}
private final Handler mHandler = new AdvOptionsDialogHandler(this);
public void initPlaybackSpeed () {
if (mService.getRate() == 1.0f) {
mPlaybackSpeed.setText(null);
mPlaybackSpeed.setCompoundDrawablesWithIntrinsicBounds(0,
Util.getResourceFromAttribute(mActivity, R.attr.ic_speed_normal_style),
0, 0);
} else {
mPlaybackSpeed.setText(Strings.formatRateString(mService.getRate()));
mPlaybackSpeed.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_speed_on, 0, 0);
}
}
private final Handler mHandler = new AdvOptionsDialogHandler(this);
private static class AdvOptionsDialogHandler extends WeakHandler<AdvOptionsDialog> {
......@@ -281,13 +291,6 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
if (owner == null || owner.isDetached())
return;
switch (msg.what) {
case SPEED_TEXT:
text = (String) msg.obj;
owner.mPlaybackSpeedValue.setText(text);
owner.mPlaybackSpeedIcon.setImageResource(VLCApplication.sPlayerSleepTime == null ?
Util.getResourceFromAttribute(owner.getActivity(), R.attr.ic_speed_normal_style) :
R.drawable.ic_speed_on);
break;
case TOGGLE_CANCEL:
owner.mSleepIcon.setImageResource(VLCApplication.sPlayerSleepTime == null ?
Util.getResourceFromAttribute(owner.getActivity(), R.attr.ic_sleep_normal_style):
......@@ -329,7 +332,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
mHandler.sendEmptyMessage(TOGGLE_CANCEL);
}
break;
case R.id.playback_speed_icon:
case R.id.playback_speed:
showPlayBackSpeedDialog();
break;
case R.id.jump_chapter_title:
......@@ -356,6 +359,17 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
}
}
public boolean onLongClick (View v) {
switch (v.getId()) {
case R.id.playback_speed:
mService.setRate(1);
initPlaybackSpeed();
return true;
}
return false;
}
private DialogInterface.OnDismissListener onDismissListener;
public void setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) {
......@@ -386,15 +400,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
public void onConnected(PlaybackService service) {
mService = service;
// Init Playback Speed
if (mService.getRate() == 1.0f) {
mPlaybackSpeedValue.setText(null);
mPlaybackSpeedIcon.setImageResource(
Util.getResourceFromAttribute(this.getActivity(), R.attr.ic_speed_normal_style));
} else {
mPlaybackSpeedValue.setText(Strings.formatRateString(mService.getRate()));
mPlaybackSpeedIcon.setImageResource(R.drawable.ic_speed_on);
}
initPlaybackSpeed();
if (mMode == MODE_VIDEO) {
// Init Chapter
......
......@@ -44,9 +44,10 @@ public class PlaybackSpeedDialog extends DialogFragment implements PlaybackServi
private TextView mSpeedValue;
private SeekBar mSeekSpeed;
private ImageView mResetSpeed;
private ImageView mPlaybackSpeedIcon;
protected PlaybackService mService;
protected int mTextColor;
public PlaybackSpeedDialog() {
}
......@@ -73,10 +74,14 @@ public class PlaybackSpeedDialog extends DialogFragment implements PlaybackServi
View view = inflater.inflate(R.layout.dialog_playback_speed, container);
mSpeedValue = (TextView) view.findViewById(R.id.playback_speed_value);
mSeekSpeed = (SeekBar) view.findViewById(R.id.playback_speed_seek);
mResetSpeed = (ImageView) view.findViewById(R.id.playback_speed_reset);
mPlaybackSpeedIcon = (ImageView) view.findViewById(R.id.playback_speed_icon);
mSeekSpeed.setOnSeekBarChangeListener(mSeekBarListener);
mResetSpeed.setOnClickListener(mResetListener);
mPlaybackSpeedIcon.setOnClickListener(mResetListener);
mSpeedValue.setOnClickListener(mResetListener);
mTextColor = mSpeedValue.getCurrentTextColor();
getDialog().setCancelable(true);
getDialog().setCanceledOnTouchOutside(true);
......@@ -93,6 +98,7 @@ public class PlaybackSpeedDialog extends DialogFragment implements PlaybackServi
speed = 100 * (1 + Math.log(speed) / Math.log(4));
mSeekSpeed.setProgress((int) speed);
}
updateInterface();
}
private SeekBar.OnSeekBarChangeListener mSeekBarListener = new SeekBar.OnSeekBarChangeListener() {
......@@ -104,6 +110,7 @@ public class PlaybackSpeedDialog extends DialogFragment implements PlaybackServi
float rate = (float) Math.pow(4, ((double) progress / (double) 100) - 1);
mSpeedValue.setText(Strings.formatRateString(rate));
mService.setRate(rate);
updateInterface();
}
public void onStartTrackingTouch(SeekBar seekBar) {
......@@ -119,11 +126,25 @@ public class PlaybackSpeedDialog extends DialogFragment implements PlaybackServi
if (mService == null)
return;
if (mService.getRate() == 1.0d)
return;
mSeekSpeed.setProgress(100);
mService.setRate(1);
}
};
private void updateInterface() {
if (mService.getRate() != 1.0d) {
mPlaybackSpeedIcon.setImageResource(R.drawable.ic_speed_reset);
mSpeedValue.setTextColor(getResources().getColor(R.color.orange500));
} else {
mPlaybackSpeedIcon.setImageResource(Util.getResourceFromAttribute(getActivity(), R.attr.ic_speed_normal_style));
mSpeedValue.setTextColor(mTextColor);
}
}
@Override
public void onStart() {
super.onStart();
......
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