1.相機過渡界面方向旋轉?
Android 10 - 相機過渡界面默認角度
同A10 有些區別,再次增加記錄修改。
這個文件沒有修改,只是說明
src/com/android/camera/CameraActivity.javaprivate void freezeScreenCommon(boolean async) {long startTime = System.currentTimeMillis();mCameraAppUI.setModeCoverState(1);mStartTime = startTime;if (mCurrentModule.isUseSurfaceView()) {Bitmap screenShot = getSurfaceViewBitmap();if (screenShot == null) {freezeScreenUntilPreviewReady();//SPRD:fix bug1116034} else {//CameraUtil.saveBitmapToFile(screenShot);// 經過注釋驗證,將下面的兩個方法注釋,就不會顯示過渡畫面screenShot = CameraUtil.blurBitmap(CameraUtil.computeScale(screenShot, 0.2f), mAppContext);mCameraAppUI.freezeScreenUntilPreviewReady(screenShot, async);}} else {freezeScreenUntilPreviewReady(async);}Log.i(TAG, "freezeScreenCommon cost: " + (System.currentTimeMillis() - startTime));}
src/com/android/camera/util/CameraUtil.java// 旋轉 Bitmap 的輔助方法
private static Bitmap rotateBitmap(Bitmap source, float angle) {if (source == null) {return null;}Log.d(TAG, "Original width: " + source.getWidth() + ", height: " + source.getHeight());Matrix matrix = new Matrix();matrix.postRotate(angle);Bitmap rotatedBitmap = Bitmap.createBitmap(source,0, 0,source.getWidth(),source.getHeight(),matrix,true);// 打印旋轉后圖片寬高Log.d(TAG, "Rotated width: " + rotatedBitmap.getWidth() + ", height: " + rotatedBitmap.getHeight());return rotatedBitmap;
}public static Bitmap blurBitmap(Bitmap bitmap, Context context) {if (bitmap == null) {return null;}long startMs = System.currentTimeMillis();// 這里是新增加的方法,實現過渡畫面的角度,當前項目旋轉90度即可bitmap = rotateBitmap(bitmap, 90);// Instantiate a new RenderscriptRenderScript rs = RenderScript.create(context);
src/com/android/camera/app/CameraAppUI.javapublic void freezeScreenUntilPreviewReady(Bitmap bitmap, boolean async) {Log.v(TAG, "freezeScreenUntilPreviewReady bitmap=" + bitmap + "; async=" + async + " getPreviewArea :" + getPreviewAreaLocal());// lichang 修改原有獲取預覽區域方法為自行獲取,原尺寸異常freezeScreen(bitmap, getPreviewAreaLocal(), async);}/*** 根據寬高比獲取預覽區域*/public RectF getPreviewAreaLocal() {Log.v(TAG, "getPreviewAreaLocal getAspectRation() = " + getAspectRation());float previewWidth = 960f;float screenWidth = 1280f;float aspectRation = getAspectRation();float epsilon = 0.001f; // 允許的誤差范圍if (Math.abs(aspectRation - (4f / 3f)) < epsilon) {// 4:3 比例(≈1.333)previewWidth = 960f;} else if (Math.abs(aspectRation - (16f / 9f)) < epsilon) {// 16:9 比例(≈1.777)previewWidth = 1280f;} else {// 其他比例,默認值或錯誤處理previewWidth = 1280f; // 或 throw new IllegalArgumentException("Unsupported aspect ratio");}float left = (screenWidth - previewWidth) / 2f;Log.v(TAG, "getPreviewAreaLocal left = " + left + " right = " + left + previewWidth);return new RectF(left, 0f, left + previewWidth, 720f);}// 新增方法public float getAspectRation() {return mTextureViewHelper.getAspectRation();}
src/com/android/camera/TextureViewHelper.javapublic void setAspectRation(float aspectRation) {mAspectRatio = aspectRation;}// 新增方法,獲取當前寬高比public float getAspectRation() {return mAspectRatio;}
2.相機圖標位置居中
+++ b/src/com/android/camera/ui/ModeTransitionView.java
@@ -143,6 +143,7 @@ public class ModeTransitionView extends View {mIconDrawable.setAlpha(alpha);}}
+ Log.e(TAG, " updateShade mWidth = " + mWidth + " mHeight = " + mHeight);invalidate();}}
@@ -172,6 +173,7 @@ public class ModeTransitionView extends View {@Overridepublic void onDraw(Canvas canvas) {
+ Log.e(TAG, " lichang onDraw ");if (mAnimationType == PEEP_HOLE_ANIMATION) {canvas.drawColor(mBackgroundColor);if (mPeepHoleAnimator != null) {
@@ -227,8 +229,9 @@ public class ModeTransitionView extends View {mWidth = displaySize.getWidth();mHeight = displaySize.getHeight();boolean landscape = mWidth > mHeight;
- int centerW = landscape ? mHeight : mWidth;
- int centerH = landscape ? mWidth : mHeight;
+ // lichang 橫屏也不需要調換位置,修改打開相機顯示的圖標位置
+ int centerW = !landscape ? mHeight : mWidth;
+ int centerH = !landscape ? mWidth : mHeight;if (CameraUtil.hasCutout()) {centerH -= CameraUtil.getCutoutHeight();
3.預覽畫面居中
默認4:3,顯示的預覽畫面偏移,需要重新計算位置。
+++ b/src/com/android/camera/SurfaceViewEx.java
@@ -19,6 +19,8 @@package com.android.camera;+import android.util.DisplayMetrics;
+import android.view.WindowManager;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory;
@@ -165,8 +167,16 @@ public class SurfaceViewEx extends SurfaceView {params.height = (int) scaledTextureHeight;RectF rect = mCameraAppUI.getPreviewArea();// horizontal direction
- params.setMargins((int) rect.left, (int) rect.top, 0, 0);
-
+ //params.setMargins((int) rect.left, (int) rect.top, 0, 0);
+ // lichang 將預覽畫面居中
+ /*@start*/
+ DisplayMetrics displayMetrics = new DisplayMetrics();
+ ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(displayMetrics);
+ int screenWidth = displayMetrics.widthPixels;
+ int screenHeight = displayMetrics.heightPixels;
+ Log.i(TAG, "setTransformMatrix(): screenWidth = " + screenWidth + " screenHeight = " + screenHeight);
+ params.setMargins((int) (screenWidth - scaledTextureWidth) / 2, (int) (screenHeight - scaledTextureHeight) / 2, 0, 0);
+ /*end*/setLayoutParams(params);Log.i(TAG, "setTransformMatrix(): width = " + previewWidth
?