2 * Copyright (C) 2014 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.settings.location;
19 import android.content.Context;
20 import android.graphics.drawable.Drawable;
21 import android.preference.Preference;
22 import android.util.AttributeSet;
25 * A preference item that can dim the icon when it's disabled, either directly or because its parent
28 public class DimmableIconPreference extends Preference {
29 private static final int ICON_ALPHA_ENABLED = 255;
30 private static final int ICON_ALPHA_DISABLED = 102;
32 public DimmableIconPreference(Context context, AttributeSet attrs, int defStyle) {
33 super(context, attrs, defStyle);
36 public DimmableIconPreference(Context context, AttributeSet attrs) {
37 super(context, attrs);
40 public DimmableIconPreference(Context context) {
44 private void dimIcon(boolean dimmed) {
45 Drawable icon = getIcon();
47 icon.mutate().setAlpha(dimmed ? ICON_ALPHA_DISABLED : ICON_ALPHA_ENABLED);
53 public void onParentChanged(Preference parent, boolean disableChild) {
54 dimIcon(disableChild);
55 super.onParentChanged(parent, disableChild);
59 public void setEnabled(boolean enabled) {
61 super.setEnabled(enabled);