diff options
-rw-r--r-- | res/values/arrays.xml | 4 | ||||
-rw-r--r-- | res/values/strings.xml | 2 | ||||
-rw-r--r-- | res/xml/camera_preferences.xml | 2 | ||||
-rw-r--r-- | src/com/android/camera/BooleanListPreference.java | 51 | ||||
-rw-r--r-- | src/com/android/camera/Camera.java | 8 | ||||
-rw-r--r-- | src/com/android/camera/CameraSettings.java | 11 | ||||
-rw-r--r-- | src/com/android/camera/RecordLocationPreference.java | 65 |
7 files changed, 82 insertions, 61 deletions
diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 746f015..a457055 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -125,8 +125,8 @@ </array> <string-array name="pref_camera_recordlocation_entryvalues" translatable="false"> - <item>false</item> - <item>true</item> + <item>off</item> + <item>on</item> </string-array> <array name="pref_camera_recordlocation_entries" translatable="false"> diff --git a/res/values/strings.xml b/res/values/strings.xml index 5a1dc4b..02310f8 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -129,7 +129,7 @@ <!-- Settings screen, setting title text --> <string name="pref_camera_recordlocation_title">Store location</string> - <string name="pref_camera_recordlocation_default" translatable="false">false</string> + <string name="pref_camera_recordlocation_default" translatable="false">none</string> <!-- Settings screen, Record location dialog choices --> <string name="pref_camera_recordlocation_entry_off">Off</string> diff --git a/res/xml/camera_preferences.xml b/res/xml/camera_preferences.xml index a59de44..3c348a7 100644 --- a/res/xml/camera_preferences.xml +++ b/res/xml/camera_preferences.xml @@ -47,7 +47,7 @@ android:entries="@array/pref_camera_coloreffect_entries" android:entryValues="@array/pref_camera_coloreffect_entryvalues" android:dialogTitle="@string/pref_camera_coloreffect_dialogtitle" /> - <com.android.camera.BooleanListPreference + <com.android.camera.RecordLocationPreference android:key="pref_camera_recordlocation_key" android:defaultValue="@string/pref_camera_recordlocation_default" android:title="@string/pref_camera_recordlocation_title" diff --git a/src/com/android/camera/BooleanListPreference.java b/src/com/android/camera/BooleanListPreference.java deleted file mode 100644 index e04709f..0000000 --- a/src/com/android/camera/BooleanListPreference.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera; - -import android.content.Context; -import android.preference.ListPreference; -import android.util.AttributeSet; - -/** {@code BooleanListPreference} is used for those {@code SharedPreference} - * which stores value in the type of {@code Boolean} but would like to be shown - * as two radio buttons instead of a checkbox. - */ -public class BooleanListPreference extends ListPreference { - - public BooleanListPreference(Context context, AttributeSet attrs) { - super(context, attrs); - CharSequence values[] = getEntryValues(); - if (values.length == 2) { - boolean x = Boolean.valueOf(values[0].toString()); - boolean y = Boolean.valueOf(values[1].toString()); - if (x != y) return; - } - throw new IllegalStateException( - "EntryValues should be boolean strings"); - } - - @Override - protected boolean persistString(String value) { - return persistBoolean(Boolean.valueOf(value)); - } - - @Override - protected String getPersistedString(String defaultValue) { - return Boolean.toString( - getPersistedBoolean(Boolean.valueOf(defaultValue))); - } -} diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index c3fb90a..8db1613 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -1053,7 +1053,6 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, mParameters.getWhiteBalance()); } } - mSettings.setVisible(true); } @@ -1248,8 +1247,8 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, } private void readPreference() { - mRecordLocation = mPreferences.getBoolean( - "pref_camera_recordlocation_key", false); + mRecordLocation = RecordLocationPreference.get( + mPreferences, getContentResolver()); mFocusMode = mPreferences.getString( CameraSettings.KEY_FOCUS_MODE, getString(R.string.pref_camera_focusmode_default)); @@ -2060,7 +2059,8 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, if (mPausing) return; if (CameraSettings.KEY_RECORD_LOCATION.equals(key)) { - mRecordLocation = preferences.getBoolean(key, false); + mRecordLocation = RecordLocationPreference.get( + preferences, getContentResolver()); if (mRecordLocation) { startReceivingLocationUpdates(); } else { diff --git a/src/com/android/camera/CameraSettings.java b/src/com/android/camera/CameraSettings.java index 9010243..bd98a13 100644 --- a/src/com/android/camera/CameraSettings.java +++ b/src/com/android/camera/CameraSettings.java @@ -42,7 +42,7 @@ public class CameraSettings { public static final String KEY_VERSION = "pref_version_key"; public static final String KEY_RECORD_LOCATION = - "pref_camera_recordlocation_key"; + RecordLocationPreference.KEY; public static final String KEY_VIDEO_QUALITY = "pref_camera_videoquality_key"; public static final String KEY_VIDEO_DURATION = @@ -56,7 +56,7 @@ public class CameraSettings { "pref_camera_whitebalance_key"; public static final String KEY_SCENE_MODE = "pref_camera_scenemode_key"; - public static final int CURRENT_VERSION = 2; + public static final int CURRENT_VERSION = 3; // max mms video duration in seconds. public static final int MMS_VIDEO_DURATION = @@ -283,6 +283,13 @@ public class CameraSettings { editor.putString(KEY_JPEG_QUALITY, quality); version = 2; } + if (version == 2) { + editor.putString(KEY_RECORD_LOCATION, + pref.getBoolean(KEY_RECORD_LOCATION, false) + ? RecordLocationPreference.VALUE_ON + : RecordLocationPreference.VALUE_NONE); + version = 3; + } editor.putInt(KEY_VERSION, CURRENT_VERSION); editor.commit(); } diff --git a/src/com/android/camera/RecordLocationPreference.java b/src/com/android/camera/RecordLocationPreference.java new file mode 100644 index 0000000..6a668e7 --- /dev/null +++ b/src/com/android/camera/RecordLocationPreference.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.camera; + +import android.content.Context; +import android.content.ContentResolver; +import android.content.SharedPreferences; +import android.preference.ListPreference; +import android.provider.Settings; +import android.util.AttributeSet; +import android.util.Log; + +/** + * {@code RecordLocationPreference} is used to keep the "store locaiton" + * option in {@code SharedPreference}. + */ +public class RecordLocationPreference extends ListPreference { + + public static final String KEY = "pref_camera_recordlocation_key"; + + public static final String VALUE_NONE = "none"; + public static final String VALUE_ON = "on"; + public static final String VALUE_OFF = "off"; + + private ContentResolver mResolver; + + public RecordLocationPreference(Context context, AttributeSet attrs) { + super(context, attrs); + mResolver = context.getContentResolver(); + } + + @Override + public String getValue() { + return get(getSharedPreferences(), mResolver) ? VALUE_ON : VALUE_OFF; + } + + @Override + public CharSequence getEntry() { + return getEntries()[findIndexOfValue(getValue())]; + } + + public static boolean get( + SharedPreferences pref, ContentResolver resolver) { + String value = pref.getString(KEY, VALUE_NONE); + if (VALUE_NONE.equals(value)) { + return Settings.Secure.getInt(resolver, + Settings.Secure.USE_LOCATION_FOR_SERVICES, 0) != 0; + } + return VALUE_ON.equals(value); + } +} |