[Android] [PATCH] deterministic focus change following closeDrawer

Mik Amchislavsky hailmikhail at gmail.com
Mon Oct 6 03:00:52 CEST 2014


---
 .../src/org/videolan/vlc/gui/MainActivity.java     |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 416ee52..9ee26c1 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -132,6 +132,7 @@ 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) {
@@ -234,6 +235,8 @@ public class MainActivity extends ActionBarActivity {
                 Fragment current = getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder);
 
                 if(current == null || (entry != null && current.getTag().equals(entry.id))) { /* Already selected */
+                    if (mFocusedPrior != 0)
+                        findViewById(R.id.ml_menu_search).requestFocus();
                     mRootContainer.closeDrawer(mListView);
                     return;
                 }
@@ -268,6 +271,8 @@ public class MainActivity extends ActionBarActivity {
                 if(current.getTag().equals("tracks"))
                     getFragment("audio").setUserVisibleHint(false);
 
+                if (mFocusedPrior != 0)
+                    findViewById(R.id.ml_menu_search).requestFocus();
                 mRootContainer.closeDrawer(mListView);
             }
         });
@@ -409,6 +414,7 @@ public class MainActivity extends ActionBarActivity {
 
         mAudioController.removeAudioPlayer(mAudioPlayer);
         AudioServiceController.getInstance().unbindAudioService(this);
+        mFocusedPrior = 0;
     }
 
     @Override
@@ -431,6 +437,8 @@ public class MainActivity extends ActionBarActivity {
     public void onBackPressed() {
         if(mRootContainer.isDrawerOpen(mListView)) {
             /* Close the menu first */
+            if (mFocusedPrior != 0)
+                findViewById(R.id.ml_menu_search).requestFocus();
             mRootContainer.closeDrawer(mListView);
             return;
         }
@@ -686,6 +694,13 @@ public class MainActivity extends ActionBarActivity {
         }
     }
 
+    // Note. 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);
+    }
+
     private void reloadPreferences() {
         SharedPreferences sharedPrefs = getSharedPreferences("MainActivity", MODE_PRIVATE);
         mCurrentFragment = sharedPrefs.getString("fragment", "video");
-- 
1.7.9.5



More information about the Android mailing list