OSDN Git Service

Remove white balance and non-HDR scene mode settings
[android-x86/packages-apps-Camera2.git] / src / com / android / camera / settings / SettingsManager.java
index a85fc9f..187bfd8 100644 (file)
@@ -20,12 +20,12 @@ import android.content.Context;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
 import android.preference.PreferenceManager;
-import android.util.Log;
 import android.util.SparseArray;
 
 import com.android.camera.ListPreference;
 import com.android.camera.app.AppController;
 import com.android.camera.app.LocationManager;
+import com.android.camera.debug.Log;
 import com.android.camera.util.CameraUtil;
 import com.android.camera.util.SettingsHelper;
 import com.android.camera2.R;
@@ -38,7 +38,7 @@ import java.util.List;
  * local SharedPreferences.
  */
 public class SettingsManager {
-    private static final String TAG = "SettingsManager";
+    private static final Log.Tag TAG = new Log.Tag("SettingsManager");
 
     private final Context mContext;
     private final SharedPreferences mDefaultSettings;
@@ -94,7 +94,7 @@ public class SettingsManager {
      * strictly on app upgrades, when the upgrade behavior differs from the general,
      * lazy upgrade strategies.
      */
-    private static final int STRICT_UPGRADE_VERSION = 1;
+    private static final int STRICT_UPGRADE_VERSION = 2;
 
     /**
      * A List of OnSettingChangedListener's, maintained to compare to new
@@ -350,11 +350,8 @@ public class SettingsManager {
     public static final int SETTING_FOCUS_MODE = 7;
     public static final int SETTING_FLASH_MODE = 8;
     public static final int SETTING_VIDEOCAMERA_FLASH_MODE = 9;
-    public static final int SETTING_WHITE_BALANCE = 10;
     public static final int SETTING_SCENE_MODE = 11;
     public static final int SETTING_EXPOSURE = 12;
-    public static final int SETTING_TIMER = 13;
-    public static final int SETTING_TIMER_SOUND_EFFECTS = 14;
     public static final int SETTING_VIDEO_EFFECT = 15;
     public static final int SETTING_CAMERA_ID = 16;
     public static final int SETTING_CAMERA_HDR = 17;
@@ -362,14 +359,12 @@ public class SettingsManager {
     public static final int SETTING_CAMERA_FIRST_USE_HINT_SHOWN = 19;
     public static final int SETTING_VIDEO_FIRST_USE_HINT_SHOWN = 20;
     public static final int SETTING_STARTUP_MODULE_INDEX = 21;
-    public static final int SETTING_SHIMMY_REMAINING_PLAY_TIMES_INDEX = 22;
     public static final int SETTING_KEY_CAMERA_MODULE_LAST_USED_INDEX = 23;
     public static final int SETTING_CAMERA_PANO_ORIENTATION = 24;
     public static final int SETTING_CAMERA_GRID_LINES = 25;
     public static final int SETTING_RELEASE_DIALOG_LAST_SHOWN_VERSION = 26;
     public static final int SETTING_FLASH_SUPPORTED_BACK_CAMERA = 27;
     public static final int SETTING_STRICT_UPGRADE_VERSION = 28;
-    public static final int SETTING_FILMSTRIP_PEEK_ANIM_REMAINING_PLAY_TIMES_INDEX = 29;
     // A boolean for requesting to return to HDR plus
     // as soon as possible, if a user requests a setting/mode option
     // that forces them to leave HDR plus.
@@ -387,11 +382,8 @@ public class SettingsManager {
     public static final String KEY_FOCUS_MODE = "pref_camera_focusmode_key";
     public static final String KEY_FLASH_MODE = "pref_camera_flashmode_key";
     public static final String KEY_VIDEOCAMERA_FLASH_MODE = "pref_camera_video_flashmode_key";
-    public static final String KEY_WHITE_BALANCE = "pref_camera_whitebalance_key";
     public static final String KEY_SCENE_MODE = "pref_camera_scenemode_key";
     public static final String KEY_EXPOSURE = "pref_camera_exposure_key";
-    public static final String KEY_TIMER = "pref_camera_timer_key";
-    public static final String KEY_TIMER_SOUND_EFFECTS = "pref_camera_timer_sound_key";
     public static final String KEY_VIDEO_EFFECT = "pref_video_effect_key";
     public static final String KEY_CAMERA_ID = "pref_camera_id_key";
     public static final String KEY_CAMERA_HDR = "pref_camera_hdr_key";
@@ -401,8 +393,6 @@ public class SettingsManager {
     public static final String KEY_VIDEO_FIRST_USE_HINT_SHOWN =
             "pref_video_first_use_hint_shown_key";
     public static final String KEY_STARTUP_MODULE_INDEX = "camera.startup_module";
-    public static final String KEY_SHIMMY_REMAINING_PLAY_TIMES =
-            "pref_shimmy_remaining_play_times";
     public static final String KEY_CAMERA_MODULE_LAST_USED =
             "pref_camera_module_last_used_index";
     public static final String KEY_CAMERA_PANO_ORIENTATION = "pref_camera_pano_orientation";
@@ -412,8 +402,6 @@ public class SettingsManager {
     public static final String KEY_FLASH_SUPPORTED_BACK_CAMERA =
             "pref_flash_supported_back_camera";
     public static final String KEY_STRICT_UPGRADE_VERSION = "pref_strict_upgrade_version";
-    public static final String KEY_FILMSTRIP_PEEK_ANIM_REMAINING_PLAY_TIMES =
-            "pref_filmstrip_peek_anim_remaining_play_times";
     public static final String KEY_REQUEST_RETURN_HDR_PLUS = "pref_request_return_hdr_plus";
 
     public static final int WHITE_BALANCE_DEFAULT_INDEX = 2;
@@ -433,7 +421,7 @@ public class SettingsManager {
         /**
          * A constructor used to store a setting's profile.
          */
-        Setting(String source, String type, String defaultValue, String key,
+        public Setting(String source, String type, String defaultValue, String key,
                 String[] values, boolean flushOnCameraChange) {
             mSource = source;
             mType = type;
@@ -497,7 +485,10 @@ public class SettingsManager {
      * Get the SharedPreferences needed to query/update the setting.
      */
     public SharedPreferences getSettingSource(Setting setting) {
-        String source = setting.getSource();
+        return getSettingSource(setting.getSource());
+    }
+
+    private SharedPreferences getSettingSource(String source) {
         if (source.equals(SOURCE_DEFAULT)) {
             return mDefaultSettings;
         }
@@ -570,9 +561,9 @@ public class SettingsManager {
     /**
      * Returns whether this Setting was last set as a String.
      */
-    private boolean isString(int id) {
+    private boolean isString(int id, String source) {
         Setting setting = mSettingsCache.get(id);
-        SharedPreferences preferences = getSettingSource(setting);
+        SharedPreferences preferences = getSettingSource(source);
         try {
             preferences.getString(setting.getKey(), null);
             return true;
@@ -584,9 +575,9 @@ public class SettingsManager {
     /**
      * Returns whether this Setting was last set as a boolean.
      */
-    private boolean isBoolean(int id) {
+    private boolean isBoolean(int id, String source) {
         Setting setting = mSettingsCache.get(id);
-        SharedPreferences preferences = getSettingSource(setting);
+        SharedPreferences preferences = getSettingSource(source);
         try {
             preferences.getBoolean(setting.getKey(), false);
             return true;
@@ -598,9 +589,9 @@ public class SettingsManager {
     /**
      * Returns whether this Setting was last set as an Integer.
      */
-    private boolean isInteger(int id) {
+    private boolean isInteger(int id, String source) {
         Setting setting = mSettingsCache.get(id);
-        SharedPreferences preferences = getSettingSource(setting);
+        SharedPreferences preferences = getSettingSource(source);
         try {
             preferences.getInt(setting.getKey(), 0);
             return true;
@@ -614,20 +605,20 @@ public class SettingsManager {
      * is known and the type conversion is successful, otherwise
      * reset to the default.
      */
-    private String recoverToString(int id) {
+    private String recoverToString(int id, String source) {
         String value;
         try {
-            if (isBoolean(id)) {
-                value = (getBoolean(id) ? VALUE_ON : VALUE_OFF);
-            } else if (isInteger(id)) {
-                value = Integer.toString(getInt(id));
+            if (isBoolean(id, source)) {
+                value = (getBoolean(id, source) ? VALUE_ON : VALUE_OFF);
+            } else if (isInteger(id, source)) {
+                value = Integer.toString(getInt(id, source));
             } else {
                 throw new Exception();
             }
         } catch (Exception e) {
             value = mSettingsCache.get(id).getDefault();
         }
-        set(id, value);
+        set(id, source, value);
         return value;
     }
 
@@ -636,20 +627,20 @@ public class SettingsManager {
      * is known and the type conversion is successful, otherwise
      * reset to the default.
      */
-    private boolean recoverToBoolean(int id) {
+    private boolean recoverToBoolean(int id, String source) {
         boolean value;
         try {
-            if (isString(id)) {
-                value = VALUE_ON.equals(get(id));
-            } else if (isInteger(id)) {
-                value = getInt(id) != 0;
+            if (isString(id, source)) {
+                value = VALUE_ON.equals(get(id, source));
+            } else if (isInteger(id, source)) {
+                value = getInt(id, source) != 0;
             } else {
                 throw new Exception();
             }
         } catch (Exception e) {
             value = VALUE_ON.equals(mSettingsCache.get(id).getDefault());
         }
-        setBoolean(id, value);
+        setBoolean(id, source, value);
         return value;
     }
 
@@ -658,13 +649,13 @@ public class SettingsManager {
      * is known and the type conversion is successful, otherwise
      * reset to the default.
      */
-    private int recoverToInteger(int id) {
+    private int recoverToInteger(int id, String source) {
         int value;
         try {
-            if (isString(id)) {
-                value = Integer.parseInt(get(id));
-            } else if (isBoolean(id)) {
-                value = getBoolean(id) ? 1 : 0;
+            if (isString(id, source)) {
+                value = Integer.parseInt(get(id, source));
+            } else if (isBoolean(id, source)) {
+                value = getBoolean(id, source) ? 1 : 0;
             } else {
                 throw new Exception();
             }
@@ -693,18 +684,18 @@ public class SettingsManager {
     /**
      * Get a Setting's String value based on Setting id.
      */
-    // TODO: rename to something more descriptive.
+    // TODO: rename to something more descriptive like getString.
     public String get(int id) {
         Setting setting = mSettingsCache.get(id);
-        if (!TYPE_STRING.equals(setting.getType())) {
-            // Incorrect use of the api, the defaults will
-            // probably be defined as the wrong type, no recovery.
-            throw new IllegalArgumentException(
-                "Trying to get String when Setting id=" + id
-                + " is defined as a " + setting.getType());
-        }
+        return get(id, setting.getSource());
+    }
 
-        SharedPreferences preferences = getSettingSource(setting);
+    /**
+     * Get a Setting's String value based on Setting id and a source file id.
+     */
+    public String get(int id, String source) {
+        Setting setting = mSettingsCache.get(id);
+        SharedPreferences preferences = getSettingSource(source);
         if (preferences != null) {
             try {
                 String value = preferences.getString(setting.getKey(), setting.getDefault());
@@ -713,11 +704,11 @@ public class SettingsManager {
                 // If the api defines this Setting as a String, but the
                 // last set saved it as a different type, try to recover
                 // the value, but if impossible reset to default.
-                return recoverToString(id);
+                return recoverToString(id, source);
             }
         } else {
             throw new IllegalStateException(
-                "Setting source=" + setting.getSource() + " is unitialized.");
+                "Setting source=" + source + " is unitialized.");
         }
     }
 
@@ -726,15 +717,15 @@ public class SettingsManager {
      */
     public boolean getBoolean(int id) {
         Setting setting = mSettingsCache.get(id);
-        if (!TYPE_BOOLEAN.equals(setting.getType())) {
-            // Incorrect use of the api, the defaults will
-            // probably be defined as the wrong type, no recovery.
-            throw new IllegalArgumentException(
-                "Trying to get boolean when Setting id=" + id
-                + " is defined as a " + setting.getType());
-        }
+        return getBoolean(id, setting.getSource());
+    }
 
-        SharedPreferences preferences = getSettingSource(setting);
+    /**
+     * Get a Setting's boolean value based on a Setting id and a source file id.
+     */
+    public boolean getBoolean(int id, String source) {
+        Setting setting = mSettingsCache.get(id);
+        SharedPreferences preferences = getSettingSource(source);
         boolean defaultValue = VALUE_ON.equals(setting.getDefault());
         if (preferences != null) {
             try {
@@ -743,11 +734,11 @@ public class SettingsManager {
                 // If the api defines this Setting as a boolean, but the
                 // last set saved it as a different type, try to recover
                 // the value, but if impossible reset to default.
-                return recoverToBoolean(id);
+                return recoverToBoolean(id, source);
             }
         } else {
             throw new IllegalStateException(
-                "Setting source=" + setting.getSource() + " is unitialized.");
+                "Setting source=" + source + " is unitialized.");
         }
     }
 
@@ -756,15 +747,15 @@ public class SettingsManager {
      */
     public int getInt(int id) {
         Setting setting = mSettingsCache.get(id);
-        if (!TYPE_INTEGER.equals(setting.getType())) {
-            // Incorrect use of the api, the defaults will
-            // probably be defined as the wrong type, no recovery.
-            throw new IllegalArgumentException(
-                "Trying to get Integer when Setting id=" + id
-                + " is defined as a " + setting.getType());
-        }
+        return getInt(id, setting.getSource());
+    }
 
-        SharedPreferences preferences = getSettingSource(setting);
+    /**
+     * Get a Setting's int value based on Setting id and a source file id.
+     */
+    public int getInt(int id, String source) {
+        Setting setting = mSettingsCache.get(id);
+        SharedPreferences preferences = getSettingSource(source);
         int defaultValue = Integer.parseInt(setting.getDefault());
         if (preferences != null) {
             try {
@@ -773,11 +764,11 @@ public class SettingsManager {
                 // If the api defines this Setting as an Integer, but the
                 // last set saved it as a different type, try to recover
                 // the value, but if impossible reset to default.
-                return recoverToInteger(id);
+                return recoverToInteger(id, source);
             }
         } else {
             throw new IllegalStateException(
-                "Setting source=" + setting.getSource() + " is unitialized.");
+                "Setting source=" + source + " is unitialized.");
         }
     }
 
@@ -787,13 +778,21 @@ public class SettingsManager {
     // TODO: rename to something more descriptive.
     public void set(int id, String value) {
         Setting setting = mSettingsCache.get(id);
+        set(id, setting.getSource(), value);
+    }
+
+    /**
+     * Set a Setting with a String value based on Setting id and a source file id.
+     */
+    public void set(int id, String source, String value) {
+        Setting setting = mSettingsCache.get(id);
         value = sanitize(setting, value);
-        SharedPreferences preferences = getSettingSource(setting);
+        SharedPreferences preferences = getSettingSource(source);
         if (preferences != null) {
             preferences.edit().putString(setting.getKey(), value).apply();
         } else {
             throw new IllegalStateException(
-                "Setting source=" + setting.getSource() + " is unitialized.");
+                "Setting source=" + source + " is unitialized.");
         }
     }
 
@@ -802,12 +801,19 @@ public class SettingsManager {
      */
     public void setBoolean(int id, boolean value) {
         Setting setting = mSettingsCache.get(id);
-        SharedPreferences preferences = getSettingSource(setting);
+        setBoolean(id, setting.getSource(), value);
+    }
+    /**
+     * Set a Setting with a boolean value based on Setting id and a source file id.
+     */
+    public void setBoolean(int id, String source, boolean value) {
+        Setting setting = mSettingsCache.get(id);
+        SharedPreferences preferences = getSettingSource(source);
         if (preferences != null) {
             preferences.edit().putBoolean(setting.getKey(), value).apply();
         } else {
             throw new IllegalStateException(
-                "Setting source=" + setting.getSource() + " is unitialized.");
+                "Setting source=" + source + " is unitialized.");
         }
     }
 
@@ -816,12 +822,20 @@ public class SettingsManager {
      */
     public void setInt(int id, int value) {
         Setting setting = mSettingsCache.get(id);
-        SharedPreferences preferences = getSettingSource(setting);
+        setInt(id, setting.getSource(), value);
+    }
+
+    /**
+     * Set a Setting with an int value based on Setting id and a source file id.
+     */
+    public void setInt(int id, String source, int value) {
+        Setting setting = mSettingsCache.get(id);
+        SharedPreferences preferences = getSettingSource(source);
         if (preferences != null) {
             preferences.edit().putInt(setting.getKey(), value).apply();
         } else {
             throw new IllegalStateException(
-                "Setting source=" + setting.getSource() + " is unitialized.");
+                "Setting source=" + source + " is unitialized.");
         }
     }
 
@@ -830,7 +844,15 @@ public class SettingsManager {
      */
     public boolean isSet(int id) {
         Setting setting = mSettingsCache.get(id);
-        SharedPreferences preferences = getSettingSource(setting);
+        return isSet(id, setting.getSource());
+    }
+
+    /**
+     * Check if a Setting has ever been set based on Setting id and a source file id.
+     */
+    public boolean isSet(int id, String source) {
+        Setting setting = mSettingsCache.get(id);
+        SharedPreferences preferences = getSettingSource(source);
         if (preferences != null) {
             return preferences.contains(setting.getKey());
         } else {
@@ -929,14 +951,6 @@ public class SettingsManager {
                 values, FLUSH_ON);
     }
 
-    public static Setting getWhiteBalanceSetting(Context context) {
-        String defaultValue = context.getString(R.string.pref_camera_whitebalance_default);
-        String[] values = context.getResources().getStringArray(
-                R.array.pref_camera_whitebalance_entryvalues);
-        return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_WHITE_BALANCE,
-                values, FLUSH_OFF);
-    }
-
     public static Setting getHdrSetting(Context context) {
         String defaultValue = context.getString(R.string.pref_camera_hdr_default);
         String[] values = context.getResources().getStringArray(
@@ -995,21 +1009,6 @@ public class SettingsManager {
                 values, FLUSH_OFF);
     }
 
-    public static Setting getTimerSetting(Context context) {
-        String defaultValue = context.getString(R.string.pref_camera_timer_default);
-        String[] values = null; // TODO: get the values dynamically.
-        return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_TIMER,
-                values, FLUSH_OFF);
-    }
-
-    public static Setting getTimerSoundSetting(Context context) {
-        String defaultValue = context.getString(R.string.pref_camera_timer_sound_default);
-        String[] values = context.getResources().getStringArray(
-                R.array.pref_camera_timer_sound_entryvalues);
-        return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_TIMER_SOUND_EFFECTS,
-                values, FLUSH_OFF);
-    }
-
     public static Setting getVideoQualityBackSetting(Context context) {
         String defaultValue = context.getString(R.string.pref_video_quality_default);
         String[] values = context.getResources().getStringArray(
@@ -1074,12 +1073,6 @@ public class SettingsManager {
                 KEY_STARTUP_MODULE_INDEX, values, FLUSH_OFF);
     }
 
-    public static Setting getShimmyRemainingTimesSetting(Context context) {
-        String defaultValue = context.getString(R.string.pref_shimmy_play_times);
-        return new Setting(SOURCE_DEFAULT, TYPE_INTEGER, defaultValue,
-                KEY_SHIMMY_REMAINING_PLAY_TIMES, null, FLUSH_OFF);
-    }
-
     public static Setting getLastUsedCameraModule(Context context) {
         String defaultValue = Integer.toString(context.getResources()
                 .getInteger(R.integer.camera_mode_photo));
@@ -1120,12 +1113,6 @@ public class SettingsManager {
                 KEY_STRICT_UPGRADE_VERSION, null, FLUSH_OFF);
     }
 
-    public static Setting getPeekAnimRemainingTimesSetting(Context context) {
-        String defaultValue = context.getString(R.string.pref_filmstrip_peek_anim_play_times);
-        return new Setting(SOURCE_DEFAULT, TYPE_INTEGER, defaultValue,
-                KEY_FILMSTRIP_PEEK_ANIM_REMAINING_PLAY_TIMES, null, FLUSH_OFF);
-    }
-
     public static Setting getRequestReturnHdrPlusSetting(Context context) {
         String defaultValue = context.getString(R.string.setting_none_value);
         return new Setting(SOURCE_MODULE, TYPE_BOOLEAN, VALUE_OFF,
@@ -1147,6 +1134,14 @@ public class SettingsManager {
      * Returns whether hdr plus mode is set on.
      */
     public boolean isHdrPlusOn() {
+        String hdrOn = get(SettingsManager.SETTING_CAMERA_HDR_PLUS);
+        return hdrOn.equals(SettingsManager.VALUE_ON);
+    }
+
+    /**
+     * Returns whether hdr mode is set on.
+     */
+    public boolean isHdrOn() {
         String hdrOn = get(SettingsManager.SETTING_CAMERA_HDR);
         return hdrOn.equals(SettingsManager.VALUE_ON);
     }