The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.content.res.TypedArray; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import android.util.AttributeSet; |
| 22 | import android.view.View; |
| 23 | import android.widget.Checkable; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * A {@link Preference} that provides checkbox widget |
| 27 | * functionality. |
| 28 | * <p> |
| 29 | * This preference will store a boolean into the SharedPreferences. |
| 30 | * |
| 31 | * @attr ref android.R.styleable#CheckBoxPreference_summaryOff |
| 32 | * @attr ref android.R.styleable#CheckBoxPreference_summaryOn |
| 33 | * @attr ref android.R.styleable#CheckBoxPreference_disableDependentsState |
| 34 | */ |
Adam Powell | be0a453 | 2010-11-29 17:47:48 -0800 | [diff] [blame] | 35 | public class CheckBoxPreference extends TwoStatePreference { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | public CheckBoxPreference(Context context, AttributeSet attrs, int defStyle) { |
| 38 | super(context, attrs, defStyle); |
| 39 | |
| 40 | TypedArray a = context.obtainStyledAttributes(attrs, |
| 41 | com.android.internal.R.styleable.CheckBoxPreference, defStyle, 0); |
Adam Powell | be0a453 | 2010-11-29 17:47:48 -0800 | [diff] [blame] | 42 | setSummaryOn(a.getString(com.android.internal.R.styleable.CheckBoxPreference_summaryOn)); |
| 43 | setSummaryOff(a.getString(com.android.internal.R.styleable.CheckBoxPreference_summaryOff)); |
| 44 | setDisableDependentsState(a.getBoolean( |
| 45 | com.android.internal.R.styleable.CheckBoxPreference_disableDependentsState, false)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | a.recycle(); |
| 47 | } |
| 48 | |
| 49 | public CheckBoxPreference(Context context, AttributeSet attrs) { |
| 50 | this(context, attrs, com.android.internal.R.attr.checkBoxPreferenceStyle); |
| 51 | } |
| 52 | |
| 53 | public CheckBoxPreference(Context context) { |
| 54 | this(context, null); |
| 55 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 56 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | @Override |
| 58 | protected void onBindView(View view) { |
| 59 | super.onBindView(view); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 60 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | View checkboxView = view.findViewById(com.android.internal.R.id.checkbox); |
| 62 | if (checkboxView != null && checkboxView instanceof Checkable) { |
| 63 | ((Checkable) checkboxView).setChecked(mChecked); |
Svetoslav Ganov | 7650259 | 2011-07-29 10:44:59 -0700 | [diff] [blame] | 64 | sendAccessibilityEvent(checkboxView); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Adam Powell | be0a453 | 2010-11-29 17:47:48 -0800 | [diff] [blame] | 67 | syncSummaryView(view); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | } |