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 static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; 20 21 import android.content.Context; 22 import android.graphics.PorterDuff; 23 import android.util.AttributeSet; 24 import android.widget.CheckBox; 25 26 import com.android.settingslib.RestrictedLockUtils; 27 import com.android.settingslib.RestrictedLockUtilsInternal; 28 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 */ 33 public class RestrictedCheckBox extends CheckBox { 34 private Context mContext; 35 private boolean mDisabledByAdmin; 36 private EnforcedAdmin mEnforcedAdmin; 37 RestrictedCheckBox(Context context)38 public RestrictedCheckBox(Context context) { 39 this(context, null); 40 } 41 RestrictedCheckBox(Context context, AttributeSet attrs)42 public RestrictedCheckBox(Context context, AttributeSet attrs) { 43 super(context, attrs); 44 mContext = context; 45 } 46 47 @Override performClick()48 public boolean performClick() { 49 if (mDisabledByAdmin) { 50 RestrictedLockUtils.sendShowAdminSupportDetailsIntent(mContext, mEnforcedAdmin); 51 return true; 52 } 53 return super.performClick(); 54 } 55 setDisabledByAdmin(EnforcedAdmin admin)56 public void setDisabledByAdmin(EnforcedAdmin admin) { 57 final boolean disabled = (admin != null); 58 mEnforcedAdmin = admin; 59 if (mDisabledByAdmin != disabled) { 60 mDisabledByAdmin = disabled; 61 RestrictedLockUtilsInternal.setTextViewAsDisabledByAdmin(mContext, this, 62 mDisabledByAdmin); 63 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 isDisabledByAdmin()72 public boolean isDisabledByAdmin() { 73 return mDisabledByAdmin; 74 } 75 }