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_UPGRADE_VERSION = "pref_upgrade_version"; 66 public static final String KEY_REQUEST_RETURN_HDR_PLUS = "pref_request_return_hdr_plus"; 67 public static final String KEY_SHOULD_SHOW_REFOCUS_VIEWER_CLING = 68 "pref_should_show_refocus_viewer_cling"; 69 public static final String KEY_EXPOSURE_COMPENSATION_ENABLED = 70 "pref_camera_exposure_compensation_key"; 71 public static final String KEY_USER_SELECTED_ASPECT_RATIO = "pref_user_selected_aspect_ratio"; 72 public static final String KEY_COUNTDOWN_DURATION = "pref_camera_countdown_duration_key"; 73 public static final String KEY_HDR_PLUS_FLASH_MODE = "pref_hdr_plus_flash_mode"; 74 public static final String KEY_SHOULD_SHOW_SETTINGS_BUTTON_CLING = 75 "pref_should_show_settings_button_cling"; 76 77 /** 78 * Set some number of defaults for the defined keys. 79 * It's not necessary to set all defaults. 80 */ setDefaults(SettingsManager settingsManager, Context context)81 public static void setDefaults(SettingsManager settingsManager, Context context) { 82 settingsManager.setDefaults(KEY_COUNTDOWN_DURATION, 0, 83 context.getResources().getIntArray(R.array.pref_countdown_duration)); 84 85 settingsManager.setDefaults(KEY_CAMERA_ID, 86 context.getString(R.string.pref_camera_id_default), 87 context.getResources().getStringArray(R.array.camera_id_entryvalues)); 88 89 settingsManager.setDefaults(KEY_SCENE_MODE, 90 context.getString(R.string.pref_camera_scenemode_default), 91 context.getResources().getStringArray(R.array.pref_camera_scenemode_entryvalues)); 92 93 settingsManager.setDefaults(KEY_FLASH_MODE, 94 context.getString(R.string.pref_camera_flashmode_default), 95 context.getResources().getStringArray(R.array.pref_camera_flashmode_entryvalues)); 96 97 settingsManager.setDefaults(KEY_CAMERA_HDR, false); 98 settingsManager.setDefaults(KEY_CAMERA_HDR_PLUS, false); 99 100 settingsManager.setDefaults(KEY_CAMERA_FIRST_USE_HINT_SHOWN, true); 101 102 settingsManager.setDefaults(KEY_FOCUS_MODE, 103 context.getString(R.string.pref_camera_focusmode_default), 104 context.getResources().getStringArray(R.array.pref_camera_focusmode_entryvalues)); 105 106 String videoQualityBackDefaultValue = context.getString(R.string.pref_video_quality_large); 107 // TODO: We tweaked the default setting based on model string which is not ideal. Detecting 108 // CamcorderProfile capability is a better way to get this job done. However, 109 // |CamcorderProfile.hasProfile| needs camera id info. We need a way to provide camera id to 110 // this method. b/17445274 111 // Don't set the default resolution to be large if the device supports 4k video. 112 if (ApiHelper.IS_NEXUS_6) { 113 videoQualityBackDefaultValue = context.getString(R.string.pref_video_quality_medium); 114 } 115 settingsManager.setDefaults( 116 KEY_VIDEO_QUALITY_BACK, 117 videoQualityBackDefaultValue, 118 context.getResources().getStringArray(R.array.pref_video_quality_entryvalues)); 119 if (!settingsManager.isSet(SettingsManager.SCOPE_GLOBAL, Keys.KEY_VIDEO_QUALITY_BACK)) { 120 settingsManager.setToDefault(SettingsManager.SCOPE_GLOBAL, 121 Keys.KEY_VIDEO_QUALITY_BACK); 122 } 123 124 settingsManager.setDefaults(KEY_VIDEO_QUALITY_FRONT, 125 context.getString(R.string.pref_video_quality_large), 126 context.getResources().getStringArray(R.array.pref_video_quality_entryvalues)); 127 if (!settingsManager.isSet(SettingsManager.SCOPE_GLOBAL, Keys.KEY_VIDEO_QUALITY_FRONT)) { 128 settingsManager.setToDefault(SettingsManager.SCOPE_GLOBAL, 129 Keys.KEY_VIDEO_QUALITY_FRONT); 130 } 131 132 settingsManager.setDefaults(KEY_JPEG_QUALITY, 133 context.getString(R.string.pref_camera_jpeg_quality_normal), 134 context.getResources().getStringArray( 135 R.array.pref_camera_jpeg_quality_entryvalues)); 136 137 settingsManager.setDefaults(KEY_VIDEOCAMERA_FLASH_MODE, 138 context.getString(R.string.pref_camera_video_flashmode_default), 139 context.getResources().getStringArray( 140 R.array.pref_camera_video_flashmode_entryvalues)); 141 142 settingsManager.setDefaults(KEY_VIDEO_EFFECT, 143 context.getString(R.string.pref_video_effect_default), 144 context.getResources().getStringArray(R.array.pref_video_effect_entryvalues)); 145 146 settingsManager.setDefaults(KEY_VIDEO_FIRST_USE_HINT_SHOWN, true); 147 148 settingsManager.setDefaults(KEY_STARTUP_MODULE_INDEX, 0, 149 context.getResources().getIntArray(R.array.camera_modes)); 150 151 settingsManager.setDefaults(KEY_CAMERA_MODULE_LAST_USED, 152 context.getResources().getInteger(R.integer.camera_mode_photo), 153 context.getResources().getIntArray(R.array.camera_modes)); 154 155 settingsManager.setDefaults(KEY_CAMERA_PANO_ORIENTATION, 156 context.getString(R.string.pano_orientation_horizontal), 157 context.getResources().getStringArray( 158 R.array.pref_camera_pano_orientation_entryvalues)); 159 160 settingsManager.setDefaults(KEY_CAMERA_GRID_LINES, false); 161 162 settingsManager.setDefaults(KEY_SHOULD_SHOW_REFOCUS_VIEWER_CLING, true); 163 164 settingsManager.setDefaults(KEY_HDR_PLUS_FLASH_MODE, 165 context.getString(R.string.pref_camera_hdr_plus_flashmode_default), 166 context.getResources().getStringArray( 167 R.array.pref_camera_hdr_plus_flashmode_entryvalues)); 168 169 settingsManager.setDefaults(KEY_SHOULD_SHOW_SETTINGS_BUTTON_CLING, true); 170 171 } 172 173 /** Helper functions for some defined keys. */ 174 175 /** 176 * Returns whether the camera has been set to back facing in settings. 177 */ isCameraBackFacing(SettingsManager settingsManager, String moduleScope)178 public static boolean isCameraBackFacing(SettingsManager settingsManager, 179 String moduleScope) { 180 return settingsManager.isDefault(moduleScope, KEY_CAMERA_ID); 181 } 182 183 /** 184 * Returns whether hdr plus mode is set on. 185 */ isHdrPlusOn(SettingsManager settingsManager)186 public static boolean isHdrPlusOn(SettingsManager settingsManager) { 187 return settingsManager.getBoolean(SettingsManager.SCOPE_GLOBAL, 188 KEY_CAMERA_HDR_PLUS); 189 } 190 191 /** 192 * Returns whether hdr mode is set on. 193 */ isHdrOn(SettingsManager settingsManager)194 public static boolean isHdrOn(SettingsManager settingsManager) { 195 return settingsManager.getBoolean(SettingsManager.SCOPE_GLOBAL, 196 KEY_CAMERA_HDR); 197 } 198 199 /** 200 * Returns whether the app should return to hdr plus mode if possible. 201 */ requestsReturnToHdrPlus(SettingsManager settingsManager, String moduleScope)202 public static boolean requestsReturnToHdrPlus(SettingsManager settingsManager, 203 String moduleScope) { 204 return settingsManager.getBoolean(moduleScope, KEY_REQUEST_RETURN_HDR_PLUS); 205 } 206 207 /** 208 * Returns whether grid lines are set on. 209 */ areGridLinesOn(SettingsManager settingsManager)210 public static boolean areGridLinesOn(SettingsManager settingsManager) { 211 return settingsManager.getBoolean(SettingsManager.SCOPE_GLOBAL, 212 KEY_CAMERA_GRID_LINES); 213 } 214 215 /** 216 * Returns whether pano orientation is horizontal. 217 */ isPanoOrientationHorizontal(SettingsManager settingsManager)218 public static boolean isPanoOrientationHorizontal(SettingsManager settingsManager) { 219 return settingsManager.isDefault(SettingsManager.SCOPE_GLOBAL, 220 KEY_CAMERA_PANO_ORIENTATION); 221 } 222 223 /** 224 * Sets the settings for whether location recording should be enabled or 225 * not. Also makes sure to pass on the change to the location manager. 226 */ setLocation(SettingsManager settingsManager, boolean on, LocationManager locationManager)227 public static void setLocation(SettingsManager settingsManager, boolean on, 228 LocationManager locationManager) { 229 settingsManager.set(SettingsManager.SCOPE_GLOBAL, KEY_RECORD_LOCATION, on); 230 locationManager.recordLocation(on); 231 } 232 233 /** 234 * Sets the user selected aspect ratio setting to selected. 235 */ setAspectRatioSelected(SettingsManager settingsManager)236 public static void setAspectRatioSelected(SettingsManager settingsManager) { 237 settingsManager.set(SettingsManager.SCOPE_GLOBAL, 238 KEY_USER_SELECTED_ASPECT_RATIO, true); 239 } 240 241 /** 242 * Sets the manual exposure compensation enabled setting 243 * to on/off based on the given argument. 244 */ setManualExposureCompensation(SettingsManager settingsManager, boolean on)245 public static void setManualExposureCompensation(SettingsManager settingsManager, 246 boolean on) { 247 settingsManager.set(SettingsManager.SCOPE_GLOBAL, 248 KEY_EXPOSURE_COMPENSATION_ENABLED, on); 249 } 250 251 /** 252 * Reads the current location recording settings and passes it on to the 253 * given location manager. 254 */ syncLocationManager(SettingsManager settingsManager, LocationManager locationManager)255 public static void syncLocationManager(SettingsManager settingsManager, 256 LocationManager locationManager) { 257 boolean value = settingsManager.getBoolean(SettingsManager.SCOPE_GLOBAL, 258 KEY_RECORD_LOCATION); 259 locationManager.recordLocation(value); 260 } 261 262 } 263 264