blob: 828c4434d95da36f3bd278bd84418b5119147609 [file] [log] [blame]
Adrian Roos059b0fa2016-05-11 15:49:20 -04001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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
15 */
16
17package com.android.settings;
18
19import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
20
21import android.content.Context;
22import android.graphics.PorterDuff;
23import android.util.AttributeSet;
24import android.widget.CheckBox;
Adrian Roos059b0fa2016-05-11 15:49:20 -040025
26import com.android.settingslib.RestrictedLockUtils;
Philip P. Moltmanne3f72112018-08-28 15:01:43 -070027import com.android.settingslib.RestrictedLockUtilsInternal;
Adrian Roos059b0fa2016-05-11 15:49:20 -040028
29/**
30 * A checkbox that can be restricted by device policy, in which case it shows a dialog explaining
31 * what component restricted it.
32 */
33public class RestrictedCheckBox extends CheckBox {
34 private Context mContext;
35 private boolean mDisabledByAdmin;
36 private EnforcedAdmin mEnforcedAdmin;
37
38 public RestrictedCheckBox(Context context) {
39 this(context, null);
40 }
41
42 public RestrictedCheckBox(Context context, AttributeSet attrs) {
43 super(context, attrs);
44 mContext = context;
45 }
46
47 @Override
48 public boolean performClick() {
49 if (mDisabledByAdmin) {
50 RestrictedLockUtils.sendShowAdminSupportDetailsIntent(mContext, mEnforcedAdmin);
51 return true;
52 }
53 return super.performClick();
54 }
55
56 public void setDisabledByAdmin(EnforcedAdmin admin) {
57 final boolean disabled = (admin != null);
58 mEnforcedAdmin = admin;
59 if (mDisabledByAdmin != disabled) {
60 mDisabledByAdmin = disabled;
Philip P. Moltmanne3f72112018-08-28 15:01:43 -070061 RestrictedLockUtilsInternal.setTextViewAsDisabledByAdmin(mContext, this,
62 mDisabledByAdmin);
Adrian Roos059b0fa2016-05-11 15:49:20 -040063 if (mDisabledByAdmin) {
64 getButtonDrawable().setColorFilter(mContext.getColor(R.color.disabled_text_color),
65 PorterDuff.Mode.MULTIPLY);
66 } else {
67 getButtonDrawable().clearColorFilter();
68 }
69 }
70 }
71
72 public boolean isDisabledByAdmin() {
73 return mDisabledByAdmin;
74 }
75}