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.widget.Switch; 20 21 import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; 22 23 /* 24 * The switch controller that is used to update the switch widget in the SwitchBar layout. 25 */ 26 public class SwitchBarController extends SwitchWidgetController implements 27 SwitchBar.OnSwitchChangeListener { 28 29 private final SwitchBar mSwitchBar; 30 SwitchBarController(SwitchBar switchBar)31 public SwitchBarController(SwitchBar switchBar) { 32 mSwitchBar = switchBar; 33 } 34 35 @Override setupView()36 public void setupView() { 37 mSwitchBar.show(); 38 } 39 40 @Override teardownView()41 public void teardownView() { 42 mSwitchBar.hide(); 43 } 44 45 @Override setTitle(String title)46 public void setTitle(String title) { 47 } 48 49 @Override startListening()50 public void startListening() { 51 mSwitchBar.addOnSwitchChangeListener(this); 52 } 53 54 @Override stopListening()55 public void stopListening() { 56 mSwitchBar.removeOnSwitchChangeListener(this); 57 } 58 59 @Override setChecked(boolean checked)60 public void setChecked(boolean checked) { 61 mSwitchBar.setChecked(checked); 62 } 63 64 @Override isChecked()65 public boolean isChecked() { 66 return mSwitchBar.isChecked(); 67 } 68 69 @Override setEnabled(boolean enabled)70 public void setEnabled(boolean enabled) { 71 mSwitchBar.setEnabled(enabled); 72 } 73 74 @Override onSwitchChanged(Switch switchView, boolean isChecked)75 public void onSwitchChanged(Switch switchView, boolean isChecked) { 76 if (mListener != null) { 77 mListener.onSwitchToggled(isChecked); 78 } 79 } 80 81 @Override setDisabledByAdmin(EnforcedAdmin admin)82 public void setDisabledByAdmin(EnforcedAdmin admin) { 83 mSwitchBar.setDisabledByAdmin(admin); 84 } 85 } 86