diff --git a/api/current.xml b/api/current.xml
index 81049508b61bc..e17e31d69a0c1 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -75570,6 +75570,19 @@
visibility="public"
>
+
+
+
+
+
+
+
+
+
+
optimal focus distance > near focus distance. If
+ * the far focus distance is infinity, the value will be
+ * Float.POSITIVE_INFINITY.
+ *
+ * @param output focus distances in meters. output must be a float
+ * array with three elements. Near focus distance, optimal focus
+ * distance, and far focus distance will be filled in the array.
+ * @see #NEAR_FOCUS_DISTANCE_INDEX
+ * @see #OPTIMAL_FOCUS_DISTANCE_INDEX
+ * @see #FAR_FOCUS_DISTANCE_INDEX
+ */
+ public void getFocusDistances(float[] output) {
+ if (output == null || output.length != 3) {
+ throw new IllegalArgumentException(
+ "output must be an float array with three elements.");
+ }
+ List distances = splitFloat(get(KEY_FOCUS_DISTANCES));
+ output[0] = distances.get(0);
+ output[1] = distances.get(1);
+ output[2] = distances.get(2);
+ }
+
// Splits a comma delimited string to an ArrayList of String.
// Return null if the passing string is null or the size is 0.
private ArrayList split(String str) {
@@ -1843,6 +1901,21 @@ public class Camera {
return substrings;
}
+ // Splits a comma delimited string to an ArrayList of Float.
+ // Return null if the passing string is null or the size is 0.
+ private ArrayList splitFloat(String str) {
+ if (str == null) return null;
+
+ StringTokenizer tokenizer = new StringTokenizer(str, ",");
+ ArrayList substrings = new ArrayList();
+ while (tokenizer.hasMoreElements()) {
+ String token = tokenizer.nextToken();
+ substrings.add(Float.parseFloat(token));
+ }
+ if (substrings.size() == 0) return null;
+ return substrings;
+ }
+
// Returns the value of a float parameter.
private float getFloat(String key, float defaultValue) {
try {
diff --git a/include/camera/CameraParameters.h b/include/camera/CameraParameters.h
index 979df9f166400..19b052ba81919 100644
--- a/include/camera/CameraParameters.h
+++ b/include/camera/CameraParameters.h
@@ -221,9 +221,30 @@ public:
// Example value: "true". Read only.
static const char KEY_SMOOTH_ZOOM_SUPPORTED[];
+ // The distances (in meters) from the camera to where an object appears to
+ // be in focus. The object is sharpest at the optimal focus distance. The
+ // depth of field is the far focus distance minus near focus distance.
+ //
+ // Applications can read this parameter anytime to get the latest focus
+ // distances. If the focus mode is FOCUS_MODE_EDOF, the values may be all
+ // 0, which means focus distance is not applicable. If the focus mode is
+ // FOCUS_MODE_CONTINUOUS and autofocus has started, focus distances may
+ // change from time to time.
+ //
+ // Far focus distance > optimal focus distance > near focus distance. If
+ // the far focus distance is infinity, the value should be "Infinity" (case
+ // sensitive). The format is three float values separated by commas. The
+ // first is near focus distance. The second is optimal focus distance. The
+ // third is far focus distance.
+ // Example value: "0.95,1.9,Infinity" or "0.049,0.05,0.051". Read only.
+ static const char KEY_FOCUS_DISTANCES[];
+
// Value for KEY_ZOOM_SUPPORTED or KEY_SMOOTH_ZOOM_SUPPORTED.
static const char TRUE[];
+ // Value for KEY_FOCUS_DISTANCES.
+ static const char INFINITY[];
+
// Values for white balance settings.
static const char WHITE_BALANCE_AUTO[];
static const char WHITE_BALANCE_INCANDESCENT[];
diff --git a/libs/camera/CameraParameters.cpp b/libs/camera/CameraParameters.cpp
index cfb7ba1e79f71..035fa9fa67b58 100644
--- a/libs/camera/CameraParameters.cpp
+++ b/libs/camera/CameraParameters.cpp
@@ -69,8 +69,10 @@ const char CameraParameters::KEY_MAX_ZOOM[] = "max-zoom";
const char CameraParameters::KEY_ZOOM_RATIOS[] = "zoom-ratios";
const char CameraParameters::KEY_ZOOM_SUPPORTED[] = "zoom-supported";
const char CameraParameters::KEY_SMOOTH_ZOOM_SUPPORTED[] = "smooth-zoom-supported";
+const char CameraParameters::KEY_FOCUS_DISTANCES[] = "focus-distances";
const char CameraParameters::TRUE[] = "true";
+const char CameraParameters::INFINITY[] = "Infinity";
// Values for white balance settings.
const char CameraParameters::WHITE_BALANCE_AUTO[] = "auto";