Bug 956075 - Add a custom view flipper to avoid Gingerbread bugs with touching ViewGroups. r=lucasr, a=sledru
authorWes Johnston <wjohnston@mozilla.com>
Tue, 28 Jan 2014 09:15:36 -0800
changeset 182690 f7b84245670d99e9ffb81d1a3467f90bdb74de3d
parent 182689 4a2daed7e4cd830c3d48e5169d3432c5cfb8c71d
child 182691 4eed11407e52053d7eef66d10892122e8e534d12
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr, sledru
bugs956075
milestone29.0a2
Bug 956075 - Add a custom view flipper to avoid Gingerbread bugs with touching ViewGroups. r=lucasr, a=sledru
mobile/android/base/moz.build
mobile/android/base/resources/layout/gecko_app.xml
mobile/android/base/widget/GeckoViewFlipper.java
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -357,16 +357,17 @@ gbjar.sources += [
     'widget/ClickableWhenDisabledEditText.java',
     'widget/DateTimePicker.java',
     'widget/Divider.java',
     'widget/DoorHanger.java',
     'widget/FaviconView.java',
     'widget/FlowLayout.java',
     'widget/GeckoActionProvider.java',
     'widget/GeckoPopupMenu.java',
+    'widget/GeckoViewFlipper.java',
     'widget/IconTabWidget.java',
     'widget/SquaredImageView.java',
     'widget/TabRow.java',
     'widget/ThumbnailView.java',
     'widget/TwoWayView.java',
     'ZoomConstraints.java',
 ]
 gbjar.sources += [ thirdparty_source_dir + f for f in [
--- a/mobile/android/base/resources/layout/gecko_app.xml
+++ b/mobile/android/base/resources/layout/gecko_app.xml
@@ -70,17 +70,17 @@
                      android:visibility="invisible"/>
 
         <!-- When focus is cleared from from BrowserToolbar's EditText to
              lower the virtual keyboard, focus will be returned to the root
              view. To make sure the EditText is not the first focusable view in
              the root view, BrowserToolbar should be specified as low in the
              view hierarchy as possible. -->
 
-        <ViewFlipper android:id="@id/browser_actionbar"
+        <org.mozilla.gecko.widget.GeckoViewFlipper android:id="@id/browser_actionbar"
                 android:layout_width="fill_parent"
                 android:layout_height="@dimen/browser_toolbar_height"
                 android:clickable="true"
                 android:focusable="true">
 
             <org.mozilla.gecko.toolbar.BrowserToolbar
                 android:id="@+id/browser_toolbar"
                 style="@style/BrowserToolbar"
@@ -90,17 +90,17 @@
                 android:focusable="true"
                 android:background="@drawable/url_bar_bg"/>
 
             <org.mozilla.gecko.ActionModeCompatView android:id="@+id/actionbar"
                                                     android:layout_height="fill_parent"
                                                     android:layout_width="fill_parent"
                                                     style="@style/GeckoActionBar"/>
 
-        </ViewFlipper>
+        </org.mozilla.gecko.widget.GeckoViewFlipper>
 
     </view>
 
     <LinearLayout android:id="@+id/toast"
                   style="@style/Toast">
 
         <TextView android:id="@+id/toast_message"
                   style="@style/ToastMessage" />
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/widget/GeckoViewFlipper.java
@@ -0,0 +1,47 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko.widget;
+
+import org.mozilla.gecko.animation.ViewHelper;
+
+import android.content.Context;
+import android.graphics.Rect;
+import android.os.Build;
+import android.view.MotionEvent;
+import android.widget.ViewFlipper;
+import android.util.Log;
+import android.util.AttributeSet;
+
+/* This extends the normal ViewFlipper only to fix bug 956075 on < 3.0 devices.
+ * i.e. It ignores touch events on the ViewFlipper when its hidden. */
+
+public class GeckoViewFlipper extends ViewFlipper {
+    private static final String LOGTAG = "GeckoViewFlipper";
+    private Rect mRect = new Rect();
+
+    public GeckoViewFlipper(Context context) {
+        super(context);
+    }
+
+    public GeckoViewFlipper(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    @Override
+    public boolean dispatchTouchEvent(MotionEvent ev) {
+        if (Build.VERSION.SDK_INT < 11) {
+            // Fix bug 956075. Don't allow touching this View if its hidden.
+            getHitRect(mRect);
+            mRect.offset((int) ViewHelper.getTranslationX(this), (int) ViewHelper.getTranslationY(this));
+
+            if (!mRect.contains((int) ev.getX(), (int) ev.getY())) {
+                return false;
+            }
+        }
+
+        return super.dispatchTouchEvent(ev);
+    }
+}