From e01a0b8630d9f72d571e78a6816fcb14ad460533 Mon Sep 17 00:00:00 2001 From: Ferdian Sulaiman Date: Thu, 21 Jun 2018 17:47:23 +0700 Subject: [PATCH] fix get aspect ratio to get full screen (including virtual button) --- .../com/google/android/cameraview/CameraView.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/google/android/cameraview/CameraView.java b/library/src/main/java/com/google/android/cameraview/CameraView.java index 145377ed..7140225a 100644 --- a/library/src/main/java/com/google/android/cameraview/CameraView.java +++ b/library/src/main/java/com/google/android/cameraview/CameraView.java @@ -27,6 +27,7 @@ import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Path; +import android.graphics.Point; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; @@ -42,7 +43,9 @@ import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.TypedValue; +import android.view.Display; import android.view.ViewTreeObserver; +import android.view.WindowManager; import android.widget.FrameLayout; import java.lang.annotation.Retention; @@ -143,9 +146,13 @@ public CameraView(Context context, AttributeSet attrs, int defStyleAttr) { @Override public void onGlobalLayout() { getViewTreeObserver().removeOnGlobalLayoutListener(this); - DisplayMetrics displayMetrics = getResources().getDisplayMetrics(); - deviceWidth = displayMetrics.widthPixels; - deviceHeight = displayMetrics.heightPixels; + WindowManager wm = ((WindowManager) + getContext().getSystemService(Context.WINDOW_SERVICE)); + Display display = wm.getDefaultDisplay(); + Point screenSize = new Point(); + display.getRealSize(screenSize); + deviceWidth = screenSize.x; + deviceHeight = screenSize.y; setAspectRatio(AspectRatio.of(deviceHeight, deviceWidth)); } });