Bug 924480 - Part 1.5: Make HomePager focusable. r=lucasr
☠☠ backed out by 7b8e9988e6c7 ☠ ☠
authorMichael Comella <michael.l.comella@gmail.com>
Mon, 28 Oct 2013 12:06:25 -0700
changeset 152639 1c70214e37d0ad3f943f88b9e5e337bca0ed0ede
parent 152638 36eded3813d64b17d2490bcf1652655e00dd9c4e
child 152640 29fb758db4021e05879846601687e4bc1851e777
push id35608
push useremorley@mozilla.com
push dateTue, 29 Oct 2013 16:36:07 +0000
treeherdermozilla-inbound@936a5d4b340d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs924480
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 924480 - Part 1.5: Make HomePager focusable. r=lucasr
mobile/android/base/home/HomePager.java
--- a/mobile/android/base/home/HomePager.java
+++ b/mobile/android/base/home/HomePager.java
@@ -91,16 +91,23 @@ public class HomePager extends ViewPager
 
     public HomePager(Context context, AttributeSet attrs) {
         super(context, attrs);
         mContext = context;
 
         // This is to keep all 4 pages in memory after they are
         // selected in the pager.
         setOffscreenPageLimit(3);
+
+        //  We can call HomePager.requestFocus to steal focus from the URL bar and drop the soft
+        //  keyboard. However, if there are no focusable views (e.g. an empty reading list), the
+        //  URL bar will be refocused. Therefore, we make the HomePager container focusable to
+        //  ensure there is always a focusable view. This would ordinarily be done via an XML
+        //  attribute, but it is not working properly.
+        setFocusableInTouchMode(true);
     }
 
     @Override
     public void addView(View child, int index, ViewGroup.LayoutParams params) {
         if (child instanceof Decor) {
             ((ViewPager.LayoutParams) params).isDecor = true;
             mDecor = (Decor) child;
             setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@@ -319,18 +326,15 @@ public class HomePager extends ViewPager
                 homePage.setCanLoadHint(canLoadHint);
             }
         }
     }
 
     @Override
     public boolean onInterceptTouchEvent(MotionEvent event) {
         if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
-            // XXX: Drop the soft keyboard by stealing focus. Note that the HomePager (via XML
-            // attr) is focusable after its descendants allowing requestFocus to succeed and drop
-            // the soft keyboard even if there are no other focusable views on the screen (e.g.
-            // the Reading List is empty).
+            // Drop the soft keyboard by stealing focus from the URL bar.
             requestFocus();
         }
 
         return super.onInterceptTouchEvent(event);
     }
 }