• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.wifi.p2p;
18 
19 import android.content.Context;
20 
21 import androidx.preference.Preference;
22 import androidx.preference.PreferenceGroup;
23 import androidx.preference.PreferenceScreen;
24 
25 import com.android.settings.core.PreferenceControllerMixin;
26 import com.android.settingslib.core.AbstractPreferenceController;
27 
28 public abstract class P2pCategoryPreferenceController extends AbstractPreferenceController
29         implements PreferenceControllerMixin {
30 
31     protected PreferenceGroup mCategory;
32 
P2pCategoryPreferenceController(Context context)33     public P2pCategoryPreferenceController(Context context) {
34         super(context);
35     }
36 
37     @Override
isAvailable()38     public boolean isAvailable() {
39         return mCategory.getPreferenceCount() > 0;
40     }
41 
42     @Override
displayPreference(PreferenceScreen screen)43     public void displayPreference(PreferenceScreen screen) {
44         mCategory = screen.findPreference(getPreferenceKey());
45         super.displayPreference(screen);
46     }
47 
removeAllChildren()48     public void removeAllChildren() {
49         if (mCategory != null) {
50             mCategory.removeAll();
51             mCategory.setVisible(false);
52         }
53     }
54 
addChild(Preference child)55     public void addChild(Preference child) {
56         if (mCategory != null) {
57             mCategory.addPreference(child);
58             mCategory.setVisible(true);
59         }
60     }
61 
setEnabled(boolean enabled)62     public void setEnabled(boolean enabled) {
63         if (mCategory != null) {
64             mCategory.setEnabled(enabled);
65         }
66     }
67 }
68