[Android] [PATCH] AudioBrowserFragment: focus related functional improvement
Geoffrey Métais
geoffrey.metais at gmail.com
Tue Oct 14 12:15:12 CEST 2014
Why don't you return *true* when the KeyEvent is handled?
On Sun, Oct 12, 2014 at 9:59 PM, Mik Amchislavsky <hailmikhail at gmail.com>
wrote:
> ---
> .../vlc/gui/audio/AudioBrowserFragment.java | 66
> ++++++++++++++++++++
> 1 file changed, 66 insertions(+)
>
> 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..1de9b56 100644
> --- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
> +++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
> @@ -64,6 +64,7 @@ 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
>
> _______________________________________________
> 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/20141014/b962d769/attachment.html>
More information about the Android
mailing list