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

Commit 11d9346d authored by Lyn Han's avatar Lyn Han Committed by Android (Google) Code Review
Browse files

Merge "Center bubbles in landscape" into qt-r1-bubbles-dev

parents 0812979c f4730310
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -287,8 +287,8 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
    @Override
    public void onConfigChanged(Configuration newConfig) {
        if (mStackView != null && newConfig != null && newConfig.orientation != mOrientation) {
            mStackView.onOrientationChanged();
            mOrientation = newConfig.orientation;
            mStackView.onOrientationChanged(newConfig.orientation);
        }
    }

+19 −7
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.animation.ValueAnimator;
import android.annotation.NonNull;
import android.app.Notification;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
@@ -163,7 +164,7 @@ public class BubbleStackView extends FrameLayout {
    private Runnable mHideFlyout = () -> animateFlyoutCollapsed(true, 0 /* velX */);

    /** Layout change listener that moves the stack to the nearest valid position on rotation. */
    private OnLayoutChangeListener mMoveStackToValidPositionOnLayoutListener;
    private OnLayoutChangeListener mOrientationChangedListener;
    /** Whether the stack was on the left side of the screen prior to rotation. */
    private boolean mWasOnLeftBeforeRotation = false;
    /**
@@ -291,6 +292,8 @@ public class BubbleStackView extends FrameLayout {
    private boolean mSuppressNewDot = false;
    private boolean mSuppressFlyout = false;

    private int mOrientation = Configuration.ORIENTATION_UNDEFINED;

    public BubbleStackView(Context context, BubbleData data,
            @Nullable SurfaceSynchronizer synchronizer) {
        super(context);
@@ -326,8 +329,9 @@ public class BubbleStackView extends FrameLayout {
        int elevation = res.getDimensionPixelSize(R.dimen.bubble_elevation);

        mStackAnimationController = new StackAnimationController();

        mExpandedAnimationController = new ExpandedAnimationController(
                mDisplaySize, mExpandedViewPadding);
                mDisplaySize, mExpandedViewPadding, res.getConfiguration().orientation);
        mSurfaceSynchronizer = synchronizer != null ? synchronizer : DEFAULT_SURFACE_SYNCHRONIZER;

        mBubbleContainer = new PhysicsAnimationLayout(context);
@@ -417,13 +421,20 @@ public class BubbleStackView extends FrameLayout {
            return view.onApplyWindowInsets(insets);
        });

        mMoveStackToValidPositionOnLayoutListener =
        mOrientationChangedListener =
                (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
                    mExpandedAnimationController.updateOrientation(mOrientation);
                    if (mIsExpanded) {
                        // Re-draw bubble row and pointer for new orientation.
                        mExpandedAnimationController.expandFromStack(() -> {
                            updatePointerPosition();
                        } /* after */);
                    }
                    if (mVerticalPosPercentBeforeRotation >= 0) {
                        mStackAnimationController.moveStackToSimilarPositionAfterRotation(
                                mWasOnLeftBeforeRotation, mVerticalPosPercentBeforeRotation);
                    }
                    removeOnLayoutChangeListener(mMoveStackToValidPositionOnLayoutListener);
                    removeOnLayoutChangeListener(mOrientationChangedListener);
                };

        // This must be a separate OnDrawListener since it should be called for every draw.
@@ -464,14 +475,15 @@ public class BubbleStackView extends FrameLayout {
    }

    /** Respond to the phone being rotated by repositioning the stack and hiding any flyouts. */
    public void onOrientationChanged() {
    public void onOrientationChanged(int orientation) {
        mOrientation = orientation;

        final RectF allowablePos = mStackAnimationController.getAllowableStackPositionRegion();
        mWasOnLeftBeforeRotation = mStackAnimationController.isStackOnLeftSide();
        mVerticalPosPercentBeforeRotation =
                (mStackAnimationController.getStackPosition().y - allowablePos.top)
                        / (allowablePos.bottom - allowablePos.top);
        addOnLayoutChangeListener(mMoveStackToValidPositionOnLayoutListener);

        addOnLayoutChangeListener(mOrientationChangedListener);
        hideFlyoutImmediate();
    }

+20 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.bubbles.animation;

import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.PointF;
@@ -64,6 +65,8 @@ public class ExpandedAnimationController
    private Point mDisplaySize;
    /** Max number of bubbles shown in row above expanded view.*/
    private int mBubblesMaxRendered;
    /** Width of current screen orientation. */
    private float mScreenWidth;

    /** Whether the dragged-out bubble is in the dismiss target. */
    private boolean mIndividualBubbleWithinDismissTarget = false;
@@ -88,8 +91,10 @@ public class ExpandedAnimationController
    private int mExpandedViewPadding;
    private float mLauncherGridDiff;

    public ExpandedAnimationController(Point displaySize, int expandedViewPadding) {
    public ExpandedAnimationController(Point displaySize, int expandedViewPadding,
            int orientation) {
        mDisplaySize = displaySize;
        updateOrientation(orientation);
        mExpandedViewPadding = expandedViewPadding;
        mLauncherGridDiff = 30f;
    }
@@ -124,6 +129,18 @@ public class ExpandedAnimationController
        startOrUpdateCollapseAnimation();
    }

    /**
     * Update effective screen width based on current orientation.
     * @param orientation Landscape or portrait.
     */
    public void updateOrientation(int orientation) {
        if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            mScreenWidth = mDisplaySize.y;
            return;
        }
        mScreenWidth = mDisplaySize.x;
    }

    private void startOrUpdateExpandAnimation() {
        animationsForChildrenFromIndex(
                0, /* startIndex */
@@ -421,7 +438,7 @@ public class ExpandedAnimationController
        final float totalGapWidth = (bubbleCount - 1) * getSpaceBetweenBubbles();
        final float rowWidth = totalGapWidth + totalBubbleWidth;

        final float centerScreen = mDisplaySize.x / 2f;
        final float centerScreen = mScreenWidth / 2f;
        final float halfRow = rowWidth / 2f;
        final float rowLeft = centerScreen - halfRow;

@@ -441,7 +458,7 @@ public class ExpandedAnimationController
         *  Launcher's app icon grid edge that we must match
         */
        final float rowMargins = (mExpandedViewPadding + mLauncherGridDiff) * 2;
        final float maxRowWidth = mDisplaySize.x - rowMargins;
        final float maxRowWidth = mScreenWidth - rowMargins;

        final float totalBubbleWidth = mBubblesMaxRendered * mBubbleSizePx;
        final float totalGapWidth = maxRowWidth - totalBubbleWidth;
+3 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.mockito.Mockito.verify;

import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.PointF;
@@ -46,13 +47,14 @@ public class ExpandedAnimationControllerTest extends PhysicsAnimationLayoutTestC
    private int mDisplayWidth = 500;
    private int mDisplayHeight = 1000;
    private int mExpandedViewPadding = 10;
    private int mOrientation = Configuration.ORIENTATION_PORTRAIT;
    private float mLauncherGridDiff = 30f;

    @Spy
    private ExpandedAnimationController mExpandedController =
            new ExpandedAnimationController(
                    new Point(mDisplayWidth, mDisplayHeight) /* displaySize */,
                    mExpandedViewPadding);
                    mExpandedViewPadding, mOrientation);

    private int mStackOffset;
    private float mBubblePaddingTop;