Home | History | Annotate | Download | only in settings
      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 import android.widget.RadioButton;
     26 import android.widget.TextView;
     27 
     28 import com.android.settingslib.RestrictedLockUtils;
     29 
     30 /**
     31  * A checkbox that can be restricted by device policy, in which case it shows a dialog explaining
     32  * what component restricted it.
     33  */
     34 public class RestrictedCheckBox extends CheckBox {
     35     private Context mContext;
     36     private boolean mDisabledByAdmin;
     37     private EnforcedAdmin mEnforcedAdmin;
     38 
     39     public RestrictedCheckBox(Context context) {
     40         this(context, null);
     41     }
     42 
     43     public RestrictedCheckBox(Context context, AttributeSet attrs) {
     44         super(context, attrs);
     45         mContext = context;
     46     }
     47 
     48     @Override
     49     public boolean performClick() {
     50         if (mDisabledByAdmin) {
     51             RestrictedLockUtils.sendShowAdminSupportDetailsIntent(mContext, mEnforcedAdmin);
     52             return true;
     53         }
     54         return super.performClick();
     55     }
     56 
     57     public void setDisabledByAdmin(EnforcedAdmin admin) {
     58         final boolean disabled = (admin != null);
     59         mEnforcedAdmin = admin;
     60         if (mDisabledByAdmin != disabled) {
     61             mDisabledByAdmin = disabled;
     62             RestrictedLockUtils.setTextViewAsDisabledByAdmin(mContext, this, 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 
     72     public boolean isDisabledByAdmin() {
     73         return mDisabledByAdmin;
     74     }
     75 }