Cheng-Ru Lin | a8bbcd7 | 2009-09-26 04:46:06 +0800 | [diff] [blame^] | 1 | /* |
| 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 | |
| 17 | package com.android.camera; |
| 18 | |
| 19 | import android.app.AlertDialog.Builder; |
| 20 | import android.content.Context; |
| 21 | import android.content.res.Resources; |
| 22 | import android.content.res.TypedArray; |
| 23 | import android.graphics.drawable.Drawable; |
| 24 | import android.preference.ListPreference; |
| 25 | import android.os.Parcel; |
| 26 | import android.os.Parcelable; |
| 27 | import 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 | */ |
| 33 | public 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 | } |