blob: 94ec1cb0f6496fe1b7bd605748e82b93e90a9a7f [file] [log] [blame]
Cheng-Ru Lina8bbcd72009-09-26 04:46:06 +08001/*
2 * Copyright (C) 2009 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;
18
19import android.app.AlertDialog.Builder;
20import android.content.Context;
21import android.content.res.Resources;
22import android.content.res.TypedArray;
23import android.graphics.drawable.Drawable;
24import android.preference.ListPreference;
25import android.os.Parcel;
26import android.os.Parcelable;
27import android.util.AttributeSet;
28
29/** {@code BooleanListPreference} is used for those {@code SharedPreference}
30 * which stores value in the type of {@code Boolean} but would like to be shown
31 * as two radio buttons instead of a checkbox.
32 */
33public class BooleanListPreference extends ListPreference {
34
35 public BooleanListPreference(Context context, AttributeSet attrs) {
36 super(context, attrs);
37 CharSequence values[] = getEntryValues();
38 if (values.length == 2) {
39 boolean x = Boolean.valueOf(values[0].toString());
40 boolean y = Boolean.valueOf(values[1].toString());
41 if (x != y) return;
42 }
43 throw new IllegalStateException(
44 "EntryValues should be boolean strings");
45 }
46
47 @Override
48 protected boolean persistString(String value) {
49 return persistBoolean(Boolean.valueOf(value));
50 }
51
52 @Override
53 protected String getPersistedString(String defaultValue) {
54 return Boolean.toString(
55 getPersistedBoolean(Boolean.valueOf(defaultValue)));
56 }
57}