[Android] [PATCH 3/3] ticket #11927 1a-c, 3b-c

Mik Amchislavsky hailmikhail at gmail.com
Sun Sep 7 14:33:27 CEST 2014


retry
On Sep 6, 2014 4:44 PM, "Mik Amchislavsky" <hailmikhail at gmail.com> wrote:

> Focus support
>
> Audio fragment focus change support.
>
>
> index 71605f4..c81444b 100644
> --- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
> +++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
> @@ -726,6 +726,30 @@ public class MainActivity extends ActionBarActivity {
>   public boolean onKeyUp(int keyCode, KeyEvent event) {
>   int id = getCurrentFocus().getId();
>
> + /* Scope reduction.
> + *
> + * Simplify logic by limiting mFlingViewGroup scrolling
> + * in AudioBrowserFragment to the header.
> + *
> + * In the future, remove this restriction and support scrolling.
> + */
> + if (mCurrentFragment.equals("audio")) {
> + if ((id == R.id.songs_list) ||
> + (id == R.id.genres_list) ||
> + (id == R.id.artists_list) ||
> + (id == R.id.albums_list))
> + mFocusedPrior = id;
> + else if (((mFocusedPrior == R.id.songs_list) ||
> + (mFocusedPrior == R.id.genres_list) ||
> + (mFocusedPrior == R.id.artists_list) ||
> + (mFocusedPrior == R.id.albums_list)) &&
> +   ((keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) ||
> + (keyCode == KeyEvent.KEYCODE_DPAD_LEFT))) {
> + findViewById(R.id.header).requestFocus();
> + return true;
> + }
> + }
> +
>   /* Menu-opening automation for Overlflow and Sliding
>   * menus.
>   *
>
> index 187f5a0..2734e25 100644
> --- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
> +++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
> @@ -65,6 +65,8 @@ 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";
>
> @@ -87,7 +89,9 @@ public class AudioBrowserFragment extends Fragment {
>      public final static int MODE_ALBUM = 1;
>      public final static int MODE_SONG = 2;
>      public final static int MODE_GENRE = 3;
> +
> + private ListView[] mLists;
> +
>      /* All subclasses of Fragment must include a public empty
> constructor. */
>      public AudioBrowserFragment() { }
>
> @@ -128,7 +132,8 @@ public class AudioBrowserFragment extends Fragment {
>                  return true;
>              }
>          });
>
> + mHeader.setOnKeyListener(keyListener);
> +
>          mEmptyView = v.findViewById(R.id.no_media);
>
>          ListView songsList = (ListView)v.findViewById(R.id.songs_list);
> @@ -146,6 +151,22 @@ public class AudioBrowserFragment extends Fragment {
>          albumList.setOnItemClickListener(albumListListener);
>          genreList.setOnItemClickListener(genreListListener);
>
> + /* Focus support.
> + *
> + * For convenience, create an array of ListViews to be
> + * used within event handlers.
> + *
> + * Set common properties associated with focus support.
> + */
> + mLists = new ListView[] {artistList, albumList, songsList, genreList};
> + {
> + int i;
> + for (i=0;i<MODE_TOTAL;i++) {
> + mLists[i].setOnKeyListener(keyListener);
> + mLists[i].setFocusable(false);
> + }
> + }
> +
>          registerForContextMenu(songsList);
>          registerForContextMenu(artistList);
>          registerForContextMenu(albumList);
> @@ -168,8 +189,51 @@ public class AudioBrowserFragment extends Fragment {
>          mHeader.scroll(mFlingViewPosition / 3.f);
>          updateLists();
>          mMediaLibrary.addUpdateHandler(mHandler);
> +        mLists[mFlingViewPosition].setFocusable(true);
>      }
>
> + // Focus support. Start.
> + View.OnKeyListener keyListener = new View.OnKeyListener() {
> + @Override
> + public boolean onKey(View v, int keyCode, KeyEvent event) {
> + int newPosition = mFlingViewPosition;
> +
> + if (event.getAction() != KeyEvent.ACTION_UP)
> + return false;
> +
> + /* Scope reduction.
> + * Simplify logic by limiting scrolling to the header.
> + */
> + if (!mHeader.isFocused())
> + return false;
> +
> + 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;
> + default:
> + return false;
> + }
> +
> + if (newPosition != mFlingViewPosition) {
> + mLists[newPosition].setFocusable(true);
> + mLists[mFlingViewPosition].setFocusable(false);
> + mFlingViewPosition = newPosition;
> + mFlingViewGroup.setPosition(mFlingViewPosition);
> + mFlingViewGroup.scrollTo(mFlingViewPosition);
> + }
> +
> +            // always return false so that MainActivity may clean up
> + return false;
> + }
> + };
> + // Focus support. End.
> +
>      OnItemClickListener songListener = new OnItemClickListener() {
>          @Override
>          public void onItemClick(AdapterView<?> av, View v, int p, long
> id) {
> @@ -334,6 +398,11 @@ public class AudioBrowserFragment extends Fragment {
>
>          @Override
>          public void onSwitched(int position) {
> + /* Focus support. Before changing to a new list, update
> + * focus of prior list and the new list.
> + */
> + mLists[mFlingViewPosition].setFocusable(false);
> + mLists[position].setFocusable(true);
>              mHeader.highlightTab(mFlingViewPosition, position);
>              mFlingViewPosition = position;
>          }
>
> index e576f51..90fd043 100644
> --- a/vlc-android/res/drawable/background_item.xml
> +++ b/vlc-android/res/drawable/background_item.xml
> @@ -1,5 +1,10 @@
>  <?xml version="1.0" encoding="utf-8"?>
>  <selector xmlns:android="http://schemas.android.com/apk/res/android">
> + <item android:state_focused="true" android:state_selected="false">
> + <shape android:shape="rectangle">
> + <solid android:color="@color/darkgrey" />
> + </shape>
> + </item>
>      <item android:state_focused="true" android:state_selected="false">
>          <shape android:shape="rectangle">
>              <solid android:color="@color/darkgrey" />
>
> index 68e70af..cf9d950 100644
> --- a/vlc-android/res/layout/audio_browser.xml
> +++ b/vlc-android/res/layout/audio_browser.xml
> @@ -12,8 +12,8 @@
>          android:scrollbars="none"
>          android:fadingEdge="none"
>          android:layout_width="fill_parent"
> -        android:background="?attr/background_header">
> + android:background="@drawable/background_header_item">
>          <LinearLayout
>              android:id="@+id/header_layout"
>              android:layout_width="wrap_content"
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/android/attachments/20140907/f841f4f8/attachment.html>


More information about the Android mailing list