From 391f3f8b5e8f97e002cbbc6a7535cfd73a8d16b3 Mon Sep 17 00:00:00 2001 From: Wu-cheng Li Date: Sun, 31 Jan 2010 14:19:38 +0800 Subject: [PATCH] Add float support for set and get in CameraParameters. bug:2375989 bug:2375987 --- include/ui/CameraParameters.h | 2 ++ libs/ui/CameraParameters.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/ui/CameraParameters.h b/include/ui/CameraParameters.h index b9c2bbe3b..2c29bfb0e 100644 --- a/include/ui/CameraParameters.h +++ b/include/ui/CameraParameters.h @@ -34,8 +34,10 @@ public: void set(const char *key, const char *value); void set(const char *key, int value); + void setFloat(const char *key, float value); const char *get(const char *key) const; int getInt(const char *key) const; + float getFloat(const char *key) const; /* preview-size=176x144 */ void setPreviewSize(int width, int height); diff --git a/libs/ui/CameraParameters.cpp b/libs/ui/CameraParameters.cpp index 495e16469..c4958a085 100644 --- a/libs/ui/CameraParameters.cpp +++ b/libs/ui/CameraParameters.cpp @@ -209,6 +209,13 @@ void CameraParameters::set(const char *key, int value) set(key, str); } +void CameraParameters::setFloat(const char *key, float value) +{ + char str[16]; // 14 should be enough. We overestimate to be safe. + snprintf(str, sizeof(str), "%g", value); + set(key, str); +} + const char *CameraParameters::get(const char *key) const { String8 v = mMap.valueFor(String8(key)); @@ -225,6 +232,13 @@ int CameraParameters::getInt(const char *key) const return strtol(v, 0, 0); } +float CameraParameters::getFloat(const char *key) const +{ + const char *v = get(key); + if (v == 0) return -1; + return strtof(v, 0); +} + static int parse_size(const char *str, int &width, int &height) { // Find the width.