2 * Copyright (C) 2013 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.settings;
19 import android.content.Context;
20 import android.content.SharedPreferences;
21 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
22 import android.preference.PreferenceManager;
23 import android.util.Log;
24 import android.util.SparseArray;
26 import com.android.camera.ListPreference;
27 import com.android.camera.app.AppController;
28 import com.android.camera.util.SettingsHelper;
29 import com.android.camera2.R;
31 import java.util.ArrayList;
32 import java.util.List;
35 * SettingsManager class provides an api for getting and setting both
36 * global and local SharedPreferences.
38 public class SettingsManager {
39 private static final String TAG = "SettingsManager";
41 private final Context mContext;
42 private final SharedPreferences mDefaultSettings;
43 private final SettingsCache mSettingsCache;
44 private SharedPreferences mGlobalSettings;
45 private SharedPreferences mCameraSettings;
46 private final SparseArray<SharedPreferences> mModuleSettings
47 = new SparseArray<SharedPreferences>();
48 private SettingsCapabilities mCapabilities;
50 private int mCameraId = -1;
51 private AppController mAppController;
54 * A List of OnSettingChangedListener's, maintained
55 * to compare to new listeners and prevent duplicate
58 private final List<OnSettingChangedListener>
59 mListeners = new ArrayList<OnSettingChangedListener>();
62 * A List of OnSharedPreferenceChangeListener's, maintained
63 * to hold pointers to actually registered listeners,
64 * so they can be unregistered.
66 private final List<OnSharedPreferenceChangeListener>
67 mSharedPreferenceListeners = new ArrayList<OnSharedPreferenceChangeListener>();
69 public SettingsManager(Context context, AppController app, int nCameras) {
73 SettingsCache.ExtraSettings extraSettings = new SettingsHelper();
74 mSettingsCache = new SettingsCache(mContext, extraSettings);
76 mDefaultSettings = PreferenceManager.getDefaultSharedPreferences(context);
81 * Initialize global SharedPreferences.
83 private void initGlobal() {
84 String globalKey = mContext.getPackageName() + "_preferences_camera";
85 mGlobalSettings = mContext.getSharedPreferences(globalKey, Context.MODE_PRIVATE);
89 * Load and cache a module specific SharedPreferences.
91 public SharedPreferences getModulePreferences(int modeIndex) {
92 SharedPreferences sharedPreferences = mModuleSettings.get(modeIndex);
93 if (sharedPreferences == null) {
94 String moduleKey = mContext.getPackageName() + "_preferences_module_" + modeIndex;
95 sharedPreferences = mContext.getSharedPreferences(moduleKey, Context.MODE_PRIVATE);
96 mModuleSettings.put(modeIndex, sharedPreferences);
98 return sharedPreferences;
102 * Initialize SharedPreferences for other cameras.
104 public void changeCamera(int cameraId, SettingsCapabilities capabilities) {
105 mCapabilities = capabilities;
106 mSettingsCache.setCapabilities(mCapabilities);
108 if (cameraId == mCameraId) {
112 // We've changed camera ids, that means we need to flush the
113 // settings cache of settings dependent on SettingsCapabilities.
114 mSettingsCache.flush();
116 // Cache the camera id so we don't need to reload preferences
117 // if we're using the same camera.
118 mCameraId = cameraId;
120 String cameraKey = mContext.getPackageName() + "_preferences_" + cameraId;
121 mCameraSettings = mContext.getSharedPreferences(
122 cameraKey, Context.MODE_PRIVATE);
124 for (OnSharedPreferenceChangeListener listener : mSharedPreferenceListeners) {
125 mCameraSettings.registerOnSharedPreferenceChangeListener(listener);
130 * Interface with Camera Parameters and Modules.
132 public interface OnSettingChangedListener {
134 * Called every time a SharedPreference has been changed.
136 public void onSettingChanged(SettingsManager settingsManager, int setting);
139 private OnSharedPreferenceChangeListener getSharedPreferenceListener(
140 final OnSettingChangedListener listener) {
141 return new OnSharedPreferenceChangeListener() {
143 public void onSharedPreferenceChanged(
144 SharedPreferences sharedPreferences, String key) {
145 Integer settingId = mSettingsCache.getId(key);
146 if (settingId != null) {
147 listener.onSettingChanged(SettingsManager.this, settingId);
149 Log.w(TAG, "Setting id from key=" + key + " is null");
156 * Add an OnSettingChangedListener to the SettingsManager, which will execute
157 * onSettingsChanged when any SharedPreference has been updated.
159 public void addListener(final OnSettingChangedListener listener) {
160 if (listener == null) {
161 throw new IllegalArgumentException("OnSettingChangedListener cannot be null.");
164 if (mListeners.contains(listener)) {
168 mListeners.add(listener);
169 OnSharedPreferenceChangeListener sharedPreferenceListener =
170 getSharedPreferenceListener(listener);
171 mSharedPreferenceListeners.add(sharedPreferenceListener);
173 if (mGlobalSettings != null) {
174 mGlobalSettings.registerOnSharedPreferenceChangeListener(sharedPreferenceListener);
177 if (mCameraSettings != null) {
178 mCameraSettings.registerOnSharedPreferenceChangeListener(sharedPreferenceListener);
181 if (mDefaultSettings != null) {
182 mDefaultSettings.registerOnSharedPreferenceChangeListener(sharedPreferenceListener);
187 * Remove a specific SettingsListener.
188 * This should be done in onPause if a listener has been set.
190 public void removeListener(OnSettingChangedListener listener) {
191 if (listener == null) {
192 throw new IllegalArgumentException();
195 if (!mListeners.contains(listener)) {
199 int index = mListeners.indexOf(listener);
200 mListeners.remove(listener);
202 // Get the reference to the actual OnSharedPreferenceChangeListener
203 // that was registered.
204 OnSharedPreferenceChangeListener sharedPreferenceListener =
205 mSharedPreferenceListeners.get(index);
206 mSharedPreferenceListeners.remove(index);
208 if (mGlobalSettings != null) {
209 mGlobalSettings.unregisterOnSharedPreferenceChangeListener(
210 sharedPreferenceListener);
213 if (mCameraSettings != null) {
214 mCameraSettings.unregisterOnSharedPreferenceChangeListener(
215 sharedPreferenceListener);
218 if (mDefaultSettings != null) {
219 mDefaultSettings.unregisterOnSharedPreferenceChangeListener(
220 sharedPreferenceListener);
225 * Remove all OnSharedPreferenceChangedListener's.
226 * This should be done in onDestroy.
228 public void removeAllListeners() {
229 for (OnSharedPreferenceChangeListener listener : mSharedPreferenceListeners) {
230 if (mGlobalSettings != null) {
231 mGlobalSettings.unregisterOnSharedPreferenceChangeListener(listener);
234 if (mCameraSettings != null) {
235 mCameraSettings.unregisterOnSharedPreferenceChangeListener(listener);
238 if (mDefaultSettings != null) {
239 mDefaultSettings.unregisterOnSharedPreferenceChangeListener(listener);
242 mSharedPreferenceListeners.clear();
247 * SettingsCapabilities defines constraints around settings that need to be
248 * queried from external sources, like the camera parameters.
250 * This interface is camera api agnostic.
252 public interface SettingsCapabilities {
254 * Returns a dynamically calculated list of
255 * exposure values, based on the min and max
256 * exposure compensation supported by the camera device.
258 public String[] getSupportedExposureValues();
261 * Returns a list of camera ids based on the number
262 * of cameras available on the device.
264 public String[] getSupportedCameraIds();
268 * Get the camera id for which the SettingsManager has loaded camera
269 * specific preferences.
271 public int getRegisteredCameraId() {
275 // Manage individual settings.
276 public static final String VALUE_NONE = "none";
277 public static final String VALUE_ON = "on";
278 public static final String VALUE_OFF = "off";
280 public static final String TYPE_STRING = "string";
281 public static final String TYPE_BOOLEAN = "boolean";
282 public static final String TYPE_INTEGER = "integer";
284 public static final String SOURCE_DEFAULT = "default";
285 public static final String SOURCE_GLOBAL = "global";
286 public static final String SOURCE_CAMERA = "camera";
287 public static final String SOURCE_MODULE = "module";
289 public static final boolean FLUSH_ON = true;
290 public static final boolean FLUSH_OFF = false;
292 // For quick lookup from id to Setting.
293 public static final int SETTING_RECORD_LOCATION = 0;
294 public static final int SETTING_VIDEO_QUALITY = 1;
295 public static final int SETTING_VIDEO_TIME_LAPSE_FRAME_INTERVAL = 2;
296 public static final int SETTING_PICTURE_SIZE = 3;
297 public static final int SETTING_JPEG_QUALITY = 4;
298 public static final int SETTING_FOCUS_MODE = 5;
299 public static final int SETTING_FLASH_MODE = 6;
300 public static final int SETTING_VIDEOCAMERA_FLASH_MODE = 7;
301 public static final int SETTING_WHITE_BALANCE = 8;
302 public static final int SETTING_SCENE_MODE = 9;
303 public static final int SETTING_EXPOSURE = 10;
304 public static final int SETTING_TIMER = 11;
305 public static final int SETTING_TIMER_SOUND_EFFECTS = 12;
306 public static final int SETTING_VIDEO_EFFECT = 13;
307 public static final int SETTING_CAMERA_ID = 14;
308 public static final int SETTING_CAMERA_HDR = 15;
309 public static final int SETTING_CAMERA_HDR_PLUS = 16;
310 public static final int SETTING_CAMERA_FIRST_USE_HINT_SHOWN = 17;
311 public static final int SETTING_VIDEO_FIRST_USE_HINT_SHOWN = 18;
312 public static final int SETTING_STARTUP_MODULE_INDEX = 19;
313 public static final int SETTING_SHIMMY_REMAINING_PLAY_TIMES_INDEX = 20;
314 public static final int SETTING_KEY_CAMERA_MODULE_LAST_USED_INDEX = 21;
315 public static final int SETTING_CAMERA_PANO_ORIENTATION = 22;
316 public static final int SETTING_CAMERA_GRID_LINES = 23;
318 // Shared preference keys.
319 public static final String KEY_RECORD_LOCATION = "pref_camera_recordlocation_key";
320 public static final String KEY_VIDEO_QUALITY = "pref_video_quality_key";
321 public static final String KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL =
322 "pref_video_time_lapse_frame_interval_key";
323 public static final String KEY_PICTURE_SIZE = "pref_camera_picturesize_key";
324 public static final String KEY_JPEG_QUALITY = "pref_camera_jpegquality_key";
325 public static final String KEY_FOCUS_MODE = "pref_camera_focusmode_key";
326 public static final String KEY_FLASH_MODE = "pref_camera_flashmode_key";
327 public static final String KEY_VIDEOCAMERA_FLASH_MODE = "pref_camera_video_flashmode_key";
328 public static final String KEY_WHITE_BALANCE = "pref_camera_whitebalance_key";
329 public static final String KEY_SCENE_MODE = "pref_camera_scenemode_key";
330 public static final String KEY_EXPOSURE = "pref_camera_exposure_key";
331 public static final String KEY_TIMER = "pref_camera_timer_key";
332 public static final String KEY_TIMER_SOUND_EFFECTS = "pref_camera_timer_sound_key";
333 public static final String KEY_VIDEO_EFFECT = "pref_video_effect_key";
334 public static final String KEY_CAMERA_ID = "pref_camera_id_key";
335 public static final String KEY_CAMERA_HDR = "pref_camera_hdr_key";
336 public static final String KEY_CAMERA_HDR_PLUS = "pref_camera_hdr_plus_key";
337 public static final String KEY_CAMERA_FIRST_USE_HINT_SHOWN =
338 "pref_camera_first_use_hint_shown_key";
339 public static final String KEY_VIDEO_FIRST_USE_HINT_SHOWN =
340 "pref_video_first_use_hint_shown_key";
341 public static final String KEY_STARTUP_MODULE_INDEX = "camera.startup_module";
342 public static final String KEY_SHIMMY_REMAINING_PLAY_TIMES =
343 "pref_shimmy_remaining_play_times";
344 public static final String KEY_CAMERA_MODULE_LAST_USED =
345 "pref_camera_module_last_used_index";
346 public static final String KEY_CAMERA_PANO_ORIENTATION = "pref_camera_pano_orientation";
347 public static final String KEY_CAMERA_GRID_LINES = "pref_camera_grid_lines";
349 public static final int WHITE_BALANCE_DEFAULT_INDEX = 2;
353 * Defines a simple class for holding a the spec of a setting.
354 * This spec is used by the generic api methods to query and
357 public static class Setting {
358 private final String mSource;
359 private final String mType;
360 private final String mDefault;
361 private final String mKey;
362 private final String[] mValues;
363 private final boolean mFlushOnCameraChange;
366 * A constructor used to store a setting's profile.
368 Setting(String source, String type, String defaultValue, String key,
369 String[] values, boolean flushOnCameraChange) {
372 mDefault = defaultValue;
375 mFlushOnCameraChange = flushOnCameraChange;
379 * Returns the id of a SharedPreferences instance from which
380 * this Setting may be found.
381 * Possible values are {@link #SOURCE_DEFAULT}, {@link #SOURCE_GLOBAL},
382 * {@link #SOURCE_CAMERA}.
384 public String getSource() {
389 * Returns the type of the setting stored in SharedPreferences.
390 * Possible values are {@link #TYPE_STRING}, {@link #TYPE_INTEGER},
391 * {@link #TYPE_BOOLEAN}.
393 public String getType() {
398 * Returns the default value of this setting.
400 public String getDefault() {
405 * Returns the SharedPreferences key for this setting.
407 public String getKey() {
412 * Returns an array of possible String values for this setting.
413 * If this setting is not of type {@link #TYPE_STRING}, or
414 * it's not possible to generate the string values, this should
417 public String[] getStringValues() {
422 * Returns whether the setting should be flushed from the cache
423 * when the camera device has changed.
425 public boolean isFlushedOnCameraChanged() {
426 return mFlushOnCameraChange;
431 * Get the SharedPreferences needed to query/update the setting.
433 public SharedPreferences getSettingSource(Setting setting) {
434 String source = setting.getSource();
435 if (source.equals(SOURCE_DEFAULT)) {
436 return mDefaultSettings;
438 if (source.equals(SOURCE_GLOBAL)) {
439 return mGlobalSettings;
441 if (source.equals(SOURCE_CAMERA)) {
442 return mCameraSettings;
444 if (source.equals(SOURCE_MODULE)) {
445 int modeIndex = mAppController.getCurrentModuleIndex();
446 return getModulePreferences(modeIndex);
452 * Based on Setting id, finds the index of a Setting's
453 * String value in an array of possible String values.
455 * If the Setting is not of type String, this returns -1.
457 * <p>TODO: make this a supported api call for all types.</p>
459 public int getStringValueIndex(int id) {
460 Setting setting = mSettingsCache.get(id);
461 if (setting == null || !TYPE_STRING.equals(setting.getType())) {
465 String value = get(id);
467 String[] possibleValues = setting.getStringValues();
468 if (possibleValues != null) {
469 for (int i = 0; i < possibleValues.length; i++) {
470 if (value.equals(possibleValues[i])) {
480 * Based on Setting id, sets a Setting's String value using the
481 * index into an array of possible String values.
483 * Fails to set a value if the index is out of bounds or the Setting
484 * is not of type String.
486 * @return Whether the value was set.
488 public boolean setStringValueIndex(int id, int index) {
489 Setting setting = mSettingsCache.get(id);
490 if (setting == null || setting.getType() != TYPE_STRING) {
494 String[] possibleValues = setting.getStringValues();
495 if (possibleValues != null) {
496 if (index >= 0 && index < possibleValues.length) {
497 set(id, possibleValues[index]);
505 * Get a Setting's String value based on Setting id.
507 // TODO: rename to something more descriptive.
508 public String get(int id) {
509 Setting setting = mSettingsCache.get(id);
510 SharedPreferences preferences = getSettingSource(setting);
511 if (preferences != null) {
512 return preferences.getString(setting.getKey(), setting.getDefault());
519 * Get a Setting's boolean value based on Setting id.
521 public boolean getBoolean(int id) {
522 Setting setting = mSettingsCache.get(id);
523 SharedPreferences preferences = getSettingSource(setting);
524 boolean defaultValue = setting.getDefault().equals(VALUE_ON);
525 if (preferences != null) {
526 return preferences.getBoolean(setting.getKey(), defaultValue);
533 * Get a Setting's int value based on Setting id.
535 public int getInt(int id) {
536 Setting setting = mSettingsCache.get(id);
537 SharedPreferences preferences = getSettingSource(setting);
538 int defaultValue = Integer.parseInt(setting.getDefault());
539 if (preferences != null) {
540 return preferences.getInt(setting.getKey(), defaultValue);
547 * Set a Setting with a String value based on Setting id.
549 // TODO: rename to something more descriptive.
550 public void set(int id, String value) {
551 Setting setting = mSettingsCache.get(id);
552 SharedPreferences preferences = getSettingSource(setting);
553 if (preferences != null) {
554 preferences.edit().putString(setting.getKey(), value).apply();
559 * Set a Setting with a boolean value based on Setting id.
561 public void setBoolean(int id, boolean value) {
562 Setting setting = mSettingsCache.get(id);
563 SharedPreferences preferences = getSettingSource(setting);
564 if (preferences != null) {
565 preferences.edit().putBoolean(setting.getKey(), value).apply();
570 * Set a Setting with an int value based on Setting id.
572 public void setInt(int id, int value) {
573 Setting setting = mSettingsCache.get(id);
574 SharedPreferences preferences = getSettingSource(setting);
575 if (preferences != null) {
576 preferences.edit().putInt(setting.getKey(), value).apply();
581 * Check if a Setting has ever been set based on Setting id.
583 public boolean isSet(int id) {
584 Setting setting = mSettingsCache.get(id);
585 SharedPreferences preferences = getSettingSource(setting);
586 if (preferences != null) {
587 return (preferences.getString(setting.getKey(), null) != null);
594 * Set a Setting to its default value based on Setting id.
596 public void setDefault(int id) {
597 Setting setting = mSettingsCache.get(id);
598 SharedPreferences preferences = getSettingSource(setting);
599 if (preferences != null) {
600 preferences.edit().putString(setting.getKey(), setting.getDefault());
605 * Check if a Setting is set to its default value.
607 public boolean isDefault(int id) {
608 Setting setting = mSettingsCache.get(id);
609 SharedPreferences preferences = getSettingSource(setting);
610 if (preferences != null) {
611 String type = setting.getType();
612 if (TYPE_STRING.equals(type)) {
613 String value = get(id);
614 return (value.equals(setting.getDefault()));
615 } else if (TYPE_BOOLEAN.equals(type)) {
616 boolean value = getBoolean(id);
617 boolean defaultValue = VALUE_ON.equals(setting.getDefault());
618 return (value == defaultValue);
619 } else if (TYPE_INTEGER.equals(type)) {
620 int value = getInt(id);
621 int defaultValue = Integer.parseInt(setting.getDefault());
622 return (value == defaultValue);
624 throw new IllegalArgumentException("Type " + type + " is not known.");
631 public static Setting getLocationSetting(Context context) {
632 String defaultValue = context.getString(R.string.setting_none_value);
633 String[] values = context.getResources().getStringArray(
634 R.array.pref_camera_recordlocation_entryvalues);
635 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_RECORD_LOCATION,
639 public static Setting getPictureSizeSetting(Context context) {
640 String defaultValue = null;
641 String[] values = context.getResources().getStringArray(
642 R.array.pref_camera_picturesize_entryvalues);
643 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_PICTURE_SIZE,
647 public static Setting getDefaultCameraIdSetting(Context context,
648 SettingsCapabilities capabilities) {
649 String defaultValue = context.getString(R.string.pref_camera_id_default);
650 String[] values = null;
651 if (capabilities != null) {
652 values = capabilities.getSupportedCameraIds();
654 return new Setting(SOURCE_MODULE, TYPE_STRING, defaultValue, KEY_CAMERA_ID,
658 public static Setting getWhiteBalanceSetting(Context context) {
659 String defaultValue = context.getString(R.string.pref_camera_whitebalance_default);
660 String[] values = context.getResources().getStringArray(
661 R.array.pref_camera_whitebalance_entryvalues);
662 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_WHITE_BALANCE,
666 public static Setting getHdrSetting(Context context) {
667 String defaultValue = context.getString(R.string.pref_camera_hdr_default);
668 String[] values = context.getResources().getStringArray(
669 R.array.pref_camera_hdr_entryvalues);
670 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_CAMERA_HDR,
674 public static Setting getHdrPlusSetting(Context context) {
675 String defaultValue = context.getString(R.string.pref_camera_hdr_plus_default);
676 String[] values = context.getResources().getStringArray(
677 R.array.pref_camera_hdr_plus_entryvalues);
678 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_CAMERA_HDR_PLUS,
682 public static Setting getSceneModeSetting(Context context) {
683 String defaultValue = context.getString(R.string.pref_camera_scenemode_default);
684 String[] values = context.getResources().getStringArray(
685 R.array.pref_camera_scenemode_entryvalues);
686 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_SCENE_MODE,
690 public static Setting getFlashSetting(Context context) {
691 String defaultValue = context.getString(R.string.pref_camera_flashmode_default);
692 String[] values = context.getResources().getStringArray(
693 R.array.pref_camera_flashmode_entryvalues);
694 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_FLASH_MODE,
698 public static Setting getExposureSetting(Context context,
699 SettingsCapabilities capabilities) {
700 String defaultValue = context.getString(R.string.pref_exposure_default);
701 String[] values = null;
702 if (capabilities != null) {
703 values = capabilities.getSupportedExposureValues();
705 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_EXPOSURE,
709 public static Setting getHintSetting(Context context) {
710 String defaultValue = context.getString(R.string.setting_on_value);
711 String[] values = null;
712 return new Setting(SOURCE_GLOBAL, TYPE_BOOLEAN, defaultValue,
713 KEY_CAMERA_FIRST_USE_HINT_SHOWN, values, FLUSH_OFF);
716 public static Setting getFocusModeSetting(Context context) {
717 String defaultValue = null;
718 String[] values = context.getResources().getStringArray(
719 R.array.pref_camera_focusmode_entryvalues);
720 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_FOCUS_MODE,
724 public static Setting getTimerSetting(Context context) {
725 String defaultValue = context.getString(R.string.pref_camera_timer_default);
726 String[] values = null; // TODO: get the values dynamically.
727 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_TIMER,
731 public static Setting getTimerSoundSetting(Context context) {
732 String defaultValue = context.getString(R.string.pref_camera_timer_sound_default);
733 String[] values = context.getResources().getStringArray(
734 R.array.pref_camera_timer_sound_entryvalues);
735 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_TIMER_SOUND_EFFECTS,
739 public static Setting getVideoQualitySetting(Context context) {
740 String defaultValue = context.getString(R.string.pref_video_quality_default);
741 String[] values = context.getResources().getStringArray(
742 R.array.pref_video_quality_entryvalues);
743 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_VIDEO_QUALITY,
747 public static Setting getTimeLapseFrameIntervalSetting(Context context) {
748 String defaultValue = context.getString(
749 R.string.pref_video_time_lapse_frame_interval_default);
750 String[] values = context.getResources().getStringArray(
751 R.array.pref_video_time_lapse_frame_interval_entryvalues);
752 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue,
753 KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL, values, FLUSH_OFF);
756 public static Setting getJpegQualitySetting(Context context) {
757 String defaultValue = context.getString(
758 R.string.pref_camera_jpeg_quality_normal);
759 String[] values = context.getResources().getStringArray(
760 R.array.pref_camera_jpeg_quality_entryvalues);
761 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_JPEG_QUALITY,
765 public static Setting getVideoFlashSetting(Context context) {
766 String defaultValue = context.getString(R.string.pref_camera_video_flashmode_default);
767 String[] values = context.getResources().getStringArray(
768 R.array.pref_camera_video_flashmode_entryvalues);
769 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue,
770 KEY_VIDEOCAMERA_FLASH_MODE, values, FLUSH_OFF);
773 public static Setting getVideoEffectSetting(Context context) {
774 String defaultValue = context.getString(R.string.pref_video_effect_default);
775 String[] values = context.getResources().getStringArray(
776 R.array.pref_video_effect_entryvalues);
777 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_VIDEO_EFFECT,
781 public static Setting getHintVideoSetting(Context context) {
782 String defaultValue = context.getString(R.string.setting_on_value);
783 String[] values = null;
784 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue,
785 KEY_VIDEO_FIRST_USE_HINT_SHOWN, values, FLUSH_OFF);
788 public static Setting getStartupModuleSetting(Context context) {
789 String defaultValue = context.getString(R.string.pref_camera_startup_index_default);
790 String[] values = null;
791 return new Setting(SOURCE_DEFAULT, TYPE_INTEGER, defaultValue,
792 KEY_STARTUP_MODULE_INDEX, values, FLUSH_OFF);
795 public static Setting getShimmyRemainingTimesSetting(Context context) {
796 String defaultValue = context.getString(R.string.pref_shimmy_play_times);
797 return new Setting(SOURCE_DEFAULT, TYPE_INTEGER, defaultValue,
798 KEY_SHIMMY_REMAINING_PLAY_TIMES, null, FLUSH_OFF);
801 public static Setting getLastUsedCameraModule(Context context) {
802 String defaultValue = Integer.toString(context.getResources()
803 .getInteger(R.integer.camera_mode_photo));
804 return new Setting(SOURCE_DEFAULT, TYPE_INTEGER, defaultValue,
805 KEY_CAMERA_MODULE_LAST_USED, null, FLUSH_OFF);
808 public static Setting getPanoOrientationSetting(Context context) {
809 String defaultValue = context.getString(R.string.pano_orientation_horizontal);
810 String[] values = context.getResources().getStringArray(
811 R.array.pref_camera_pano_orientation_entryvalues);
812 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue,
813 KEY_CAMERA_PANO_ORIENTATION, values, FLUSH_OFF);
816 public static Setting getGridLinesSetting(Context context) {
817 String defaultValue = context.getString(R.string.setting_off_value);
818 String[] values = context.getResources().getStringArray(
819 R.array.pref_camera_gridlines_entryvalues);
820 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue,
821 KEY_CAMERA_GRID_LINES, values, FLUSH_OFF);
827 * Returns whether the camera has been set to back facing
830 public boolean isCameraBackFacing() {
831 String cameraFacing = get(SETTING_CAMERA_ID);
832 String backFacing = mContext.getString(R.string.pref_camera_id_default);
833 return (Integer.parseInt(cameraFacing) == Integer.parseInt(backFacing));
837 * Returns whether hdr plus mode is set on.
839 public boolean isHdrPlusOn() {
840 String hdrOn = get(SettingsManager.SETTING_CAMERA_HDR);
841 return hdrOn.equals(SettingsManager.VALUE_ON);
845 * Returns whether grid lines are set on.
847 public boolean areGridLinesOn() {
848 String gridLinesOn = get(SettingsManager.SETTING_CAMERA_GRID_LINES);
849 return gridLinesOn.equals(SettingsManager.VALUE_ON);
852 //TODO: refactor this into a separate utils module.
855 * Get a String value from first the ListPreference, and if not found
856 * from the SettingsManager.
858 * This is a wrapper that adds backwards compatibility to views that
859 * rely on PreferenceGroups.
861 public String getValueFromPreference(ListPreference pref) {
862 String value = pref.getValue();
864 Integer id = mSettingsCache.getId(pref.getKey());
874 * Set a String value first from the ListPreference, and if unable
875 * from the SettingsManager.
877 * This is a wrapper that adds backwards compatibility to views that
878 * rely on PreferenceGroups.
880 public void setValueFromPreference(ListPreference pref, String value) {
881 boolean set = pref.setValue(value);
883 Integer id = mSettingsCache.getId(pref.getKey());
891 * Set a String value first from the ListPreference based on a
892 * ListPreference index, and if unable use the ListPreference key
893 * to set the value using the SettingsManager.
895 * This is a wrapper that adds backwards compatibility to views that
896 * rely on PreferenceGroups.
898 public void setValueIndexFromPreference(ListPreference pref, int index) {
899 boolean set = pref.setValueIndex(index);
901 Integer id = mSettingsCache.getId(pref.getKey());
903 String value = pref.getValueAtIndex(index);