If there's no adjustment needed, this method returns {@code 0}. + */ + public float getHotseatAdjustedBorderSpaceForBubbleBar(Context context) { + // only need to adjust when QSB is on top of the hotseat. + if (isQsbInline) { + return 0; + } + + // no need to adjust if there's enough space for the bubble bar to the right of the hotseat. + if (getHotseatLayoutPadding(context).right > mBubbleBarSpaceThresholdPx) { + return 0; + } + + // The adjustment is shrinking the hotseat's width by 1 icon on either side. + int iconsWidth = + iconSizePx * numShownHotseatIcons + hotseatBorderSpace * (numShownHotseatIcons - 1); + int newWidth = iconsWidth - 2 * iconSizePx; + // Evenly space the icons within the boundaries of the new width. + return (float) (newWidth - iconSizePx * numShownHotseatIcons) / (numShownHotseatIcons - 1); + } + /** * Returns the padding for hotseat view */ @@ -2165,5 +2197,4 @@ public class DeviceProfile { mIsGestureMode, mViewScaleProvider, mOverrideProvider); } } - } diff --git a/src/com/android/launcher3/Hotseat.java b/src/com/android/launcher3/Hotseat.java index 03afba11c1..3b12b86bf7 100644 --- a/src/com/android/launcher3/Hotseat.java +++ b/src/com/android/launcher3/Hotseat.java @@ -16,6 +16,12 @@ package com.android.launcher3; +import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_X; +import static com.android.launcher3.util.MultiTranslateDelegate.INDEX_BUBBLE_ADJUSTMENT_ANIM; + +import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; +import android.animation.ValueAnimator; import android.content.Context; import android.graphics.Rect; import android.util.AttributeSet; @@ -27,6 +33,10 @@ import android.view.ViewDebug; import android.view.ViewGroup; import android.widget.FrameLayout; +import com.android.launcher3.util.HorizontalInsettableView; +import com.android.launcher3.util.MultiTranslateDelegate; +import com.android.launcher3.views.ActivityContext; + /** * View class that represents the bottom row of the home screen. */ @@ -34,6 +44,7 @@ public class Hotseat extends CellLayout implements Insettable { // Ratio of empty space, qsb should take up to appear visually centered. public static final float QSB_CENTER_FACTOR = .325f; + private static final int BUBBLE_BAR_ADJUSTMENT_ANIMATION_DURATION_MS = 250; @ViewDebug.ExportedProperty(category = "launcher") private boolean mHasVerticalHotseat; @@ -72,9 +83,36 @@ public class Hotseat extends CellLayout implements Insettable { } public void resetLayout(boolean hasVerticalHotseat) { + ActivityContext activityContext = ActivityContext.lookupContext(getContext()); + boolean bubbleBarEnabled = activityContext.isBubbleBarEnabled(); + boolean hasBubbles = activityContext.hasBubbles(); removeAllViewsInLayout(); mHasVerticalHotseat = hasVerticalHotseat; DeviceProfile dp = mActivity.getDeviceProfile(); + + if (bubbleBarEnabled) { + float adjustedBorderSpace = dp.getHotseatAdjustedBorderSpaceForBubbleBar(getContext()); + if (hasBubbles && Float.compare(adjustedBorderSpace, 0f) != 0) { + getShortcutsAndWidgets().setTranslationProvider(child -> { + int index = getShortcutsAndWidgets().indexOfChild(child); + float borderSpaceDelta = adjustedBorderSpace - dp.hotseatBorderSpace; + return dp.iconSizePx + index * borderSpaceDelta; + }); + if (mQsb instanceof HorizontalInsettableView) { + HorizontalInsettableView insettableQsb = (HorizontalInsettableView) mQsb; + final float insetFraction = (float) dp.iconSizePx / dp.hotseatQsbWidth; + // post this to the looper so that QSB has a chance to redraw itself, e.g. + // after device rotation + mQsb.post(() -> insettableQsb.setHorizontalInsets(insetFraction)); + } + } else { + getShortcutsAndWidgets().setTranslationProvider(null); + if (mQsb instanceof HorizontalInsettableView) { + ((HorizontalInsettableView) mQsb).setHorizontalInsets(0); + } + } + } + resetCellSize(dp); if (hasVerticalHotseat) { setGridSize(1, dp.numShownHotseatIcons); @@ -83,6 +121,62 @@ public class Hotseat extends CellLayout implements Insettable { } } + /** + * Adjust the hotseat icons for the bubble bar. + * + *
When the bubble bar becomes visible, if needed, this method animates the hotseat icons + * to reduce the spacing between them and make room for the bubble bar. The QSB width is + * animated as well to align with the hotseat icons. + * + *
When the bubble bar goes away, any adjustments that were previously made are reversed.
+ */
+ public void adjustForBubbleBar(boolean isBubbleBarVisible) {
+ DeviceProfile dp = mActivity.getDeviceProfile();
+ float adjustedBorderSpace = dp.getHotseatAdjustedBorderSpaceForBubbleBar(getContext());
+ if (Float.compare(adjustedBorderSpace, 0f) == 0) {
+ return;
+ }
+
+ ShortcutAndWidgetContainer icons = getShortcutsAndWidgets();
+ AnimatorSet animatorSet = new AnimatorSet();
+ float borderSpaceDelta = adjustedBorderSpace - dp.hotseatBorderSpace;
+
+ // update the translation provider for future layout passes of hotseat icons.
+ if (isBubbleBarVisible) {
+ icons.setTranslationProvider(child -> {
+ int index = icons.indexOfChild(child);
+ return dp.iconSizePx + index * borderSpaceDelta;
+ });
+ } else {
+ icons.setTranslationProvider(null);
+ }
+
+ for (int i = 0; i < icons.getChildCount(); i++) {
+ View child = icons.getChildAt(i);
+ float tx = isBubbleBarVisible ? dp.iconSizePx + i * borderSpaceDelta : 0;
+ if (child instanceof Reorderable) {
+ MultiTranslateDelegate mtd = ((Reorderable) child).getTranslateDelegate();
+ animatorSet.play(
+ mtd.getTranslationX(INDEX_BUBBLE_ADJUSTMENT_ANIM).animateToValue(tx));
+ } else {
+ animatorSet.play(ObjectAnimator.ofFloat(child, VIEW_TRANSLATE_X, tx));
+ }
+ }
+ if (mQsb instanceof HorizontalInsettableView) {
+ HorizontalInsettableView horizontalInsettableQsb = (HorizontalInsettableView) mQsb;
+ ValueAnimator qsbAnimator = ValueAnimator.ofFloat(0f, 1f);
+ qsbAnimator.addUpdateListener(animation -> {
+ float fraction = qsbAnimator.getAnimatedFraction();
+ float insetFraction = isBubbleBarVisible
+ ? (float) dp.iconSizePx * fraction / dp.hotseatQsbWidth
+ : (float) dp.iconSizePx * (1 - fraction) / dp.hotseatQsbWidth;
+ horizontalInsettableQsb.setHorizontalInsets(insetFraction);
+ });
+ animatorSet.play(qsbAnimator);
+ }
+ animatorSet.setDuration(BUBBLE_BAR_ADJUSTMENT_ANIMATION_DURATION_MS).start();
+ }
+
@Override
public void setInsets(Rect insets) {
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 1fef2f80a0..b8e7737798 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -2325,6 +2325,7 @@ public class Launcher extends StatefulActivity
* Implementation of the method from LauncherModel.Callbacks.
*/
+ @Override
public void startBinding() {
TraceHelper.INSTANCE.beginSection("startBinding");
// Floating panels (except the full widget sheet) are associated with individual icons. If
diff --git a/src/com/android/launcher3/ShortcutAndWidgetContainer.java b/src/com/android/launcher3/ShortcutAndWidgetContainer.java
index 5e7f21bcd0..b22b690260 100644
--- a/src/com/android/launcher3/ShortcutAndWidgetContainer.java
+++ b/src/com/android/launcher3/ShortcutAndWidgetContainer.java
@@ -21,6 +21,7 @@ import static android.view.MotionEvent.ACTION_DOWN;
import static com.android.launcher3.CellLayout.FOLDER;
import static com.android.launcher3.CellLayout.HOTSEAT;
import static com.android.launcher3.CellLayout.WORKSPACE;
+import static com.android.launcher3.util.MultiTranslateDelegate.INDEX_BUBBLE_ADJUSTMENT_ANIM;
import static com.android.launcher3.util.MultiTranslateDelegate.INDEX_WIDGET_CENTERING;
import android.app.WallpaperManager;
@@ -33,6 +34,8 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
+import androidx.annotation.Nullable;
+
import com.android.launcher3.CellLayout.ContainerType;
import com.android.launcher3.celllayout.CellLayoutLayoutParams;
import com.android.launcher3.folder.FolderIcon;
@@ -62,6 +65,9 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.
private final ActivityContext mActivity;
private boolean mInvertIfRtl = false;
+ @Nullable
+ private TranslationProvider mTranslationProvider = null;
+
public ShortcutAndWidgetContainer(Context context, @ContainerType int containerType) {
super(context);
mActivity = ActivityContext.lookupContext(context);
@@ -229,6 +235,16 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.
childLeft, childTop, childLeft + lp.width, childTop + lp.height);
}
child.layout(childLeft, childTop, childLeft + lp.width, childTop + lp.height);
+ if (mTranslationProvider != null) {
+ final float tx = mTranslationProvider.getTranslationX(child);
+ if (child instanceof Reorderable) {
+ ((Reorderable) child).getTranslateDelegate()
+ .getTranslationX(INDEX_BUBBLE_ADJUSTMENT_ANIM)
+ .setValue(tx);
+ } else {
+ child.setTranslationX(tx);
+ }
+ }
if (lp.dropped) {
lp.dropped = false;
@@ -298,4 +314,13 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.
cl.clearFolderLeaveBehind();
}
}
+
+ void setTranslationProvider(@Nullable TranslationProvider provider) {
+ mTranslationProvider = provider;
+ }
+
+ /** Provides translation values to apply when laying out child views. */
+ interface TranslationProvider {
+ float getTranslationX(View child);
+ }
}
diff --git a/src/com/android/launcher3/util/MultiTranslateDelegate.java b/src/com/android/launcher3/util/MultiTranslateDelegate.java
index 1cb7a453af..0e32ba7bfc 100644
--- a/src/com/android/launcher3/util/MultiTranslateDelegate.java
+++ b/src/com/android/launcher3/util/MultiTranslateDelegate.java
@@ -40,6 +40,9 @@ public class MultiTranslateDelegate {
// Specific for widgets
public static final int INDEX_WIDGET_CENTERING = 3;
+ // Specific for hotseat items when adjusting for bubbles
+ public static final int INDEX_BUBBLE_ADJUSTMENT_ANIM = 3;
+
public static final int COUNT = 5;
private final MultiPropertyFactory