Prepare BubbleBarViewController to support persistent task bar.

Added required resources for the transient taskbar. Unified
BubbleBarViewController logic for the persistent taskbar.

Bug: 350065038
Flag: com.android.wm.shell.enable_bubble_bar
Test: atest
Change-Id: I24e6d2d43bf8145cdcc71c75da0cb6f6e84373da
This commit is contained in:
mpodolian
2024-07-17 22:21:18 +01:00
parent 300ca3422f
commit f667c3bc3b
2 changed files with 47 additions and 11 deletions
@@ -31,6 +31,7 @@ import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;
import com.android.launcher3.anim.AnimatedFloat;
import com.android.launcher3.taskbar.TaskbarActivityContext;
@@ -62,6 +63,7 @@ public class BubbleBarViewController {
private final TaskbarActivityContext mActivity;
private final BubbleBarView mBarView;
private int mIconSize;
private int mBubbleBarPadding;
// Initialized in init.
private BubbleStashController mBubbleStashController;
@@ -110,10 +112,9 @@ public class BubbleBarViewController {
mTaskbarStashController = controllers.taskbarStashController;
mTaskbarInsetsController = controllers.taskbarInsetsController;
mBubbleBarViewAnimator = new BubbleBarViewAnimator(mBarView, mBubbleStashController);
onBubbleBarConfigurationChanged(/* animate= */ false);
mActivity.addOnDeviceProfileChangeListener(
dp -> updateBubbleBarIconSize(dp.taskbarIconSize, /* animate= */ true));
updateBubbleBarIconSize(mActivity.getDeviceProfile().taskbarIconSize, /* animate= */ false);
dp -> onBubbleBarConfigurationChanged(/* animate= */ true));
mBubbleBarScale.updateValue(1f);
mBubbleClickListener = v -> onBubbleClicked(v);
mBubbleBarClickListener = v -> onBubbleBarClicked();
@@ -334,27 +335,60 @@ public class BubbleBarViewController {
// Modifying view related properties.
//
private void updateBubbleBarIconSize(int newIconSize, boolean animate) {
/** Notifies controller of configuration change, so bubble bar can be adjusted */
public void onBubbleBarConfigurationChanged(boolean animate) {
int newIconSize;
int newPadding;
Resources res = mActivity.getResources();
if (mBubbleStashController.isBubblesShowingOnHome()) {
newIconSize = getBubbleBarIconSizeFromDeviceProfile(res);
newPadding = getBubbleBarPaddingFromDeviceProfile(res);
} else {
// the bubble bar is shown inside the persistent task bar, use preset sizes
newIconSize = res.getDimensionPixelSize(R.dimen.bubblebar_icon_size_persistent_taskbar);
newPadding = res.getDimensionPixelSize(
R.dimen.bubblebar_icon_spacing_persistent_taskbar);
}
updateBubbleBarIconSizeAndPadding(newIconSize, newPadding, animate);
}
private int getBubbleBarIconSizeFromDeviceProfile(Resources res) {
DeviceProfile deviceProfile = mActivity.getDeviceProfile();
DisplayMetrics dm = res.getDisplayMetrics();
float smallIconSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
APP_ICON_SMALL_DP, dm);
float mediumIconSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
APP_ICON_MEDIUM_DP, dm);
float largeIconSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
APP_ICON_LARGE_DP, dm);
float smallMediumThreshold = (smallIconSize + mediumIconSize) / 2f;
float mediumLargeThreshold = (mediumIconSize + largeIconSize) / 2f;
mIconSize = newIconSize <= smallMediumThreshold
int taskbarIconSize = deviceProfile.taskbarIconSize;
return taskbarIconSize <= smallMediumThreshold
? res.getDimensionPixelSize(R.dimen.bubblebar_icon_size_small) :
res.getDimensionPixelSize(R.dimen.bubblebar_icon_size);
float bubbleBarPadding = newIconSize >= mediumLargeThreshold
}
private int getBubbleBarPaddingFromDeviceProfile(Resources res) {
DeviceProfile deviceProfile = mActivity.getDeviceProfile();
DisplayMetrics dm = res.getDisplayMetrics();
float mediumIconSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
APP_ICON_MEDIUM_DP, dm);
float largeIconSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
APP_ICON_LARGE_DP, dm);
float mediumLargeThreshold = (mediumIconSize + largeIconSize) / 2f;
return deviceProfile.taskbarIconSize >= mediumLargeThreshold
? res.getDimensionPixelSize(R.dimen.bubblebar_icon_spacing_large) :
res.getDimensionPixelSize(R.dimen.bubblebar_icon_spacing);
}
private void updateBubbleBarIconSizeAndPadding(int iconSize, int padding, boolean animate) {
if (mIconSize == iconSize && mBubbleBarPadding == padding) return;
mIconSize = iconSize;
mBubbleBarPadding = padding;
if (animate) {
mBarView.animateBubbleBarIconSize(mIconSize, bubbleBarPadding);
mBarView.animateBubbleBarIconSize(iconSize, padding);
} else {
mBarView.setIconSizeAndPadding(mIconSize, bubbleBarPadding);
mBarView.setIconSizeAndPadding(iconSize, padding);
}
}