2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.camera.ui;
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.view.accessibility.AccessibilityEvent;
22 import android.widget.CheckBox;
23 import android.widget.CompoundButton;
24 import android.widget.CompoundButton.OnCheckedChangeListener;
27 import com.android.camera.ListPreference;
28 import com.android.camera.R;
30 /* A check box setting control which turns on/off the setting. */
31 public class InLineSettingCheckBox extends InLineSettingItem {
32 private CheckBox mCheckBox;
34 OnCheckedChangeListener mCheckedChangeListener = new OnCheckedChangeListener() {
36 public void onCheckedChanged(CompoundButton buttonView, boolean desiredState) {
37 changeIndex(desiredState ? 1 : 0);
41 public InLineSettingCheckBox(Context context, AttributeSet attrs) {
42 super(context, attrs);
46 protected void onFinishInflate() {
47 super.onFinishInflate();
48 mCheckBox = (CheckBox) findViewById(R.id.setting_check_box);
49 mCheckBox.setOnCheckedChangeListener(mCheckedChangeListener);
53 public void initialize(ListPreference preference) {
54 super.initialize(preference);
55 // Add content descriptions for the increment and decrement buttons.
56 mCheckBox.setContentDescription(getContext().getResources().getString(
57 R.string.accessibility_check_box, mPreference.getTitle()));
61 protected void updateView() {
62 mCheckBox.setOnCheckedChangeListener(null);
63 if (mOverrideValue == null) {
64 mCheckBox.setChecked(mIndex == 1);
66 int index = mPreference.findIndexOfValue(mOverrideValue);
67 mCheckBox.setChecked(index == 1);
69 mCheckBox.setOnCheckedChangeListener(mCheckedChangeListener);
73 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
74 event.getText().add(mPreference.getTitle());
79 public void setEnabled(boolean enable) {
80 if (mTitle != null) mTitle.setEnabled(enable);
81 if (mCheckBox != null) mCheckBox.setEnabled(enable);