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 379772 60f7b76c8f7f7d3c00a2f7be03aebe23b90b3ae2
parent 379771 bc9e3b8c4100e8ea2a2f9d500a8decc3827cdec8
child 379773 e5e5c095a5eb86fea7ebe6aa28d566b794cf4c51
push id50793
push usermozilla@buttercookie.de
push dateFri, 08 Sep 2017 18:08:22 +0000
treeherderautoland@e5e5c095a5eb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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
--- 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);
     private void growCloseButtonHitArea() {
-        getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
+        addOnLayoutChangeListener(new OnLayoutChangeListener() {
-            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;