1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17 package com.android.camera.settings; 18 19 import android.content.Context; 20 21 import com.android.camera.app.LocationManager; 22 import com.android.camera.util.ApiHelper; 23 import com.android.camera2.R; 24 25 /** 26 * Keys is a class for storing SharedPreferences keys and configuring 27 * their defaults. 28 * 29 * For each key that has a default value and set of possible values, it 30 * stores those defaults so they can be used by the SettingsManager 31 * on lookup. This step is optional, and it can be done anytime before 32 * a setting is accessed by the SettingsManager API. 33 */ 34 public class Keys { 35 36 public static final String KEY_RECORD_LOCATION = "pref_camera_recordlocation_key"; 37 public static final String KEY_VIDEO_QUALITY_BACK = "pref_video_quality_back_key"; 38 public static final String KEY_VIDEO_QUALITY_FRONT = "pref_video_quality_front_key"; 39 public static final String KEY_PICTURE_SIZE_BACK = "pref_camera_picturesize_back_key"; 40 public static final String KEY_PICTURE_SIZE_FRONT = "pref_camera_picturesize_front_key"; 41 public static final String KEY_JPEG_QUALITY = "pref_camera_jpegquality_key"; 42 public static final String KEY_FOCUS_MODE = "pref_camera_focusmode_key"; 43 public static final String KEY_FLASH_MODE = "pref_camera_flashmode_key"; 44 public static final String KEY_VIDEOCAMERA_FLASH_MODE = "pref_camera_video_flashmode_key"; 45 public static final String KEY_SCENE_MODE = "pref_camera_scenemode_key"; 46 public static final String KEY_EXPOSURE = "pref_camera_exposure_key"; 47 public static final String KEY_VIDEO_EFFECT = "pref_video_effect_key"; 48 public static final String KEY_CAMERA_ID = "pref_camera_id_key"; 49 50 public static final String KEY_CAMERA_HDR = "pref_camera_hdr_key"; 51 public static final String KEY_CAMERA_HDR_PLUS = "pref_camera_hdr_plus_key"; 52 public static final String KEY_CAMERA_FIRST_USE_HINT_SHOWN = 53 "pref_camera_first_use_hint_shown_key"; 54 public static final String KEY_VIDEO_FIRST_USE_HINT_SHOWN = 55 "pref_video_first_use_hint_shown_key"; 56 public static final String KEY_STARTUP_MODULE_INDEX = "camera.startup_module"; 57 public static final String KEY_CAMERA_MODULE_LAST_USED = 58 "pref_camera_module_last_used_index"; 59 public static final String KEY_CAMERA_PANO_ORIENTATION = "pref_camera_pano_orientation"; 60 public static final String KEY_CAMERA_GRID_LINES = "pref_camera_grid_lines"; 61 public static final String KEY_RELEASE_DIALOG_LAST_SHOWN_VERSION = 62 "pref_release_dialog_last_shown_version"; 63 public static final String KEY_FLASH_SUPPORTED_BACK_CAMERA = 64 "pref_flash_supported_back_camera"; 65 public static final String KEY_HDR_SUPPORT_MODE_BACK_CAMERA = 66 "pref_hdr_support_mode_back_camera"; 67 public static final String KEY_UPGRADE_VERSION = "pref_upgrade_version"; 68 public static final String KEY_REQUEST_RETURN_HDR_PLUS = "pref_request_return_hdr_plus"; 69 public static final String KEY_SHOULD_SHOW_REFOCUS_VIEWER_CLING = 70 "pref_should_show_refocus_viewer_cling"; 71 public static final String KEY_EXPOSURE_COMPENSATION_ENABLED = 72 "pref_camera_exposure_compensation_key"; 73 74 /** 75 * Whether the user has chosen an aspect ratio on the first run dialog. 76 */ 77 public static final String KEY_USER_SELECTED_ASPECT_RATIO = "pref_user_selected_aspect_ratio"; 78 79 public static final String KEY_COUNTDOWN_DURATION = "pref_camera_countdown_duration_key"; 80 public static final String KEY_HDR_PLUS_FLASH_MODE = "pref_hdr_plus_flash_mode"; 81 public static final String KEY_SHOULD_SHOW_SETTINGS_BUTTON_CLING = 82 "pref_should_show_settings_button_cling"; 83 public static final String KEY_HAS_SEEN_PERMISSIONS_DIALOGS = "pref_has_seen_permissions_dialogs"; 84 85 /** 86 * Set some number of defaults for the defined keys. 87 * It's not necessary to set all defaults. 88 */ setDefaults(SettingsManager settingsManager, Context context)89 public static void setDefaults(SettingsManager settingsManager, Context context) { 90 settingsManager.setDefaults(KEY_COUNTDOWN_DURATION, 0, 91 context.getResources().getIntArray(R.array.pref_countdown_duration)); 92 93 settingsManager.setDefaults(KEY_CAMERA_ID, 94 context.getString(R.string.pref_camera_id_default), 95 context.getResources().getStringArray(R.array.camera_id_entryvalues)); 96 97 settingsManager.setDefaults(KEY_SCENE_MODE, 98 context.getString(R.string.pref_camera_scenemode_default), 99 context.getResources().getStringArray(R.array.pref_camera_scenemode_entryvalues)); 100 101 settingsManager.setDefaults(KEY_FLASH_MODE, 102 context.getString(R.string.pref_camera_flashmode_default), 103 context.getResources().getStringArray(R.array.pref_camera_flashmode_entryvalues)); 104 105 settingsManager.setDefaults(KEY_HDR_SUPPORT_MODE_BACK_CAMERA, 106 context.getString(R.string.pref_camera_hdr_supportmode_none), 107 context.getResources().getStringArray(R.array.pref_camera_hdr_supportmode_entryvalues)); 108 109 settingsManager.setDefaults(KEY_CAMERA_HDR, false); 110 settingsManager.setDefaults(KEY_CAMERA_HDR_PLUS, false); 111 112 settingsManager.setDefaults(KEY_CAMERA_FIRST_USE_HINT_SHOWN, true); 113 114 settingsManager.setDefaults(KEY_FOCUS_MODE, 115 context.getString(R.string.pref_camera_focusmode_default), 116 context.getResources().getStringArray(R.array.pref_camera_focusmode_entryvalues)); 117 118 String videoQualityBackDefaultValue = context.getString(R.string.pref_video_quality_large); 119 // TODO: We tweaked the default setting based on model string which is not ideal. Detecting 120 // CamcorderProfile capability is a better way to get this job done. However, 121 // |CamcorderProfile.hasProfile| needs camera id info. We need a way to provide camera id to 122 // this method. b/17445274 123 // Don't set the default resolution to be large if the device supports 4k video. 124 if (ApiHelper.IS_NEXUS_6) { 125 videoQualityBackDefaultValue = context.getString(R.string.pref_video_quality_medium); 126 } 127 settingsManager.setDefaults( 128 KEY_VIDEO_QUALITY_BACK, 129 videoQualityBackDefaultValue, 130 context.getResources().getStringArray(R.array.pref_video_quality_entryvalues)); 131 if (!settingsManager.isSet(SettingsManager.SCOPE_GLOBAL, Keys.KEY_VIDEO_QUALITY_BACK)) { 132 settingsManager.setToDefault(SettingsManager.SCOPE_GLOBAL, 133 Keys.KEY_VIDEO_QUALITY_BACK); 134 } 135 136 settingsManager.setDefaults(KEY_VIDEO_QUALITY_FRONT, 137 context.getString(R.string.pref_video_quality_large), 138 context.getResources().getStringArray(R.array.pref_video_quality_entryvalues)); 139 if (!settingsManager.isSet(SettingsManager.SCOPE_GLOBAL, Keys.KEY_VIDEO_QUALITY_FRONT)) { 140 settingsManager.setToDefault(SettingsManager.SCOPE_GLOBAL, 141 Keys.KEY_VIDEO_QUALITY_FRONT); 142 } 143 144 settingsManager.setDefaults(KEY_JPEG_QUALITY, 145 context.getString(R.string.pref_camera_jpeg_quality_normal), 146 context.getResources().getStringArray( 147 R.array.pref_camera_jpeg_quality_entryvalues)); 148 149 settingsManager.setDefaults(KEY_VIDEOCAMERA_FLASH_MODE, 150 context.getString(R.string.pref_camera_video_flashmode_default), 151 context.getResources().getStringArray( 152 R.array.pref_camera_video_flashmode_entryvalues)); 153 154 settingsManager.setDefaults(KEY_VIDEO_EFFECT, 155 context.getString(R.string.pref_video_effect_default), 156 context.getResources().getStringArray(R.array.pref_video_effect_entryvalues)); 157 158 settingsManager.setDefaults(KEY_VIDEO_FIRST_USE_HINT_SHOWN, true); 159 160 settingsManager.setDefaults(KEY_STARTUP_MODULE_INDEX, 0, 161 context.getResources().getIntArray(R.array.camera_modes)); 162 163 settingsManager.setDefaults(KEY_CAMERA_MODULE_LAST_USED, 164 context.getResources().getInteger(R.integer.camera_mode_photo), 165 context.getResources().getIntArray(R.array.camera_modes)); 166 167 settingsManager.setDefaults(KEY_CAMERA_PANO_ORIENTATION, 168 context.getString(R.string.pano_orientation_horizontal), 169 context.getResources().getStringArray( 170 R.array.pref_camera_pano_orientation_entryvalues)); 171 172 settingsManager.setDefaults(KEY_CAMERA_GRID_LINES, false); 173 174 settingsManager.setDefaults(KEY_SHOULD_SHOW_REFOCUS_VIEWER_CLING, true); 175 176 settingsManager.setDefaults(KEY_HDR_PLUS_FLASH_MODE, 177 context.getString(R.string.pref_camera_hdr_plus_flashmode_default), 178 context.getResources().getStringArray( 179 R.array.pref_camera_hdr_plus_flashmode_entryvalues)); 180 181 settingsManager.setDefaults(KEY_SHOULD_SHOW_SETTINGS_BUTTON_CLING, true); 182 183 } 184 185 /** Helper functions for some defined keys. */ 186 187 /** 188 * Returns whether the camera has been set to back facing in settings. 189 */ isCameraBackFacing(SettingsManager settingsManager, String moduleScope)190 public static boolean isCameraBackFacing(SettingsManager settingsManager, 191 String moduleScope) { 192 return settingsManager.isDefault(moduleScope, KEY_CAMERA_ID); 193 } 194 195 /** 196 * Returns whether hdr plus mode is set on. 197 */ isHdrPlusOn(SettingsManager settingsManager)198 public static boolean isHdrPlusOn(SettingsManager settingsManager) { 199 return settingsManager.getBoolean(SettingsManager.SCOPE_GLOBAL, 200 KEY_CAMERA_HDR_PLUS); 201 } 202 203 /** 204 * Returns whether hdr mode is set on. 205 */ isHdrOn(SettingsManager settingsManager)206 public static boolean isHdrOn(SettingsManager settingsManager) { 207 return settingsManager.getBoolean(SettingsManager.SCOPE_GLOBAL, 208 KEY_CAMERA_HDR); 209 } 210 211 /** 212 * Returns whether the app should return to hdr plus mode if possible. 213 */ requestsReturnToHdrPlus(SettingsManager settingsManager, String moduleScope)214 public static boolean requestsReturnToHdrPlus(SettingsManager settingsManager, 215 String moduleScope) { 216 return settingsManager.getBoolean(moduleScope, KEY_REQUEST_RETURN_HDR_PLUS); 217 } 218 219 /** 220 * Returns whether grid lines are set on. 221 */ areGridLinesOn(SettingsManager settingsManager)222 public static boolean areGridLinesOn(SettingsManager settingsManager) { 223 return settingsManager.getBoolean(SettingsManager.SCOPE_GLOBAL, 224 KEY_CAMERA_GRID_LINES); 225 } 226 } 227 228