Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 76492fbb authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Read battery and icon colors from theme

QuickStatusBarHeader doesn't listen for dark events, so it should be
reading text colors from the default theme instead.

Test: change to dark theme, change to light theme
Test: change battery level via adb
Fixes: 179685319
Change-Id: I35f59af58c501c6b6f204be31750b10d73158b71
parent 8319d597
Loading
Loading
Loading
Loading
+11 −36
Original line number Original line Diff line number Diff line
@@ -49,7 +49,6 @@ import android.widget.TextView;


import androidx.annotation.StyleRes;
import androidx.annotation.StyleRes;


import com.android.settingslib.Utils;
import com.android.settingslib.graph.ThemedBatteryDrawable;
import com.android.settingslib.graph.ThemedBatteryDrawable;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.plugins.DarkIconDispatcher;
import com.android.systemui.plugins.DarkIconDispatcher;
@@ -105,11 +104,6 @@ public class BatteryMeterView extends LinearLayout implements
    private DualToneHandler mDualToneHandler;
    private DualToneHandler mDualToneHandler;
    private int mUser;
    private int mUser;


    /**
     * Whether we should use colors that adapt based on wallpaper/the scrim behind quick settings.
     */
    private boolean mUseWallpaperTextColors;

    private int mNonAdaptedSingleToneColor;
    private int mNonAdaptedSingleToneColor;
    private int mNonAdaptedForegroundColor;
    private int mNonAdaptedForegroundColor;
    private int mNonAdaptedBackgroundColor;
    private int mNonAdaptedBackgroundColor;
@@ -242,31 +236,6 @@ public class BatteryMeterView extends LinearLayout implements
        mIsSubscribedForTunerUpdates = false;
        mIsSubscribedForTunerUpdates = false;
    }
    }


    /**
     * Sets whether the battery meter view uses the wallpaperTextColor. If we're not using it, we'll
     * revert back to dark-mode-based/tinted colors.
     *
     * @param shouldUseWallpaperTextColor whether we should use wallpaperTextColor for all
     *                                    components
     */
    public void useWallpaperTextColor(boolean shouldUseWallpaperTextColor) {
        if (shouldUseWallpaperTextColor == mUseWallpaperTextColors) {
            return;
        }

        mUseWallpaperTextColors = shouldUseWallpaperTextColor;

        if (mUseWallpaperTextColors) {
            updateColors(
                    Utils.getColorAttrDefaultColor(mContext, R.attr.wallpaperTextColor),
                    Utils.getColorAttrDefaultColor(mContext, R.attr.wallpaperTextColorSecondary),
                    Utils.getColorAttrDefaultColor(mContext, R.attr.wallpaperTextColor));
        } else {
            updateColors(mNonAdaptedForegroundColor, mNonAdaptedBackgroundColor,
                    mNonAdaptedSingleToneColor);
        }
    }

    public void setColorsFromContext(Context context) {
    public void setColorsFromContext(Context context) {
        if (context == null) {
        if (context == null) {
            return;
            return;
@@ -476,13 +445,19 @@ public class BatteryMeterView extends LinearLayout implements
        mNonAdaptedForegroundColor = mDualToneHandler.getFillColor(intensity);
        mNonAdaptedForegroundColor = mDualToneHandler.getFillColor(intensity);
        mNonAdaptedBackgroundColor = mDualToneHandler.getBackgroundColor(intensity);
        mNonAdaptedBackgroundColor = mDualToneHandler.getBackgroundColor(intensity);


        if (!mUseWallpaperTextColors) {
        updateColors(mNonAdaptedForegroundColor, mNonAdaptedBackgroundColor,
        updateColors(mNonAdaptedForegroundColor, mNonAdaptedBackgroundColor,
                mNonAdaptedSingleToneColor);
                mNonAdaptedSingleToneColor);
    }
    }
    }


    private void updateColors(int foregroundColor, int backgroundColor, int singleToneColor) {
    /**
     * Sets icon and text colors. This will be overridden by {@code onDarkChanged} events,
     * if registered.
     *
     * @param foregroundColor
     * @param backgroundColor
     * @param singleToneColor
     */
    public void updateColors(int foregroundColor, int backgroundColor, int singleToneColor) {
        mDrawable.setColors(foregroundColor, backgroundColor, singleToneColor);
        mDrawable.setColors(foregroundColor, backgroundColor, singleToneColor);
        mTextColor = singleToneColor;
        mTextColor = singleToneColor;
        if (mBatteryPercentView != null) {
        if (mBatteryPercentView != null) {
+6 −15
Original line number Original line Diff line number Diff line
@@ -29,7 +29,6 @@ import android.media.AudioManager;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.util.MathUtils;
import android.util.MathUtils;
import android.util.Pair;
import android.util.Pair;
import android.view.ContextThemeWrapper;
import android.view.DisplayCutout;
import android.view.DisplayCutout;
import android.view.View;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup;
@@ -48,7 +47,6 @@ import androidx.lifecycle.LifecycleRegistry;


import com.android.settingslib.Utils;
import com.android.settingslib.Utils;
import com.android.systemui.BatteryMeterView;
import com.android.systemui.BatteryMeterView;
import com.android.systemui.DualToneHandler;
import com.android.systemui.Interpolators;
import com.android.systemui.Interpolators;
import com.android.systemui.R;
import com.android.systemui.R;
import com.android.systemui.privacy.OngoingPrivacyChip;
import com.android.systemui.privacy.OngoingPrivacyChip;
@@ -75,7 +73,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements LifecycleOwn
    protected QuickQSPanel mHeaderQsPanel;
    protected QuickQSPanel mHeaderQsPanel;
    private TouchAnimator mStatusIconsAlphaAnimator;
    private TouchAnimator mStatusIconsAlphaAnimator;
    private TouchAnimator mHeaderTextContainerAlphaAnimator;
    private TouchAnimator mHeaderTextContainerAlphaAnimator;
    private DualToneHandler mDualToneHandler;


    private View mSystemIconsView;
    private View mSystemIconsView;
    private View mQuickQsStatusIcons;
    private View mQuickQsStatusIcons;
@@ -110,8 +107,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements LifecycleOwn


    public QuickStatusBarHeader(Context context, AttributeSet attrs) {
    public QuickStatusBarHeader(Context context, AttributeSet attrs) {
        super(context, attrs);
        super(context, attrs);
        mDualToneHandler = new DualToneHandler(
                new ContextThemeWrapper(context, R.style.QSHeaderTheme));
    }
    }


    @Override
    @Override
@@ -149,10 +144,8 @@ public class QuickStatusBarHeader extends RelativeLayout implements LifecycleOwn
    }
    }


    void onAttach(TintedIconManager iconManager) {
    void onAttach(TintedIconManager iconManager) {
        int colorForeground = Utils.getColorAttrDefaultColor(getContext(),
        int fillColor = Utils.getColorAttrDefaultColor(getContext(),
                android.R.attr.colorForeground);
                android.R.attr.textColorPrimary);
        float intensity = getColorIntensity(colorForeground);
        int fillColor = mDualToneHandler.getSingleColor(intensity);


        // Set the correct tint for the status icons so they contrast
        // Set the correct tint for the status icons so they contrast
        iconManager.setTint(fillColor);
        iconManager.setTint(fillColor);
@@ -271,14 +264,12 @@ public class QuickStatusBarHeader extends RelativeLayout implements LifecycleOwn


        int textColor = Utils.getColorAttrDefaultColor(mContext, android.R.attr.textColorPrimary);
        int textColor = Utils.getColorAttrDefaultColor(mContext, android.R.attr.textColorPrimary);
        if (textColor != mTextColorPrimary) {
        if (textColor != mTextColorPrimary) {
            int textColorSecondary = Utils.getColorAttrDefaultColor(mContext,
                    android.R.attr.textColorSecondary);
            mTextColorPrimary = textColor;
            mTextColorPrimary = textColor;
            mClockView.setTextColor(textColor);
            mClockView.setTextColor(textColor);

            mBatteryRemainingIcon.updateColors(mTextColorPrimary, textColorSecondary,
            float intensity = getColorIntensity(textColor);
                    mTextColorPrimary);
            int fillColor = mDualToneHandler.getSingleColor(intensity);

            Rect tintArea = new Rect(0, 0, 0, 0);
            mBatteryRemainingIcon.onDarkChanged(tintArea, intensity, fillColor);
        }
        }


        updateStatusIconAlphaAnimator();
        updateStatusIconAlphaAnimator();
+2 −13
Original line number Original line Diff line number Diff line
@@ -28,9 +28,7 @@ import android.widget.TextView;


import com.android.settingslib.Utils;
import com.android.settingslib.Utils;
import com.android.settingslib.graph.SignalDrawable;
import com.android.settingslib.graph.SignalDrawable;
import com.android.systemui.DualToneHandler;
import com.android.systemui.R;
import com.android.systemui.R;
import com.android.systemui.qs.QuickStatusBarHeader;


import java.util.Objects;
import java.util.Objects;


@@ -40,9 +38,6 @@ public class QSCarrier extends LinearLayout {
    private TextView mCarrierText;
    private TextView mCarrierText;
    private ImageView mMobileSignal;
    private ImageView mMobileSignal;
    private ImageView mMobileRoaming;
    private ImageView mMobileRoaming;
    private DualToneHandler mDualToneHandler;
    private ColorStateList mColorForegroundStateList;
    private float mColorForegroundIntensity;
    private CellSignalState mLastSignalState;
    private CellSignalState mLastSignalState;


    public QSCarrier(Context context) {
    public QSCarrier(Context context) {
@@ -64,7 +59,6 @@ public class QSCarrier extends LinearLayout {
    @Override
    @Override
    protected void onFinishInflate() {
    protected void onFinishInflate() {
        super.onFinishInflate();
        super.onFinishInflate();
        mDualToneHandler = new DualToneHandler(getContext());
        mMobileGroup = findViewById(R.id.mobile_combo);
        mMobileGroup = findViewById(R.id.mobile_combo);
        if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL)) {
        if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL)) {
            mMobileRoaming = findViewById(R.id.mobile_roaming_large);
            mMobileRoaming = findViewById(R.id.mobile_roaming_large);
@@ -74,11 +68,6 @@ public class QSCarrier extends LinearLayout {
        mMobileSignal = findViewById(R.id.mobile_signal);
        mMobileSignal = findViewById(R.id.mobile_signal);
        mCarrierText = findViewById(R.id.qs_carrier_text);
        mCarrierText = findViewById(R.id.qs_carrier_text);
        mMobileSignal.setImageDrawable(new SignalDrawable(mContext));
        mMobileSignal.setImageDrawable(new SignalDrawable(mContext));

        int colorForeground = Utils.getColorAttrDefaultColor(mContext,
                android.R.attr.colorForeground);
        mColorForegroundStateList = ColorStateList.valueOf(colorForeground);
        mColorForegroundIntensity = QuickStatusBarHeader.getColorIntensity(colorForeground);
    }
    }


    /**
    /**
@@ -92,8 +81,8 @@ public class QSCarrier extends LinearLayout {
        mMobileGroup.setVisibility(state.visible ? View.VISIBLE : View.GONE);
        mMobileGroup.setVisibility(state.visible ? View.VISIBLE : View.GONE);
        if (state.visible) {
        if (state.visible) {
            mMobileRoaming.setVisibility(state.roaming ? View.VISIBLE : View.GONE);
            mMobileRoaming.setVisibility(state.roaming ? View.VISIBLE : View.GONE);
            ColorStateList colorStateList = ColorStateList.valueOf(
            ColorStateList colorStateList = Utils.getColorAttr(mContext,
                    mDualToneHandler.getSingleColor(mColorForegroundIntensity));
                    android.R.attr.textColorPrimary);
            mMobileRoaming.setImageTintList(colorStateList);
            mMobileRoaming.setImageTintList(colorStateList);
            mMobileSignal.setImageTintList(colorStateList);
            mMobileSignal.setImageTintList(colorStateList);
            mMobileSignal.setImageLevel(state.mobileSignalIconId);
            mMobileSignal.setImageLevel(state.mobileSignalIconId);