blob: c3cd1979d279feb6d36d1a03462edc72a73f2733 [file] [log] [blame]
Michael Kolb8872c232013-01-29 10:33:22 -08001/*
2 * Copyright (C) 2011 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 com.android.camera.ui;
18
19import android.content.Context;
20import android.util.AttributeSet;
21import android.view.accessibility.AccessibilityEvent;
22import android.widget.CheckBox;
23import android.widget.CompoundButton;
24import android.widget.CompoundButton.OnCheckedChangeListener;
25
Michael Kolb8872c232013-01-29 10:33:22 -080026import com.android.camera.ListPreference;
Sascha Haeberling8e963a52013-08-06 11:43:02 -070027import com.android.camera2.R;
Michael Kolb8872c232013-01-29 10:33:22 -080028
29/* A check box setting control which turns on/off the setting. */
30public class InLineSettingCheckBox extends InLineSettingItem {
31 private CheckBox mCheckBox;
32
33 OnCheckedChangeListener mCheckedChangeListener = new OnCheckedChangeListener() {
34 @Override
35 public void onCheckedChanged(CompoundButton buttonView, boolean desiredState) {
36 changeIndex(desiredState ? 1 : 0);
37 }
38 };
39
40 public InLineSettingCheckBox(Context context, AttributeSet attrs) {
41 super(context, attrs);
42 }
43
44 @Override
45 protected void onFinishInflate() {
46 super.onFinishInflate();
47 mCheckBox = (CheckBox) findViewById(R.id.setting_check_box);
48 mCheckBox.setOnCheckedChangeListener(mCheckedChangeListener);
49 }
50
51 @Override
52 public void initialize(ListPreference preference) {
53 super.initialize(preference);
54 // Add content descriptions for the increment and decrement buttons.
55 mCheckBox.setContentDescription(getContext().getResources().getString(
56 R.string.accessibility_check_box, mPreference.getTitle()));
57 }
58
59 @Override
60 protected void updateView() {
61 mCheckBox.setOnCheckedChangeListener(null);
62 if (mOverrideValue == null) {
63 mCheckBox.setChecked(mIndex == 1);
64 } else {
65 int index = mPreference.findIndexOfValue(mOverrideValue);
66 mCheckBox.setChecked(index == 1);
67 }
68 mCheckBox.setOnCheckedChangeListener(mCheckedChangeListener);
69 }
70
71 @Override
72 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
73 event.getText().add(mPreference.getTitle());
74 return true;
75 }
76
77 @Override
78 public void setEnabled(boolean enable) {
79 if (mTitle != null) mTitle.setEnabled(enable);
80 if (mCheckBox != null) mCheckBox.setEnabled(enable);
81 }
82}