[Android] [PATCH 2/2] AudioBrowserFragment: focus related functional improvements
Mik Amchislavsky
hailmikhail at gmail.com
Mon Oct 6 05:40:18 CEST 2014
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
index 187f5a0..d2c8c59 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -64,7 +64,8 @@ import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
-
+import android.view.KeyEvent;
public class AudioBrowserFragment extends Fragment {
public final static String TAG = "VLC/AudioBrowserFragment";
@@ -128,6 +129,7 @@ public class AudioBrowserFragment extends Fragment {
return true;
}
});
+ mHeader.setOnKeyListener(keyListener);
mEmptyView = v.findViewById(R.id.no_media);
@@ -146,6 +148,11 @@ public class AudioBrowserFragment extends Fragment {
albumList.setOnItemClickListener(albumListListener);
genreList.setOnItemClickListener(genreListListener);
+ artistList.setOnKeyListener(keyListener);
+ albumList.setOnKeyListener(keyListener);
+ songsList.setOnKeyListener(keyListener);
+ genreList.setOnKeyListener(keyListener);
+
registerForContextMenu(songsList);
registerForContextMenu(artistList);
registerForContextMenu(albumList);
@@ -170,6 +177,65 @@ public class AudioBrowserFragment extends Fragment {
mMediaLibrary.addUpdateHandler(mHandler);
}
+ // Focus support. Start.
+ View.OnKeyListener keyListener = new View.OnKeyListener() {
+ @Override
+ public boolean onKey(View v, int keyCode, KeyEvent event) {
+
+ /* Qualify key action to prevent redundant event
+ * handling.
+ *
+ * ACTION_DOWN occurs before focus change and
+ * may be used to find if change originated from the
+ * header or if the header must be updated explicitely with
+ * a call to mHeader.scroll(...).
+ */
+ if (event.getAction() == KeyEvent.ACTION_DOWN) {
+ int newPosition = mFlingViewPosition;
+
+ switch (event.getKeyCode()) {
+ case KeyEvent.KEYCODE_DPAD_RIGHT:
+ if (newPosition < (MODE_TOTAL - 1))
+ newPosition++;
+ break;
+ case KeyEvent.KEYCODE_DPAD_LEFT:
+ if (newPosition > 0)
+ newPosition--;
+ break;
+ case KeyEvent.KEYCODE_DPAD_DOWN:
+ mFlingViewPosition = 0xFF;
+ break;
+ default:
+ return false;
+ }
+
+ if (newPosition != mFlingViewPosition) {
+ int[] lists = { R.id.artists_list, R.id.albums_list,
+ R.id.songs_list, R.id.genres_list };
+ ListView vList = (ListView)v.getRootView().
+ findViewById(lists[newPosition]);
+
+ if (!mHeader.isFocused())
+ mHeader.scroll(newPosition / 3.f);
+
+ if (vList.getCount() == 0)
+ mHeader.setNextFocusDownId(R.id.header);
+ else
+ mHeader.setNextFocusDownId(lists[newPosition]);
+
+ mFlingViewGroup.scrollTo(newPosition);
+
+ // assigned in onSwitched following mHeader.scroll
+ mFlingViewPosition = newPosition;
+ }
+ }
+
+ // clean up with MainActivity
+ return false;
+ }
+ };
+ // Focus support. End.
+
OnItemClickListener songListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> av, View v, int p, long id) {
--
1.7.9.5
More information about the Android
mailing list