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

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


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

> Focus support.
>
> Menu-opening automation for Overflow and Sliding menus.
> Menu-closing automation for Overflow menus.
> Temporary solution to avoid focus of invisible items.
>
> index 362f2f7..71605f4 100644
> --- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
> +++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
> @@ -93,6 +93,8 @@ import android.widget.TextView;
>
>  import com.slidingmenu.lib.SlidingMenu;
>
> +import android.view.KeyEvent;
> +
>  public class MainActivity extends ActionBarActivity {
>      public final static String TAG = "VLC/MainActivity";
>
> @@ -133,7 +135,8 @@ public class MainActivity extends ActionBarActivity {
>      private boolean mScanNeeded = true;
>
>      private Handler mHandler = new MainActivityHandler(this);
>
> + private int mFocusedPrior = 0;
> +
>      @Override
>      protected void onCreate(Bundle savedInstanceState) {
>          if (!LibVlcUtil.hasCompatibleCPU(this)) {
> @@ -580,6 +583,18 @@ public class MainActivity extends ActionBarActivity {
>          // Enable the clear search history function for the search
> fragment.
>          if (mCurrentFragment != null && mCurrentFragment.equals("search"))
>              menu.findItem(R.id.search_clear_history).setVisible(true);
> +
> + /* Focus support. Provide menu-closing automation for Overlflow
> + * and Sortby menues
> + */
> + if (mFocusedPrior != R.id.ml_menu_refresh) {
> + menu.findItem(R.id.ml_close_options).setVisible(false);
> + menu.findItem(R.id.ml_close_sortby).setVisible(false);
> + } else {
> + menu.findItem(R.id.ml_close_options).setVisible(true);
> + menu.findItem(R.id.ml_close_sortby).setVisible(true);
> + }
> +
>          return true;
>      }
>
> @@ -673,6 +688,13 @@ public class MainActivity extends ActionBarActivity {
>              case R.id.search_clear_history:
>                  MediaDatabase.getInstance().clearSearchHistory();
>                  break;
> +            /* Focus support. Menu-closing automation
> +             */
> + case R.id.ml_close_options:
> + case R.id.ml_close_sortby:
> + closeOptionsMenu();
> + findViewById(R.id.ml_menu_refresh).requestFocus();
> + break;
>          }
>          return super.onOptionsItemSelected(item);
>      }
> @@ -691,6 +713,83 @@ public class MainActivity extends ActionBarActivity {
>          }
>      }
>
> + /* Focus support. Start. */
> +
> + // onKeyDown will not occur while moving within a list
> + @Override
> + public boolean onKeyDown(int keyCode, KeyEvent event) {
> + mFocusedPrior = getCurrentFocus().getId();
> + return super .onKeyDown(keyCode, event);
> + }
> +
> + @Override
> + public boolean onKeyUp(int keyCode, KeyEvent event) {
> + int id = getCurrentFocus().getId();
> +
> + /* Menu-opening automation for Overlflow and Sliding
> + * menus.
> + *
> + * R.id of -1 matches Overflow and App Icon. The two may be
> + * distinguished by the prior ID. Overflow menu resides next to
> + * ml_menu_refresh.
> + */
> + if  (id == -1) {
> + if (mFocusedPrior == R.id.ml_menu_refresh) {
> + openOptionsMenu();
> + } else {
> + if (mMenu.isMenuShowing() == false) {
> + mMenu.showMenu();
> + View myView = mMenu.getMenu();
> + myView.scrollTo(0,0);
> + myView.requestFocus();
> + }
> + }
> + return true;
> + }
> +
> + /* Menu-closing automation.
> + *
> + * While navigating a single list, onKeyDown doesn't fire but,
> + * onKeyUp continues to occur. In the event mFocusedPrior equals
> + * R.id.list, the user navigated from one list to another.
> + */
> + if (((mFocusedPrior == android.R.id.list) ||
> +     (id != android.R.id.list)) &&
> +    (mFocusedPrior != -1) &&
> +    (mFocusedPrior != ml_menu_search) &&
> +    (mMenu.isMenuShowing())) {
> + mMenu.showContent();
> + return true;
> + }
> +
> + /* Scope reduction.
> + *
> + * Through hard codign, the following will force focus to a
> + * visible control in the event focus reaches an invisible
> + * control.
> + *
> + * In the future, focusable property must be managed in
> + * tandem with the visible property.
> + */
> + if ((id == R.id.play_pause) ||
> + (id == R.id.repeat) ||
> + (id == R.id.shuffle) ||
> + (id == R.id.header_play_pause) ||
> + (id == R.id.timeline) ||
> + (id == R.id.next)) {
> +
> + if (mSlidingPane.getState() == mSlidingPane.STATE_OPENED_ENTIRELY)
> + findViewById(R.id.ml_menu_search).requestFocus();
> + else
> + findViewById(R.id.play_pause).requestFocus();
> +
> + return true;
> + }
> +
> + return  super .onKeyUp(keyCode, event);
> + }
> + /* Focus support. End. */
> +
>      private void reloadPreferences() {
>          SharedPreferences sharedPrefs =
> getSharedPreferences("MainActivity", MODE_PRIVATE);
>          mCurrentFragment = sharedPrefs.getString("fragment", "video");
>
> index 856e35a..7a9938a 100644
> --- a/vlc-android/res/menu-v10/media_library.xml
> +++ b/vlc-android/res/menu-v10/media_library.xml
> @@ -23,6 +23,10 @@
>              <item
>                  android:id="@+id/ml_menu_sortby_length"
>                  android:title="@string/sortby_length" />
> + <item
> + android:id="@+id/ml_close_sortby"
> + android:icon="@drawable/dots"
> + android:title="@string/exit_menu" />
>          </menu>
>      </item>
>      <item
> @@ -52,4 +56,8 @@
>          android:visible="false"
>          android:icon="@android:drawable/ic_menu_close_clear_cancel"
>          android:id="@+id/search_clear_history" />
> + <item
> + android:id="@+id/ml_close_options"
> + android:icon="@drawable/dots"
> + android:title="@string/exit_menu" />
>  </menu>
>
> index 2c434b0..02b4959 100644
> --- a/vlc-android/res/menu-v13/media_library.xml
> +++ b/vlc-android/res/menu-v13/media_library.xml
> @@ -23,6 +23,10 @@
>              <item
>                  android:id="@+id/ml_menu_sortby_length"
>                  android:title="@string/sortby_length" />
> + <item
> + android:id="@+id/ml_close_sortby"
> + android:icon="@drawable/dots"
> + android:title="@string/exit_menu" />
>          </menu>
>      </item>
>      <item
> @@ -52,4 +56,8 @@
>          android:visible="false"
>          android:icon="@android:drawable/ic_menu_close_clear_cancel"
>          android:id="@+id/search_clear_history" />
> + <item
> + android:id="@+id/ml_close_options"
> + android:icon="@drawable/dots"
> + android:title="@string/exit_menu" />
>  </menu>
>
> index 856e35a..7a9938a 100644
> --- a/vlc-android/res/menu-v7/media_library.xml
> +++ b/vlc-android/res/menu-v7/media_library.xml
> @@ -23,6 +23,10 @@
>              <item
>                  android:id="@+id/ml_menu_sortby_length"
>                  android:title="@string/sortby_length" />
> + <item
> + android:id="@+id/ml_close_sortby"
> + android:icon="@drawable/dots"
> + android:title="@string/exit_menu" />
>          </menu>
>      </item>
>      <item
> @@ -52,4 +56,8 @@
>          android:visible="false"
>          android:icon="@android:drawable/ic_menu_close_clear_cancel"
>          android:id="@+id/search_clear_history" />
> + <item
> + android:id="@+id/ml_close_options"
> + android:icon="@drawable/dots"
> + android:title="@string/exit_menu" />
>  </menu>
>
> index d9a2a11..4d1d7dc 100644
> --- a/vlc-android/res/values/strings.xml
> +++ b/vlc-android/res/values/strings.xml
> @@ -106,6 +106,7 @@
>      <string name="thumbnail">Thumbnail</string>
>      <string name="unseekable_stream">Unseekable stream</string>
>      <string name="refresh">Refresh</string>
> + <string name="exit_menu">Return</string>
>      <string name="track_audio">Audio track</string>
>      <string name="track_video">Video track</string>
>      <string name="track_text">Subtitles track</string>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/android/attachments/20140907/615c1217/attachment-0001.html>


More information about the Android mailing list