From b923d1e1f01a3a135d3e708af609a626c9c26368 Mon Sep 17 00:00:00 2001 From: JianYang Liu Date: Thu, 24 Oct 2019 17:19:44 -0700 Subject: [PATCH] Changed Notification shade's background alpha initial and final values to be configurable. Bug: 143372960 Test: manual - took before and after videos Merged-In: Ia0b6a56859889d538e21f807a88bc5217d89e64a Change-Id: Ia0b6a56859889d538e21f807a88bc5217d89e64a --- packages/CarSystemUI/res/values/config.xml | 15 +++++++++ .../systemui/statusbar/car/CarStatusBar.java | 39 ++++++++++++++++++---- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/packages/CarSystemUI/res/values/config.xml b/packages/CarSystemUI/res/values/config.xml index 467c4a41893d..cbf22870af96 100644 --- a/packages/CarSystemUI/res/values/config.xml +++ b/packages/CarSystemUI/res/values/config.xml @@ -40,4 +40,19 @@ slots that may be reused for things like IME control. --> 0 + + 0 + + 100 + diff --git a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java index b7aa496b3d5d..80a824020c78 100644 --- a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java +++ b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java @@ -101,6 +101,9 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt private float mOpeningVelocity = DEFAULT_FLING_VELOCITY; private float mClosingVelocity = DEFAULT_FLING_VELOCITY; + private float mBackgroundAlphaDiff; + private float mInitialBackgroundAlpha; + private TaskStackListenerImpl mTaskStackListener; private FullscreenUserSwitcher mFullscreenUserSwitcher; @@ -214,6 +217,25 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt // created. mHvacController = new HvacController(mContext); + // Notification bar related setup. + mInitialBackgroundAlpha = (float) mContext.getResources().getInteger( + R.integer.config_initialNotificationBackgroundAlpha) / 100; + if (mInitialBackgroundAlpha < 0 || mInitialBackgroundAlpha > 100) { + throw new RuntimeException( + "Unable to setup notification bar due to incorrect initial background alpha" + + " percentage"); + } + float finalBackgroundAlpha = Math.max( + mInitialBackgroundAlpha, + (float) mContext.getResources().getInteger( + R.integer.config_finalNotificationBackgroundAlpha) / 100); + if (finalBackgroundAlpha < 0 || finalBackgroundAlpha > 100) { + throw new RuntimeException( + "Unable to setup notification bar due to incorrect final background alpha" + + " percentage"); + } + mBackgroundAlphaDiff = finalBackgroundAlpha - mInitialBackgroundAlpha; + super.start(); mTaskStackListener = new TaskStackListenerImpl(); mActivityManagerWrapper = ActivityManagerWrapper.getInstance(); @@ -1155,17 +1177,22 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt mHandleBar.setTranslationY(height - mHandleBar.getHeight() - lp.bottomMargin); } if (mNotificationView.getHeight() > 0) { - // Calculates the alpha value for the background based on how much of the notification - // shade is visible to the user. When the notification shade is completely open then - // alpha value will be 1. - float alpha = (float) height / mNotificationView.getHeight(); Drawable background = mNotificationView.getBackground().mutate(); - - background.setAlpha((int) (alpha * 255)); + background.setAlpha((int) (getBackgroundAlpha(height) * 255)); mNotificationView.setBackground(background); } } + /** + * Calculates the alpha value for the background based on how much of the notification + * shade is visible to the user. When the notification shade is completely open then + * alpha value will be 1. + */ + private float getBackgroundAlpha(int height) { + return mInitialBackgroundAlpha + + ((float) height / mNotificationView.getHeight() * mBackgroundAlphaDiff); + } + private void calculatePercentageFromBottom(float height) { if (mNotificationView.getHeight() > 0) { mPercentageFromBottom = (int) Math.abs( -- 2.11.0