Merge "Prepare for wiring bubble bar flyout" into main

This commit is contained in:
Liran Binyamin authored and Android (Google) Code Review committed 2024-10-09 19:23:54 +00:00
commit 024b0e63da
3 files changed
+127 -4

No files matched your search

@@ -1492,6 +1492,38 @@ public class BubbleBarView extends FrameLayout {
return bubbles;
}
/**
* Returns the distance between the top left corner of the bubble bar to the center of the dot
* of the selected bubble.
*/
PointF getSelectedBubbleDotDistanceFromTopLeft() {
if (mSelectedBubbleView == null) {
return new PointF(0, 0);
}
final int indexOfSelectedBubble = indexOfChild(mSelectedBubbleView);
final boolean onLeft = mBubbleBarLocation.isOnLeft(isLayoutRtl());
final float selectedBubbleTx = isExpanded()
? getExpandedBubbleTranslationX(indexOfSelectedBubble, getChildCount(), onLeft)
: getCollapsedBubbleTranslationX(indexOfSelectedBubble, getChildCount(), onLeft);
PointF selectedBubbleDotCenter = mSelectedBubbleView.getDotCenter();
return new PointF(
selectedBubbleTx + selectedBubbleDotCenter.x,
mBubbleBarPadding + mPointerSize + selectedBubbleDotCenter.y);
}
int getSelectedBubbleDotColor() {
return mSelectedBubbleView == null ? 0 : mSelectedBubbleView.getDotColor();
}
int getPointerSize() {
return mPointerSize;
}
float getBubbleElevation() {
return mBubbleElevation;
}
/** Interface for BubbleBarView to communicate with its controller. */
interface Controller {
@@ -42,6 +42,7 @@ import com.android.launcher3.taskbar.TaskbarControllers;
import com.android.launcher3.taskbar.TaskbarInsetsController;
import com.android.launcher3.taskbar.TaskbarStashController;
import com.android.launcher3.taskbar.bubbles.animation.BubbleBarViewAnimator;
import com.android.launcher3.taskbar.bubbles.flyout.BubbleBarFlyoutPositioner;
import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController;
import com.android.launcher3.util.MultiPropertyFactory;
import com.android.launcher3.util.MultiValueAlpha;
@@ -63,6 +64,8 @@ public class BubbleBarViewController {
private static final float APP_ICON_SMALL_DP = 44f;
private static final float APP_ICON_MEDIUM_DP = 48f;
private static final float APP_ICON_LARGE_DP = 52f;
/** The dot size is defined as a percentage of the icon size. */
private static final float DOT_TO_BUBBLE_SIZE_RATIO = 0.228f;
private final SystemUiProxy mSystemUiProxy;
private final TaskbarActivityContext mActivity;
private final BubbleBarView mBarView;
@@ -208,6 +211,59 @@ public class BubbleBarViewController {
};
}
private BubbleBarFlyoutPositioner createFlyoutPositioner() {
return new BubbleBarFlyoutPositioner() {
@Override
public boolean isOnLeft() {
return mBarView.getBubbleBarLocation().isOnLeft(mBarView.isLayoutRtl());
}
@Override
public float getTargetTy() {
return mBarView.getTranslationY() - mBarView.getHeight();
}
@Override
@NonNull
public PointF getDistanceToCollapsedPosition() {
// the flyout animates from the selected bubble dot. calculate the distance it needs
// to translate itself to its starting position.
PointF distanceToDotCenter = mBarView.getSelectedBubbleDotDistanceFromTopLeft();
// if we're gravitating left, return the distance between the top left corner of the
// bubble bar and the bottom left corner of the dot.
// if we're gravitating right, return the distance between the top right corner of
// the bubble bar and the bottom right corner of the dot.
float distanceX = isOnLeft()
? distanceToDotCenter.x - getCollapsedSize() / 2
: mBarView.getWidth() - distanceToDotCenter.x - getCollapsedSize() / 2;
float distanceY = distanceToDotCenter.y + getCollapsedSize() / 2;
return new PointF(distanceX, distanceY);
}
@Override
public float getCollapsedSize() {
return mIconSize * DOT_TO_BUBBLE_SIZE_RATIO;
}
@Override
public int getCollapsedColor() {
return mBarView.getSelectedBubbleDotColor();
}
@Override
public float getCollapsedElevation() {
return mBarView.getBubbleElevation();
}
@Override
public float getDistanceToRevealTriangle() {
return getDistanceToCollapsedPosition().y - mBarView.getPointerSize();
}
};
}
private void onBubbleClicked(BubbleView bubbleView) {
bubbleView.markSeen();
BubbleBarItem bubble = bubbleView.getBubble();
@@ -22,6 +22,7 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
@@ -67,8 +68,7 @@ public class BubbleView extends ConstraintLayout {
private float mAnimatingToDotScale;
// The current scale value of the dot
private float mDotScale;
private boolean mProvideShadowOutline = true;
private boolean mDotSuppressedForBubbleUpdate = false;
// TODO: (b/273310265) handle RTL
// Whether the bubbles are positioned on the left or right side of the screen
@@ -300,6 +300,10 @@ public class BubbleView extends ConstraintLayout {
}
void updateDotVisibility(boolean animate) {
if (mDotSuppressedForBubbleUpdate) {
// if the dot is suppressed for
return;
}
final float targetScale = hasUnseenContent() ? 1f : 0f;
if (animate) {
animateDotScale(targetScale);
@@ -317,6 +321,20 @@ public class BubbleView extends ConstraintLayout {
}
}
/**
* Suppresses or un-suppresses drawing the dot due to an update for this bubble.
*
* <p>If the dot is being suppressed and is already visible, it remains visible because it is
* used as a starting point for the animation. If the dot is being unsuppressed, it is
* redrawn if needed.
*/
public void suppressDotForBubbleUpdate(boolean suppress) {
mDotSuppressedForBubbleUpdate = suppress;
if (!suppress) {
showDotIfNeeded(/* animate= */ false);
}
}
boolean hasUnseenContent() {
return mBubble != null
&& mBubble instanceof BubbleBarBubble
@@ -353,8 +371,8 @@ public class BubbleView extends ConstraintLayout {
}
void showDotIfNeeded(boolean animate) {
// only show the dot if we have unseen content
if (!hasUnseenContent()) {
// only show the dot if we have unseen content and it's not suppressed
if (!hasUnseenContent() || mDotSuppressedForBubbleUpdate) {
return;
}
if (animate) {
@@ -406,6 +424,23 @@ public class BubbleView extends ConstraintLayout {
}).start();
}
/**
* Returns the distance from the top left corner of this bubble view to the center of its dot.
*/
public PointF getDotCenter() {
float[] dotPosition =
mOnLeft ? mDotRenderer.getLeftDotPosition() : mDotRenderer.getRightDotPosition();
getDrawingRect(mTempBounds);
float dotCenterX = mTempBounds.width() * dotPosition[0];
float dotCenterY = mTempBounds.height() * dotPosition[1];
return new PointF(dotCenterX, dotCenterY);
}
/** Returns the dot color. */
public int getDotColor() {
return mDotColor;
}
@Override
public String toString() {
String toString = mBubble != null ? mBubble.getKey() : "null";