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

Commit 0ed6caf8 authored by Edgar Wang's avatar Edgar Wang Committed by Android (Google) Code Review
Browse files

Merge "Support gray out preference icon when the preference is restricted" into main

parents e5156003 e586c04e
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -133,6 +133,12 @@ public class PrimarySwitchPreference extends RestrictedPreference {
        }
    }

    @Override
    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
        setSwitchEnabled(enabled);
    }

    @VisibleForTesting(otherwise = VisibleForTesting.NONE)
    public boolean isSwitchEnabled() {
        return mEnableSwitch;
+7 −4
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.UserHandle;
import android.text.TextUtils;
@@ -229,13 +230,15 @@ public class RestrictedPreferenceHelper {
    }

    private void updateDisabledState() {
        boolean isEnabled = !(mDisabledByAdmin || mDisabledByAppOps);
        if (!(mPreference instanceof RestrictedTopLevelPreference)) {
            mPreference.setEnabled(!(mDisabledByAdmin || mDisabledByAppOps));
            mPreference.setEnabled(isEnabled);
        }

        if (mPreference instanceof PrimarySwitchPreference) {
            ((PrimarySwitchPreference) mPreference)
                    .setSwitchEnabled(!(mDisabledByAdmin || mDisabledByAppOps));
        Drawable icon = mPreference.getIcon();
        if (!isEnabled && icon != null) {
            Utils.convertToGrayscale(icon);
            mPreference.setIcon(icon);
        }
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -700,4 +700,14 @@ public class Utils {
        return false;
    }

    /**
     *  Convert a drawable to grayscale drawable
     */
    public static void convertToGrayscale(@NonNull Drawable drawable) {
        ColorMatrix matrix = new ColorMatrix();
        matrix.setSaturation(0.0f);

        ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
        drawable.setColorFilter(filter);
    }
}