Sudheer Shanka | 1901ae3 | 2016-01-08 20:40:55 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.settings; |
| 18 | |
Fan Zhang | c7162cd | 2018-06-18 15:21:41 -0700 | [diff] [blame] | 19 | import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; |
| 20 | |
Sudheer Shanka | 1901ae3 | 2016-01-08 20:40:55 +0000 | [diff] [blame] | 21 | import android.content.Context; |
Sudheer Shanka | 1901ae3 | 2016-01-08 20:40:55 +0000 | [diff] [blame] | 22 | import android.util.AttributeSet; |
| 23 | import android.widget.RadioButton; |
| 24 | import android.widget.TextView; |
| 25 | |
Sudheer Shanka | 1901ae3 | 2016-01-08 20:40:55 +0000 | [diff] [blame] | 26 | import com.android.settingslib.RestrictedLockUtils; |
Philip P. Moltmann | e3f7211 | 2018-08-28 15:01:43 -0700 | [diff] [blame] | 27 | import com.android.settingslib.RestrictedLockUtilsInternal; |
Raff Tsai | f7e3095 | 2019-07-18 01:03:43 +0800 | [diff] [blame] | 28 | import com.android.settingslib.utils.ColorUtil; |
Sudheer Shanka | 1901ae3 | 2016-01-08 20:40:55 +0000 | [diff] [blame] | 29 | |
Sudheer Shanka | 1901ae3 | 2016-01-08 20:40:55 +0000 | [diff] [blame] | 30 | public 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. Moltmann | e3f7211 | 2018-08-28 15:01:43 -0700 | [diff] [blame] | 67 | RestrictedLockUtilsInternal.setTextViewAsDisabledByAdmin(mContext, |
Sudheer Shanka | 1901ae3 | 2016-01-08 20:40:55 +0000 | [diff] [blame] | 68 | (TextView) this, mDisabledByAdmin); |
| 69 | if (mDisabledByAdmin) { |
Raff Tsai | f7e3095 | 2019-07-18 01:03:43 +0800 | [diff] [blame] | 70 | getButtonDrawable().setAlpha( |
| 71 | (int) (255 * ColorUtil.getDisabledAlpha(mContext))); |
Sudheer Shanka | 1901ae3 | 2016-01-08 20:40:55 +0000 | [diff] [blame] | 72 | } else { |
Raff Tsai | f7e3095 | 2019-07-18 01:03:43 +0800 | [diff] [blame] | 73 | getButtonDrawable().setAlpha(0); |
Sudheer Shanka | 1901ae3 | 2016-01-08 20:40:55 +0000 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | public boolean isDisabledByAdmin() { |
| 79 | return mDisabledByAdmin; |
| 80 | } |
| 81 | } |