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

Commit e586c04e authored by Edgar Wang's avatar Edgar Wang
Browse files

Support gray out preference icon when the preference is restricted

Bug: 223602527
Test: visual
Change-Id: Ib78b6208fc7dba1a5a3189f193084a9805431d03
parent 77c76ec9
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);
    }
}