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 public class PreferenceCategory extends PreferenceGroup { 34 private static final String TAG = "PreferenceCategory"; 35 PreferenceCategory( Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)36 public PreferenceCategory( 37 Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 38 super(context, attrs, defStyleAttr, defStyleRes); 39 } 40 PreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr)41 public PreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr) { 42 this(context, attrs, defStyleAttr, 0); 43 } 44 PreferenceCategory(Context context, AttributeSet attrs)45 public PreferenceCategory(Context context, AttributeSet attrs) { 46 this(context, attrs, com.android.internal.R.attr.preferenceCategoryStyle); 47 } 48 PreferenceCategory(Context context)49 public PreferenceCategory(Context context) { 50 this(context, null); 51 } 52 53 @Override onPrepareAddPreference(Preference preference)54 protected boolean onPrepareAddPreference(Preference preference) { 55 if (preference instanceof PreferenceCategory) { 56 throw new IllegalArgumentException( 57 "Cannot add a " + TAG + " directly to a " + TAG); 58 } 59 60 return super.onPrepareAddPreference(preference); 61 } 62 63 @Override isEnabled()64 public boolean isEnabled() { 65 return false; 66 } 67 68 @Override shouldDisableDependents()69 public boolean shouldDisableDependents() { 70 return !super.isEnabled(); 71 } 72 } 73