diff --git a/app/build.gradle b/app/build.gradle index 4828ac08aaa4f2f86a2a4f111027779f6b6b2e4b..0902d363c272349d327a0cede862bff1fd1ef421 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,7 +1,7 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 29 + compileSdkVersion 30 compileOptions.encoding = 'UTF-8' compileOptions { @@ -12,7 +12,7 @@ android { defaultConfig { applicationId "foundation.e.camera" minSdkVersion 21 - targetSdkVersion 29 + targetSdkVersion 30 renderscriptTargetApi 21 //renderscriptSupportModeEnabled true // don't use support library as it bloats the APK, and we don't need pre-4.4 support diff --git a/app/src/main/java/net/sourceforge/opencamera/MainActivity.java b/app/src/main/java/net/sourceforge/opencamera/MainActivity.java index adf98555d7bc73f9b42fc27c32fc6bc0ca7d3875..a92a7d8972924a0a51cd4045b219efcb7d5093dd 100644 --- a/app/src/main/java/net/sourceforge/opencamera/MainActivity.java +++ b/app/src/main/java/net/sourceforge/opencamera/MainActivity.java @@ -651,13 +651,48 @@ public class MainActivity extends Activity { notificationManager.createNotificationChannel(channel); } + calculateNavigationGap(); + if( MyDebug.LOG ) Log.d(TAG, "onCreate: total time for Activity startup: " + (System.currentTimeMillis() - debug_time)); + } + /** + * if navigationMode is no gesture, then retrieve navigationBar's height & update navigation_gap + */ + private void calculateNavigationGap() { + int resourceId = getResources().getIdentifier("config_navBarInteractionMode", "integer", "android"); + if (resourceId > 0) { + int navType = getResources().getInteger(resourceId); + if (navType != 2) { //gesture mode = 2 + resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android"); + if (resourceId > 0) { + navigation_gap = getResources().getDimensionPixelSize(resourceId); + } + } + } + } + public void handleDecorFitsSystemWindows() { + setDecorFitsSystemWindows(!isInFullScreenMode()); } + /** + * check is the preview size = maximise && is not in video mode, then return true + */ + public boolean isInFullScreenMode() { + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); + String preview_size = sharedPreferences.getString(PreferenceKeys.PreviewSizePreferenceKey, "preference_preview_size_display"); + return !(preview_size.equals("preference_preview_size_wysiwyg") || preview.isVideo()); + } + + /** + * if sdk>=R & not in full screen, means the DecorFitsSystemWindows=true, then we can ignore navigationGap. + */ public int getNavigationGap() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !isInFullScreenMode()) { + return 0; + } return want_no_limits ? navigation_gap : 0; } @@ -2653,6 +2688,18 @@ public class MainActivity extends Activity { } } + /** + * setDecorFitsSystemWindows for build >=R + * @return if the operation successful or not + */ + public boolean setDecorFitsSystemWindows(boolean decorFitsSystemWindows) { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + getWindow().setDecorFitsSystemWindows(decorFitsSystemWindows); + return true; + } + return false; + } + /** Sets the brightness level for normal operation (when camera preview is visible). * If force_max is true, this always forces maximum brightness; otherwise this depends on user preference. */ @@ -2823,6 +2870,7 @@ public class MainActivity extends Activity { } setImmersiveMode(false); + setDecorFitsSystemWindows(true); camera_in_background = true; // we disable location listening when showing settings or a dialog etc - saves battery life, also better for privacy diff --git a/app/src/main/java/net/sourceforge/opencamera/preview/Preview.java b/app/src/main/java/net/sourceforge/opencamera/preview/Preview.java index cb7369a69d3fa57c7fc57953c89b1f0a5fd5cd17..58bd0738efe19bf01cd22c5ee502fe05218a2f1a 100644 --- a/app/src/main/java/net/sourceforge/opencamera/preview/Preview.java +++ b/app/src/main/java/net/sourceforge/opencamera/preview/Preview.java @@ -1,7 +1,7 @@ package net.sourceforge.opencamera.preview; +import net.sourceforge.opencamera.MainActivity; import net.sourceforge.opencamera.cameracontroller.RawImage; -//import net.sourceforge.opencamera.MainActivity; import net.sourceforge.opencamera.MyDebug; import foundation.e.camera.R; @@ -3470,6 +3470,21 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu return optimalSize; } + private static CameraController.Size getClosestSizeForFullScreen(List sizes, double targetRatio) { + if (MyDebug.LOG) + Log.d(TAG, "getClosestSize()"); + CameraController.Size optimalSize = null; + double minDiff = Double.MIN_VALUE; + for (CameraController.Size size : sizes) { + double ratio = (double) size.width / size.height; + if ((ratio - targetRatio) > minDiff) { + optimalSize = size; + minDiff = ratio - targetRatio; + } + } + return (optimalSize != null) ? optimalSize : getClosestSize(sizes, targetRatio, null); + } + public CameraController.Size getOptimalPreviewSize(List sizes) { if (MyDebug.LOG) Log.d(TAG, "getOptimalPreviewSize()"); @@ -3503,6 +3518,7 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu if (MyDebug.LOG) Log.d(TAG, "display_size: " + display_size.x + " x " + display_size.y); } + ((MainActivity)getContext()).handleDecorFitsSystemWindows(); double targetRatio = calculateTargetRatioForPreview(display_size); int targetHeight = Math.min(display_size.y, display_size.x); if (targetHeight <= 0) { @@ -3524,7 +3540,11 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu // can't find match for aspect ratio, so find closest one if (MyDebug.LOG) Log.d(TAG, "no preview size matches the aspect ratio"); - optimalSize = getClosestSize(sizes, targetRatio, null); + if (((MainActivity)getContext()).isInFullScreenMode()) { + optimalSize = getClosestSizeForFullScreen(sizes, targetRatio); + } else { + optimalSize = getClosestSize(sizes, targetRatio, null); + } } if (MyDebug.LOG) { Log.d(TAG, "chose optimalSize: " + optimalSize.width + " x " + optimalSize.height); @@ -4315,12 +4335,14 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu } else { if (this.isOnTimer()) { cancelTimer(); + ((MainActivity)getContext()).setDecorFitsSystemWindows(true); this.is_video = true; } else if (this.phase == PHASE_TAKING_PHOTO) { // wait until photo taken if (MyDebug.LOG) Log.d(TAG, "wait until photo taken"); } else { + ((MainActivity)getContext()).setDecorFitsSystemWindows(true); this.is_video = true; } }