OSDN Git Service

Put conversion from string to size into SettingsManager.
authorSascha Haeberling <haeberling@google.com>
Wed, 30 Jul 2014 00:08:18 +0000 (17:08 -0700)
committerSascha Haeberling <haeberling@google.com>
Wed, 30 Jul 2014 00:26:56 +0000 (17:26 -0700)
This way we don't have to spread this logic throughout the codebase.

Change-Id: I2d534d0756a9030e6d67b479a67c86c1cf596589

src/com/android/camera/settings/SettingsManager.java

index 0774dc1..d394278 100644 (file)
@@ -19,16 +19,12 @@ package com.android.camera.settings;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
-import android.content.res.Resources;
-import android.hardware.Camera;
 import android.preference.PreferenceManager;
-import android.text.TextUtils;
+import android.util.Size;
 
 import com.android.camera.debug.Log;
 
-import java.util.Arrays;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 
 /**
@@ -80,7 +76,7 @@ public class SettingsManager {
     private final String mPackageName;
     private final SharedPreferences mDefaultPreferences;
     private SharedPreferences mCustomPreferences;
-    private DefaultsStore mDefaultsStore = new DefaultsStore();
+    private final DefaultsStore mDefaultsStore = new DefaultsStore();
 
     /**
      * A List of OnSettingChangedListener's, maintained to compare to new
@@ -372,6 +368,30 @@ public class SettingsManager {
     }
 
     /**
+     * Retrieve a setting's value as a {@link Size}. Returns <code>null</code>
+     * if value could not be parsed as a size.
+     */
+    public Size getSize(String scope, String key) {
+        String strValue = getString(scope, key);
+        if (strValue == null) {
+            return null;
+        }
+
+        String[] widthHeight = strValue.split("x");
+        if (widthHeight.length != 2) {
+            return null;
+        }
+
+        try {
+            int width = Integer.parseInt(widthHeight[0]);
+            int height = Integer.parseInt(widthHeight[1]);
+            return new Size(width, height);
+        } catch (NumberFormatException ex) {
+            return null;
+        }
+    }
+
+    /**
      * If possible values are stored for this key, return the
      * index into that list of the currently set value.
      *