1 /*
2  * Copyright (C) 2007 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 android.preference;
18 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 
22 /**
23  * Used to group {@link Preference} objects
24  * and provide a disabled title above the group.
25  *
26  * <div class="special reference">
27  * <h3>Developer Guides</h3>
28  * <p>For information about building a settings UI with Preferences,
29  * read the <a href="{@docRoot}guide/topics/ui/settings.html">Settings</a>
30  * guide.</p>
31  * </div>
32  *
33  * @deprecated Use the <a href="{@docRoot}jetpack/androidx.html">AndroidX</a>
34  *      <a href="{@docRoot}reference/androidx/preference/package-summary.html">
35  *      Preference Library</a> for consistent behavior across all devices. For more information on
36  *      using the AndroidX Preference Library see
37  *      <a href="{@docRoot}guide/topics/ui/settings.html">Settings</a>.
38  */
39 @Deprecated
40 public class PreferenceCategory extends PreferenceGroup {
41     private static final String TAG = "PreferenceCategory";
42 
PreferenceCategory( Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)43     public PreferenceCategory(
44             Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
45         super(context, attrs, defStyleAttr, defStyleRes);
46     }
47 
PreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr)48     public PreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr) {
49         this(context, attrs, defStyleAttr, 0);
50     }
51 
PreferenceCategory(Context context, AttributeSet attrs)52     public PreferenceCategory(Context context, AttributeSet attrs) {
53         this(context, attrs, com.android.internal.R.attr.preferenceCategoryStyle);
54     }
55 
PreferenceCategory(Context context)56     public PreferenceCategory(Context context) {
57         this(context, null);
58     }
59 
60     @Override
onPrepareAddPreference(Preference preference)61     protected boolean onPrepareAddPreference(Preference preference) {
62         if (preference instanceof PreferenceCategory) {
63             throw new IllegalArgumentException(
64                     "Cannot add a " + TAG + " directly to a " + TAG);
65         }
66 
67         return super.onPrepareAddPreference(preference);
68     }
69 
70     @Override
isEnabled()71     public boolean isEnabled() {
72         return false;
73     }
74 
75     @Override
shouldDisableDependents()76     public boolean shouldDisableDependents() {
77         return !super.isEnabled();
78     }
79 }
80