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 updateTitle(boolean isChecked)46 public void updateTitle(boolean isChecked) { 47 mSwitchBar.setTextViewLabelAndBackground(isChecked); 48 } 49 50 @Override startListening()51 public void startListening() { 52 mSwitchBar.addOnSwitchChangeListener(this); 53 } 54 55 @Override stopListening()56 public void stopListening() { 57 mSwitchBar.removeOnSwitchChangeListener(this); 58 } 59 60 @Override setChecked(boolean checked)61 public void setChecked(boolean checked) { 62 mSwitchBar.setChecked(checked); 63 } 64 65 @Override isChecked()66 public boolean isChecked() { 67 return mSwitchBar.isChecked(); 68 } 69 70 @Override setEnabled(boolean enabled)71 public void setEnabled(boolean enabled) { 72 mSwitchBar.setEnabled(enabled); 73 } 74 75 @Override onSwitchChanged(Switch switchView, boolean isChecked)76 public void onSwitchChanged(Switch switchView, boolean isChecked) { 77 if (mListener != null) { 78 mListener.onSwitchToggled(isChecked); 79 } 80 } 81 82 @Override setDisabledByAdmin(EnforcedAdmin admin)83 public void setDisabledByAdmin(EnforcedAdmin admin) { 84 mSwitchBar.setDisabledByAdmin(admin); 85 } 86 } 87