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

Commit 80f8b87e authored by Menghan Li's avatar Menghan Li
Browse files

fix(ColorCorrection): Palette preview text contrast Issue

Root Cause: The palette preview's text color inherits dynamic colors from the BC pattern, leading to insufficient contrast against some backgrounds. This wasn't a problem in the original design, as the BC pattern was introduced later.

Solution: Set the palette preview text color to textColorPrimary to ensure the text remains legible against a wider range of background colors.

Bug: 378775277
Flag: EXEMPT bugfix
Test: atest PaletteListPreferenceTest

Change-Id: I8efb9f9d916d618b450df169292202e499d8ac0d
parent aa7114cf
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static com.android.settings.accessibility.AccessibilityUtil.getScreenWidt
import static com.google.common.primitives.Ints.max;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Paint.FontMetrics;
import android.graphics.drawable.GradientDrawable;
import android.util.AttributeSet;
@@ -39,6 +40,7 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;

import com.android.settings.R;
import com.android.settingslib.Utils;

import com.google.common.primitives.Floats;
import com.google.common.primitives.Ints;
@@ -128,6 +130,8 @@ public final class PaletteListPreference extends Preference {
        final List<Integer> paletteColors = getPaletteColors(context);
        final List<String> paletteData = getPaletteData(context);

        final ColorStateList textColor =
                Utils.getColorAttr(getContext(), android.R.attr.textColorPrimary);
        final float textPadding =
                context.getResources().getDimension(R.dimen.accessibility_layout_margin_start_end);
        final String maxLengthData =
@@ -143,6 +147,7 @@ public final class PaletteListPreference extends Preference {
        for (int i = 0; i < paletteData.size(); ++i) {
            final TextView textView = new TextView(context);
            textView.setText(paletteData.get(i));
            textView.setTextColor(textColor);
            textView.setHeight(paletteItemHeight);
            textView.setPaddingRelative(Math.round(textPadding), 0, 0, 0);
            textView.setGravity(Gravity.CENTER_VERTICAL);
+15 −4
Original line number Diff line number Diff line
@@ -16,17 +16,20 @@

package com.android.settings.accessibility;

import static org.junit.Assert.assertEquals;
import static com.google.common.truth.Truth.assertThat;

import android.content.Context;
import android.content.res.ColorStateList;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.preference.PreferenceViewHolder;
import androidx.test.core.app.ApplicationProvider;

import com.android.settings.R;
import com.android.settingslib.Utils;

import org.junit.Before;
import org.junit.Test;
@@ -53,12 +56,20 @@ public final class PaletteListPreferenceTest {

    @Test
    public void initPaletteView_success() {
        final int expectedCount =
                mContext.getResources().getStringArray(R.array.setting_palette_data).length;
        final ColorStateList expectedTextColor =
                Utils.getColorAttr(mContext, android.R.attr.textColorPrimary);

        mPaletteListPreference.onBindViewHolder(mPreferenceViewHolder);

        final ViewGroup viewGroup =
                mPreferenceViewHolder.itemView.findViewById(R.id.palette_view);
        final int expectedCount =
                mContext.getResources().getStringArray(R.array.setting_palette_data).length;
        assertEquals(expectedCount, viewGroup.getChildCount());
        final int childCount = viewGroup.getChildCount();
        assertThat(childCount).isEqualTo(expectedCount);
        for (int i = 0; i < childCount; i++) {
            final TextView textView = (TextView) viewGroup.getChildAt(i);
            assertThat(textView.getTextColors()).isEqualTo(expectedTextColor);
        }
    }
}