Commit dfc310b3 authored by Sébastien Toque's avatar Sébastien Toque

UI: restore the "wheel bar" as an option

parent e09ad691
......@@ -118,33 +118,14 @@
android:textColor="#ffffff"
android:textSize="15dip" />
<ImageButton
android:id="@+id/player_overlay_backward"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_below="@+id/player_overlay_seekbar"
android:layout_centerHorizontal="true"
android:layout_toLeftOf="@+id/player_overlay_play"
android:background="@drawable/ic_backward" />
<ImageButton
android:id="@+id/player_overlay_play"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_below="@+id/player_overlay_seekbar"
android:layout_centerHorizontal="true"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@drawable/ic_pause" />
<ImageButton
android:id="@+id/player_overlay_forward"
android:layout_width="50dip"
<FrameLayout
android:id="@+id/player_control"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_below="@+id/player_overlay_seekbar"
android:layout_centerHorizontal="true"
android:layout_toRightOf="@+id/player_overlay_play"
android:background="@drawable/ic_forward" />
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp" />
<ImageButton
android:id="@+id/player_overlay_size"
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<ImageButton
android:id="@+id/player_overlay_backward"
android:layout_width="50dip"
android:layout_height="50dip"
android:background="@drawable/ic_backward" />
<ImageButton
android:id="@+id/player_overlay_play"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@drawable/ic_pause" />
<ImageButton
android:id="@+id/player_overlay_forward"
android:layout_width="50dip"
android:layout_height="50dip"
android:background="@drawable/ic_forward" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<SeekBar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/player_overlay_wheelbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:maxHeight="5dp"
android:minHeight="5dp"
android:progressDrawable="@drawable/wheel_background"
android:thumb="@drawable/wheel_pause"
android:thumbOffset="0px" />
......@@ -71,6 +71,7 @@
<string name="quit">Quitter l\'application</string>
<string name="detect_headset">Détecter le casque</string>
<string name="detect_headset_detail">Pause lors du débranchement du casque, Reprise lors du branchement du casque</string>
<string name="enable_wheel_bar">Activer la wheel bar</string>
<string name="refresh">Rafraîchir</string>
<string name="track_audio">Piste audio</string>
<string name="track_video">Piste vidéo</string>
......
......@@ -74,6 +74,7 @@
<string name="clear_media_db">Clear media database</string>
<string name="detect_headset">Detect headset</string>
<string name="detect_headset_detail">Pause on headset removed, Resume on headset inserted</string>
<string name="enable_wheel_bar">Enable wheel bar</string>
<string name="refresh">Refresh</string>
<string name="track_audio">Audio track</string>
<string name="track_video">Video track</string>
......
......@@ -24,6 +24,11 @@
android:summary="@string/detect_headset_detail"
android:defaultValue="true">
</CheckBoxPreference>
<CheckBoxPreference
android:key="enable_wheel_bar"
android:title="@string/enable_wheel_bar"
android:defaultValue="false">
</CheckBoxPreference>
</PreferenceCategory>
<PreferenceCategory android:title="@string/searchable_hint">
<PreferenceScreen
......
......@@ -30,6 +30,10 @@ import org.videolan.vlc.LibVlcException;
import org.videolan.vlc.R;
import org.videolan.vlc.Util;
import org.videolan.vlc.gui.PreferencesActivity;
import org.videolan.vlc.interfaces.IPlayerControl;
import org.videolan.vlc.interfaces.OnPlayerControlListener;
import org.videolan.vlc.widget.PlayerControlClassic;
import org.videolan.vlc.widget.PlayerControlWheel;
import android.app.Activity;
import android.app.AlertDialog;
......@@ -50,6 +54,7 @@ import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.preference.PreferenceManager;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.Display;
......@@ -63,6 +68,7 @@ import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
......@@ -102,9 +108,7 @@ public class VideoPlayerActivity extends Activity {
private TextView mTime;
private TextView mLength;
private TextView mInfo;
private ImageButton mBackward;
private ImageButton mPlayPause;
private ImageButton mForward;
private IPlayerControl mControls;
private ImageButton mAudio;
private ImageButton mLock;
private ImageButton mSize;
......@@ -129,6 +133,8 @@ public class VideoPlayerActivity extends Activity {
super.onCreate(savedInstanceState);
setContentView(R.layout.player);
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
// stop screen from dimming
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, TAG);
......@@ -147,12 +153,12 @@ public class VideoPlayerActivity extends Activity {
// the info textView is not on the overlay
mInfo = (TextView) findViewById(R.id.player_overlay_info);
mBackward = (ImageButton) findViewById(R.id.player_overlay_backward);
mBackward.setOnClickListener(mBackwardListener);
mPlayPause = (ImageButton) findViewById(R.id.player_overlay_play);
mPlayPause.setOnClickListener(mPlayPauseListener);
mForward = (ImageButton) findViewById(R.id.player_overlay_forward);
mForward.setOnClickListener(mForwardListener);
mControls = pref.getBoolean("enable_wheel_bar", false)
? new PlayerControlWheel(this)
: new PlayerControlClassic(this);
mControls.setOnPlayerControlListener(mPlayerControlListener);
FrameLayout mControlContainer = (FrameLayout) findViewById(R.id.player_control);
mControlContainer.addView((View) mControls);
mAudio = (ImageButton) findViewById(R.id.player_overlay_audio);
mAudio.setOnClickListener(mAudioListener);
......@@ -534,30 +540,6 @@ public class VideoPlayerActivity extends Activity {
/**
*
*/
private OnClickListener mBackwardListener = new OnClickListener() {
@Override
public void onClick(View v) {
long position = mLibVLC.getTime();
mLibVLC.setTime(position - 10000);
showOverlay();
}
};
private OnClickListener mPlayPauseListener = new OnClickListener() {
@Override
public void onClick(View v) {
doPausePlay();
showOverlay();
}
};
private OnClickListener mForwardListener = new OnClickListener() {
@Override
public void onClick(View v) {
long position = mLibVLC.getTime();
mLibVLC.setTime(position + 10000);
showOverlay();
}
};
private OnClickListener mAudioListener = new OnClickListener() {
public void onClick(View v) {
if (mAudioTracks == null || mAudioTracks.length <= 1)
......@@ -578,6 +560,49 @@ public class VideoPlayerActivity extends Activity {
}
};
/**
*
*/
private OnPlayerControlListener mPlayerControlListener = new OnPlayerControlListener() {
@Override
public void onPlayPause() {
if (mLibVLC.isPlaying())
pause();
else
play();
showOverlay();
}
@Override
public void onSeek(int delta) {
long position = mLibVLC.getTime();
mLibVLC.setTime(position + delta);
showOverlay();
}
@Override
public void onSeekTo(long position) {
mLibVLC.setTime(position);
mTime.setText(Util.millisToString(position));
}
@Override
public long onWheelStart() {
showOverlay(3600000);
return mLibVLC.getTime();
}
@Override
public void onShowInfo(String info) {
if (info != null)
showInfo(info);
else {
hideInfo();
showOverlay();
}
}
};
/**
*
*/
......@@ -708,7 +733,7 @@ public class VideoPlayerActivity extends Activity {
* Android 3.0 and later
*/
private void dimStatusBar(boolean dim) {
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
if (dim) {
mSurface.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
} else {
......@@ -717,29 +742,12 @@ public class VideoPlayerActivity extends Activity {
}
}
private void updateOverlayPausePlay() {
if (mLibVLC == null) {
return;
}
if (mLibVLC.isPlaying()) {
mPlayPause.setBackgroundResource(R.drawable.ic_pause);
} else {
mPlayPause.setBackgroundResource(R.drawable.ic_play);
}
}
/**
* play or pause the media
*/
private void doPausePlay() {
if (mLibVLC.isPlaying()) {
pause();
} else {
play();
}
mControls.setState(mLibVLC.isPlaying());
}
/**
......
/*****************************************************************************
* IPlayerControl.java
*****************************************************************************
* Copyright © 2011-2012 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.interfaces;
public interface IPlayerControl {
void setState(boolean isPlaying);
void setOnPlayerControlListener(OnPlayerControlListener listener);
}
/*****************************************************************************
* OnPlayerControlListener.java
*****************************************************************************
* Copyright © 2012 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.interfaces;
public interface OnPlayerControlListener {
public abstract void onPlayPause();
public abstract long onWheelStart();
public abstract void onSeek(int delta);
public abstract void onSeekTo(long position);
public abstract void onShowInfo(String info);
}
/*****************************************************************************
* PlayerControlClassic.java
*****************************************************************************
* Copyright © 2012 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.widget;
import org.videolan.vlc.R;
import org.videolan.vlc.interfaces.IPlayerControl;
import org.videolan.vlc.interfaces.OnPlayerControlListener;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
public class PlayerControlClassic extends LinearLayout implements IPlayerControl {
private ImageButton mBackward;
private ImageButton mPlayPause;
private ImageButton mForward;
private OnPlayerControlListener listener = null;
public PlayerControlClassic(Context context) {
super(context);
LayoutInflater.from(context).inflate(R.layout.player_contol_classic, this, true);
mBackward = (ImageButton) findViewById(R.id.player_overlay_backward);
mBackward.setOnClickListener(mBackwardListener);
mPlayPause = (ImageButton) findViewById(R.id.player_overlay_play);
mPlayPause.setOnClickListener(mPlayPauseListener);
mForward = (ImageButton) findViewById(R.id.player_overlay_forward);
mForward.setOnClickListener(mForwardListener);
}
private OnClickListener mBackwardListener = new OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null)
listener.onSeek(-10000);
}
};
private OnClickListener mPlayPauseListener = new OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null)
listener.onPlayPause();
}
};
private OnClickListener mForwardListener = new OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null)
listener.onSeek(10000);
}
};
@Override
public void setState(boolean isPlaying) {
if (isPlaying) {
mPlayPause.setBackgroundResource(R.drawable.ic_pause);
} else {
mPlayPause.setBackgroundResource(R.drawable.ic_play);
}
}
@Override
public void setOnPlayerControlListener(OnPlayerControlListener listener) {
this.listener = listener;
}
}
/*****************************************************************************
* PlayerControlWheel.java
*****************************************************************************
* Copyright © 2012 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.widget;
import org.videolan.vlc.R;
import org.videolan.vlc.Util;
import org.videolan.vlc.interfaces.IPlayerControl;
import org.videolan.vlc.interfaces.OnPlayerControlListener;
import android.content.Context;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
public class PlayerControlWheel extends LinearLayout implements IPlayerControl {
private SeekBar mWheel;
private OnPlayerControlListener listener = null;
private static final int WHEEL_DEAD_ZONE = 7;
private static final int WHEEL_RANGE = 60;
private int mMiddle = 0;
private long mPosition = 0;
private long mSeekTo = -1;
public PlayerControlWheel(Context context) {
super(context);
LayoutInflater.from(context).inflate(R.layout.player_contol_wheel, this, true);
mWheel = (SeekBar) findViewById(R.id.player_overlay_wheelbar);
mWheel.setMax((WHEEL_DEAD_ZONE + WHEEL_RANGE) * 2);
mMiddle = WHEEL_DEAD_ZONE + WHEEL_RANGE;
mWheel.setProgress(mMiddle);
mWheel.setOnSeekBarChangeListener(mWheelListener);
}
private OnSeekBarChangeListener mWheelListener = new OnSeekBarChangeListener() {
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
mPosition = listener != null ? listener.onWheelStart() : 0;
mSeekTo = -1;
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
if (listener != null) {
// if in dead zone, pause/unpause
if (mSeekTo < 0)
listener.onPlayPause();
else
listener.onSeekTo(mSeekTo);
listener.onShowInfo(null);
}
seekBar.setProgress(mMiddle);
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (!fromUser)
return;
int delta = progress - mMiddle;
if (Math.abs(delta) >= WHEEL_DEAD_ZONE) {
delta -= Math.signum(delta) * WHEEL_DEAD_ZONE;
mSeekTo = Math.max(0, mPosition + delta * 1000);
}
else
delta = 0;
if (mSeekTo >= 0 && listener != null)
listener.onShowInfo(String.format("%s%ds (%s)", delta >= 0 ? "+" : "", delta, Util.millisToString(mSeekTo)));
}
};
@Override
public void setState(boolean isPlaying) {
if (isPlaying) {
mWheel.setThumb(getResources().getDrawable(R.drawable.wheel_pause));
} else {
mWheel.setThumb(getResources().getDrawable(R.drawable.wheel_play));
}
mWheel.setThumbOffset(0);
//force a refresh
mWheel.layout(mWheel.getLeft() - 1, mWheel.getTop(), mWheel.getRight(), mWheel.getBottom());
mWheel.layout(mWheel.getLeft() + 1, mWheel.getTop(), mWheel.getRight(), mWheel.getBottom());
}
@Override
public void setOnPlayerControlListener(OnPlayerControlListener listener) {
this.listener = listener;
}
}
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