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

Geoffrey Métais geoffrey.metais at gmail.com
Fri Apr 22 10:20:46 CEST 2016


Hi,

First, you can fix lua build:
git pull --rebase in vlc/directory then ./bootstrap

About your patch:
there is no need to handle key events, this is ok. The only thing we have
to do is to change the color of the focused item.

Selected background color should be Orange800.
So I recommend you to use
ContextCompat.getColor(VLCApplication.getAppContext(), R.color.orange800);
and
ContextCompat.getColor(VLCApplication.getAppContext(), R.color.transparent);
to get them.

You can set a OnFocusChangelistener to the itemView to update its
background color.

On Fri, Apr 22, 2016 at 9:24 AM Chegou Junior KEITA <chegoujk at gmail.com>
wrote:

> 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
>
> _______________________________________________
> Android mailing list
> Android at videolan.org
> https://mailman.videolan.org/listinfo/android
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/android/attachments/20160422/c6e2252e/attachment-0001.html>


More information about the Android mailing list