From 7d779b689dd06b3ba04708d3f6212570bb9986df Mon Sep 17 00:00:00 2001 From: Caitlin Shkuratov Date: Wed, 9 Nov 2022 16:14:05 +0000 Subject: [PATCH] [Dock Defend] Ensure the bottom of the battery icon is always aligned with the bottom of the other icons, even if the shield is displayed. Bug: 255625888 Test: manual: Verify battery icon bottom stays aligned with other icon bottoms both with and without the shield. See video attached to bug. Change-Id: Ib203e8ce27d515a177e8371958fa43ecf8b20e74 Change-Id: I1d8c53cc2beae90f6dca14cf339733bfb085a56e --- packages/SystemUI/res/values/dimens.xml | 6 ++++++ .../systemui/battery/BatteryMeterView.java | 18 +++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index e8ae929a67824..e2ae7cfc4466b 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -105,6 +105,12 @@ so the width of the icon should be 13.0dp * (12.0 / 20.0) --> 7.8dp + + 1dp + 14sp diff --git a/packages/SystemUI/src/com/android/systemui/battery/BatteryMeterView.java b/packages/SystemUI/src/com/android/systemui/battery/BatteryMeterView.java index d301858505b9f..4c16566fff8fc 100644 --- a/packages/SystemUI/src/com/android/systemui/battery/BatteryMeterView.java +++ b/packages/SystemUI/src/com/android/systemui/battery/BatteryMeterView.java @@ -378,14 +378,26 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver { float fullBatteryIconWidth = BatterySpecs.getFullBatteryWidth(mainBatteryWidth, displayShield); - // TODO(b/255625888): Add some marginTop so that, even when the battery icon has the shield, - // the bottom of the main icon is still aligned with the bottom of all the other icons. + int marginTop; + if (displayShield) { + // If the shield is displayed, we need some extra marginTop so that the bottom of the + // main icon is still aligned with the bottom of all the other system icons. + int shieldHeightAddition = Math.round(fullBatteryIconHeight - mainBatteryHeight); + // However, the other system icons have some embedded bottom padding that the battery + // doesn't have, so we shouldn't move the battery icon down by the full amount. + // See b/258672854. + marginTop = shieldHeightAddition + - res.getDimensionPixelSize(R.dimen.status_bar_battery_extra_vertical_spacing); + } else { + marginTop = 0; + } + int marginBottom = res.getDimensionPixelSize(R.dimen.battery_margin_bottom); LinearLayout.LayoutParams scaledLayoutParams = new LinearLayout.LayoutParams( Math.round(fullBatteryIconWidth), Math.round(fullBatteryIconHeight)); - scaledLayoutParams.setMargins(0, 0, 0, marginBottom); + scaledLayoutParams.setMargins(0, marginTop, 0, marginBottom); mDrawable.setDisplayShield(displayShield); mBatteryIconView.setLayoutParams(scaledLayoutParams);