2 * Copyright (C) 2016 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;
19 import android.content.Context;
20 import android.graphics.PorterDuff;
21 import android.util.AttributeSet;
22 import android.widget.RadioButton;
23 import android.widget.TextView;
25 import java.util.List;
27 import com.android.settingslib.RestrictedLockUtils;
29 import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
31 public class RestrictedRadioButton extends RadioButton {
32 private Context mContext;
33 private boolean mDisabledByAdmin;
34 private EnforcedAdmin mEnforcedAdmin;
36 public RestrictedRadioButton(Context context) {
40 public RestrictedRadioButton(Context context, AttributeSet attrs) {
41 this(context, attrs, com.android.internal.R.attr.radioButtonStyle);
44 public RestrictedRadioButton(Context context, AttributeSet attrs, int defStyleAttr) {
45 this(context, attrs, defStyleAttr, 0);
48 public RestrictedRadioButton(Context context, AttributeSet attrs, int defStyleAttr,
50 super(context, attrs, defStyleAttr, defStyleRes);
55 public boolean performClick() {
56 if (mDisabledByAdmin) {
57 RestrictedLockUtils.sendShowAdminSupportDetailsIntent(mContext, mEnforcedAdmin);
60 return super.performClick();
63 public void setDisabledByAdmin(EnforcedAdmin admin) {
64 final boolean disabled = (admin != null);
65 mEnforcedAdmin = admin;
66 if (mDisabledByAdmin != disabled) {
67 mDisabledByAdmin = disabled;
68 RestrictedLockUtils.setTextViewAsDisabledByAdmin(mContext,
69 (TextView) this, mDisabledByAdmin);
70 if (mDisabledByAdmin) {
71 getButtonDrawable().setColorFilter(mContext.getColor(R.color.disabled_text_color),
72 PorterDuff.Mode.MULTIPLY);
74 getButtonDrawable().clearColorFilter();
79 public boolean isDisabledByAdmin() {
80 return mDisabledByAdmin;