blob: 24a1b784448a31f77406950f479868b656f6303c [file] [log] [blame]
Sudheer Shanka1901ae32016-01-08 20:40:55 +00001/*
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
Fan Zhangc7162cd2018-06-18 15:21:41 -070019import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
20
Sudheer Shanka1901ae32016-01-08 20:40:55 +000021import android.content.Context;
Sudheer Shanka1901ae32016-01-08 20:40:55 +000022import android.util.AttributeSet;
23import android.widget.RadioButton;
24import android.widget.TextView;
25
Sudheer Shanka1901ae32016-01-08 20:40:55 +000026import com.android.settingslib.RestrictedLockUtils;
Philip P. Moltmanne3f72112018-08-28 15:01:43 -070027import com.android.settingslib.RestrictedLockUtilsInternal;
Raff Tsaif7e30952019-07-18 01:03:43 +080028import com.android.settingslib.utils.ColorUtil;
Sudheer Shanka1901ae32016-01-08 20:40:55 +000029
Sudheer Shanka1901ae32016-01-08 20:40:55 +000030public class RestrictedRadioButton extends RadioButton {
31 private Context mContext;
32 private boolean mDisabledByAdmin;
33 private EnforcedAdmin mEnforcedAdmin;
34
35 public RestrictedRadioButton(Context context) {
36 this(context, null);
37 }
38
39 public RestrictedRadioButton(Context context, AttributeSet attrs) {
40 this(context, attrs, com.android.internal.R.attr.radioButtonStyle);
41 }
42
43 public RestrictedRadioButton(Context context, AttributeSet attrs, int defStyleAttr) {
44 this(context, attrs, defStyleAttr, 0);
45 }
46
47 public RestrictedRadioButton(Context context, AttributeSet attrs, int defStyleAttr,
48 int defStyleRes) {
49 super(context, attrs, defStyleAttr, defStyleRes);
50 mContext = context;
51 }
52
53 @Override
54 public boolean performClick() {
55 if (mDisabledByAdmin) {
56 RestrictedLockUtils.sendShowAdminSupportDetailsIntent(mContext, mEnforcedAdmin);
57 return true;
58 }
59 return super.performClick();
60 }
61
62 public void setDisabledByAdmin(EnforcedAdmin admin) {
63 final boolean disabled = (admin != null);
64 mEnforcedAdmin = admin;
65 if (mDisabledByAdmin != disabled) {
66 mDisabledByAdmin = disabled;
Philip P. Moltmanne3f72112018-08-28 15:01:43 -070067 RestrictedLockUtilsInternal.setTextViewAsDisabledByAdmin(mContext,
Sudheer Shanka1901ae32016-01-08 20:40:55 +000068 (TextView) this, mDisabledByAdmin);
69 if (mDisabledByAdmin) {
Raff Tsaif7e30952019-07-18 01:03:43 +080070 getButtonDrawable().setAlpha(
71 (int) (255 * ColorUtil.getDisabledAlpha(mContext)));
Sudheer Shanka1901ae32016-01-08 20:40:55 +000072 } else {
Raff Tsaif7e30952019-07-18 01:03:43 +080073 getButtonDrawable().setAlpha(0);
Sudheer Shanka1901ae32016-01-08 20:40:55 +000074 }
75 }
76 }
77
78 public boolean isDisabledByAdmin() {
79 return mDisabledByAdmin;
80 }
81}