diff options
author | Ruben Brunk <rubenbrunk@google.com> | 2013-10-09 17:44:54 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-10-09 17:44:54 -0700 |
commit | c89b91221152d84f6792c530cf75aebb066e58ed (patch) | |
tree | 7e361aed8d2f48f957fa0f7c90e72de853086a29 | |
parent | 3f552685349fc1b447dc09c54d66de397270da9a (diff) | |
parent | b5eb1ffab6db3f311def4f9b28a189a991396537 (diff) | |
download | android_packages_apps_Snap-c89b91221152d84f6792c530cf75aebb066e58ed.tar.gz android_packages_apps_Snap-c89b91221152d84f6792c530cf75aebb066e58ed.tar.bz2 android_packages_apps_Snap-c89b91221152d84f6792c530cf75aebb066e58ed.zip |
am b5eb1ffa: Merge "gcam: Fix preview FOV." into gb-ub-photos-carlsbad
* commit 'b5eb1ffab6db3f311def4f9b28a189a991396537':
gcam: Fix preview FOV.
-rw-r--r-- | src/com/android/camera/util/CameraUtil.java | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/src/com/android/camera/util/CameraUtil.java b/src/com/android/camera/util/CameraUtil.java index 7c1a415da..ea62d2ccc 100644 --- a/src/com/android/camera/util/CameraUtil.java +++ b/src/com/android/camera/util/CameraUtil.java @@ -447,11 +447,25 @@ public class CameraUtil { public static Size getOptimalPreviewSize(Activity currentActivity, List<Size> sizes, double targetRatio) { + + Point[] points = new Point[sizes.size()]; + + int index = 0; + for (Size s : sizes) { + points[index++] = new Point(s.width, s.height); + } + + int optimalPickIndex = getOptimalPreviewSize(currentActivity, points, targetRatio); + return (optimalPickIndex == -1) ? null : sizes.get(optimalPickIndex); + } + + public static int getOptimalPreviewSize(Activity currentActivity, + Point[] sizes, double targetRatio) { // Use a very small tolerance because we want an exact match. - final double ASPECT_TOLERANCE = 0.001; - if (sizes == null) return null; + final double ASPECT_TOLERANCE = 0.01; + if (sizes == null) return -1; - Size optimalSize = null; + int optimalSizeIndex = -1; double minDiff = Double.MAX_VALUE; // Because of bugs of overlay and layout, we sometimes will try to @@ -462,27 +476,29 @@ public class CameraUtil { Point point = getDefaultDisplaySize(currentActivity, new Point()); int targetHeight = Math.min(point.x, point.y); // Try to find an size match aspect ratio and size - for (Size size : sizes) { - double ratio = (double) size.width / size.height; + for (int i = 0; i < sizes.length; i++) { + Point size = sizes[i]; + double ratio = (double) size.x / size.y; if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue; - if (Math.abs(size.height - targetHeight) < minDiff) { - optimalSize = size; - minDiff = Math.abs(size.height - targetHeight); + if (Math.abs(size.y - targetHeight) < minDiff) { + optimalSizeIndex = i; + minDiff = Math.abs(size.y - targetHeight); } } // Cannot find the one match the aspect ratio. This should not happen. // Ignore the requirement. - if (optimalSize == null) { + if (optimalSizeIndex == -1) { Log.w(TAG, "No preview size match the aspect ratio"); minDiff = Double.MAX_VALUE; - for (Size size : sizes) { - if (Math.abs(size.height - targetHeight) < minDiff) { - optimalSize = size; - minDiff = Math.abs(size.height - targetHeight); + for (int i = 0; i < sizes.length; i++) { + Point size = sizes[i]; + if (Math.abs(size.y - targetHeight) < minDiff) { + optimalSizeIndex = i; + minDiff = Math.abs(size.y - targetHeight); } } } - return optimalSize; + return optimalSizeIndex; } // Returns the largest picture size which matches the given aspect ratio. |