Home | History | Annotate | Download | only in widget
      1 /*
      2  * Copyright (C) 2017 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.widget;
     18 
     19 import android.support.v7.preference.Preference;
     20 import android.widget.Switch;
     21 import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
     22 
     23 /*
     24  * The switch controller that is used to update the switch widget in the MasterSwitchPreference
     25  * layout.
     26  */
     27 public class MasterSwitchController extends SwitchWidgetController implements
     28     Preference.OnPreferenceChangeListener {
     29 
     30     private final MasterSwitchPreference mPreference;
     31 
     32     public MasterSwitchController(MasterSwitchPreference preference) {
     33         mPreference = preference;
     34     }
     35 
     36     @Override
     37     public void updateTitle(boolean isChecked) {
     38     }
     39 
     40     @Override
     41     public void startListening() {
     42         mPreference.setOnPreferenceChangeListener(this);
     43     }
     44 
     45     @Override
     46     public void stopListening() {
     47         mPreference.setOnPreferenceChangeListener(null);
     48     }
     49 
     50     @Override
     51     public void setChecked(boolean checked) {
     52         mPreference.setChecked(checked);
     53     }
     54 
     55     @Override
     56     public boolean isChecked() {
     57         return mPreference.isChecked();
     58     }
     59 
     60     @Override
     61     public void setEnabled(boolean enabled) {
     62         mPreference.setSwitchEnabled(enabled);
     63     }
     64 
     65     @Override
     66     public boolean onPreferenceChange(Preference preference, Object newValue) {
     67         if (mListener != null) {
     68             return mListener.onSwitchToggled((Boolean) newValue);
     69         }
     70         return false;
     71     }
     72 
     73     @Override
     74     public void setDisabledByAdmin(EnforcedAdmin admin) {
     75         mPreference.setDisabledByAdmin(admin);
     76     }
     77 }
     78