<div dir="ltr">Why don't you return <b>true</b> when the KeyEvent is handled?<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Oct 12, 2014 at 9:59 PM, Mik Amchislavsky <span dir="ltr"><<a href="mailto:hailmikhail@gmail.com" target="_blank">hailmikhail@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">---<br>
 .../vlc/gui/audio/AudioBrowserFragment.java        |   66 ++++++++++++++++++++<br>
 1 file changed, 66 insertions(+)<br>
<br>
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java<br>
index 187f5a0..1de9b56 100644<br>
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java<br>
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java<br>
@@ -64,6 +64,7 @@ import android.widget.ExpandableListView.ExpandableListContextMenuInfo;<br>
 import android.widget.ListView;<br>
 import android.widget.PopupMenu;<br>
 import android.widget.PopupMenu.OnMenuItemClickListener;<br>
+import android.view.KeyEvent;<br>
<br>
 public class AudioBrowserFragment extends Fragment {<br>
     public final static String TAG = "VLC/AudioBrowserFragment";<br>
@@ -128,6 +129,7 @@ public class AudioBrowserFragment extends Fragment {<br>
                 return true;<br>
             }<br>
         });<br>
+        mHeader.setOnKeyListener(keyListener);<br>
<br>
         mEmptyView = v.findViewById(R.id.no_media);<br>
<br>
@@ -146,6 +148,11 @@ public class AudioBrowserFragment extends Fragment {<br>
         albumList.setOnItemClickListener(albumListListener);<br>
         genreList.setOnItemClickListener(genreListListener);<br>
<br>
+        artistList.setOnKeyListener(keyListener);<br>
+        albumList.setOnKeyListener(keyListener);<br>
+        songsList.setOnKeyListener(keyListener);<br>
+        genreList.setOnKeyListener(keyListener);<br>
+<br>
         registerForContextMenu(songsList);<br>
         registerForContextMenu(artistList);<br>
         registerForContextMenu(albumList);<br>
@@ -170,6 +177,65 @@ public class AudioBrowserFragment extends Fragment {<br>
         mMediaLibrary.addUpdateHandler(mHandler);<br>
     }<br>
<br>
+    // Focus support. Start.<br>
+    View.OnKeyListener keyListener = new View.OnKeyListener() {<br>
+        @Override<br>
+        public boolean onKey(View v, int keyCode, KeyEvent event) {<br>
+<br>
+            /* Qualify key action to prevent redundant event<br>
+             * handling.<br>
+             *<br>
+             * ACTION_DOWN occurs before focus change and<br>
+             * may be used to find if change originated from the<br>
+             * header or if the header must be updated explicitely with<br>
+             * a call to mHeader.scroll(...).<br>
+             */<br>
+            if (event.getAction() == KeyEvent.ACTION_DOWN) {<br>
+                int newPosition = mFlingViewPosition;<br>
+<br>
+                switch (event.getKeyCode()) {<br>
+                    case KeyEvent.KEYCODE_DPAD_RIGHT:<br>
+                        if (newPosition < (MODE_TOTAL - 1))<br>
+                            newPosition++;<br>
+                        break;<br>
+                    case KeyEvent.KEYCODE_DPAD_LEFT:<br>
+                        if (newPosition > 0)<br>
+                            newPosition--;<br>
+                        break;<br>
+                    case KeyEvent.KEYCODE_DPAD_DOWN:<br>
+                        mFlingViewPosition = 0xFF;<br>
+                        break;<br>
+                    default:<br>
+                        return false;<br>
+                }<br>
+<br>
+                if (newPosition != mFlingViewPosition) {<br>
+                    int[] lists = { R.id.artists_list, R.id.albums_list,<br>
+                        R.id.songs_list, R.id.genres_list };<br>
+                    ListView vList = (ListView)v.getRootView().<br>
+                        findViewById(lists[newPosition]);<br>
+<br>
+                    if (!mHeader.isFocused())<br>
+                        mHeader.scroll(newPosition / 3.f);<br>
+<br>
+                    if (vList.getCount() == 0)<br>
+                        mHeader.setNextFocusDownId(R.id.header);<br>
+                    else<br>
+                        mHeader.setNextFocusDownId(lists[newPosition]);<br>
+<br>
+                    mFlingViewGroup.scrollTo(newPosition);<br>
+<br>
+                    // assigned in onSwitched following mHeader.scroll<br>
+                    mFlingViewPosition = newPosition;<br>
+                }<br>
+            }<br>
+<br>
+            // clean up with MainActivity<br>
+            return false;<br>
+        }<br>
+    };<br>
+    // Focus support. End.<br>
+<br>
     OnItemClickListener songListener = new OnItemClickListener() {<br>
         @Override<br>
         public void onItemClick(AdapterView<?> av, View v, int p, long id) {<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.9.5<br>
<br>
_______________________________________________<br>
Android mailing list<br>
<a href="mailto:Android@videolan.org">Android@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/android" target="_blank">https://mailman.videolan.org/listinfo/android</a><br>
</font></span></blockquote></div><br></div>