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.hardware.Camera.Size;
23 import android.preference.PreferenceManager;
24 import android.util.Log;
26 import com.android.camera.ListPreference;
27 import com.android.camera.util.SettingsHelper;
28 import com.android.camera2.R;
30 import java.util.List;
31 import java.util.ArrayList;
34 * SettingsManager class provides an api for getting and setting both
35 * global and local SharedPreferences.
37 public class SettingsManager {
38 private static final String TAG = "SettingsManager";
40 private final Context mContext;
41 private final SharedPreferences mDefaultSettings;
42 private final SettingsCache mSettingsCache;
43 private SharedPreferences mGlobalSettings;
44 private SharedPreferences mCameraSettings;
45 private SettingsCapabilities mCapabilities;
47 private int mCameraId = -1;
49 private final List<OnSharedPreferenceChangeListener>
50 mSharedPreferenceListeners =
51 new ArrayList<OnSharedPreferenceChangeListener>();
53 public SettingsManager(Context context, int nCameras) {
56 SettingsCache.ExtraSettings extraSettings = new SettingsHelper();
57 mSettingsCache = new SettingsCache(mContext, extraSettings);
59 mDefaultSettings = PreferenceManager.getDefaultSharedPreferences(context);
62 int cameraId = Integer.parseInt(get(SETTING_CAMERA_ID));
63 if (cameraId < 0 || cameraId >= nCameras) {
64 setDefault(SETTING_CAMERA_ID);
69 * Initialize global SharedPreferences.
71 private void initGlobal() {
72 String globalKey = mContext.getPackageName() + "_preferences_camera";
73 mGlobalSettings = mContext.getSharedPreferences(globalKey, Context.MODE_PRIVATE);
77 * Initialize SharedPreferences for other cameras.
79 public void changeCamera(int cameraId, SettingsCapabilities capabilities) {
80 mCapabilities = capabilities;
81 mSettingsCache.setCapabilities(mCapabilities);
83 if (cameraId == mCameraId) {
87 // We've changed camera ids, that means we need to flush the
88 // settings cache of settings dependent on SettingsCapabilities.
89 mSettingsCache.flush();
91 // Cache the camera id so we don't need to reload preferences
92 // if we're using the same camera.
95 String cameraKey = mContext.getPackageName() + "_preferences_" + cameraId;
96 mCameraSettings = mContext.getSharedPreferences(
97 cameraKey, Context.MODE_PRIVATE);
98 for (OnSharedPreferenceChangeListener listener : mSharedPreferenceListeners) {
99 mCameraSettings.registerOnSharedPreferenceChangeListener(listener);
104 * Interface with Camera Parameters and Modules.
106 public interface OnSettingChangedListener {
108 * Called every time a SharedPreference has been changed.
110 public void onSettingChanged(SettingsManager settingsManager, int setting);
113 private OnSharedPreferenceChangeListener getSharedPreferenceListener(
114 final OnSettingChangedListener listener) {
115 return new OnSharedPreferenceChangeListener() {
117 public void onSharedPreferenceChanged(
118 SharedPreferences sharedPreferences, String key) {
119 int settingId = mSettingsCache.getId(key);
120 listener.onSettingChanged(SettingsManager.this, settingId);
126 * Add an OnSettingChangedListener to the SettingsManager, which will execute
127 * onSettingsChanged when any SharedPreference has been updated.
129 public void addListener(final OnSettingChangedListener listener) {
130 if (listener == null) {
131 throw new IllegalArgumentException("OnSettingChangedListener cannot be null.");
134 OnSharedPreferenceChangeListener sharedPreferenceListener =
135 getSharedPreferenceListener(listener);
137 if (!mSharedPreferenceListeners.contains(sharedPreferenceListener)) {
138 mSharedPreferenceListeners.add(sharedPreferenceListener);
140 if (mGlobalSettings != null) {
141 mGlobalSettings.registerOnSharedPreferenceChangeListener(sharedPreferenceListener);
144 if (mCameraSettings != null) {
145 mCameraSettings.registerOnSharedPreferenceChangeListener(sharedPreferenceListener);
148 if (mDefaultSettings != null) {
149 mDefaultSettings.registerOnSharedPreferenceChangeListener(sharedPreferenceListener);
155 * Remove a specific SettingsListener.
156 * This should be done in onPause if a listener has been set.
158 public void removeListener(OnSettingChangedListener listener) {
159 if (listener == null) {
160 throw new IllegalArgumentException();
163 OnSharedPreferenceChangeListener sharedPreferenceListener =
164 getSharedPreferenceListener(listener);
166 if (mSharedPreferenceListeners.contains(sharedPreferenceListener)) {
167 mSharedPreferenceListeners.remove(sharedPreferenceListener);
169 if (mGlobalSettings != null) {
170 mGlobalSettings.unregisterOnSharedPreferenceChangeListener(
171 sharedPreferenceListener);
174 if (mCameraSettings != null) {
175 mCameraSettings.unregisterOnSharedPreferenceChangeListener(
176 sharedPreferenceListener);
179 if (mDefaultSettings != null) {
180 mDefaultSettings.unregisterOnSharedPreferenceChangeListener(
181 sharedPreferenceListener);
187 * Remove all OnSharedPreferenceChangedListener's.
188 * This should be done in onDestroy.
190 public void removeAllListeners() {
191 for (OnSharedPreferenceChangeListener listener : mSharedPreferenceListeners) {
192 if (mGlobalSettings != null) {
193 mGlobalSettings.unregisterOnSharedPreferenceChangeListener(listener);
196 if (mCameraSettings != null) {
197 mCameraSettings.unregisterOnSharedPreferenceChangeListener(listener);
200 if (mDefaultSettings != null) {
201 mDefaultSettings.unregisterOnSharedPreferenceChangeListener(listener);
204 mSharedPreferenceListeners.clear();
208 * SettingsCapabilities defines constraints around settings that need to be
209 * queried from external sources, like the camera parameters.
211 * This interface is camera api agnostic.
213 public interface SettingsCapabilities {
215 * Returns a list of the picture sizes currently
216 * supported by the camera device.
218 public List<Size> getSupportedPictureSizes();
221 * Returns a dynamically calculated list of
222 * exposure values, based on the min and max
223 * exposure compensation supported by the camera device.
225 public String[] getSupportedExposureValues();
228 * Returns a list of camera ids based on the number
229 * of cameras available on the device.
231 public String[] getSupportedCameraIds();
235 * Exposes SettingsCapabilities functionality.
237 public List<Size> getSupportedPictureSizes() {
238 if (mCapabilities != null) {
239 return mCapabilities.getSupportedPictureSizes();
246 * Get the camera id for which the SettingsManager has loaded camera
247 * specific preferences.
249 public int getRegisteredCameraId() {
253 // Manage individual settings.
254 public static final String VALUE_NONE = "none";
255 public static final String VALUE_ON = "on";
256 public static final String VALUE_OFF = "off";
258 public static final String TYPE_STRING = "string";
259 public static final String TYPE_BOOLEAN = "boolean";
260 public static final String TYPE_INTEGER = "integer";
262 public static final String SOURCE_DEFAULT = "default";
263 public static final String SOURCE_GLOBAL = "global";
264 public static final String SOURCE_CAMERA = "camera";
266 public static final boolean FLUSH_ON = true;
267 public static final boolean FLUSH_OFF = false;
269 // For quick lookup from id to Setting.
270 public static final int SETTING_RECORD_LOCATION = 0;
271 public static final int SETTING_VIDEO_QUALITY = 1;
272 public static final int SETTING_VIDEO_TIME_LAPSE_FRAME_INTERVAL = 2;
273 public static final int SETTING_PICTURE_SIZE = 3;
274 public static final int SETTING_JPEG_QUALITY = 4;
275 public static final int SETTING_FOCUS_MODE = 5;
276 public static final int SETTING_FLASH_MODE = 6;
277 public static final int SETTING_VIDEOCAMERA_FLASH_MODE = 7;
278 public static final int SETTING_WHITE_BALANCE = 8;
279 public static final int SETTING_SCENE_MODE = 9;
280 public static final int SETTING_EXPOSURE = 10;
281 public static final int SETTING_TIMER = 11;
282 public static final int SETTING_TIMER_SOUND_EFFECTS = 12;
283 public static final int SETTING_VIDEO_EFFECT = 13;
284 public static final int SETTING_CAMERA_ID = 14;
285 public static final int SETTING_CAMERA_HDR = 15;
286 public static final int SETTING_CAMERA_HDR_PLUS = 16;
287 public static final int SETTING_CAMERA_FIRST_USE_HINT_SHOWN = 17;
288 public static final int SETTING_VIDEO_FIRST_USE_HINT_SHOWN = 18;
289 public static final int SETTING_STARTUP_MODULE_INDEX = 19;
290 public static final int SETTING_CAMERA_REFOCUS = 20;
292 // Shared preference keys.
293 public static final String KEY_RECORD_LOCATION = "pref_camera_recordlocation_key";
294 public static final String KEY_VIDEO_QUALITY = "pref_video_quality_key";
295 public static final String KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL =
296 "pref_video_time_lapse_frame_interval_key";
297 public static final String KEY_PICTURE_SIZE = "pref_camera_picturesize_key";
298 public static final String KEY_JPEG_QUALITY = "pref_camera_jpegquality_key";
299 public static final String KEY_FOCUS_MODE = "pref_camera_focusmode_key";
300 public static final String KEY_FLASH_MODE = "pref_camera_flashmode_key";
301 public static final String KEY_VIDEOCAMERA_FLASH_MODE = "pref_camera_video_flashmode_key";
302 public static final String KEY_WHITE_BALANCE = "pref_camera_whitebalance_key";
303 public static final String KEY_SCENE_MODE = "pref_camera_scenemode_key";
304 public static final String KEY_EXPOSURE = "pref_camera_exposure_key";
305 public static final String KEY_TIMER = "pref_camera_timer_key";
306 public static final String KEY_TIMER_SOUND_EFFECTS = "pref_camera_timer_sound_key";
307 public static final String KEY_VIDEO_EFFECT = "pref_video_effect_key";
308 public static final String KEY_CAMERA_ID = "pref_camera_id_key";
309 public static final String KEY_CAMERA_HDR = "pref_camera_hdr_key";
310 public static final String KEY_CAMERA_HDR_PLUS = "pref_camera_hdr_plus_key";
311 public static final String KEY_CAMERA_FIRST_USE_HINT_SHOWN =
312 "pref_camera_first_use_hint_shown_key";
313 public static final String KEY_VIDEO_FIRST_USE_HINT_SHOWN =
314 "pref_video_first_use_hint_shown_key";
315 public static final String KEY_STARTUP_MODULE_INDEX = "camera.startup_module";
316 public static final String KEY_CAMERA_REFOCUS = "pref_camera_refocus";
318 public static final int WHITE_BALANCE_DEFAULT_INDEX = 2;
322 * Defines a simple class for holding a the spec of a setting.
323 * This spec is used by the generic api methods to query and
326 public static class Setting {
327 private final String mSource;
328 private final String mType;
329 private final String mDefault;
330 private final String mKey;
331 private final String[] mValues;
332 private final boolean mFlushOnCameraChange;
335 * A constructor used to store a setting's profile.
337 Setting(String source, String type, String defaultValue, String key,
338 String[] values, boolean flushOnCameraChange) {
341 mDefault = defaultValue;
344 mFlushOnCameraChange = flushOnCameraChange;
348 * Returns the id of a SharedPreferences instance from which
349 * this Setting may be found.
350 * Possible values are {@link #SOURCE_DEFAULT}, {@link #SOURCE_GLOBAL},
351 * {@link #SOURCE_CAMERA}.
353 public String getSource() {
358 * Returns the type of the setting stored in SharedPreferences.
359 * Possible values are {@link #TYPE_STRING}, {@link #TYPE_INTEGER},
360 * {@link #TYPE_BOOLEAN}.
362 public String getType() {
367 * Returns the default value of this setting.
369 public String getDefault() {
374 * Returns the SharedPreferences key for this setting.
376 public String getKey() {
381 * Returns an array of possible String values for this setting.
382 * If this setting is not of type {@link #TYPE_STRING}, or
383 * it's not possible to generate the string values, this should
386 public String[] getStringValues() {
391 * Returns whether the setting should be flushed from the cache
392 * when the camera device has changed.
394 public boolean isFlushedOnCameraChanged() {
395 return mFlushOnCameraChange;
400 * Get the SharedPreferences needed to query/update the setting.
402 public SharedPreferences getSettingSource(Setting setting) {
403 String source = setting.getSource();
404 if (source.equals(SOURCE_DEFAULT)) {
405 return mDefaultSettings;
407 if (source.equals(SOURCE_GLOBAL)) {
408 return mGlobalSettings;
410 if (source.equals(SOURCE_CAMERA)) {
411 return mCameraSettings;
417 * Based on Setting id, finds the index of a Setting's
418 * String value in an array of possible String values.
420 * If the Setting is not of type String, this returns -1.
422 * <p>TODO: make this a supported api call for all types.</p>
424 public int getStringValueIndex(int id) {
425 Setting setting = mSettingsCache.get(id);
426 if (setting == null || !TYPE_STRING.equals(setting.getType())) {
430 String value = get(id);
432 String[] possibleValues = setting.getStringValues();
433 if (possibleValues != null) {
434 for (int i = 0; i < possibleValues.length; i++) {
435 if (value.equals(possibleValues[i])) {
445 * Based on Setting id, sets a Setting's String value using the
446 * index into an array of possible String values.
448 * Fails to set a value if the index is out of bounds or the Setting
449 * is not of type String.
451 * @return Whether the value was set.
453 public boolean setStringValueIndex(int id, int index) {
454 Setting setting = mSettingsCache.get(id);
455 if (setting == null || setting.getType() != TYPE_STRING) {
459 String[] possibleValues = setting.getStringValues();
460 if (possibleValues != null) {
461 if (index >= 0 && index < possibleValues.length) {
462 set(id, possibleValues[index]);
470 * Get a Setting's String value based on Setting id.
472 // TODO: rename to something more descriptive.
473 public String get(int id) {
474 Setting setting = mSettingsCache.get(id);
475 SharedPreferences preferences = getSettingSource(setting);
476 if (preferences != null) {
477 return preferences.getString(setting.getKey(), setting.getDefault());
484 * Get a Setting's boolean value based on Setting id.
486 public boolean getBoolean(int id) {
487 Setting setting = mSettingsCache.get(id);
488 SharedPreferences preferences = getSettingSource(setting);
489 boolean defaultValue = setting.getDefault().equals(VALUE_ON);
490 if (preferences != null) {
491 return preferences.getBoolean(setting.getKey(), defaultValue);
498 * Get a Setting's int value based on Setting id.
500 public int getInt(int id) {
501 Setting setting = mSettingsCache.get(id);
502 SharedPreferences preferences = getSettingSource(setting);
503 int defaultValue = Integer.parseInt(setting.getDefault());
504 if (preferences != null) {
505 return preferences.getInt(setting.getKey(), defaultValue);
512 * Set a Setting with a String value based on Setting id.
514 // TODO: rename to something more descriptive.
515 public void set(int id, String value) {
516 Setting setting = mSettingsCache.get(id);
517 SharedPreferences preferences = getSettingSource(setting);
518 if (preferences != null) {
519 preferences.edit().putString(setting.getKey(), value).apply();
524 * Set a Setting with a boolean value based on Setting id.
526 public void setBoolean(int id, boolean value) {
527 Setting setting = mSettingsCache.get(id);
528 SharedPreferences preferences = getSettingSource(setting);
529 if (preferences != null) {
530 preferences.edit().putBoolean(setting.getKey(), value).apply();
535 * Set a Setting with an int value based on Setting id.
537 public void setInt(int id, int value) {
538 Setting setting = mSettingsCache.get(id);
539 SharedPreferences preferences = getSettingSource(setting);
540 if (preferences != null) {
541 preferences.edit().putInt(setting.getKey(), value).apply();
546 * Check if a Setting has ever been set based on Setting id.
548 public boolean isSet(int id) {
549 Setting setting = mSettingsCache.get(id);
550 SharedPreferences preferences = getSettingSource(setting);
551 if (preferences != null) {
552 return (preferences.getString(setting.getKey(), null) != null);
559 * Set a Setting to its default value based on Setting id.
561 public void setDefault(int id) {
562 Setting setting = mSettingsCache.get(id);
563 SharedPreferences preferences = getSettingSource(setting);
564 if (preferences != null) {
565 preferences.edit().putString(setting.getKey(), setting.getDefault());
570 * Check if a Setting is set to its default value.
572 public boolean isDefault(int id) {
573 Setting setting = mSettingsCache.get(id);
574 SharedPreferences preferences = getSettingSource(setting);
575 if (preferences != null) {
576 String type = setting.getType();
577 if (TYPE_STRING.equals(type)) {
578 String value = get(id);
579 return (value.equals(setting.getDefault()));
580 } else if (TYPE_BOOLEAN.equals(type)) {
581 boolean value = getBoolean(id);
582 boolean defaultValue = VALUE_ON.equals(setting.getDefault());
583 return (value == defaultValue);
584 } else if (TYPE_INTEGER.equals(type)) {
585 int value = getInt(id);
586 int defaultValue = Integer.parseInt(setting.getDefault());
587 return (value == defaultValue);
589 throw new IllegalArgumentException("Type " + type + " is not known.");
596 public static Setting getLocationSetting(Context context) {
597 String defaultValue = context.getString(R.string.setting_none_value);
598 String[] values = context.getResources().getStringArray(
599 R.array.pref_camera_recordlocation_entryvalues);
600 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_RECORD_LOCATION,
604 public static Setting getPictureSizeSetting(Context context) {
605 String defaultValue = null;
606 String[] values = context.getResources().getStringArray(
607 R.array.pref_camera_picturesize_entryvalues);
608 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_PICTURE_SIZE,
612 public static Setting getDefaultCameraIdSetting(Context context,
613 SettingsCapabilities capabilities) {
614 String defaultValue = context.getString(R.string.pref_camera_id_default);
615 String[] values = null;
616 if (capabilities != null) {
617 values = capabilities.getSupportedCameraIds();
619 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_CAMERA_ID,
623 public static Setting getWhiteBalanceSetting(Context context) {
624 String defaultValue = context.getString(R.string.pref_camera_whitebalance_default);
625 String[] values = context.getResources().getStringArray(
626 R.array.pref_camera_whitebalance_entryvalues);
627 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_WHITE_BALANCE,
631 public static Setting getHdrSetting(Context context) {
632 String defaultValue = context.getString(R.string.pref_camera_hdr_default);
633 String[] values = context.getResources().getStringArray(
634 R.array.pref_camera_hdr_entryvalues);
635 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_CAMERA_HDR,
639 public static Setting getHdrPlusSetting(Context context) {
640 String defaultValue = context.getString(R.string.pref_camera_hdr_plus_default);
641 String[] values = context.getResources().getStringArray(
642 R.array.pref_camera_hdr_plus_entryvalues);
643 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_CAMERA_HDR_PLUS,
647 public static Setting getSceneModeSetting(Context context) {
648 String defaultValue = context.getString(R.string.pref_camera_scenemode_default);
649 String[] values = context.getResources().getStringArray(
650 R.array.pref_camera_scenemode_entryvalues);
651 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_SCENE_MODE,
655 public static Setting getFlashSetting(Context context) {
656 String defaultValue = context.getString(R.string.pref_camera_flashmode_default);
657 String[] values = context.getResources().getStringArray(
658 R.array.pref_camera_flashmode_entryvalues);
659 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_FLASH_MODE,
663 public static Setting getExposureSetting(Context context,
664 SettingsCapabilities capabilities) {
665 String defaultValue = context.getString(R.string.pref_exposure_default);
666 String[] values = null;
667 if (capabilities != null) {
668 values = capabilities.getSupportedExposureValues();
670 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_EXPOSURE,
674 public static Setting getHintSetting(Context context) {
675 String defaultValue = context.getString(R.string.setting_on_value);
676 String[] values = null;
677 return new Setting(SOURCE_GLOBAL, TYPE_BOOLEAN, defaultValue,
678 KEY_CAMERA_FIRST_USE_HINT_SHOWN, values, FLUSH_OFF);
681 public static Setting getFocusModeSetting(Context context) {
682 String defaultValue = null;
683 String[] values = context.getResources().getStringArray(
684 R.array.pref_camera_focusmode_entryvalues);
685 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_FOCUS_MODE,
689 public static Setting getTimerSetting(Context context) {
690 String defaultValue = context.getString(R.string.pref_camera_timer_default);
691 String[] values = null; // TODO: get the values dynamically.
692 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_TIMER,
696 public static Setting getTimerSoundSetting(Context context) {
697 String defaultValue = context.getString(R.string.pref_camera_timer_sound_default);
698 String[] values = context.getResources().getStringArray(
699 R.array.pref_camera_timer_sound_entryvalues);
700 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_TIMER_SOUND_EFFECTS,
704 public static Setting getVideoQualitySetting(Context context) {
705 String defaultValue = context.getString(R.string.pref_video_quality_default);
706 String[] values = context.getResources().getStringArray(
707 R.array.pref_video_quality_entryvalues);
708 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_VIDEO_QUALITY,
712 public static Setting getTimeLapseFrameIntervalSetting(Context context) {
713 String defaultValue = context.getString(
714 R.string.pref_video_time_lapse_frame_interval_default);
715 String[] values = context.getResources().getStringArray(
716 R.array.pref_video_time_lapse_frame_interval_entryvalues);
717 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue,
718 KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL, values, FLUSH_OFF);
721 public static Setting getJpegQualitySetting(Context context) {
722 String defaultValue = context.getString(
723 R.string.pref_camera_jpeg_quality_normal);
724 String[] values = context.getResources().getStringArray(
725 R.array.pref_camera_jpeg_quality_entryvalues);
726 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_JPEG_QUALITY,
730 public static Setting getVideoFlashSetting(Context context) {
731 String defaultValue = context.getString(R.string.pref_camera_video_flashmode_default);
732 String[] values = context.getResources().getStringArray(
733 R.array.pref_camera_video_flashmode_entryvalues);
734 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue,
735 KEY_VIDEOCAMERA_FLASH_MODE, values, FLUSH_OFF);
738 public static Setting getVideoEffectSetting(Context context) {
739 String defaultValue = context.getString(R.string.pref_video_effect_default);
740 String[] values = context.getResources().getStringArray(
741 R.array.pref_video_effect_entryvalues);
742 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_VIDEO_EFFECT,
746 public static Setting getHintVideoSetting(Context context) {
747 String defaultValue = context.getString(R.string.setting_on_value);
748 String[] values = null;
749 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue,
750 KEY_VIDEO_FIRST_USE_HINT_SHOWN, values, FLUSH_OFF);
753 public static Setting getStartupModuleSetting(Context context) {
754 String defaultValue = context.getString(R.string.pref_camera_startup_index_default);
755 String[] values = null;
756 return new Setting(SOURCE_DEFAULT, TYPE_INTEGER, defaultValue,
757 KEY_STARTUP_MODULE_INDEX, values, FLUSH_OFF);
760 public static Setting getRefocusSetting(Context context) {
761 String defaultValue = context.getString(R.string.setting_off_value);
762 String[] values = context.getResources().getStringArray(
763 R.array.pref_camera_refocus_entryvalues);
764 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue,
765 KEY_CAMERA_REFOCUS, values, FLUSH_OFF);
771 * Returns whether the camera has been set to back facing
774 public boolean isCameraBackFacing() {
775 int cameraFacingIndex = getStringValueIndex(SETTING_CAMERA_ID);
776 String backFacingIndex = mContext.getString(R.string.pref_camera_id_index_back);
777 return (cameraFacingIndex == Integer.parseInt(backFacingIndex));
781 * Returns whether refocus mode is set on.
783 public boolean isRefocusOn() {
784 String refocusOn = get(SettingsManager.SETTING_CAMERA_REFOCUS);
785 return refocusOn.equals(SettingsManager.VALUE_ON);
789 * Returns whether hdr plus mode is set on.
791 public boolean isHdrPlusOn() {
792 String hdrOn = get(SettingsManager.SETTING_CAMERA_HDR);
793 return hdrOn.equals(SettingsManager.VALUE_ON);
796 //TODO: refactor this into a separate utils module.
799 * Get a String value from first the ListPreference, and if not found
800 * from the SettingsManager.
802 * This is a wrapper that adds backwards compatibility to views that
803 * rely on PreferenceGroups.
805 public String getValueFromPreference(ListPreference pref) {
806 String value = pref.getValue();
808 Integer id = mSettingsCache.getId(pref.getKey());
818 * Set a String value first from the ListPreference, and if unable
819 * from the SettingsManager.
821 * This is a wrapper that adds backwards compatibility to views that
822 * rely on PreferenceGroups.
824 public void setValueFromPreference(ListPreference pref, String value) {
825 boolean set = pref.setValue(value);
827 Integer id = mSettingsCache.getId(pref.getKey());
835 * Set a String value first from the ListPreference based on a
836 * ListPreference index, and if unable use the ListPreference key
837 * to set the value using the SettingsManager.
839 * This is a wrapper that adds backwards compatibility to views that
840 * rely on PreferenceGroups.
842 public void setValueIndexFromPreference(ListPreference pref, int index) {
843 boolean set = pref.setValueIndex(index);
845 Integer id = mSettingsCache.getId(pref.getKey());
847 String value = pref.getValueAtIndex(index);