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 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; 24 25 import java.util.List; 26 27 import com.android.settingslib.RestrictedLockUtils; 28 29 import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; 30 31 public class RestrictedRadioButton extends RadioButton { 32 private Context mContext; 33 private boolean mDisabledByAdmin; 34 private EnforcedAdmin mEnforcedAdmin; 35 36 public RestrictedRadioButton(Context context) { 37 this(context, null); 38 } 39 40 public RestrictedRadioButton(Context context, AttributeSet attrs) { 41 this(context, attrs, com.android.internal.R.attr.radioButtonStyle); 42 } 43 44 public RestrictedRadioButton(Context context, AttributeSet attrs, int defStyleAttr) { 45 this(context, attrs, defStyleAttr, 0); 46 } 47 48 public RestrictedRadioButton(Context context, AttributeSet attrs, int defStyleAttr, 49 int defStyleRes) { 50 super(context, attrs, defStyleAttr, defStyleRes); 51 mContext = context; 52 } 53 54 @Override 55 public boolean performClick() { 56 if (mDisabledByAdmin) { 57 RestrictedLockUtils.sendShowAdminSupportDetailsIntent(mContext, mEnforcedAdmin); 58 return true; 59 } 60 return super.performClick(); 61 } 62 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); 73 } else { 74 getButtonDrawable().clearColorFilter(); 75 } 76 } 77 } 78 79 public boolean isDisabledByAdmin() { 80 return mDisabledByAdmin; 81 } 82 }