From 901e7a826dcde851f61bd7811eceba2456fb9c25 Mon Sep 17 00:00:00 2001 From: ReallySnow Date: Thu, 15 Sep 2022 13:38:48 +0800 Subject: [PATCH 29/34] SystemUI: Follow light/dark theme in SplitShade Header * Google's default implementation is dark, which means it doesn't need to follow the light/dark color change, but we broke it, so add it to complete the SplitShade Header color change Co-authored-by: Col_or Change-Id: I5464039885197eeb43bd31b822bfcba7a1b08776 --- .../systemui/shade/ShadeHeaderController.kt | 28 +++++++++++++++++++ .../systemui/shade/carrier/ShadeCarrier.java | 8 ++++++ .../shade/carrier/ShadeCarrierGroup.java | 16 +++++++++++ .../shade/ShadeHeaderControllerTest.kt | 1 + 4 files changed, 53 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/shade/ShadeHeaderController.kt b/packages/SystemUI/src/com/android/systemui/shade/ShadeHeaderController.kt index 593260996198..5a5cb792c10b 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/ShadeHeaderController.kt +++ b/packages/SystemUI/src/com/android/systemui/shade/ShadeHeaderController.kt @@ -21,8 +21,11 @@ import android.animation.AnimatorListenerAdapter import android.annotation.IdRes import android.app.PendingIntent import android.app.StatusBarManager +import android.content.Context import android.content.Intent +import android.content.res.ColorStateList import android.content.res.Configuration +import android.graphics.Color import android.graphics.Insets import android.os.Bundle import android.os.Trace @@ -91,6 +94,7 @@ constructor( private val privacyIconsController: HeaderPrivacyIconsController, private val insetsProvider: StatusBarContentInsetsProvider, private val configurationController: ConfigurationController, + private val context: Context, private val variableDateViewControllerFactory: VariableDateViewController.Factory, @Named(SHADE_HEADER) private val batteryMeterViewController: BatteryMeterViewController, private val dumpManager: DumpManager, @@ -142,6 +146,7 @@ constructor( private var cutout: DisplayCutout? = null private var lastInsets: WindowInsets? = null private var nextAlarmIntent: PendingIntent? = null + private var textColorPrimary = Color.TRANSPARENT private var qsDisabled = false private var visible = false @@ -288,6 +293,10 @@ constructor( updateCarrierGroupPadding() clock.onDensityOrFontScaleChanged() } + + override fun onUiModeChanged() { + updateResources() + } } private val nextAlarmCallback = @@ -341,6 +350,7 @@ constructor( demoModeController.addCallback(demoModeReceiver) statusBarIconController.addIconGroup(iconManager) nextAlarmController.addCallback(nextAlarmCallback) + updateResources() systemIconsHoverContainer.setOnHoverListener( statusOverlayHoverListenerFactory.createListener(systemIconsHoverContainer) ) @@ -544,6 +554,24 @@ constructor( header.setPadding(padding, header.paddingTop, padding, header.paddingBottom) updateQQSPaddings() qsBatteryModeController.updateResources() + + val textColor = Utils.getColorAttrDefaultColor(context, android.R.attr.textColorPrimary) + val colorStateList = Utils.getColorAttr(context, android.R.attr.textColorPrimary) + if (textColor != textColorPrimary) { + val textColorSecondary = Utils.getColorAttrDefaultColor(context, + android.R.attr.textColorSecondary) + textColorPrimary = textColor + if (iconManager != null) { + iconManager.setTint( + textColorPrimary, + Utils.getColorAttrDefaultColor(context, android.R.attr.textColorPrimaryInverse), + ) + } + clock.setTextColor(textColorPrimary) + date.setTextColor(textColorPrimary) + mShadeCarrierGroup.updateColors(textColorPrimary, colorStateList) + batteryIcon.updateColors(textColorPrimary, textColorSecondary, textColorPrimary) + } } private fun updateQQSPaddings() { diff --git a/packages/SystemUI/src/com/android/systemui/shade/carrier/ShadeCarrier.java b/packages/SystemUI/src/com/android/systemui/shade/carrier/ShadeCarrier.java index 6ca0ad47a0a7..24a1e7cda1fd 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/carrier/ShadeCarrier.java +++ b/packages/SystemUI/src/com/android/systemui/shade/carrier/ShadeCarrier.java @@ -152,6 +152,14 @@ public class ShadeCarrier extends LinearLayout { com.android.settingslib.R.string.not_default_data_content_description)); } + public void updateColors(ColorStateList colorStateList) { + final boolean visible = !mIsSingleCarrier; + if (visible) { + mMobileRoaming.setImageTintList(colorStateList); + mMobileSignal.setImageTintList(colorStateList); + } + } + @VisibleForTesting View getRSSIView() { return mMobileGroup; diff --git a/packages/SystemUI/src/com/android/systemui/shade/carrier/ShadeCarrierGroup.java b/packages/SystemUI/src/com/android/systemui/shade/carrier/ShadeCarrierGroup.java index e84fb485829c..a5bcfeacff31 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/carrier/ShadeCarrierGroup.java +++ b/packages/SystemUI/src/com/android/systemui/shade/carrier/ShadeCarrierGroup.java @@ -18,8 +18,11 @@ package com.android.systemui.shade.carrier; import android.annotation.StyleRes; import android.content.Context; +import android.content.res.ColorStateList; +import android.graphics.PorterDuff; import android.util.AttributeSet; import android.view.View; +import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -58,6 +61,19 @@ public class ShadeCarrierGroup extends LinearLayout { return findViewById(R.id.shade_carrier_divider2); } + public void updateColors(int color, ColorStateList colorStateList) { + getNoSimTextView().setTextColor(color); + ShadeCarrier[] shadeCarriers = { getCarrier1View(), getCarrier2View(), getCarrier3View() }; + for (ShadeCarrier shadeCarrier : shadeCarriers) { + for (int i = 0; i < shadeCarrier.getChildCount(); i++) { + shadeCarrier.updateColors(colorStateList); + if (shadeCarrier.getChildAt(i) instanceof TextView) { + ((TextView) shadeCarrier.getChildAt(i)).setTextColor(color); + } + } + } + } + public void updateTextAppearance(@StyleRes int resId) { FontSizeUtils.updateFontSizeFromStyle(getNoSimTextView(), resId); getCarrier1View().updateTextAppearance(resId); diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/ShadeHeaderControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/shade/ShadeHeaderControllerTest.kt index 9fa173ab040a..de321ba62105 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/ShadeHeaderControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/ShadeHeaderControllerTest.kt @@ -189,6 +189,7 @@ class ShadeHeaderControllerTest : SysuiTestCase() { privacyIconsController, insetsProvider, configurationController, + mockedContext, variableDateViewControllerFactory, batteryMeterViewController, dumpManager, -- 2.34.1