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

Commit dd5c04e7 authored by Johannes Gallmann's avatar Johannes Gallmann
Browse files

Fix battery chip screenshot test instability

This CL contains two changes that fix the battery chip color instability:
1. The colors that are passed into the BatteryMeterView from the BatteryStatusChip are corrected. It should always be black!
2. The BatteryMeterView adjusts its colors automatically when switching the theme from dark to light (and vice versa). A check is added to bypass this automatic color adjustment such that the BatterMeterView always keeps the black color (when it is inside a BatterStatusChip).

Bug: 308605791
Flag: NONE
Test: StatusbarChipsScreenshotTest
Change-Id: I541d282e36a3d4b16de6837fedcc494a671a4ceb
parent a891bc20
Loading
Loading
Loading
Loading
+12 −10
Original line number Diff line number Diff line
@@ -47,9 +47,9 @@ import androidx.annotation.VisibleForTesting;

import com.android.app.animation.Interpolators;
import com.android.systemui.DualToneHandler;
import com.android.systemui.res.R;
import com.android.systemui.plugins.DarkIconDispatcher;
import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver;
import com.android.systemui.res.R;
import com.android.systemui.statusbar.policy.BatteryController;

import java.io.PrintWriter;
@@ -87,10 +87,7 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
    private Drawable mUnknownStateDrawable;

    private DualToneHandler mDualToneHandler;

    private int mNonAdaptedSingleToneColor;
    private int mNonAdaptedForegroundColor;
    private int mNonAdaptedBackgroundColor;
    private boolean mIsStaticColor = false;

    private BatteryEstimateFetcher mBatteryEstimateFetcher;

@@ -447,13 +444,18 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {

    @Override
    public void onDarkChanged(ArrayList<Rect> areas, float darkIntensity, int tint) {
        if (mIsStaticColor) return;
        float intensity = DarkIconDispatcher.isInAreas(areas, this) ? darkIntensity : 0;
        mNonAdaptedSingleToneColor = mDualToneHandler.getSingleColor(intensity);
        mNonAdaptedForegroundColor = mDualToneHandler.getFillColor(intensity);
        mNonAdaptedBackgroundColor = mDualToneHandler.getBackgroundColor(intensity);
        int nonAdaptedSingleToneColor = mDualToneHandler.getSingleColor(intensity);
        int nonAdaptedForegroundColor = mDualToneHandler.getFillColor(intensity);
        int nonAdaptedBackgroundColor = mDualToneHandler.getBackgroundColor(intensity);

        updateColors(nonAdaptedForegroundColor, nonAdaptedBackgroundColor,
                nonAdaptedSingleToneColor);
    }

        updateColors(mNonAdaptedForegroundColor, mNonAdaptedBackgroundColor,
                mNonAdaptedSingleToneColor);
    public void setStaticColor(boolean isStaticColor) {
        mIsStaticColor = isStaticColor;
    }

    /**
+4 −7
Original line number Diff line number Diff line
@@ -22,9 +22,8 @@ import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout
import android.widget.LinearLayout
import com.android.settingslib.Utils
import com.android.systemui.res.R
import com.android.systemui.battery.BatteryMeterView
import com.android.systemui.res.R
import com.android.systemui.statusbar.events.BackgroundAnimatableView

class BatteryStatusChip @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
@@ -39,6 +38,9 @@ class BatteryStatusChip @JvmOverloads constructor(context: Context, attrs: Attri
        inflate(context, R.layout.battery_status_chip, this)
        roundedContainer = requireViewById(R.id.rounded_container)
        batteryMeterView = requireViewById(R.id.battery_meter_view)
        batteryMeterView.setStaticColor(true)
        val primaryColor = context.resources.getColor(android.R.color.black, context.theme)
        batteryMeterView.updateColors(primaryColor, primaryColor, primaryColor)
        updateResources()
    }

@@ -63,11 +65,6 @@ class BatteryStatusChip @JvmOverloads constructor(context: Context, attrs: Attri

    @SuppressLint("UseCompatLoadingForDrawables")
    private fun updateResources() {
        val primaryColor =
            Utils.getColorAttrDefaultColor(context, com.android.internal.R.attr.colorPrimary)
        val textColorSecondary =
            Utils.getColorAttrDefaultColor(mContext, android.R.attr.textColorSecondary)
        batteryMeterView.updateColors(primaryColor, textColorSecondary, primaryColor)
        roundedContainer.background = mContext.getDrawable(R.drawable.statusbar_chip_bg)
    }
}