blob: f757aa4e4dab6facd1b9339db0c1e047a8aef01a [file] [log] [blame]
jeffreyhuang12ba4462017-10-06 11:40:59 -07001/*
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
17package com.android.settingslib.development;
18
19import android.content.Context;
Fan Zhangf7802ea2018-08-28 15:15:19 -070020
Aurimas Liutikasfd52c142018-04-17 09:50:46 -070021import androidx.preference.Preference;
22import androidx.preference.PreferenceScreen;
jeffreyhuang12ba4462017-10-06 11:40:59 -070023
24import com.android.settingslib.core.AbstractPreferenceController;
25
26/**
27 * This controller is used handle changes for the master switch in the developer options page.
28 *
29 * All Preference Controllers that are a part of the developer options page should inherit this
30 * class.
31 */
Doris Ling7e919322018-02-28 16:06:19 -080032public abstract class DeveloperOptionsPreferenceController extends AbstractPreferenceController {
33
34 protected Preference mPreference;
jeffreyhuang12ba4462017-10-06 11:40:59 -070035
36 public DeveloperOptionsPreferenceController(Context context) {
37 super(context);
38 }
39
40 /**
41 * Child classes should override this method to create custom logic for hiding preferences.
42 *
43 * @return true if the preference is to be displayed.
44 */
45 @Override
46 public boolean isAvailable() {
47 return true;
48 }
49
Doris Ling7e919322018-02-28 16:06:19 -080050 @Override
51 public void displayPreference(PreferenceScreen screen) {
52 super.displayPreference(screen);
53 mPreference = screen.findPreference(getPreferenceKey());
54 }
55
jeffreyhuang12ba4462017-10-06 11:40:59 -070056 /**
57 * Called when developer options is enabled
58 */
59 public void onDeveloperOptionsEnabled() {
60 if (isAvailable()) {
61 onDeveloperOptionsSwitchEnabled();
62 }
63 }
64
65 /**
66 * Called when developer options is disabled
67 */
68 public void onDeveloperOptionsDisabled() {
69 if (isAvailable()) {
70 onDeveloperOptionsSwitchDisabled();
71 }
72 }
73
74 /**
75 * Called when developer options is enabled and the preference is available
76 */
jeffreyhuang5c4d82a2017-10-09 10:24:09 -070077 protected void onDeveloperOptionsSwitchEnabled() {
Doris Ling7e919322018-02-28 16:06:19 -080078 mPreference.setEnabled(true);
jeffreyhuang5c4d82a2017-10-09 10:24:09 -070079 }
jeffreyhuang12ba4462017-10-06 11:40:59 -070080
81 /**
82 * Called when developer options is disabled and the preference is available
83 */
jeffreyhuang5c4d82a2017-10-09 10:24:09 -070084 protected void onDeveloperOptionsSwitchDisabled() {
Doris Ling7e919322018-02-28 16:06:19 -080085 mPreference.setEnabled(false);
jeffreyhuang5c4d82a2017-10-09 10:24:09 -070086 }
jeffreyhuang12ba4462017-10-06 11:40:59 -070087
88}