diff options
author | Eric Erfanian <erfanian@google.com> | 2017-06-19 11:26:01 -0700 |
---|---|---|
committer | Eric Erfanian <erfanian@google.com> | 2017-06-19 11:30:45 -0700 |
commit | 2f1c7586bcce334ca69022eb8dc6d8965ceb6a05 (patch) | |
tree | bf00ada449ee3de31ec983a14e84159200aa18c2 /java/com/android/dialer/callcomposer/camera | |
parent | 3d0ca68e466482971a4cf46576c50cb2bd42bcb5 (diff) |
Update AOSP Dialer source from internal google3 repository at
cl/159428781.
Test: make, treehugger
This CL updates the AOSP Dialer source with all the changes that have
gone into the private google3 repository. This includes all the
changes from cl/152373142 (4/06/2017) to cl/159428781 (6/19/2017).
This goal of these drops is to keep the AOSP source in sync with the
internal google3 repository. Currently these sync are done by hand
with very minor modifications to the internal source code.
See the Android.mk file for list of modifications.
Our current goal is to do frequent drops (daily if possible) and
eventually switched to an automated process.
Change-Id: Ie60a84b3936efd0ea3d95d7c86bf96d2b1663030
Diffstat (limited to 'java/com/android/dialer/callcomposer/camera')
3 files changed, 87 insertions, 75 deletions
diff --git a/java/com/android/dialer/callcomposer/camera/CameraManager.java b/java/com/android/dialer/callcomposer/camera/CameraManager.java index 4cc08ba32..5915ce331 100644 --- a/java/com/android/dialer/callcomposer/camera/CameraManager.java +++ b/java/com/android/dialer/callcomposer/camera/CameraManager.java @@ -509,62 +509,61 @@ public class CameraManager implements FocusOverlayManager.Listener { }.execute(); } - /** Updates the orientation of the camera to match the orientation of the device */ - private void updateCameraOrientation() { - if (mCamera == null || mCameraPreview == null || mTakingPicture) { - return; + /** + * Updates the orientation of the {@link Camera} w.r.t. the orientation of the device and the + * orientation that the physical camera is mounted on the device. + * + * @param camera that needs to be reorientated + * @param screenRotation rotation of the physical device + * @param cameraOrientation {@link CameraInfo#orientation} + * @param cameraIsFrontFacing {@link CameraInfo#CAMERA_FACING_FRONT} + * @return rotation that images returned from {@link + * android.hardware.Camera.PictureCallback#onPictureTaken(byte[], Camera)} will be rotated. + */ + @VisibleForTesting + static int updateCameraRotation( + @NonNull Camera camera, + int screenRotation, + int cameraOrientation, + boolean cameraIsFrontFacing) { + Assert.isNotNull(camera); + Assert.checkArgument(cameraOrientation % 90 == 0); + + int rotation = screenRotationToDegress(screenRotation); + boolean portrait = rotation == 0 || rotation == 180; + + if (!portrait && !cameraIsFrontFacing) { + rotation += 180; } + rotation += cameraOrientation; + rotation %= 360; - final WindowManager windowManager = - (WindowManager) mCameraPreview.getContext().getSystemService(Context.WINDOW_SERVICE); + // Rotate the camera + if (portrait && cameraIsFrontFacing) { + camera.setDisplayOrientation((rotation + 180) % 360); + } else { + camera.setDisplayOrientation(rotation); + } + + // Rotate the images returned when a picture is taken + Camera.Parameters params = camera.getParameters(); + params.setRotation(rotation); + camera.setParameters(params); + return rotation; + } - int degrees; - switch (windowManager.getDefaultDisplay().getRotation()) { + private static int screenRotationToDegress(int screenRotation) { + switch (screenRotation) { case Surface.ROTATION_0: - degrees = 0; - break; + return 0; case Surface.ROTATION_90: - degrees = 90; - break; + return 90; case Surface.ROTATION_180: - degrees = 180; - break; + return 180; case Surface.ROTATION_270: - degrees = 270; - break; + return 270; default: - throw Assert.createAssertionFailException(""); - } - - // The display orientation of the camera (this controls the preview image). - int orientation; - - // The clockwise rotation angle relative to the orientation of the camera. This affects - // pictures returned by the camera in Camera.PictureCallback. - int rotation; - if (mCameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { - orientation = (mCameraInfo.orientation + degrees) % 360; - rotation = orientation; - // compensate the mirror but only for orientation - orientation = (360 - orientation) % 360; - } else { // back-facing - orientation = (mCameraInfo.orientation - degrees + 360) % 360; - rotation = orientation; - } - mRotation = rotation; - try { - mCamera.setDisplayOrientation(orientation); - final Camera.Parameters params = mCamera.getParameters(); - params.setRotation(rotation); - mCamera.setParameters(params); - } catch (final RuntimeException e) { - LogUtil.e( - "CameraManager.updateCameraOrientation", - "RuntimeException in CameraManager.updateCameraOrientation", - e); - if (mListener != null) { - mListener.onCameraError(ERROR_OPENING_CAMERA, e); - } + throw Assert.createIllegalStateFailException("Invalid surface rotation."); } } @@ -589,13 +588,19 @@ public class CameraManager implements FocusOverlayManager.Listener { mOrientationHandler.disable(); mOrientationHandler = null; } - // releaseMediaRecorder(true /* cleanupFile */); mFocusOverlayManager.onPreviewStopped(); return; } try { mCamera.stopPreview(); - updateCameraOrientation(); + if (!mTakingPicture) { + mRotation = + updateCameraRotation( + mCamera, + getScreenRotation(), + mCameraInfo.orientation, + mCameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT); + } final Camera.Parameters params = mCamera.getParameters(); final Camera.Size pictureSize = chooseBestPictureSize(); @@ -644,6 +649,14 @@ public class CameraManager implements FocusOverlayManager.Listener { } } + private int getScreenRotation() { + return mCameraPreview + .getContext() + .getSystemService(WindowManager.class) + .getDefaultDisplay() + .getRotation(); + } + public boolean isCameraAvailable() { return mCamera != null && !mTakingPicture && mIsHardwareAccelerationSupported; } @@ -681,7 +694,14 @@ public class CameraManager implements FocusOverlayManager.Listener { @Override public void onOrientationChanged(final int orientation) { - updateCameraOrientation(); + if (!mTakingPicture) { + mRotation = + updateCameraRotation( + mCamera, + getScreenRotation(), + mCameraInfo.orientation, + mCameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT); + } } } diff --git a/java/com/android/dialer/callcomposer/camera/ImagePersistTask.java b/java/com/android/dialer/callcomposer/camera/ImagePersistTask.java index 31751e536..7cb6921e9 100644 --- a/java/com/android/dialer/callcomposer/camera/ImagePersistTask.java +++ b/java/com/android/dialer/callcomposer/camera/ImagePersistTask.java @@ -20,13 +20,11 @@ import android.annotation.TargetApi; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; -import android.graphics.Canvas; import android.graphics.Matrix; import android.net.Uri; import android.os.Build.VERSION_CODES; import android.support.v4.content.FileProvider; import com.android.dialer.callcomposer.camera.exif.ExifInterface; -import com.android.dialer.callcomposer.camera.exif.ExifTag; import com.android.dialer.callcomposer.util.BitmapResizer; import com.android.dialer.common.Assert; import com.android.dialer.common.concurrent.FallibleAsyncTask; @@ -71,13 +69,7 @@ public class ImagePersistTask extends FallibleAsyncTask<Void, Void, Uri> { File outputFile = DialerUtils.createShareableFile(mContext); try (OutputStream outputStream = new FileOutputStream(outputFile)) { - if (mHeightPercent != 1.0f) { - writeClippedBitmap(outputStream); - } else { - Bitmap bitmap = BitmapFactory.decodeByteArray(mBytes, 0, mBytes.length); - bitmap = BitmapResizer.resizeForEnrichedCalling(bitmap); - bitmap.compress(Bitmap.CompressFormat.JPEG, 90, outputStream); - } + writeClippedBitmap(outputStream); } return FileProvider.getUriForFile( @@ -105,10 +97,12 @@ public class ImagePersistTask extends FallibleAsyncTask<Void, Void, Uri> { } catch (final IOException e) { // Couldn't get exif tags, not the end of the world } + + ExifInterface.OrientationParams params = ExifInterface.getOrientationParams(orientation); Bitmap bitmap = BitmapFactory.decodeByteArray(mBytes, 0, mBytes.length); final int clippedWidth; final int clippedHeight; - if (ExifInterface.getOrientationParams(orientation).invertDimensions) { + if (params.invertDimensions) { Assert.checkState(mWidth == bitmap.getHeight()); Assert.checkState(mHeight == bitmap.getWidth()); clippedWidth = (int) (mHeight * mHeightPercent); @@ -119,24 +113,22 @@ public class ImagePersistTask extends FallibleAsyncTask<Void, Void, Uri> { clippedWidth = mWidth; clippedHeight = (int) (mHeight * mHeightPercent); } - final int offsetTop = (bitmap.getHeight() - clippedHeight) / 2; - final int offsetLeft = (bitmap.getWidth() - clippedWidth) / 2; + + int offsetTop = (bitmap.getHeight() - clippedHeight) / 2; + int offsetLeft = (bitmap.getWidth() - clippedWidth) / 2; mWidth = clippedWidth; mHeight = clippedHeight; + + Matrix matrix = new Matrix(); + matrix.postRotate(params.rotation); + Bitmap clippedBitmap = - Bitmap.createBitmap(clippedWidth, clippedHeight, Bitmap.Config.ARGB_8888); - clippedBitmap.setDensity(bitmap.getDensity()); - final Canvas clippedBitmapCanvas = new Canvas(clippedBitmap); - final Matrix matrix = new Matrix(); - matrix.postTranslate(-offsetLeft, -offsetTop); - clippedBitmapCanvas.drawBitmap(bitmap, matrix, null /* paint */); - clippedBitmapCanvas.save(); + Bitmap.createBitmap( + bitmap, offsetLeft, offsetTop, clippedWidth, clippedHeight, matrix, true); clippedBitmap = BitmapResizer.resizeForEnrichedCalling(clippedBitmap); - // EXIF data can take a big chunk of the file size and is often cleared by the - // carrier, only store orientation since that's critical - final ExifTag orientationTag = exifInterface.getTag(ExifInterface.TAG_ORIENTATION); + // EXIF data can take a big chunk of the file size and we've already manually rotated our image, + // so remove all of the exif data. exifInterface.clearExif(); - exifInterface.setTag(orientationTag); exifInterface.writeExif(clippedBitmap, outputStream); clippedBitmap.recycle(); diff --git a/java/com/android/dialer/callcomposer/camera/exif/ExifInterface.java b/java/com/android/dialer/callcomposer/camera/exif/ExifInterface.java index 92dee1c94..1bf9519ad 100644 --- a/java/com/android/dialer/callcomposer/camera/exif/ExifInterface.java +++ b/java/com/android/dialer/callcomposer/camera/exif/ExifInterface.java @@ -286,7 +286,7 @@ public class ExifInterface { /** Wrapper class to define some orientation parameters. */ public static class OrientationParams { - int rotation = 0; + public int rotation = 0; int scaleX = 1; int scaleY = 1; public boolean invertDimensions = false; |