Update prebuilts for mnc-docs

developers/build: fb039d88ed8e9183cae9ce510bf9c907d23ecc50
developers/samples/android: 7c3c09dcf092593adb8c13f8e15260f4da0a799a

Note: This was previously committed on May 18 2016, but wasn't
automerged. Replaying commit to bring browseable back into sync
downstream.

(cherry picked from commit 8e7e496ae9)
Bug: 29127946
Change-Id: I6275f830532c3c6ce006756aecc3c2ae7e06873d
This commit is contained in:
Trevor Johns
2016-05-18 00:47:32 -07:00
parent 1842261dea
commit 7e9f0673a1
72 changed files with 2033 additions and 680 deletions

View File

@@ -36,49 +36,57 @@ public class CameraHelper {
public static final int MEDIA_TYPE_VIDEO = 2;
/**
* Iterate over supported camera preview sizes to see which one best fits the
* Iterate over supported camera video sizes to see which one best fits the
* dimensions of the given view while maintaining the aspect ratio. If none can,
* be lenient with the aspect ratio.
*
* @param sizes Supported camera preview sizes.
* @param w The width of the view.
* @param h The height of the view.
* @return Best match camera preview size to fit in the view.
* @param supportedVideoSizes Supported camera video sizes.
* @param previewSizes Supported camera preview sizes.
* @param w The width of the view.
* @param h The height of the view.
* @return Best match camera video size to fit in the view.
*/
public static Camera.Size getOptimalPreviewSize(List<Camera.Size> sizes, int w, int h) {
public static Camera.Size getOptimalVideoSize(List<Camera.Size> supportedVideoSizes,
List<Camera.Size> previewSizes, int w, int h) {
// Use a very small tolerance because we want an exact match.
final double ASPECT_TOLERANCE = 0.1;
double targetRatio = (double) w / h;
if (sizes == null)
return null;
// Supported video sizes list might be null, it means that we are allowed to use the preview
// sizes
List<Camera.Size> videoSizes;
if (supportedVideoSizes != null) {
videoSizes = supportedVideoSizes;
} else {
videoSizes = previewSizes;
}
Camera.Size optimalSize = null;
// Start with max value and refine as we iterate over available preview sizes. This is the
// Start with max value and refine as we iterate over available video sizes. This is the
// minimum difference between view and camera height.
double minDiff = Double.MAX_VALUE;
// Target view height
int targetHeight = h;
// Try to find a preview size that matches aspect ratio and the target view size.
// Try to find a video size that matches aspect ratio and the target view size.
// Iterate over all available sizes and pick the largest size that can fit in the view and
// still maintain the aspect ratio.
for (Camera.Size size : sizes) {
for (Camera.Size size : videoSizes) {
double ratio = (double) size.width / size.height;
if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)
continue;
if (Math.abs(size.height - targetHeight) < minDiff) {
if (Math.abs(size.height - targetHeight) < minDiff && previewSizes.contains(size)) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
// Cannot find preview size that matches the aspect ratio, ignore the requirement
// Cannot find video size that matches the aspect ratio, ignore the requirement
if (optimalSize == null) {
minDiff = Double.MAX_VALUE;
for (Camera.Size size : sizes) {
if (Math.abs(size.height - targetHeight) < minDiff) {
for (Camera.Size size : videoSizes) {
if (Math.abs(size.height - targetHeight) < minDiff && previewSizes.contains(size)) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}