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 static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
21 import android.content.Context;
22 import android.graphics.PorterDuff;
23 import android.util.AttributeSet;
24 import android.widget.CheckBox;
25 import android.widget.RadioButton;
26 import android.widget.TextView;
28 import com.android.settingslib.RestrictedLockUtils;
31 * A checkbox that can be restricted by device policy, in which case it shows a dialog explaining
32 * what component restricted it.
34 public class RestrictedCheckBox extends CheckBox {
35 private Context mContext;
36 private boolean mDisabledByAdmin;
37 private EnforcedAdmin mEnforcedAdmin;
39 public RestrictedCheckBox(Context context) {
43 public RestrictedCheckBox(Context context, AttributeSet attrs) {
44 super(context, attrs);
49 public boolean performClick() {
50 if (mDisabledByAdmin) {
51 RestrictedLockUtils.sendShowAdminSupportDetailsIntent(mContext, mEnforcedAdmin);
54 return super.performClick();
57 public void setDisabledByAdmin(EnforcedAdmin admin) {
58 final boolean disabled = (admin != null);
59 mEnforcedAdmin = admin;
60 if (mDisabledByAdmin != disabled) {
61 mDisabledByAdmin = disabled;
62 RestrictedLockUtils.setTextViewAsDisabledByAdmin(mContext, this, mDisabledByAdmin);
63 if (mDisabledByAdmin) {
64 getButtonDrawable().setColorFilter(mContext.getColor(R.color.disabled_text_color),
65 PorterDuff.Mode.MULTIPLY);
67 getButtonDrawable().clearColorFilter();
72 public boolean isDisabledByAdmin() {
73 return mDisabledByAdmin;