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;
291 public static final int SETTING_SHIMMY_REMAINING_PLAY_TIMES_INDEX = 21;
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";
318 public static final String KEY_SHIMMY_REMAINING_PLAY_TIMES =
319 "pref_shimmy_remaining_play_times";
321 public static final int WHITE_BALANCE_DEFAULT_INDEX = 2;
325 * Defines a simple class for holding a the spec of a setting.
326 * This spec is used by the generic api methods to query and
329 public static class Setting {
330 private final String mSource;
331 private final String mType;
332 private final String mDefault;
333 private final String mKey;
334 private final String[] mValues;
335 private final boolean mFlushOnCameraChange;
338 * A constructor used to store a setting's profile.
340 Setting(String source, String type, String defaultValue, String key,
341 String[] values, boolean flushOnCameraChange) {
344 mDefault = defaultValue;
347 mFlushOnCameraChange = flushOnCameraChange;
351 * Returns the id of a SharedPreferences instance from which
352 * this Setting may be found.
353 * Possible values are {@link #SOURCE_DEFAULT}, {@link #SOURCE_GLOBAL},
354 * {@link #SOURCE_CAMERA}.
356 public String getSource() {
361 * Returns the type of the setting stored in SharedPreferences.
362 * Possible values are {@link #TYPE_STRING}, {@link #TYPE_INTEGER},
363 * {@link #TYPE_BOOLEAN}.
365 public String getType() {
370 * Returns the default value of this setting.
372 public String getDefault() {
377 * Returns the SharedPreferences key for this setting.
379 public String getKey() {
384 * Returns an array of possible String values for this setting.
385 * If this setting is not of type {@link #TYPE_STRING}, or
386 * it's not possible to generate the string values, this should
389 public String[] getStringValues() {
394 * Returns whether the setting should be flushed from the cache
395 * when the camera device has changed.
397 public boolean isFlushedOnCameraChanged() {
398 return mFlushOnCameraChange;
403 * Get the SharedPreferences needed to query/update the setting.
405 public SharedPreferences getSettingSource(Setting setting) {
406 String source = setting.getSource();
407 if (source.equals(SOURCE_DEFAULT)) {
408 return mDefaultSettings;
410 if (source.equals(SOURCE_GLOBAL)) {
411 return mGlobalSettings;
413 if (source.equals(SOURCE_CAMERA)) {
414 return mCameraSettings;
420 * Based on Setting id, finds the index of a Setting's
421 * String value in an array of possible String values.
423 * If the Setting is not of type String, this returns -1.
425 * <p>TODO: make this a supported api call for all types.</p>
427 public int getStringValueIndex(int id) {
428 Setting setting = mSettingsCache.get(id);
429 if (setting == null || !TYPE_STRING.equals(setting.getType())) {
433 String value = get(id);
435 String[] possibleValues = setting.getStringValues();
436 if (possibleValues != null) {
437 for (int i = 0; i < possibleValues.length; i++) {
438 if (value.equals(possibleValues[i])) {
448 * Based on Setting id, sets a Setting's String value using the
449 * index into an array of possible String values.
451 * Fails to set a value if the index is out of bounds or the Setting
452 * is not of type String.
454 * @return Whether the value was set.
456 public boolean setStringValueIndex(int id, int index) {
457 Setting setting = mSettingsCache.get(id);
458 if (setting == null || setting.getType() != TYPE_STRING) {
462 String[] possibleValues = setting.getStringValues();
463 if (possibleValues != null) {
464 if (index >= 0 && index < possibleValues.length) {
465 set(id, possibleValues[index]);
473 * Get a Setting's String value based on Setting id.
475 // TODO: rename to something more descriptive.
476 public String get(int id) {
477 Setting setting = mSettingsCache.get(id);
478 SharedPreferences preferences = getSettingSource(setting);
479 if (preferences != null) {
480 return preferences.getString(setting.getKey(), setting.getDefault());
487 * Get a Setting's boolean value based on Setting id.
489 public boolean getBoolean(int id) {
490 Setting setting = mSettingsCache.get(id);
491 SharedPreferences preferences = getSettingSource(setting);
492 boolean defaultValue = setting.getDefault().equals(VALUE_ON);
493 if (preferences != null) {
494 return preferences.getBoolean(setting.getKey(), defaultValue);
501 * Get a Setting's int value based on Setting id.
503 public int getInt(int id) {
504 Setting setting = mSettingsCache.get(id);
505 SharedPreferences preferences = getSettingSource(setting);
506 int defaultValue = Integer.parseInt(setting.getDefault());
507 if (preferences != null) {
508 return preferences.getInt(setting.getKey(), defaultValue);
515 * Set a Setting with a String value based on Setting id.
517 // TODO: rename to something more descriptive.
518 public void set(int id, String value) {
519 Setting setting = mSettingsCache.get(id);
520 SharedPreferences preferences = getSettingSource(setting);
521 if (preferences != null) {
522 preferences.edit().putString(setting.getKey(), value).apply();
527 * Set a Setting with a boolean value based on Setting id.
529 public void setBoolean(int id, boolean value) {
530 Setting setting = mSettingsCache.get(id);
531 SharedPreferences preferences = getSettingSource(setting);
532 if (preferences != null) {
533 preferences.edit().putBoolean(setting.getKey(), value).apply();
538 * Set a Setting with an int value based on Setting id.
540 public void setInt(int id, int value) {
541 Setting setting = mSettingsCache.get(id);
542 SharedPreferences preferences = getSettingSource(setting);
543 if (preferences != null) {
544 preferences.edit().putInt(setting.getKey(), value).apply();
549 * Check if a Setting has ever been set based on Setting id.
551 public boolean isSet(int id) {
552 Setting setting = mSettingsCache.get(id);
553 SharedPreferences preferences = getSettingSource(setting);
554 if (preferences != null) {
555 return (preferences.getString(setting.getKey(), null) != null);
562 * Set a Setting to its default value based on Setting id.
564 public void setDefault(int id) {
565 Setting setting = mSettingsCache.get(id);
566 SharedPreferences preferences = getSettingSource(setting);
567 if (preferences != null) {
568 preferences.edit().putString(setting.getKey(), setting.getDefault());
573 * Check if a Setting is set to its default value.
575 public boolean isDefault(int id) {
576 Setting setting = mSettingsCache.get(id);
577 SharedPreferences preferences = getSettingSource(setting);
578 if (preferences != null) {
579 String type = setting.getType();
580 if (TYPE_STRING.equals(type)) {
581 String value = get(id);
582 return (value.equals(setting.getDefault()));
583 } else if (TYPE_BOOLEAN.equals(type)) {
584 boolean value = getBoolean(id);
585 boolean defaultValue = VALUE_ON.equals(setting.getDefault());
586 return (value == defaultValue);
587 } else if (TYPE_INTEGER.equals(type)) {
588 int value = getInt(id);
589 int defaultValue = Integer.parseInt(setting.getDefault());
590 return (value == defaultValue);
592 throw new IllegalArgumentException("Type " + type + " is not known.");
599 public static Setting getLocationSetting(Context context) {
600 String defaultValue = context.getString(R.string.setting_none_value);
601 String[] values = context.getResources().getStringArray(
602 R.array.pref_camera_recordlocation_entryvalues);
603 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_RECORD_LOCATION,
607 public static Setting getPictureSizeSetting(Context context) {
608 String defaultValue = null;
609 String[] values = context.getResources().getStringArray(
610 R.array.pref_camera_picturesize_entryvalues);
611 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_PICTURE_SIZE,
615 public static Setting getDefaultCameraIdSetting(Context context,
616 SettingsCapabilities capabilities) {
617 String defaultValue = context.getString(R.string.pref_camera_id_default);
618 String[] values = null;
619 if (capabilities != null) {
620 values = capabilities.getSupportedCameraIds();
622 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_CAMERA_ID,
626 public static Setting getWhiteBalanceSetting(Context context) {
627 String defaultValue = context.getString(R.string.pref_camera_whitebalance_default);
628 String[] values = context.getResources().getStringArray(
629 R.array.pref_camera_whitebalance_entryvalues);
630 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_WHITE_BALANCE,
634 public static Setting getHdrSetting(Context context) {
635 String defaultValue = context.getString(R.string.pref_camera_hdr_default);
636 String[] values = context.getResources().getStringArray(
637 R.array.pref_camera_hdr_entryvalues);
638 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_CAMERA_HDR,
642 public static Setting getHdrPlusSetting(Context context) {
643 String defaultValue = context.getString(R.string.pref_camera_hdr_plus_default);
644 String[] values = context.getResources().getStringArray(
645 R.array.pref_camera_hdr_plus_entryvalues);
646 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_CAMERA_HDR_PLUS,
650 public static Setting getSceneModeSetting(Context context) {
651 String defaultValue = context.getString(R.string.pref_camera_scenemode_default);
652 String[] values = context.getResources().getStringArray(
653 R.array.pref_camera_scenemode_entryvalues);
654 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_SCENE_MODE,
658 public static Setting getFlashSetting(Context context) {
659 String defaultValue = context.getString(R.string.pref_camera_flashmode_default);
660 String[] values = context.getResources().getStringArray(
661 R.array.pref_camera_flashmode_entryvalues);
662 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_FLASH_MODE,
666 public static Setting getExposureSetting(Context context,
667 SettingsCapabilities capabilities) {
668 String defaultValue = context.getString(R.string.pref_exposure_default);
669 String[] values = null;
670 if (capabilities != null) {
671 values = capabilities.getSupportedExposureValues();
673 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_EXPOSURE,
677 public static Setting getHintSetting(Context context) {
678 String defaultValue = context.getString(R.string.setting_on_value);
679 String[] values = null;
680 return new Setting(SOURCE_GLOBAL, TYPE_BOOLEAN, defaultValue,
681 KEY_CAMERA_FIRST_USE_HINT_SHOWN, values, FLUSH_OFF);
684 public static Setting getFocusModeSetting(Context context) {
685 String defaultValue = null;
686 String[] values = context.getResources().getStringArray(
687 R.array.pref_camera_focusmode_entryvalues);
688 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_FOCUS_MODE,
692 public static Setting getTimerSetting(Context context) {
693 String defaultValue = context.getString(R.string.pref_camera_timer_default);
694 String[] values = null; // TODO: get the values dynamically.
695 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_TIMER,
699 public static Setting getTimerSoundSetting(Context context) {
700 String defaultValue = context.getString(R.string.pref_camera_timer_sound_default);
701 String[] values = context.getResources().getStringArray(
702 R.array.pref_camera_timer_sound_entryvalues);
703 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_TIMER_SOUND_EFFECTS,
707 public static Setting getVideoQualitySetting(Context context) {
708 String defaultValue = context.getString(R.string.pref_video_quality_default);
709 String[] values = context.getResources().getStringArray(
710 R.array.pref_video_quality_entryvalues);
711 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_VIDEO_QUALITY,
715 public static Setting getTimeLapseFrameIntervalSetting(Context context) {
716 String defaultValue = context.getString(
717 R.string.pref_video_time_lapse_frame_interval_default);
718 String[] values = context.getResources().getStringArray(
719 R.array.pref_video_time_lapse_frame_interval_entryvalues);
720 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue,
721 KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL, values, FLUSH_OFF);
724 public static Setting getJpegQualitySetting(Context context) {
725 String defaultValue = context.getString(
726 R.string.pref_camera_jpeg_quality_normal);
727 String[] values = context.getResources().getStringArray(
728 R.array.pref_camera_jpeg_quality_entryvalues);
729 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_JPEG_QUALITY,
733 public static Setting getVideoFlashSetting(Context context) {
734 String defaultValue = context.getString(R.string.pref_camera_video_flashmode_default);
735 String[] values = context.getResources().getStringArray(
736 R.array.pref_camera_video_flashmode_entryvalues);
737 return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue,
738 KEY_VIDEOCAMERA_FLASH_MODE, values, FLUSH_OFF);
741 public static Setting getVideoEffectSetting(Context context) {
742 String defaultValue = context.getString(R.string.pref_video_effect_default);
743 String[] values = context.getResources().getStringArray(
744 R.array.pref_video_effect_entryvalues);
745 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_VIDEO_EFFECT,
749 public static Setting getHintVideoSetting(Context context) {
750 String defaultValue = context.getString(R.string.setting_on_value);
751 String[] values = null;
752 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue,
753 KEY_VIDEO_FIRST_USE_HINT_SHOWN, values, FLUSH_OFF);
756 public static Setting getStartupModuleSetting(Context context) {
757 String defaultValue = context.getString(R.string.pref_camera_startup_index_default);
758 String[] values = null;
759 return new Setting(SOURCE_DEFAULT, TYPE_INTEGER, defaultValue,
760 KEY_STARTUP_MODULE_INDEX, values, FLUSH_OFF);
763 public static Setting getShimmyRemainingTimesSetting(Context context) {
764 String defaultValue = context.getString(R.string.pref_shimmy_play_times);
765 return new Setting(SOURCE_DEFAULT, TYPE_INTEGER, defaultValue,
766 KEY_SHIMMY_REMAINING_PLAY_TIMES, null, FLUSH_OFF);
769 public static Setting getRefocusSetting(Context context) {
770 String defaultValue = context.getString(R.string.setting_off_value);
771 String[] values = context.getResources().getStringArray(
772 R.array.pref_camera_refocus_entryvalues);
773 return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue,
774 KEY_CAMERA_REFOCUS, values, FLUSH_OFF);
780 * Returns whether the camera has been set to back facing
783 public boolean isCameraBackFacing() {
784 int cameraFacingIndex = getStringValueIndex(SETTING_CAMERA_ID);
785 String backFacingIndex = mContext.getString(R.string.pref_camera_id_index_back);
786 return (cameraFacingIndex == Integer.parseInt(backFacingIndex));
790 * Returns whether refocus mode is set on.
792 public boolean isRefocusOn() {
793 String refocusOn = get(SettingsManager.SETTING_CAMERA_REFOCUS);
794 return refocusOn.equals(SettingsManager.VALUE_ON);
798 * Returns whether hdr plus mode is set on.
800 public boolean isHdrPlusOn() {
801 String hdrOn = get(SettingsManager.SETTING_CAMERA_HDR);
802 return hdrOn.equals(SettingsManager.VALUE_ON);
805 //TODO: refactor this into a separate utils module.
808 * Get a String value from first the ListPreference, and if not found
809 * from the SettingsManager.
811 * This is a wrapper that adds backwards compatibility to views that
812 * rely on PreferenceGroups.
814 public String getValueFromPreference(ListPreference pref) {
815 String value = pref.getValue();
817 Integer id = mSettingsCache.getId(pref.getKey());
827 * Set a String value first from the ListPreference, and if unable
828 * from the SettingsManager.
830 * This is a wrapper that adds backwards compatibility to views that
831 * rely on PreferenceGroups.
833 public void setValueFromPreference(ListPreference pref, String value) {
834 boolean set = pref.setValue(value);
836 Integer id = mSettingsCache.getId(pref.getKey());
844 * Set a String value first from the ListPreference based on a
845 * ListPreference index, and if unable use the ListPreference key
846 * to set the value using the SettingsManager.
848 * This is a wrapper that adds backwards compatibility to views that
849 * rely on PreferenceGroups.
851 public void setValueIndexFromPreference(ListPreference pref, int index) {
852 boolean set = pref.setValueIndex(index);
854 Integer id = mSettingsCache.getId(pref.getKey());
856 String value = pref.getValueAtIndex(index);