[Android] add Sleep to audio

Sébastien Toque git at videolan.org
Sun Dec 30 19:30:25 CET 2012


vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Fri Dec 28 23:32:02 2012 +0100| [a4f563681d13b44796598eba6d3e4f8d90b2d82e] | committer: Sébastien Toque

add Sleep to audio

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=a4f563681d13b44796598eba6d3e4f8d90b2d82e
---

 vlc-android/res/layout-land/audio_player.xml       |   19 ++++++--------
 vlc-android/res/layout/audio_player.xml            |   22 ++++++-----------
 vlc-android/res/layout/audio_player_qvga.xml       |   18 ++++++--------
 vlc-android/src/org/videolan/vlc/AudioService.java |    8 ++++++
 .../vlc/gui/audio/AudioPlayerActivity.java         |   26 ++++++++++++++------
 5 files changed, 50 insertions(+), 43 deletions(-)

diff --git a/vlc-android/res/layout-land/audio_player.xml b/vlc-android/res/layout-land/audio_player.xml
index 4d77bd5..17df5dc 100644
--- a/vlc-android/res/layout-land/audio_player.xml
+++ b/vlc-android/res/layout-land/audio_player.xml
@@ -156,17 +156,14 @@
                 android:scaleType="fitXY"
                 android:src="@drawable/ic_repeat" />
 
-            <TextView
-                android:id="@+id/current_speed"
-                android:layout_width="60dip"
-                android:layout_height="40dip"
-                android:layout_marginBottom="10dip"
-                android:layout_marginTop="10dip"
-                android:clickable="true"
-                android:focusable="true"
-                android:onClick="onSpeedLabelClick"
-                android:text="@string/speed_placeholder"
-                android:textSize="24dp" />
+            <ImageButton
+                android:id="@+id/adv_function"
+                android:layout_width="35dp"
+                android:layout_height="35dp"
+                android:layout_marginTop="20dp"
+                android:layout_gravity="center"
+                android:onClick="showAdvanceFunction"
+                android:background="@drawable/dots" />
 
         </LinearLayout>
     </LinearLayout>
diff --git a/vlc-android/res/layout/audio_player.xml b/vlc-android/res/layout/audio_player.xml
index 9e14c30..0379ab9 100644
--- a/vlc-android/res/layout/audio_player.xml
+++ b/vlc-android/res/layout/audio_player.xml
@@ -60,19 +60,14 @@
                 android:focusable="true"
                 android:id="@+id/repeat"
                 android:onClick="onRepeatClick" />
-
-            <TextView
-                android:id="@+id/current_speed"
-                android:text="@string/speed_placeholder"
-                android:layout_height="60dip"
-                android:layout_width="60dip"
-                android:layout_marginTop="10dip"
-                android:textSize="24dp"
-                android:gravity="center"
-                android:clickable="true"
-                android:focusable="true"
-                android:onClick="onSpeedLabelClick" />
-
+            <ImageButton
+                android:id="@+id/adv_function"
+                android:layout_width="35dp"
+                android:layout_height="35dp"
+                android:layout_marginTop="20dp"
+                android:layout_gravity="center"
+                android:onClick="showAdvanceFunction"
+                android:background="@drawable/dots" />
         </LinearLayout>
     </LinearLayout>
     <FrameLayout
@@ -108,7 +103,6 @@
         android:progressDrawable="@drawable/po_seekbar"
         android:thumb="@drawable/ic_seekbar_thumb"
         android:focusable="true"
-        android:nextFocusUp="@+id/current_speed"
         android:paddingTop="5dip"
         android:paddingBottom="10dip"
         android:paddingLeft="15dip"
diff --git a/vlc-android/res/layout/audio_player_qvga.xml b/vlc-android/res/layout/audio_player_qvga.xml
index 136738c..5493248 100644
--- a/vlc-android/res/layout/audio_player_qvga.xml
+++ b/vlc-android/res/layout/audio_player_qvga.xml
@@ -55,16 +55,14 @@
                 android:layout_marginBottom="-5dip"
                 android:id="@+id/repeat"
                 android:onClick="onRepeatClick" />
-
-            <TextView
-                android:id="@+id/current_speed"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:clickable="true"
-                android:onClick="onSpeedLabelClick"
-                android:text="@string/speed_placeholder"
-                android:textSize="20dp" />
-
+            <ImageButton
+                android:id="@+id/adv_function"
+                android:layout_width="35dp"
+                android:layout_height="35dp"
+                android:layout_marginTop="20dp"
+                android:layout_gravity="center"
+                android:onClick="showAdvanceFunction"
+                android:background="@drawable/dots" />
         </LinearLayout>
     </LinearLayout>
     <LinearLayout
diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index 7716065..83b9991 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -146,6 +146,7 @@ public class AudioService extends Service {
         filter.addAction(ACTION_REMOTE_LAST_PLAYLIST);
         filter.addAction(Intent.ACTION_HEADSET_PLUG);
         filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
+        filter.addAction(VLCApplication.SLEEP_INTENT);
         registerReceiver(serviceReceiver, filter);
 
         final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
@@ -330,6 +331,13 @@ public class AudioService extends Service {
                         play();
                 }
             }
+
+            /*
+             * Sleep
+             */
+            if (action.equalsIgnoreCase(VLCApplication.SLEEP_INTENT)) {
+                stop();
+            }
         }
     };
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayerActivity.java
index 95b950f..04e3cd0 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayerActivity.java
@@ -25,8 +25,8 @@ import org.videolan.vlc.AudioServiceController;
 import org.videolan.vlc.R;
 import org.videolan.vlc.RepeatType;
 import org.videolan.vlc.Util;
+import org.videolan.vlc.gui.AdvFuncDialog;
 import org.videolan.vlc.gui.MainActivity;
-import org.videolan.vlc.gui.SpeedSelectorDialog;
 import org.videolan.vlc.interfaces.IAudioPlayer;
 
 import android.app.Activity;
@@ -55,13 +55,13 @@ public class AudioPlayerActivity extends Activity implements IAudioPlayer {
     private TextView mAlbum;
     private TextView mTime;
     private TextView mLength;
-    private TextView mSpeed;
     private ImageButton mPlayPause;
     private ImageButton mStop;
     private ImageButton mNext;
     private ImageButton mPrevious;
     private ImageButton mShuffle;
     private ImageButton mRepeat;
+    private ImageButton mAdvFunc;
     private SeekBar mTimeline;
 
     private AudioServiceController mAudioController;
@@ -69,6 +69,9 @@ public class AudioPlayerActivity extends Activity implements IAudioPlayer {
     private boolean mShowRemainingTime = false;
     private String lastTitle;
 
+    // Advance Function
+    private AdvFuncDialog mAdvFuncDialog;
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -86,13 +89,13 @@ public class AudioPlayerActivity extends Activity implements IAudioPlayer {
         mAlbum = (TextView) findViewById(R.id.album);
         mTime = (TextView) findViewById(R.id.time);
         mLength = (TextView) findViewById(R.id.length);
-        mSpeed = (TextView) findViewById(R.id.current_speed);
         mPlayPause = (ImageButton) findViewById(R.id.play_pause);
         mStop = (ImageButton) findViewById(R.id.stop);
         mNext = (ImageButton) findViewById(R.id.next);
         mPrevious = (ImageButton) findViewById(R.id.previous);
         mShuffle = (ImageButton) findViewById(R.id.shuffle);
         mRepeat = (ImageButton) findViewById(R.id.repeat);
+        mAdvFunc = (ImageButton) findViewById(R.id.adv_function);
         mTimeline = (SeekBar) findViewById(R.id.timeline);
 
         View.OnFocusChangeListener listener = new View.OnFocusChangeListener() {
@@ -104,9 +107,9 @@ public class AudioPlayerActivity extends Activity implements IAudioPlayer {
                     v.setBackgroundColor(Color.TRANSPARENT);
             }
         };
-        mSpeed.setOnFocusChangeListener(listener);
         mShuffle.setOnFocusChangeListener(listener);
         mRepeat.setOnFocusChangeListener(listener);
+        mAdvFunc.setOnFocusChangeListener(listener);
         mTimeline.setOnFocusChangeListener(listener);
         mPrevious.setOnFocusChangeListener(listener);
         mPlayPause.setOnFocusChangeListener(listener);
@@ -133,6 +136,13 @@ public class AudioPlayerActivity extends Activity implements IAudioPlayer {
         AudioServiceController.getInstance().unbindAudioService(this);
     }
 
+    @Override
+    protected void onStop() {
+        super.onStop();
+        if (mAdvFuncDialog != null)
+            mAdvFuncDialog.destroyAdvFuncDialog();
+    }
+
     public static void start(Context context) {
         start(context, false);
     }
@@ -223,7 +233,6 @@ public class AudioPlayerActivity extends Activity implements IAudioPlayer {
             mPrevious.setVisibility(ImageButton.VISIBLE);
         else
             mPrevious.setVisibility(ImageButton.INVISIBLE);
-        mSpeed.setText(Util.formatRateString(mAudioController.getRate()));
         mTimeline.setOnSeekBarChangeListener(mTimelineListner);
     }
 
@@ -319,8 +328,9 @@ public class AudioPlayerActivity extends Activity implements IAudioPlayer {
     	return super.onKeyDown(keyCode, event);
     }
 
-    public void onSpeedLabelClick(View view) {
-        new SpeedSelectorDialog(this).show();
-        update();
+    public void showAdvanceFunction(View v) {
+        if (mAdvFuncDialog == null)
+            mAdvFuncDialog = new AdvFuncDialog(this);
+        mAdvFuncDialog.show();
     }
 }



More information about the Android mailing list