[Android] AudioPlayerActivity: implement focus navigation

Edward Wang git at videolan.org
Sun Nov 4 15:18:35 CET 2012


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Sun Nov  4 08:52:57 2012 -0500| [3ad23a9e41eeacde3dd3528203a097e0be45b9ef] | committer: Edward Wang

AudioPlayerActivity: implement focus navigation

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

 vlc-android/res/layout/audio_player.xml            |   13 ++++++++++++
 .../vlc/gui/audio/AudioPlayerActivity.java         |   22 ++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/vlc-android/res/layout/audio_player.xml b/vlc-android/res/layout/audio_player.xml
index e578148..9e14c30 100644
--- a/vlc-android/res/layout/audio_player.xml
+++ b/vlc-android/res/layout/audio_player.xml
@@ -29,6 +29,7 @@
             android:background="#00ffffff"
             android:layout_marginLeft="15dip"
             android:layout_marginTop="15dip"
+            android:focusable="false"
             android:id="@+id/cover" />
         <LinearLayout
             android:layout_width="90dip"
@@ -44,6 +45,7 @@
                 android:layout_width="60dip"
                 android:layout_marginBottom="10dip"
                 android:contentDescription="@string/shuffle"
+                android:focusable="true"
                 android:id="@+id/shuffle"
                 android:onClick="onShuffleClick" />
             <ImageButton
@@ -55,6 +57,7 @@
                 android:layout_width="60dip"
                 android:layout_marginTop="10dip"
                 android:contentDescription="@string/repeat"
+                android:focusable="true"
                 android:id="@+id/repeat"
                 android:onClick="onRepeatClick" />
 
@@ -67,6 +70,7 @@
                 android:textSize="24dp"
                 android:gravity="center"
                 android:clickable="true"
+                android:focusable="true"
                 android:onClick="onSpeedLabelClick" />
 
         </LinearLayout>
@@ -103,6 +107,8 @@
         android:maxHeight="4dip"
         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"
@@ -122,6 +128,7 @@
         android:layout_marginBottom="4dip"
         android:id="@+id/title"
         android:clickable="true"
+        android:focusable="false"
         android:onClick="onTextClick" />
     <TextView
         android:layout_width="fill_parent"
@@ -137,6 +144,7 @@
         android:layout_marginBottom="4dip"
         android:id="@+id/artist"
         android:clickable="true"
+        android:focusable="false"
         android:onClick="onTextClick" />
     <TextView
         android:layout_width="fill_parent"
@@ -151,6 +159,7 @@
         android:ellipsize="marquee"
         android:id="@+id/album"
         android:clickable="true"
+        android:focusable="false"
         android:onClick="onTextClick" />
     <LinearLayout
         android:layout_width="fill_parent"
@@ -163,6 +172,7 @@
             android:layout_width="70dip"
             android:layout_height="70dip"
             android:background="#00000000"
+            android:focusable="true"
             android:contentDescription="@string/previous"
             android:onClick="onPreviousClick"
             android:scaleType="fitXY"
@@ -175,6 +185,7 @@
             android:layout_marginLeft="10dip"
             android:layout_marginRight="10dip"
             android:background="#00000000"
+            android:focusable="true"
             android:contentDescription="@string/pause"
             android:onClick="onPlayPauseClick"
             android:scaleType="fitXY"
@@ -187,6 +198,7 @@
             android:layout_marginLeft="10dip"
             android:layout_marginRight="10dip"
             android:background="#00000000"
+            android:focusable="true"
             android:contentDescription="@string/stop"
             android:onClick="onStopClick"
             android:scaleType="fitXY"
@@ -197,6 +209,7 @@
             android:layout_width="70dip"
             android:layout_height="70dip"
             android:background="#00000000"
+            android:focusable="true"
             android:contentDescription="@string/next"
             android:onClick="onNextClick"
             android:scaleType="fitXY"
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 b611d95..ebfc0ea 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayerActivity.java
@@ -29,10 +29,13 @@ import org.videolan.vlc.gui.MainActivity;
 import org.videolan.vlc.gui.SpeedSelectorDialog;
 import org.videolan.vlc.interfaces.IAudioPlayer;
 
+import com.actionbarsherlock.R.color;
+
 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
 import android.graphics.Bitmap;
+import android.graphics.Color;
 import android.media.AudioManager;
 import android.os.Bundle;
 import android.util.DisplayMetrics;
@@ -56,6 +59,7 @@ public class AudioPlayerActivity extends Activity implements IAudioPlayer {
     private TextView mLength;
     private TextView mSpeed;
     private ImageButton mPlayPause;
+    private ImageButton mStop;
     private ImageButton mNext;
     private ImageButton mPrevious;
     private ImageButton mShuffle;
@@ -86,12 +90,30 @@ public class AudioPlayerActivity extends Activity implements IAudioPlayer {
         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);
         mTimeline = (SeekBar) findViewById(R.id.timeline);
 
+        View.OnFocusChangeListener listener = new View.OnFocusChangeListener() {
+            public void onFocusChange(View v, boolean hasFocus) {
+                if(hasFocus)
+                    v.setBackgroundColor(Color.parseColor("#FFBA6F"));
+                else
+                    v.setBackgroundColor(Color.TRANSPARENT);
+            }
+        };
+        mSpeed.setOnFocusChangeListener(listener);
+        mShuffle.setOnFocusChangeListener(listener);
+        mRepeat.setOnFocusChangeListener(listener);
+        mTimeline.setOnFocusChangeListener(listener);
+        mPrevious.setOnFocusChangeListener(listener);
+        mPlayPause.setOnFocusChangeListener(listener);
+        mStop.setOnFocusChangeListener(listener);
+        mNext.setOnFocusChangeListener(listener);
+
         this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
 
         mAudioController = AudioServiceController.getInstance();



More information about the Android mailing list