[Android] Fix Down focus setting

Geoffrey Métais git at videolan.org
Mon Apr 11 15:45:12 CEST 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Apr 11 15:40:49 2016 +0200| [e9dc14054bb24392381dff3b24f37be2aedc6da2] | committer: Geoffrey Métais

Fix Down focus setting

Properly catch ActionBar icon and set its next focus ids

> https://code.videolan.org/videolan/vlc-android/commit/e9dc14054bb24392381dff3b24f37be2aedc6da2
---

 .../src/org/videolan/vlc/gui/MainActivity.java     | 97 +++++-----------------
 1 file changed, 21 insertions(+), 76 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 64c3ad3..1e3b348 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -58,6 +58,7 @@ import android.view.ViewGroup;
 import android.view.Window;
 import android.view.WindowManager;
 import android.widget.FilterQueryProvider;
+import android.widget.ImageButton;
 import android.widget.ProgressBar;
 import android.widget.TextView;
 
@@ -277,6 +278,7 @@ public class MainActivity extends AudioPlayerContainerActivity implements Filter
         super.onPostCreate(savedInstanceState);
         // Sync the toggle state after onRestoreInstanceState has occurred.
         mDrawerToggle.syncState();
+        setActionBarFocus();
     }
 
     @TargetApi(Build.VERSION_CODES.HONEYCOMB)
@@ -705,61 +707,26 @@ public class MainActivity extends AudioPlayerContainerActivity implements Filter
         }
     }
 
-    public void setMenuFocusDown(boolean idIsEmpty, int id) {
-        if (mMenu == null)
+    private void setActionBarFocus() {
+        View v = ((ViewGroup)findViewById(R.id.main_toolbar)).getChildAt(0);
+        if (v == null || ! (v instanceof ImageButton))
             return;
-        //Save menu items ids for focus control
-        final int[] menu_controls = new int[mMenu.size()+1];
-        for (int i = 0 ; i < mMenu.size() ; i++){
-            menu_controls[i] = mMenu.getItem(i).getItemId();
-        }
-        menu_controls[mMenu.size()] = mActionBarIconId;
-        /*menu_controls = new int[]{R.id.ml_menu_search,
-            R.id.ml_menu_open_mrl, R.id.ml_menu_sortby,
-            R.id.ml_menu_last_playlist, R.id.ml_menu_refresh,
-            mActionBarIconId};*/
-        int pane = mSlidingPane.getState();
-        for(int r : menu_controls) {
-            View v = findViewById(r);
-            if (v != null) {
-                if (!idIsEmpty)
-                    v.setNextFocusDownId(id);
-                else {
-                    if (pane ==  mSlidingPane.STATE_CLOSED) {
-                        v.setNextFocusDownId(R.id.play_pause);
-                    } else if (pane == mSlidingPane.STATE_OPENED) {
-                        v.setNextFocusDownId(R.id.header_play_pause);
-                    } else if (pane ==
-                            mSlidingPane.STATE_OPENED_ENTIRELY) {
-                        v.setNextFocusDownId(r);
-                    }
-                }
-            }
-        }
-    }
-
-    public void setSearchAsFocusDown(boolean idIsEmpty, View parentView, int id) {
-        View playPause = findViewById(R.id.header_play_pause);
-
-        if (!idIsEmpty) {
-            View list;
-            int pane = mSlidingPane.getState();
-
-            if (parentView == null)
-                list = findViewById(id);
-            else
-                list = parentView.findViewById(id);
-
-            if (list != null) {
-                if (pane == mSlidingPane.STATE_OPENED_ENTIRELY) {
-                    list.setNextFocusDownId(id);
-                } else if (pane == mSlidingPane.STATE_OPENED) {
-                    list.setNextFocusDownId(R.id.header_play_pause);
-                    playPause.setNextFocusUpId(id);
-                }
-            }
-        } else {
-            playPause.setNextFocusUpId(R.id.ml_menu_search);
+        if ((mActionBarIconId == -1) &&
+                (v.getId() == -1)  &&
+                (v.getNextFocusDownId() == -1) &&
+                (v.getNextFocusUpId() == -1) &&
+                (v.getNextFocusLeftId() == -1) &&
+                (v.getNextFocusRightId() == -1)) {
+            mActionBarIconId = UiTools.generateViewId();
+            v.setId(mActionBarIconId);
+            v.setNextFocusUpId(mActionBarIconId);
+            v.setNextFocusDownId(mActionBarIconId);
+            v.setNextFocusLeftId(mActionBarIconId);
+            v.setNextFocusRightId(R.id.ml_menu_search);
+            if (AndroidUtil.isHoneycombOrLater())
+                v.setNextFocusForwardId(mActionBarIconId);
+            if (findViewById(R.id.ml_menu_search) != null)
+                findViewById(R.id.ml_menu_search).setNextFocusLeftId(mActionBarIconId);
         }
     }
 
@@ -772,8 +739,6 @@ public class MainActivity extends AudioPlayerContainerActivity implements Filter
                 (Build.MANUFACTURER.compareTo("LGE") == 0)) {
             return true;
         }
-        if (mFocusedPrior == 0)
-            setMenuFocusDown(true, 0);
         if (getCurrentFocus() != null)
             mFocusedPrior = getCurrentFocus().getId();
         return super.onKeyDown(keyCode, event);
@@ -790,26 +755,6 @@ public class MainActivity extends AudioPlayerContainerActivity implements Filter
             openOptionsMenu();
             return true;
         }
-        View v = getCurrentFocus();
-        if (v == null)
-            return super.onKeyUp(keyCode, event);
-        if ((mActionBarIconId == -1) &&
-                (v.getId() == -1)  &&
-                (v.getNextFocusDownId() == -1) &&
-                (v.getNextFocusUpId() == -1) &&
-                (v.getNextFocusLeftId() == -1) &&
-                (v.getNextFocusRightId() == -1)) {
-            mActionBarIconId = UiTools.generateViewId();
-            v.setId(mActionBarIconId);
-            v.setNextFocusUpId(mActionBarIconId);
-            v.setNextFocusDownId(mActionBarIconId);
-            v.setNextFocusLeftId(mActionBarIconId);
-            v.setNextFocusRightId(R.id.ml_menu_search);
-            if (AndroidUtil.isHoneycombOrLater())
-                v.setNextFocusForwardId(mActionBarIconId);
-            if (findViewById(R.id.ml_menu_search) != null)
-                findViewById(R.id.ml_menu_search).setNextFocusLeftId(mActionBarIconId);
-        }
         return super.onKeyUp(keyCode, event);
     }
 



More information about the Android mailing list