[Android] [PATCH 1/2] DPAD navigation in main video screen

Chegou Junior KEITA chegoujk at gmail.com
Fri Apr 22 09:23:56 CEST 2016


From: KEITA chegou junior <keita at informatique.univ-paris-diderot.fr>

---
 compile-libvlc.sh                                  |  4 +-
 .../videolan/vlc/gui/video/VideoGridFragment.java  |  1 +
 .../videolan/vlc/gui/video/VideoListAdapter.java   | 47 ++++++++++++++++++++++
 3 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/compile-libvlc.sh b/compile-libvlc.sh
index c32e086..417b516 100755
--- a/compile-libvlc.sh
+++ b/compile-libvlc.sh
@@ -70,7 +70,7 @@ VLC_BOOTSTRAP_ARGS="\
     --disable-dca \
     --disable-goom \
     --disable-chromaprint \
-    --enable-lua \
+    --disable-lua \
     --disable-schroedinger \
     --disable-sdl \
     --disable-SDL_image \
@@ -119,7 +119,7 @@ VLC_CONFIGURE_ARGS="\
     --disable-update-check \
     --disable-vlm \
     --disable-dbus \
-    --enable-lua \
+    --disable-lua \
     --disable-vcd \
     --disable-v4l2 \
     --disable-gnomevfs \
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
index 9cf6b83..5b66f0c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -37,6 +37,7 @@ import android.support.v7.widget.RecyclerView;
 import android.util.DisplayMetrics;
 import android.util.Log;
 import android.view.ContextMenu;
+import android.view.KeyEvent;
 import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuInflater;
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
index 4fe2880..bf534a7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -24,11 +24,13 @@ import android.content.Context;
 import android.databinding.DataBindingUtil;
 import android.databinding.ViewDataBinding;
 import android.graphics.Bitmap;
+import android.graphics.Color;
 import android.graphics.drawable.BitmapDrawable;
 import android.support.annotation.MainThread;
 import android.support.annotation.Nullable;
 import android.support.v4.util.ArrayMap;
 import android.support.v7.widget.RecyclerView;
+import android.view.KeyEvent;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -63,6 +65,8 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
     public final static int TYPE_LIST = 0;
     public final static int TYPE_GRID = 1;
 
+    private int mCurrentItem = 0;
+
     public final static int SORT_BY_DATE = 2;
     private int mSortDirection = 1;
     private int mSortBy = SORT_BY_TITLE;
@@ -90,6 +94,11 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
         MediaWrapper media = mVideos.get(position);
         boolean asyncLoad = true;
 
+        if (mCurrentItem == position)
+            holder.itemView.setBackgroundColor(Color.GRAY);
+        else
+            holder.itemView.setBackgroundColor(Color.TRANSPARENT);
+
         holder.binding.setVariable(BR.scaleType, ImageView.ScaleType.CENTER);
         final Bitmap bitmap = BitmapUtil.getPictureFromCache(media);
         if (bitmap != null) {
@@ -111,6 +120,43 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
             AsyncImageLoader.LoadImage(new VideoCoverFetcher(holder.binding, media), null);
     }
 
+    @Override
+    public void onAttachedToRecyclerView(final RecyclerView recyclerView) {
+        super.onAttachedToRecyclerView(recyclerView);
+
+        recyclerView.setOnKeyListener(new View.OnKeyListener() {
+            @Override
+            public boolean onKey(View v, int keyCode, KeyEvent event) {
+                RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
+
+                if (event.getAction() == KeyEvent.ACTION_DOWN) {
+                    if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT)
+                        return onItemSelection(layoutManager, 1);
+                    else if (keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_LEFT)
+                        return onItemSelection(layoutManager, -1);
+                    else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
+                        MediaWrapper media = mVideos.get(mCurrentItem);
+                        VideoPlayerActivity.start(v.getContext(), media.getUri(), media.getTitle());
+                        return true;
+                    }
+                }
+                return false;
+            }
+        });
+    }
+
+    private boolean onItemSelection(RecyclerView.LayoutManager layoutManager, int direction) {
+        int nextItem = mCurrentItem + direction;
+
+        if (nextItem >= 0 && nextItem < getItemCount()) {
+            notifyItemChanged(mCurrentItem);
+            mCurrentItem = nextItem;
+            notifyItemChanged(mCurrentItem);
+            return true;
+        }
+        return false;
+    }
+
     @MainThread
     public void setTimes(ArrayMap<String, Long> times) {
         boolean notify = false;
@@ -353,6 +399,7 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
         }
 
         public void onClick(View v){
+            mCurrentItem = getAdapterPosition();
             MediaWrapper media = mVideos.get(getAdapterPosition());
             if (media instanceof MediaGroup) {
                 MainActivity activity = (MainActivity) mFragment.getActivity();
-- 
1.9.1



More information about the Android mailing list