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