[Android] Focus on item in main video screen

Chegou Junior KEITA git at videolan.org
Wed Apr 27 16:43:29 CEST 2016


vlc-android | branch: master | Chegou Junior KEITA <chegoujk at gmail.com> | Wed Apr 27 16:36:27 2016 +0200| [f0926eee2dd0c76be8c9c57d3488a35a174294fd] | committer: Geoffrey Métais

Focus on item in main video screen

Signed-off-by: Geoffrey Métais <geoffrey.metais at gmail.com>

> https://code.videolan.org/videolan/vlc-android/commit/f0926eee2dd0c76be8c9c57d3488a35a174294fd
---

 vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java    |  4 ++++
 .../src/org/videolan/vlc/gui/video/VideoListAdapter.java     | 12 +++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
index 6c59146..52e2aa2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
@@ -34,6 +34,7 @@ import android.preference.PreferenceManager;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.design.widget.Snackbar;
+import android.support.v4.content.ContextCompat;
 import android.text.Html;
 import android.text.TextUtils;
 import android.util.DisplayMetrics;
@@ -55,6 +56,9 @@ import java.util.concurrent.atomic.AtomicInteger;
 
 public class UiTools {
 
+    public static final int ITEM_FOCUS_ON = ContextCompat.getColor(VLCApplication.getAppContext(), R.color.orange800);
+    public static final int ITEM_FOCUS_OFF = ContextCompat.getColor(VLCApplication.getAppContext(), R.color.transparent);
+
     private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
 
     private static final Handler sHandler = new Handler(Looper.getMainLooper());
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 76f2510..731482c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -37,6 +37,7 @@ import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.MainActivity;
 import org.videolan.vlc.gui.SecondaryActivity;
+import org.videolan.vlc.gui.helpers.UiTools;
 import org.videolan.vlc.media.MediaGroup;
 import org.videolan.vlc.media.MediaWrapper;
 import org.videolan.vlc.util.Strings;
@@ -294,7 +295,7 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
         return super.getItemViewType(position);
     }
 
-    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener {
+    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener, View.OnFocusChangeListener {
         boolean listmode;
         public ViewDataBinding binding;
 
@@ -304,6 +305,7 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
             this.listmode = listMode;
             binding.setVariable(BR.holder, this);
             itemView.setOnLongClickListener(this);
+            itemView.setOnFocusChangeListener(this);
         }
 
         public void onClick(View v){
@@ -330,5 +332,13 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
             mFragment.mGridView.openContextMenu(getLayoutPosition());
             return true;
         }
+
+        @Override
+        public void onFocusChange(View v, boolean hasFocus) {
+            if (hasFocus)
+                itemView.setBackgroundColor(UiTools.ITEM_FOCUS_ON);
+            else
+                itemView.setBackgroundColor(UiTools.ITEM_FOCUS_OFF);
+        }
     }
 }



More information about the Android mailing list