From 9ddbe1311d0e42057013811a57c159a5bbc7d1f3 Mon Sep 17 00:00:00 2001 From: Miranda Kephart Date: Mon, 20 Apr 2020 12:43:16 -0400 Subject: [PATCH] Update screenshot UI for dark theme Updates the colors used when the dark theme is on. When a screenshot is taken, checks for the current dark theme status and updates the assets if necessary. Test: manual Bug: 146560663 Change-Id: Iccc727924e04febc5be25e2205775b52ef082f6a --- .../res/drawable/screenshot_cancel.xml | 6 +-- .../SystemUI/res/layout/global_screenshot.xml | 1 + packages/SystemUI/res/values-night/colors.xml | 9 +++- packages/SystemUI/res/values/colors.xml | 2 + .../systemui/screenshot/GlobalScreenshot.java | 41 +++++++++++++++++++ 5 files changed, 54 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/res/drawable/screenshot_cancel.xml b/packages/SystemUI/res/drawable/screenshot_cancel.xml index be3c5983bb2e6..f0dfd21a830d0 100644 --- a/packages/SystemUI/res/drawable/screenshot_cancel.xml +++ b/packages/SystemUI/res/drawable/screenshot_cancel.xml @@ -20,9 +20,9 @@ android:viewportWidth="48.0" android:viewportHeight="48.0"> + android:fillColor="@color/global_screenshot_dismiss_background" + android:pathData="M24,24m-16,0a16,16 0,1 1,32 0a16,16 0,1 1,-32 0"/> \ No newline at end of file diff --git a/packages/SystemUI/res/layout/global_screenshot.xml b/packages/SystemUI/res/layout/global_screenshot.xml index d506e7e8e7003..db109fe8a5411 100644 --- a/packages/SystemUI/res/layout/global_screenshot.xml +++ b/packages/SystemUI/res/layout/global_screenshot.xml @@ -68,6 +68,7 @@ android:visibility="gone" android:contentDescription="@string/screenshot_dismiss_ui_description"> @color/GM2_red_300 - @color/GM2_grey_900 + @color/GM2_grey_800 #42FFFFFF - @color/GM2_blue_300 + #FFFFFF + @color/GM2_grey_600 + @color/GM2_blue_300 + @color/GM2_grey_800 + #FFFFFF + #ff888888 diff --git a/packages/SystemUI/res/values/colors.xml b/packages/SystemUI/res/values/colors.xml index 4482cdac33274..8b6b5f67d5a77 100644 --- a/packages/SystemUI/res/values/colors.xml +++ b/packages/SystemUI/res/values/colors.xml @@ -198,6 +198,8 @@ @color/GM2_grey_300 #1f000000 @color/GM2_blue_500 + #FFFFFF + @color/GM2_grey_500 #F8F9FA diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java index 1efe663ca6ceb..7233b72e31155 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java @@ -36,6 +36,7 @@ import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Insets; @@ -184,9 +185,11 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset private final LinearLayout mActionsView; private final ImageView mBackgroundProtection; private final FrameLayout mDismissButton; + private final ImageView mDismissImage; private Bitmap mScreenBitmap; private Animator mScreenshotAnimation; + private boolean mInDarkMode = false; private float mScreenshotOffsetXPx; private float mScreenshotOffsetYPx; @@ -250,6 +253,7 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_EXPLICIT_DISMISSAL); clearScreenshot("dismiss_button"); }); + mDismissImage = mDismissButton.findViewById(R.id.global_screenshot_dismiss_image); mScreenshotFlash = mScreenshotLayout.findViewById(R.id.global_screenshot_flash); mScreenshotSelectorView = mScreenshotLayout.findViewById(R.id.global_screenshot_selector); @@ -356,6 +360,8 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset mScreenBitmap.setHasAlpha(false); mScreenBitmap.prepareToDraw(); + updateDarkTheme(); + mWindowManager.addView(mScreenshotLayout, mWindowLayoutParams); mScreenshotLayout.getViewTreeObserver().addOnComputeInternalInsetsListener(this); @@ -453,6 +459,41 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset mContext.getResources().getString(R.string.screenshot_preview_description)); } + /** + * Update assets (called when the dark theme status changes). We only need to update the dismiss + * button and the actions container background, since the buttons are re-inflated on demand. + */ + private void reloadAssets() { + mDismissImage.setImageDrawable(mContext.getDrawable(R.drawable.screenshot_cancel)); + mActionsContainer.setBackground( + mContext.getDrawable(R.drawable.action_chip_container_background)); + + } + + /** + * Checks the current dark theme status and updates if it has changed. + */ + private void updateDarkTheme() { + int currentNightMode = mContext.getResources().getConfiguration().uiMode + & Configuration.UI_MODE_NIGHT_MASK; + switch (currentNightMode) { + case Configuration.UI_MODE_NIGHT_NO: + // Night mode is not active, we're using the light theme + if (mInDarkMode) { + mInDarkMode = false; + reloadAssets(); + } + break; + case Configuration.UI_MODE_NIGHT_YES: + // Night mode is active, we're using dark theme + if (!mInDarkMode) { + mInDarkMode = true; + reloadAssets(); + } + break; + } + } + /** * Starts the animation after taking the screenshot */