Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ff638120 authored by Matthew Ng's avatar Matthew Ng
Browse files

Prevent nav bar from laying out dimensions of previous orientation

Layout changes occurred on "onSizeChanged" caused many issues related to
laying out children in the correct orientation. For example, rotation
from landscape to portrait sometimes uses landscape dimensions. Correct
usage is to apply changes in onMeasure to determine if the navigation
bar is vertical or not.

Test: manual
Fixes: 127092591
Change-Id: Ia63165a444d1255c6f69e47ac54015f51b2a1777
parent f80f50d9
Loading
Loading
Loading
Loading
+8 −65
Original line number Diff line number Diff line
@@ -50,8 +50,6 @@ import android.graphics.Rect;
import android.graphics.Region;
import android.graphics.Region.Op;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.util.AttributeSet;
@@ -150,10 +148,6 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
    private final NavigationBarTransitions mBarTransitions;
    private final OverviewProxyService mOverviewProxyService;

    // workaround for LayoutTransitions leaving the nav buttons in a weird state (bug 5549288)
    final static boolean WORKAROUND_INVALID_LAYOUT = true;
    final static int MSG_CHECK_INVALID_LAYOUT = 8686;

    // performs manual animation in sync with layout transitions
    private final NavTransitionListener mTransitionListener = new NavTransitionListener();

@@ -261,29 +255,6 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
        }
    };

    private class H extends Handler {
        public void handleMessage(Message m) {
            switch (m.what) {
                case MSG_CHECK_INVALID_LAYOUT:
                    final String how = "" + m.obj;
                    final int w = getWidth();
                    final int h = getHeight();
                    final int vw = getCurrentView().getWidth();
                    final int vh = getCurrentView().getHeight();

                    if (h != vh || w != vw) {
                        Log.w(TAG, String.format(
                            "*** Invalid layout in navigation bar (%s this=%dx%d cur=%dx%d)",
                            how, w, h, vw, vh));
                        if (WORKAROUND_INVALID_LAYOUT) {
                            requestLayout();
                        }
                    }
                    break;
            }
        }
    }

    private final AccessibilityDelegate mQuickStepAccessibilityDelegate
            = new AccessibilityDelegate() {
        private AccessibilityAction mToggleOverviewAction;
@@ -451,7 +422,7 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
                mQuickScrubAction, null /* swipeLeftEdgeAction */, null /* swipeRightEdgeAction */
        };

        mPrototypeController = new NavigationPrototypeController(mHandler, mContext);
        mPrototypeController = new NavigationPrototypeController(mContext);
        mPrototypeController.register();
        mPrototypeController.setOnPrototypeChangedListener(mPrototypeListener);
        mColorAdaptionController = new NavBarTintController(this, getLightTransitionsController());
@@ -598,8 +569,6 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
        getHomeButton().abortCurrentGesture();
    }

    private H mHandler = new H();

    public View getCurrentView() {
        return mCurrentView;
    }
@@ -1200,23 +1169,23 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int w = MeasureSpec.getSize(widthMeasureSpec);
        int h = MeasureSpec.getSize(heightMeasureSpec);
        if (DEBUG) Log.d(TAG, String.format(
                    "onSizeChanged: (%dx%d) old: (%dx%d)", w, h, oldw, oldh));
                "onMeasure: (%dx%d) old: (%dx%d)", w, h, getMeasuredWidth(), getMeasuredHeight()));

        final boolean newVertical = w > 0 && h > w;
        if (newVertical != mIsVertical) {
            mIsVertical = newVertical;
            if (DEBUG) {
                Log.d(TAG, String.format("onSizeChanged: h=%d, w=%d, vert=%s", h, w,
                Log.d(TAG, String.format("onMeasure: h=%d, w=%d, vert=%s", h, w,
                        mIsVertical ? "y" : "n"));
            }
            reorient();
            notifyVerticalChangedListener(newVertical);
        }

        postCheckForInvalidLayout("sizeChanged");
        super.onSizeChanged(w, h, oldw, oldh);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    private void notifyVerticalChangedListener(boolean newVertical) {
@@ -1271,28 +1240,6 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
        return uiCarModeChanged;
    }

    /*
    @Override
    protected void onLayout (boolean changed, int left, int top, int right, int bottom) {
        if (DEBUG) Log.d(TAG, String.format(
                    "onLayout: %s (%d,%d,%d,%d)",
                    changed?"changed":"notchanged", left, top, right, bottom));
        super.onLayout(changed, left, top, right, bottom);
    }

    // uncomment this for extra defensiveness in WORKAROUND_INVALID_LAYOUT situations: if all else
    // fails, any touch on the display will fix the layout.
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (DEBUG) Log.d(TAG, "onInterceptTouchEvent: " + ev.toString());
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            postCheckForInvalidLayout("touch");
        }
        return super.onInterceptTouchEvent(ev);
    }
    */


    private String getResourceName(int resId) {
        if (resId != 0) {
            final android.content.res.Resources res = getContext().getResources();
@@ -1306,10 +1253,6 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
        }
    }

    private void postCheckForInvalidLayout(final String how) {
        mHandler.obtainMessage(MSG_CHECK_INVALID_LAYOUT, 0, 0, how).sendToTarget();
    }

    private static String visibilityToString(int vis) {
        switch (vis) {
            case View.INVISIBLE:
@@ -1478,7 +1421,7 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
        void onVerticalChanged(boolean isVertical);
    }

    private final Consumer<Boolean> mDockedListener = exists -> mHandler.post(() -> {
    private final Consumer<Boolean> mDockedListener = exists -> post(() -> {
        mDockedStackExists = exists;
        updateRecentsIcon();
    });
+2 −2
Original line number Diff line number Diff line
@@ -68,8 +68,8 @@ public class NavigationPrototypeController extends ContentObserver {

    private final Context mContext;

    public NavigationPrototypeController(Handler handler, Context context) {
        super(handler);
    public NavigationPrototypeController(Context context) {
        super(new Handler());
        mContext = context;
        updateSwipeLTRBackSetting();
    }