From cded3beaf28a703e1ef8f71bbc6836e6806c3736 Mon Sep 17 00:00:00 2001 From: Tobias Thierer Date: Fri, 9 Jun 2017 14:16:05 +0000 Subject: Revert "Update AOSP Dialer source from internal google3 repository at cl/158012278. am: 91ce7d2a47" This reverts commit c67d658e7daa453fe9ad9fd1a37f81eaf2048c44. Reason for revert: This CL broke the sailfish-userdebug_javac-all target on master. Change-Id: I9b54333a654c00154ca84f4ece84bea4f07cc19b --- .../dialer/callcomposer/camera/CameraManager.java | 19 ++++++++--- .../callcomposer/camera/ImagePersistTask.java | 38 +++++++++++++--------- 2 files changed, 37 insertions(+), 20 deletions(-) (limited to 'java/com/android/dialer/callcomposer/camera') diff --git a/java/com/android/dialer/callcomposer/camera/CameraManager.java b/java/com/android/dialer/callcomposer/camera/CameraManager.java index 977f063df..4cc08ba32 100644 --- a/java/com/android/dialer/callcomposer/camera/CameraManager.java +++ b/java/com/android/dialer/callcomposer/camera/CameraManager.java @@ -522,7 +522,6 @@ public class CameraManager implements FocusOverlayManager.Listener { switch (windowManager.getDefaultDisplay().getRotation()) { case Surface.ROTATION_0: degrees = 0; - mCamera.setDisplayOrientation(90); break; case Surface.ROTATION_90: degrees = 90; @@ -532,22 +531,31 @@ public class CameraManager implements FocusOverlayManager.Listener { break; case Surface.ROTATION_270: degrees = 270; - mCamera.setDisplayOrientation(180); break; 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) { - mRotation = (mCameraInfo.orientation + degrees) % 360; + orientation = (mCameraInfo.orientation + degrees) % 360; + rotation = orientation; + // compensate the mirror but only for orientation + orientation = (360 - orientation) % 360; } else { // back-facing - mRotation = (mCameraInfo.orientation - degrees + 360) % 360; + orientation = (mCameraInfo.orientation - degrees + 360) % 360; + rotation = orientation; } + mRotation = rotation; try { + mCamera.setDisplayOrientation(orientation); final Camera.Parameters params = mCamera.getParameters(); - params.setRotation(mRotation); + params.setRotation(rotation); mCamera.setParameters(params); } catch (final RuntimeException e) { LogUtil.e( @@ -581,6 +589,7 @@ public class CameraManager implements FocusOverlayManager.Listener { mOrientationHandler.disable(); mOrientationHandler = null; } + // releaseMediaRecorder(true /* cleanupFile */); mFocusOverlayManager.onPreviewStopped(); return; } diff --git a/java/com/android/dialer/callcomposer/camera/ImagePersistTask.java b/java/com/android/dialer/callcomposer/camera/ImagePersistTask.java index b5542ab6c..31751e536 100644 --- a/java/com/android/dialer/callcomposer/camera/ImagePersistTask.java +++ b/java/com/android/dialer/callcomposer/camera/ImagePersistTask.java @@ -20,11 +20,13 @@ 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; @@ -69,7 +71,13 @@ public class ImagePersistTask extends FallibleAsyncTask { File outputFile = DialerUtils.createShareableFile(mContext); try (OutputStream outputStream = new FileOutputStream(outputFile)) { - writeClippedBitmap(outputStream); + 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); + } } return FileProvider.getUriForFile( @@ -97,12 +105,10 @@ public class ImagePersistTask extends FallibleAsyncTask { } catch (final IOException e) { // Couldn't get exif tags, not the end of the world } - Bitmap bitmap = BitmapFactory.decodeByteArray(mBytes, 0, mBytes.length); final int clippedWidth; final int clippedHeight; - boolean invert = ExifInterface.getOrientationParams(orientation).invertDimensions; - if (invert) { + if (ExifInterface.getOrientationParams(orientation).invertDimensions) { Assert.checkState(mWidth == bitmap.getHeight()); Assert.checkState(mHeight == bitmap.getWidth()); clippedWidth = (int) (mHeight * mHeightPercent); @@ -113,22 +119,24 @@ public class ImagePersistTask extends FallibleAsyncTask { clippedWidth = mWidth; clippedHeight = (int) (mHeight * mHeightPercent); } - - int offsetTop = (bitmap.getHeight() - clippedHeight) / 2; - int offsetLeft = (bitmap.getWidth() - clippedWidth) / 2; + final int offsetTop = (bitmap.getHeight() - clippedHeight) / 2; + final int offsetLeft = (bitmap.getWidth() - clippedWidth) / 2; mWidth = clippedWidth; mHeight = clippedHeight; - - Matrix matrix = new Matrix(); - matrix.postRotate(invert ? 90 : 0); - Bitmap clippedBitmap = - Bitmap.createBitmap( - bitmap, offsetLeft, offsetTop, clippedWidth, clippedHeight, matrix, true); + 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(); clippedBitmap = BitmapResizer.resizeForEnrichedCalling(clippedBitmap); - // 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. + // 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); exifInterface.clearExif(); + exifInterface.setTag(orientationTag); exifInterface.writeExif(clippedBitmap, outputStream); clippedBitmap.recycle(); -- cgit v1.2.3