Bug 1396076 - Part 3 - Switch to a LayoutChangeListener for setting up the delegates. r=jwu
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 07 Sep 2017 22:26:57 +0200
changeset 379805 60f7b76c8f7f7d3c00a2f7be03aebe23b90b3ae2
parent 379804 bc9e3b8c4100e8ea2a2f9d500a8decc3827cdec8
child 379806 e5e5c095a5eb86fea7ebe6aa28d566b794cf4c51
push id32463
push userarchaeopteryx@coole-files.de
push dateSat, 09 Sep 2017 09:43:48 +0000
treeherdermozilla-central@e0d88cd771d6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwu
bugs1396076
milestone57.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 1396076 - Part 3 - Switch to a LayoutChangeListener for setting up the delegates. r=jwu When the device is rotated between portrait and landscape mode (or vice versa), the View's final size is not yet available during the first OnPreDrawListener call for some of the TabsLayoutItemViews. It would be possible to skip the listener removal, so this is no longer used as a one-shot listener, however onPreDraw is frequently called even when the View's dimensions haven't changed. Therefore, we switch this to an OnLayoutChangeListener, which is more appropriate for what we need. MozReview-Commit-ID: 6JAzXdEBxbL
mobile/android/base/java/org/mozilla/gecko/tabs/TabsLayoutItemView.java
--- a/mobile/android/base/java/org/mozilla/gecko/tabs/TabsLayoutItemView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/tabs/TabsLayoutItemView.java
@@ -16,17 +16,16 @@ import android.content.Context;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.support.v4.widget.TextViewCompat;
 import android.support.v7.widget.ViewUtils;
 import android.util.AttributeSet;
 import android.util.TypedValue;
 import android.view.MotionEvent;
 import android.view.View;
-import android.view.ViewTreeObserver;
 import android.widget.Checkable;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
 public class TabsLayoutItemView extends LinearLayout
                                 implements Checkable {
     private static final String LOGTAG = "Gecko" + TabsLayoutItemView.class.getSimpleName();
@@ -99,31 +98,27 @@ public class TabsLayoutItemView extends 
         mThumbnail = (TabsPanelThumbnailView) findViewById(R.id.thumbnail);
         mCloseButton = (ImageView) findViewById(R.id.close);
         mThumbnailWrapper = (TabThumbnailWrapper) findViewById(R.id.wrapper);
 
         growCloseButtonHitArea();
     }
 
     private void growCloseButtonHitArea() {
-        getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
+        addOnLayoutChangeListener(new OnLayoutChangeListener() {
             @Override
-            public boolean onPreDraw() {
-                getViewTreeObserver().removeOnPreDrawListener(this);
-
+            public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                 // Ideally we want the close button hit area to be 40x40dp but we are constrained by the height of the parent, so
                 // we make it as tall as the parent view and 40dp across.
-                final int targetHitArea = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics());;
+                final int targetHitArea = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics());
 
                 final Rect hitRect = getHitRectRelatively(targetHitArea);
 
                 setTouchDelegate(new TouchDelegateWithReset(hitRect, mCloseButton));
                 setHoverDelegate(new HoverDelegateWithReset(hitRect, mCloseButton));
-
-                return true;
             }
         });
     }
 
     private Rect getHitRectRelatively(int targetHitArea) {
         final boolean isRtl = ViewUtils.isLayoutRtl(this);
         final Rect hitRect = new Rect();
         hitRect.top = 0;