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

Commit 198a0306 authored by Daniel Sandler's avatar Daniel Sandler
Browse files

Fix the seesaw behavior on the status panels.

The code in onMeasure that attempts to accommodate changing
child boundaries (i.e. an expanding/collapsing notification)
was locking the window size to the child measurement, even
though another window was trying to seesaw it closed. We now
only activate the rubberband behavior when the size of the
children changes, not on each onMeasure().

Lots of other small fixes to the panel expansion logic, too,
including ensuring that the expanded fraction doesn't jump
to 1.0f when the panel content hasn't been laid out yet
(causing the entire screen to become dim for a second thanks
to PhoneStatusBarView.panelExpansionChanged).

This change also restores the ability of Binder clients
(such as accessibility systems) to expand and collapse the
status bar.

Bug: 7008196
Bug: 6995518
Bug: 6628429
Change-Id: Ib0244a27aef2b4dbe19be98f7e039a9d38f1b80e
parent d79dd344
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -84,8 +84,8 @@ import java.util.ArrayList;

public abstract class BaseStatusBar extends SystemUI implements
        CommandQueue.Callbacks {
    static final String TAG = "StatusBar";
    private static final boolean DEBUG = false;
    public static final String TAG = "StatusBar";
    public static final boolean DEBUG = false;
    public static final boolean MULTIUSER_DEBUG = false;

    protected static final int MSG_TOGGLE_RECENTS_PANEL = 1020;
@@ -162,6 +162,9 @@ public abstract class BaseStatusBar extends SystemUI implements
    private RemoteViews.OnClickHandler mOnClickHandler = new RemoteViews.OnClickHandler() {
        @Override
        public boolean onClickHandler(View view, PendingIntent pendingIntent, Intent fillInIntent) {
            if (DEBUG) {
                Slog.v(TAG, "Notification click handler invoked for intent: " + pendingIntent);
            }
            final boolean isActivity = pendingIntent.isActivity();
            if (isActivity) {
                try {
+31 −15
Original line number Diff line number Diff line
@@ -10,22 +10,23 @@ import android.widget.FrameLayout;

public class PanelBar extends FrameLayout {
    public static final boolean DEBUG = false;
    public static final String TAG = PanelView.class.getSimpleName();
    public static final String TAG = PanelBar.class.getSimpleName();
    public static final void LOG(String fmt, Object... args) {
        if (!DEBUG) return;
        Slog.v(TAG, String.format(fmt, args));
    }

    public static final int STATE_CLOSED = 0;
    public static final int STATE_OPENING = 1;
    public static final int STATE_OPEN = 2;

    private PanelHolder mPanelHolder;
    private ArrayList<PanelView> mPanels = new ArrayList<PanelView>();
    protected PanelView mTouchingPanel;
    private static final int STATE_CLOSED = 0;
    private static final int STATE_TRANSITIONING = 1;
    private static final int STATE_OPEN = 2;
    private int mState = STATE_CLOSED;
    private boolean mTracking;

    private void go(int state) {
    public void go(int state) {
        LOG("go state: %d -> %d", mState, state);
        mState = state;
    }
@@ -80,18 +81,21 @@ public class PanelBar extends FrameLayout {

        // figure out which panel needs to be talked to here
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            mTouchingPanel = selectPanelForTouchX(event.getX());
            mPanelHolder.setSelectedPanel(mTouchingPanel);
            LOG("PanelBar.onTouch: state=%d ACTION_DOWN: panel %s", mState, mTouchingPanel.getName());
            if (mState == STATE_CLOSED || mState == STATE_OPEN) {
                go(STATE_TRANSITIONING);
                onPanelPeeked();
            }
            final PanelView panel = selectPanelForTouchX(event.getX());
            LOG("PanelBar.onTouch: state=%d ACTION_DOWN: panel %s", mState, panel);
            startOpeningPanel(panel);
        }
        final boolean result = mTouchingPanel.getHandle().dispatchTouchEvent(event);
        return result;
    }

    // called from PanelView when self-expanding, too
    public void startOpeningPanel(PanelView panel) {
        LOG("startOpeningPanel: " + panel);
        mTouchingPanel = panel;
        mPanelHolder.setSelectedPanel(mTouchingPanel);
    }

    public void panelExpansionChanged(PanelView panel, float frac) {
        boolean fullyClosed = true;
        PanelView fullyOpenedPanel = null;
@@ -99,6 +103,10 @@ public class PanelBar extends FrameLayout {
        for (PanelView pv : mPanels) {
            // adjust any other panels that may be partially visible
            if (pv.getExpandedHeight() > 0f) {
                if (mState == STATE_CLOSED) {
                    go(STATE_OPENING);
                    onPanelPeeked();
                }
                fullyClosed = false;
                final float thisFrac = pv.getExpandedFraction();
                LOG("panelExpansionChanged:  -> %s: f=%.1f", pv.getName(), thisFrac);
@@ -112,7 +120,7 @@ public class PanelBar extends FrameLayout {
        if (fullyOpenedPanel != null && !mTracking) {
            go(STATE_OPEN);
            onPanelFullyOpened(fullyOpenedPanel);
        } else if (fullyClosed && !mTracking) {
        } else if (fullyClosed && !mTracking && mState != STATE_CLOSED) {
            go(STATE_CLOSED);
            onAllPanelsCollapsed();
        }
@@ -122,13 +130,21 @@ public class PanelBar extends FrameLayout {
    }

    public void collapseAllPanels(boolean animate) {
        boolean waiting = false;
        for (PanelView pv : mPanels) {
            if (animate && pv == mTouchingPanel) {
                mTouchingPanel.collapse();
            if (animate && !pv.isFullyCollapsed()) {
                pv.collapse();
                waiting = true;
            } else {
                pv.setExpandedFraction(0); // just in case
            }
        }
        if (!waiting) {
            // it's possible that nothing animated, so we replicate the termination 
            // conditions of panelExpansionChanged here
            go(STATE_CLOSED);
            onAllPanelsCollapsed();
        }
    }

    public void onPanelPeeked() {
+26 −9
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ import android.util.Slog;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.android.systemui.R;
@@ -18,7 +19,7 @@ import com.android.systemui.statusbar.policy.LocationController;
import com.android.systemui.statusbar.policy.NetworkController;

public class PanelView extends FrameLayout {
    public static final boolean DEBUG = false;
    public static final boolean DEBUG = PanelBar.DEBUG;
    public static final String TAG = PanelView.class.getSimpleName();
    public final void LOG(String fmt, Object... args) {
        if (!DEBUG) return;
@@ -298,11 +299,17 @@ public class PanelView extends FrameLayout {

        LOG("onMeasure(%d, %d) -> (%d, %d)",
                widthMeasureSpec, heightMeasureSpec, getMeasuredWidth(), getMeasuredHeight());
        mFullHeight = getMeasuredHeight();
        // if one of our children is getting smaller, we should track that
        if (!mTracking && !mRubberbanding && !mTimeAnimator.isStarted() && mExpandedHeight > 0 && mExpandedHeight != mFullHeight) {

        // Did one of our children change size?
        int newHeight = getMeasuredHeight();
        if (newHeight != mFullHeight) {
            mFullHeight = newHeight;
            // If the user isn't actively poking us, let's rubberband to the content
            if (!mTracking && !mRubberbanding && !mTimeAnimator.isStarted() 
                    && mExpandedHeight > 0 && mExpandedHeight != mFullHeight) {
                mExpandedHeight = mFullHeight;
            }
        }
        heightMeasureSpec = MeasureSpec.makeMeasureSpec(
                    (int) mExpandedHeight, MeasureSpec.AT_MOST); // MeasureSpec.getMode(heightMeasureSpec));
        setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
@@ -310,6 +317,7 @@ public class PanelView extends FrameLayout {


    public void setExpandedHeight(float height) {
        mTracking = mRubberbanding = false;
        post(mStopAnimator);
        setExpandedHeightInternal(height);
    }
@@ -326,21 +334,26 @@ public class PanelView extends FrameLayout {
            // Hmm, full height hasn't been computed yet
        }

        LOG("setExpansion: height=%.1f fh=%.1f tracking=%s rubber=%s", h, fh, mTracking?"T":"f", mRubberbanding?"T":"f");

        if (h < 0) h = 0;
        if (!(STRETCH_PAST_CONTENTS && (mTracking || mRubberbanding)) && h > fh) h = fh;
        mExpandedHeight = h;

        LOG("setExpansion: height=%.1f fh=%.1f tracking=%s rubber=%s", h, fh, mTracking?"T":"f", mRubberbanding?"T":"f");

        requestLayout();
//        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
//        lp.height = (int) mExpandedHeight;
//        setLayoutParams(lp);

        mExpandedFraction = Math.min(1f, h / fh);
        mExpandedFraction = Math.min(1f, (fh == 0) ? 0 : h / fh);
    }

    private float getFullHeight() {
        if (mFullHeight <= 0) {
            LOG("Forcing measure() since fullHeight=" + mFullHeight);
            measure(MeasureSpec.makeMeasureSpec(LayoutParams.WRAP_CONTENT, MeasureSpec.EXACTLY),
                    MeasureSpec.makeMeasureSpec(LayoutParams.WRAP_CONTENT, MeasureSpec.EXACTLY));
        }
        return mFullHeight;
    }

@@ -385,8 +398,12 @@ public class PanelView extends FrameLayout {
    }

    public void expand() {
        if (!isFullyExpanded()) {
        if (isFullyCollapsed()) {
            mBar.startOpeningPanel(this);
            LOG("expand: calling fling(%s, true)", mSelfExpandVelocityPx);
            fling (mSelfExpandVelocityPx, /*always=*/ true);
        } else if (DEBUG) {
            LOG("skipping expansion: is expanded");
        }
    }
}
+3 −6
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ import java.util.ArrayList;

public class PhoneStatusBar extends BaseStatusBar {
    static final String TAG = "PhoneStatusBar";
    public static final boolean DEBUG = false;
    public static final boolean DEBUG = BaseStatusBar.DEBUG;
    public static final boolean SPEW = DEBUG;
    public static final boolean DUMPTRUCK = true; // extra dumpsys info

@@ -285,9 +285,6 @@ public class PhoneStatusBar extends BaseStatusBar {

        mStatusBarWindow = (StatusBarWindowView) View.inflate(context,
                R.layout.super_status_bar, null);
        if (DEBUG) {
            mStatusBarWindow.setBackgroundColor(0x6000FF80);
        }
        mStatusBarWindow.mService = this;
        mStatusBarWindow.setOnTouchListener(new View.OnTouchListener() {
            @Override
@@ -1203,7 +1200,7 @@ public class PhoneStatusBar extends BaseStatusBar {
        }

        // Ensure the panel is fully collapsed (just in case; bug 6765842)
        mStatusBarView.collapseAllPanels(/*animate=*/ false);
 // @@@        mStatusBarView.collapseAllPanels(/*animate=*/ false);

        mExpandedVisible = false;
        mPile.setLayoutTransitionsEnabled(false);
+7 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.graphics.Rect;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Slog;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
@@ -41,6 +42,8 @@ import com.android.systemui.statusbar.policy.FixedSizeDrawable;

public class PhoneStatusBarView extends PanelBar {
    private static final String TAG = "PhoneStatusBarView";
    private static final boolean DEBUG = PhoneStatusBar.DEBUG;

    PhoneStatusBar mBar;
    int mScrimColor;
    float mMinFlingGutter;
@@ -152,6 +155,10 @@ public class PhoneStatusBarView extends PanelBar {
    public void panelExpansionChanged(PanelView pv, float frac) {
        super.panelExpansionChanged(pv, frac);

        if (DEBUG) {
            Slog.v(TAG, "panelExpansionChanged: f=" + frac);
        }

        if (mFadingPanel == pv 
                && mScrimColor != 0 && ActivityManager.isHighEndGfx()) {
            // woo, special effects
Loading