[Android] deterministic focus change following closeDrawer with forgotten import

Mik Amchislavsky git at videolan.org
Thu Oct 9 14:32:55 CEST 2014


vlc-ports/android | branch: tv | Mik Amchislavsky <hailmikhail at gmail.com> | Sun Oct  5 18:21:48 2014 -0700| [8b00b21432b662bb93decc4971754616765a376d] | committer: Geoffrey Métais

deterministic focus change following closeDrawer with forgotten import

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=8b00b21432b662bb93decc4971754616765a376d
---

 vlc-android/src/org/videolan/vlc/gui/MainActivity.java |   16 ++++++++++++++++
 1 file changed, 16 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..7d1321e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -90,6 +90,7 @@ import android.widget.ListView;
 import android.widget.ProgressBar;
 import android.widget.RelativeLayout;
 import android.widget.TextView;
+import android.view.KeyEvent;
 
 public class MainActivity extends ActionBarActivity {
     public final static String TAG = "VLC/MainActivity";
@@ -132,6 +133,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 +236,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 +272,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 +415,7 @@ public class MainActivity extends ActionBarActivity {
 
         mAudioController.removeAudioPlayer(mAudioPlayer);
         AudioServiceController.getInstance().unbindAudioService(this);
+        mFocusedPrior = 0;
     }
 
     @Override
@@ -431,6 +438,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 +695,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");



More information about the Android mailing list