[Android] DPAD navigation in AudioPlayer
Geoffrey Métais
git at videolan.org
Wed Jan 14 13:51:06 CET 2015
vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Jan 14 12:53:12 2015 +0100| [ce28d03bdc0b1bafc6afc202f3ebfab268bceece] | committer: Geoffrey Métais
DPAD navigation in AudioPlayer
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=ce28d03bdc0b1bafc6afc202f3ebfab268bceece
---
vlc-android/tv/res/layout/tv_audio_player.xml | 20 +++++++++++++----
.../gui/tv/audioplayer/AudioPlayerActivity.java | 23 ++++++++++++++------
.../vlc/gui/tv/audioplayer/PlaylistAdapter.java | 12 ++++++++--
3 files changed, 42 insertions(+), 13 deletions(-)
diff --git a/vlc-android/tv/res/layout/tv_audio_player.xml b/vlc-android/tv/res/layout/tv_audio_player.xml
index d6a74c4..8c6d584 100644
--- a/vlc-android/tv/res/layout/tv_audio_player.xml
+++ b/vlc-android/tv/res/layout/tv_audio_player.xml
@@ -26,7 +26,8 @@
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
- android:scrollbars="vertical" />
+ android:scrollbars="vertical"
+ android:nextFocusLeft="@+id/button_next" />
</LinearLayout>
<!-- Media HUD -->
@@ -80,7 +81,10 @@
android:layout_height="wrap_content"
android:src="@drawable/ic_previous"
android:clickable="true"
- android:onClick="onClick"/>
+ android:onClick="onClick"
+ android:nextFocusRight="@+id/button_play"
+ android:focusable="true"
+ android:focusableInTouchMode="true"/>
<ImageView
android:id="@+id/button_play"
android:layout_width="wrap_content"
@@ -89,14 +93,22 @@
android:layout_marginRight="10dp"
android:src="@drawable/ic_play"
android:clickable="true"
- android:onClick="onClick"/>
+ android:onClick="onClick"
+ android:nextFocusRight="@+id/button_next"
+ android:nextFocusLeft="@id/button_previous"
+ android:focusable="true"
+ android:focusableInTouchMode="true"/>
<ImageView
android:id="@+id/button_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_next"
android:clickable="true"
- android:onClick="onClick"/>
+ android:onClick="onClick"
+ android:nextFocusRight="@id/playlist"
+ android:nextFocusLeft="@id/button_play"
+ android:focusable="true"
+ android:focusableInTouchMode="true"/>
</LinearLayout>
</RelativeLayout>
diff --git a/vlc-android/tv/src/org/videolan/vlc/gui/tv/audioplayer/AudioPlayerActivity.java b/vlc-android/tv/src/org/videolan/vlc/gui/tv/audioplayer/AudioPlayerActivity.java
index f7ec307..04a1092 100644
--- a/vlc-android/tv/src/org/videolan/vlc/gui/tv/audioplayer/AudioPlayerActivity.java
+++ b/vlc-android/tv/src/org/videolan/vlc/gui/tv/audioplayer/AudioPlayerActivity.java
@@ -74,7 +74,7 @@ public class AudioPlayerActivity extends Activity implements AudioServiceControl
if (mLocations == null)
mLocations = new ArrayList<String>();
else {
- mAdapter = new PlaylistAdapter(mLocations);
+ mAdapter = new PlaylistAdapter(this, mLocations);
mRecyclerView.setAdapter(mAdapter);
}
@@ -119,7 +119,7 @@ public class AudioPlayerActivity extends Activity implements AudioServiceControl
} else {
mLocations = medialocations;
update();
- mAdapter = new PlaylistAdapter(mLocations);
+ mAdapter = new PlaylistAdapter(this, mLocations);
mRecyclerView.setAdapter(mAdapter);
}
}
@@ -160,7 +160,7 @@ public class AudioPlayerActivity extends Activity implements AudioServiceControl
case KeyEvent.KEYCODE_MEDIA_PLAY:
case KeyEvent.KEYCODE_MEDIA_PAUSE:
case KeyEvent.KEYCODE_SPACE:
- case KeyEvent.KEYCODE_BUTTON_A:
+ case KeyEvent.KEYCODE_BUTTON_B:
togglePlayPause();
return true;
case KeyEvent.KEYCODE_F:
@@ -178,19 +178,28 @@ public class AudioPlayerActivity extends Activity implements AudioServiceControl
*/
case KeyEvent.KEYCODE_DPAD_UP:
selectPrevious();
+ mRecyclerView.requestFocus();
return true;
case KeyEvent.KEYCODE_DPAD_DOWN:
selectNext();
+ mRecyclerView.requestFocus();
return true;
- case KeyEvent.KEYCODE_BUTTON_X:
- mAudioController.playIndex(mSelectedItem);
- mCurrentlyPlaying = mSelectedItem;
- return true;
+ case KeyEvent.KEYCODE_DPAD_CENTER:
+ if (mRecyclerView.hasFocus()) {
+ playSelection();
+ return true;
+ } else
+ return false;
default:
return super.onKeyDown(keyCode, event);
}
}
+ public void playSelection() {
+ mAudioController.playIndex(mSelectedItem);
+ mCurrentlyPlaying = mSelectedItem;
+ }
+
public boolean dispatchGenericMotionEvent(MotionEvent event){
InputDevice mInputDevice = event.getDevice();
diff --git a/vlc-android/tv/src/org/videolan/vlc/gui/tv/audioplayer/PlaylistAdapter.java b/vlc-android/tv/src/org/videolan/vlc/gui/tv/audioplayer/PlaylistAdapter.java
index 2832fb7..cb9013c 100644
--- a/vlc-android/tv/src/org/videolan/vlc/gui/tv/audioplayer/PlaylistAdapter.java
+++ b/vlc-android/tv/src/org/videolan/vlc/gui/tv/audioplayer/PlaylistAdapter.java
@@ -30,9 +30,10 @@ import org.videolan.vlc.MediaLibrary;
import java.util.ArrayList;
-public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHolder> {
+public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHolder> implements View.OnClickListener {
public static final String TAG = "VLC/PlaylistAdapter";
+ private AudioPlayerActivity mAudioPlayerActivity;
private ArrayList<String> mDataset;
private static MediaLibrary sMediaLibrary = MediaLibrary.getInstance();
private int mSelectedItem = -1;
@@ -49,8 +50,9 @@ public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHo
}
}
- public PlaylistAdapter(ArrayList<String> myDataset) {
+ public PlaylistAdapter(AudioPlayerActivity audioPlayerActivity, ArrayList<String> myDataset) {
mDataset = myDataset;
+ mAudioPlayerActivity = audioPlayerActivity;
}
@Override
@@ -72,6 +74,7 @@ public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHo
holder.mTitleTv.setText(media.getTitle());
holder.mArtistTv.setText(media.getArtist());
holder.itemView.setActivated(position == mSelectedItem);
+ holder.itemView.setOnClickListener(this);
}
@Override
@@ -87,4 +90,9 @@ public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHo
notifyItemChanged(previous);
notifyItemChanged(mSelectedItem);
}
+
+ @Override
+ public void onClick(View v){
+ mAudioPlayerActivity.playSelection();
+ }
}
\ No newline at end of file
More information about the Android
mailing list