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 mSharedPreferenceListeners.remove(listener);
194 if (mGlobalSettings != null) {
195 mGlobalSettings.unregisterOnSharedPreferenceChangeListener(listener);
198 if (mCameraSettings != null) {
199 mCameraSettings.unregisterOnSharedPreferenceChangeListener(listener);
202 if (mDefaultSettings != null) {
203 mDefaultSettings.unregisterOnSharedPreferenceChangeListener(listener);
209 * SettingsCapabilities defines constraints around settings that need to be
210 * queried from external sources, like the camera parameters.
212 * This interface is camera api agnostic.
214 public interface SettingsCapabilities {
216 * Returns a list of the picture sizes currently
217 * supported by the camera device.
219 public List<Size> getSupportedPictureSizes();
222 * Returns a dynamically calculated list of
223 * exposure values, based on the min and max
224 * exposure compensation supported by the camera device.
226 public String[] getSupportedExposureValues();
229 * Returns a list of camera ids based on the number
230 * of cameras available on the device.
232 public String[] getSupportedCameraIds();
236 * Exposes SettingsCapabilities functionality.
238 public List<Size> getSupportedPictureSizes() {
239 if (mCapabilities != null) {
240 return mCapabilities.getSupportedPictureSizes();
247 * Get the camera id for which the SettingsManager has loaded camera
248 * specific preferences.
250 public int getRegisteredCameraId() {
254 // Manage individual settings.
255 public static final String VALUE_NONE = "none";
256 public static final String VALUE_ON = "on";
257 public static final String VALUE_OFF = "off";
259 public static final String TYPE_STRING = "string";
260 public static final String TYPE_BOOLEAN = "boolean";
261 public static final String TYPE_INTEGER = "integer";
263 public static final String SOURCE_DEFAULT = "default";
264 public static final String SOURCE_GLOBAL = "global";
265 public static final String SOURCE_CAMERA = "camera";
267 public static final boolean FLUSH_ON = true;
268 public static final boolean FLUSH_OFF = false;
270 // For quick lookup from id to Setting.
271 public static final int SETTING_RECORD_LOCATION = 0;
272 public static final int SETTING_VIDEO_QUALITY = 1;
273 public static final int SETTING_VIDEO_TIME_LAPSE_FRAME_INTERVAL = 2;
274 public static final int SETTING_PICTURE_SIZE = 3;
275 public static final int SETTING_JPEG_QUALITY = 4;
276 public static final int SETTING_FOCUS_MODE = 5;
277 public static final int SETTING_FLASH_MODE = 6;
278 public static final int SETTING_VIDEOCAMERA_FLASH_MODE = 7;
279 public static final int SETTING_WHITE_BALANCE = 8;
280 public static final int SETTING_SCENE_MODE = 9;
281 public static final int SETTING_EXPOSURE = 10;
282 public static final int SETTING_TIMER = 11;
283 public static final int SETTING_TIMER_SOUND_EFFECTS = 12;
284 public static final int SETTING_VIDEO_EFFECT = 13;
285 public static final int SETTING_CAMERA_ID = 14;
286 public static final int SETTING_CAMERA_HDR = 15;
287 public static final int SETTING_CAMERA_HDR_PLUS = 16;
288 public static final int SETTING_CAMERA_FIRST_USE_HINT_SHOWN = 17;
289 public static final int SETTING_VIDEO_FIRST_USE_HINT_SHOWN = 18;
290 public static final int SETTING_STARTUP_MODULE_INDEX = 19;
291 public static final int SETTING_CAMERA_REFOCUS = 20;
293 // Shared preference keys.
294 public static final String KEY_RECORD_LOCATION = "pref_camera_recordlocation_key";
295 public static final String KEY_VIDEO_QUALITY = "pref_video_quality_key";
296 public static final String KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL =
297 "pref_video_time_lapse_frame_interval_key";
298 public static final String KEY_PICTURE_SIZE = "pref_camera_picturesize_key";
299 public static final String KEY_JPEG_QUALITY = "pref_camera_jpegquality_key";
300 public static final String KEY_FOCUS_MODE = "pref_camera_focusmode_key";
301 public static final String KEY_FLASH_MODE = "pref_camera_flashmode_key";
302 public static final String KEY_VIDEOCAMERA_FLASH_MODE = "pref_camera_video_flashmode_key";
303 public static final String KEY_WHITE_BALANCE = "pref_camera_whitebalance_key";
304 public static final String KEY_SCENE_MODE = "pref_camera_scenemode_key";
305 public static final String KEY_EXPOSURE = "pref_camera_exposure_key";
306 public static final String KEY_TIMER = "pref_camera_timer_key";
307 public static final String KEY_TIMER_SOUND_EFFECTS = "pref_camera_timer_sound_key";
308 public static final String KEY_VIDEO_EFFECT = "pref_video_effect_key";
309 public static final String KEY_CAMERA_ID = "pref_camera_id_key";
310 public static final String KEY_CAMERA_HDR = "pref_camera_hdr_key";
311 public static final String KEY_CAMERA_HDR_PLUS = "pref_camera_hdr_plus_key";
312 public static final String KEY_CAMERA_FIRST_USE_HINT_SHOWN =
313 "pref_camera_first_use_hint_shown_key";
314 public static final String KEY_VIDEO_FIRST_USE_HINT_SHOWN =
315 "pref_video_first_use_hint_shown_key";
316 public static final String KEY_STARTUP_MODULE_INDEX = "camera.startup_module";
317 public static final String KEY_CAMERA_REFOCUS = "pref_camera_refocus";
319 public static final int WHITE_BALANCE_DEFAULT_INDEX = 2;
323 * Defines a simple class for holding a the spec of a setting.
324 * This spec is used by the generic api methods to query and
327 public static class Setting {
328 private final String mSource;
329 private final String mType;
330 private final String mDefault;
331 private final String mKey;
332 private final String[] mValues;
333 private final boolean mFlushOnCameraChange;
336 * A constructor used to store a setting's profile.
338 Setting(String source, String type, String defaultValue, String key,
339 String[] values, boolean flushOnCameraChange) {
342 mDefault = defaultValue;
345 mFlushOnCameraChange = flushOnCameraChange;
349 * Returns the id of a SharedPreferences instance from which
350 * this Setting may be found.
351 * Possible values are {@link #SOURCE_DEFAULT}, {@link #SOURCE_GLOBAL},
352 * {@link #SOURCE_CAMERA}.
354 public String getSource() {
359 * Returns the type of the setting stored in SharedPreferences.
360 * Possible values are {@link #TYPE_STRING}, {@link #TYPE_INTEGER},
361 * {@link #TYPE_BOOLEAN}.
363 public String getType() {
368 * Returns the default value of this setting.
370 public String getDefault() {
375 * Returns the SharedPreferences key for this setting.
377 public String getKey() {
382 * Returns an array of possible String values for this setting.
383 * If this setting is not of type {@link #TYPE_STRING}, or
384 * it's not possible to generate the string values, this should
387 public String[] getStringValues() {
392 * Returns whether the setting should be flushed from the cache
393 * when the camera device has changed.
395 public boolean isFlushedOnCameraChanged() {
396 return mFlushOnCameraChange;
401 * Get the SharedPreferences needed to query/update the setting.
403 public SharedPreferences getSettingSource(Setting setting) {
404 String source = setting.getSource();
405 if (source.equals(SOURCE_DEFAULT)) {
406 return mDefaultSettings;
408 if (source.equals(SOURCE_GLOBAL)) {
409 return mGlobalSettings;
411 if (source.equals(SOURCE_CAMERA)) {
412 return mCameraSettings;
418 * Based on Setting id, finds the index of a Setting's
419 * String value in an array of possible String values.
421 * If the Setting is not of type String, this returns -1.
423 * <p>TODO: make this a supported api call for all types.</p>
425 public int getStringValueIndex(int id) {
426 Setting setting = mSettingsCache.get(id);
427 if (setting == null || !TYPE_STRING.equals(setting.getType())) {
431 String value = get(id);
433 String[] possibleValues = setting.getStringValues();
434 if (possibleValues != null) {
435 for (int i = 0; i < possibleValues.length; i++) {
436 if (value.equals(possibleValues[i])) {
446 * Based on Setting id, sets a Setting's String value using the
447 * index into an array of possible String values.
449 * Fails to set a value if the index is out of bounds or the Setting
450 * is not of type String.
452 * @return Whether the value was set.
454 public boolean setStringValueIndex(int id, int index) {
455 Setting setting = mSettingsCache.get(id);
456 if (setting == null || setting.getType() != TYPE_STRING) {
460 String[] possibleValues = setting.getStringValues();
461 if (possibleValues != null) {
462 if (index >= 0 && index < possibleValues.length) {
463 set(id, possibleValues[index]);
471 * Get a Setting's String value based on Setting id.
473 // TODO: rename to something more descriptive.
474 public String get(int id) {
475 Setting setting = mSettingsCache.get(id);
476 SharedPreferences preferences = getSettingSource(setting);
477 if (preferences != null) {
478 return preferences.getString(setting.getKey(), setting.getDefault());
485 * Get a Setting's boolean value based on Setting id.
487 public boolean getBoolean(int id) {
488 Setting setting = mSettingsCache.get(id);
489 SharedPreferences preferences = getSettingSource(setting);
490 boolean defaultValue = setting.getDefault().equals(VALUE_ON);
491 if (preferences != null) {
492 return preferences.getBoolean(setting.getKey(), defaultValue);
499 * Get a Setting's int value based on Setting id.
501 public int getInt(int id) {
502 Setting setting = mSettingsCache.get(id);
503 SharedPreferences preferences = getSettingSource(setting);
504 int defaultValue = Integer.parseInt(setting.getDefault());
505 if (preferences != null) {
506 return preferences.getInt(setting.getKey(), defaultValue);
513 * Set a Setting with a String value based on Setting id.
515 // TODO: rename to something more descriptive.
516 public void set(int id, String value) {
517 Setting setting = mSettingsCache.get(id);
518 SharedPreferences preferences = getSettingSource(setting);
519 if (preferences != null) {
520 preferences.edit().putString(setting.getKey(), value).apply();
525 * Set a Setting with a boolean value based on Setting id.
527 public void setBoolean(int id, boolean value) {
528 Setting setting = mSettingsCache.get(id);
529 SharedPreferences preferences = getSettingSource(setting);
530 if (preferences != null) {
531 preferences.edit().putBoolean(setting.getKey(), value).apply();
536 * Set a Setting with an int value based on Setting id.
538 public void setInt(int id, int value) {
539 Setting setting = mSettingsCache.get(id);
540 SharedPreferences preferences = getSettingSource(setting);
541 if (preferences != null) {
542 preferences.edit().putInt(setting.getKey(), value).apply();
547 * Check if a Setting has ever been set based on Setting id.
549 public boolean isSet(int id) {
550 Setting setting = mSettingsCache.get(id);
551 SharedPreferences preferences = getSettingSource(setting);
552 if (preferences != null) {
553 return (preferences.getString(setting.getKey(), null) != null);
560 * Set a Setting to its default value based on Setting id.
562 public void setDefault(int id) {
563 Setting setting = mSettingsCache.get(id);
564 SharedPreferences preferences = getSettingSource(setting);
565 if (preferences != null) {
566 preferences.edit().putString(setting.getKey(), setting.getDefault());
571 * Check if a Setting is set to its default value.
573 public boolean isDefault(int id) {
574 Setting setting = mSettingsCache.get(id);
575 SharedPreferences preferences = getSettingSource(setting);
576 if (preferences != null) {
577 String type = setting.getType();
578 if (TYPE_STRING.equals(type)) {
579 String value = get(id);
580 return (value.equals(setting.getDefault()));
581 } else if (TYPE_BOOLEAN.equals(type)) {
582 boolean value = getBoolean(id);
583 boolean defaultValue = VALUE_ON.equals(setting.getDefault());
584 return (value == defaultValue);
585 } else if (TYPE_INTEGER.equals(type)) {
586 int value = getInt(id);
587 int defaultValue = Integer.parseInt(setting.getDefault());
588 return (value == defaultValue);
590 throw new IllegalArgumentException("Type " + type + " is not known.");
597 public static Setting getLocationSetting(Context context) {
598 String defaultValue = context.getString(R.string.setting_none_value);
599 String[] values = context.getResources().getStringArray(
600 R.array.pref_camera_recordlocation_entryvalues);
601 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_RECORD_LOCATION,
605 public static Setting getPictureSizeSetting(Context context) {
606 String defaultValue = null;
607 String[] values = context.getResources().getStringArray(
608 R.array.pref_camera_picturesize_entryvalues);
609 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_PICTURE_SIZE,
613 public static Setting getDefaultCameraIdSetting(Context context,
614 SettingsCapabilities capabilities) {
615 String defaultValue = context.getString(R.string.pref_camera_id_default);
616 String[] values = null;
617 if (capabilities != null) {
618 values = capabilities.getSupportedCameraIds();
620 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_CAMERA_ID,
624 public static Setting getWhiteBalanceSetting(Context context) {
625 String defaultValue = context.getString(R.string.pref_camera_whitebalance_default);
626 String[] values = context.getResources().getStringArray(
627 R.array.pref_camera_whitebalance_entryvalues);
628 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_WHITE_BALANCE,
632 public static Setting getHdrSetting(Context context) {
633 String defaultValue = context.getString(R.string.pref_camera_hdr_default);
634 String[] values = context.getResources().getStringArray(
635 R.array.pref_camera_hdr_entryvalues);
636 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_CAMERA_HDR,
640 public static Setting getHdrPlusSetting(Context context) {
641 String defaultValue = context.getString(R.string.pref_camera_hdr_plus_default);
642 String[] values = context.getResources().getStringArray(
643 R.array.pref_camera_hdr_plus_entryvalues);
644 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_CAMERA_HDR_PLUS,
648 public static Setting getSceneModeSetting(Context context) {
649 String defaultValue = context.getString(R.string.pref_camera_scenemode_default);
650 String[] values = context.getResources().getStringArray(
651 R.array.pref_camera_scenemode_entryvalues);
652 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_SCENE_MODE,
656 public static Setting getFlashSetting(Context context) {
657 String defaultValue = context.getString(R.string.pref_camera_flashmode_default);
658 String[] values = context.getResources().getStringArray(
659 R.array.pref_camera_flashmode_entryvalues);
660 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_FLASH_MODE,
664 public static Setting getExposureSetting(Context context,
665 SettingsCapabilities capabilities) {
666 String defaultValue = context.getString(R.string.pref_exposure_default);
667 String[] values = null;
668 if (capabilities != null) {
669 values = capabilities.getSupportedExposureValues();
671 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_EXPOSURE,
675 public static Setting getHintSetting(Context context) {
676 String defaultValue = context.getString(R.string.setting_on_value);
677 String[] values = null;
678 return new Setting(SOURCE_GLOBAL, TYPE_BOOLEAN, defaultValue,
679 KEY_CAMERA_FIRST_USE_HINT_SHOWN, values, FLUSH_OFF);
682 public static Setting getFocusModeSetting(Context context) {
683 String defaultValue = null;
684 String[] values = context.getResources().getStringArray(
685 R.array.pref_camera_focusmode_entryvalues);
686 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_FOCUS_MODE,
690 public static Setting getTimerSetting(Context context) {
691 String defaultValue = context.getString(R.string.pref_camera_timer_default);
692 String[] values = null; // TODO: get the values dynamically.
693 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_TIMER,
697 public static Setting getTimerSoundSetting(Context context) {
698 String defaultValue = context.getString(R.string.pref_camera_timer_sound_default);
699 String[] values = context.getResources().getStringArray(
700 R.array.pref_camera_timer_sound_entryvalues);
701 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_TIMER_SOUND_EFFECTS,
705 public static Setting getVideoQualitySetting(Context context) {
706 String defaultValue = context.getString(R.string.pref_video_quality_default);
707 String[] values = context.getResources().getStringArray(
708 R.array.pref_video_quality_entryvalues);
709 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_VIDEO_QUALITY,
713 public static Setting getTimeLapseFrameIntervalSetting(Context context) {
714 String defaultValue = context.getString(
715 R.string.pref_video_time_lapse_frame_interval_default);
716 String[] values = context.getResources().getStringArray(
717 R.array.pref_video_time_lapse_frame_interval_entryvalues);
718 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue,
719 KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL, values, FLUSH_OFF);
722 public static Setting getJpegQualitySetting(Context context) {
723 String defaultValue = context.getString(
724 R.string.pref_camera_jpeg_quality_normal);
725 String[] values = context.getResources().getStringArray(
726 R.array.pref_camera_jpeg_quality_entryvalues);
727 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_JPEG_QUALITY,
731 public static Setting getVideoFlashSetting(Context context) {
732 String defaultValue = context.getString(R.string.pref_camera_video_flashmode_default);
733 String[] values = context.getResources().getStringArray(
734 R.array.pref_camera_video_flashmode_entryvalues);
735 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue,
736 KEY_VIDEOCAMERA_FLASH_MODE, values, FLUSH_OFF);
739 public static Setting getVideoEffectSetting(Context context) {
740 String defaultValue = context.getString(R.string.pref_video_effect_default);
741 String[] values = context.getResources().getStringArray(
742 R.array.pref_video_effect_entryvalues);
743 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_VIDEO_EFFECT,
747 public static Setting getHintVideoSetting(Context context) {
748 String defaultValue = context.getString(R.string.setting_on_value);
749 String[] values = null;
750 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue,
751 KEY_VIDEO_FIRST_USE_HINT_SHOWN, values, FLUSH_OFF);
754 public static Setting getStartupModuleSetting(Context context) {
755 String defaultValue = context.getString(R.string.pref_camera_startup_index_default);
756 String[] values = null;
757 return new Setting(SOURCE_DEFAULT, TYPE_INTEGER, defaultValue,
758 KEY_STARTUP_MODULE_INDEX, values, FLUSH_OFF);
761 public static Setting getRefocusSetting(Context context) {
762 String defaultValue = context.getString(R.string.setting_off_value);
763 String[] values = context.getResources().getStringArray(
764 R.array.pref_camera_refocus_entryvalues);
765 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue,
766 KEY_CAMERA_REFOCUS, values, FLUSH_OFF);
772 * Returns whether the camera has been set to back facing
775 public boolean isCameraBackFacing() {
776 int cameraFacingIndex = getStringValueIndex(SETTING_CAMERA_ID);
777 String backFacingIndex = mContext.getString(R.string.pref_camera_id_index_back);
778 return (cameraFacingIndex == Integer.parseInt(backFacingIndex));
781 //TODO: refactor this into a separate utils module.
784 * Get a String value from first the ListPreference, and if not found
785 * from the SettingsManager.
787 * This is a wrapper that adds backwards compatibility to views that
788 * rely on PreferenceGroups.
790 public String getValueFromPreference(ListPreference pref) {
791 String value = pref.getValue();
793 Integer id = mSettingsCache.getId(pref.getKey());
803 * Set a String value first from the ListPreference, and if unable
804 * from the SettingsManager.
806 * This is a wrapper that adds backwards compatibility to views that
807 * rely on PreferenceGroups.
809 public void setValueFromPreference(ListPreference pref, String value) {
810 boolean set = pref.setValue(value);
812 Integer id = mSettingsCache.getId(pref.getKey());
820 * Set a String value first from the ListPreference based on a
821 * ListPreference index, and if unable use the ListPreference key
822 * to set the value using the SettingsManager.
824 * This is a wrapper that adds backwards compatibility to views that
825 * rely on PreferenceGroups.
827 public void setValueIndexFromPreference(ListPreference pref, int index) {
828 boolean set = pref.setValueIndex(index);
830 Integer id = mSettingsCache.getId(pref.getKey());
832 String value = pref.getValueAtIndex(index);