1 /* 2 * Copyright (C) 2019 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.settingslib.drawer; 18 19 import androidx.annotation.NonNull; 20 21 /** 22 * A controller that manages events for switch. 23 * 24 * @deprecated Use {@link EntriesProvider} with {@link ProviderSwitch} instead. 25 */ 26 @Deprecated 27 public abstract class SwitchController extends EntryController implements ProviderSwitch { 28 29 30 /** 31 * Returns the key for this switch. 32 */ getSwitchKey()33 public abstract String getSwitchKey(); 34 35 /** 36 * Returns the checked state of this switch. 37 */ isChecked()38 protected abstract boolean isChecked(); 39 40 /** 41 * Called when the checked state of this switch is changed. 42 * 43 * @return true if the checked state was successfully changed, otherwise false 44 */ onCheckedChanged(boolean checked)45 protected abstract boolean onCheckedChanged(boolean checked); 46 47 /** 48 * Returns the error message which will be toasted when {@link #onCheckedChanged} returns false. 49 */ getErrorMessage(boolean attemptedChecked)50 protected abstract String getErrorMessage(boolean attemptedChecked); 51 52 @Override getKey()53 public String getKey() { 54 return getSwitchKey(); 55 } 56 57 @Override isSwitchChecked()58 public boolean isSwitchChecked() { 59 return isChecked(); 60 } 61 62 @Override onSwitchCheckedChanged(boolean checked)63 public boolean onSwitchCheckedChanged(boolean checked) { 64 return onCheckedChanged(checked); 65 } 66 67 @Override getSwitchErrorMessage(boolean attemptedChecked)68 public String getSwitchErrorMessage(boolean attemptedChecked) { 69 return getErrorMessage(attemptedChecked); 70 } 71 72 /** 73 * Same as {@link EntryController.MetaData}, for backwards compatibility purpose. 74 * 75 * @deprecated Use {@link EntryController.MetaData} instead. 76 */ 77 @Deprecated 78 protected static class MetaData extends EntryController.MetaData { 79 /** 80 * @param category the category of the switch. This value must be from {@link CategoryKey}. 81 * 82 * @deprecated Use {@link EntryController.MetaData} instead. 83 */ 84 @Deprecated MetaData(@onNull String category)85 public MetaData(@NonNull String category) { 86 super(category); 87 } 88 } 89 } 90