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

Commit c9e26ba7 authored by Raff Tsai's avatar Raff Tsai
Browse files

Fix Disabled text color in dark theme

disabled_text_color is similar to background color in dark theme.
Use text color multiply disabledAlpha to get disabled text color.

Fixes: 137639665
Test: manual
Change-Id: I00bb1dbedd0032001c2fc325b412dacb08f84132
parent 6bd0cc02
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -663,7 +663,8 @@ public class RestrictedLockUtilsInternal extends RestrictedLockUtils {
        final SpannableStringBuilder sb = new SpannableStringBuilder(textView.getText());
        removeExistingRestrictedSpans(sb);
        if (disabled) {
            final int disabledColor = context.getColor(R.color.disabled_text_color);
            final int disabledColor = Utils.getDisabled(context,
                    textView.getCurrentTextColor());
            sb.setSpan(new ForegroundColorSpan(disabledColor), 0, sb.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            textView.setCompoundDrawables(null, null, getRestrictedPadlock(context), null);
+7 −0
Original line number Diff line number Diff line
@@ -218,6 +218,13 @@ public class Utils {
        return list.getDefaultColor();
    }

    /**
     * This method computes disabled color from normal color
     *
     * @param context
     * @param inputColor normal color.
     * @return disabled color.
     */
    @ColorInt
    public static int getDisabled(Context context, int inputColor) {
        return applyAlphaAttr(context, android.R.attr.disabledAlpha, inputColor);
+35 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settingslib.utils;

import android.content.Context;
import android.content.res.TypedArray;

/** Utility class for getting color attribute **/
public class ColorUtil {

    /**
     * Returns android:disabledAlpha value in context
     */
    public static float getDisabledAlpha(Context context) {
        final TypedArray ta = context.obtainStyledAttributes(
                new int[]{android.R.attr.disabledAlpha});
        final float alpha = ta.getFloat(0, 0);
        ta.recycle();
        return alpha;
    }
}