Commit ce28d03b authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

DPAD navigation in AudioPlayer

parent 06fe7f5f
......@@ -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>
......
......@@ -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();
......
......@@ -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
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