Loading app/src/main/java/net/sourceforge/opencamera/MainActivity.java +48 −0 Original line number Diff line number Diff line Loading @@ -763,10 +763,39 @@ public class MainActivity extends AppCompatActivity implements PreferenceFragmen 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()); } /** Whether to use codepaths that are compatible with scoped storage. Loading Loading @@ -3631,7 +3660,13 @@ public class MainActivity extends AppCompatActivity implements PreferenceFragmen } } /** * 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; } Loading Loading @@ -3904,6 +3939,18 @@ public class MainActivity extends AppCompatActivity implements PreferenceFragmen getWindow().getDecorView().setSystemUiVisibility(saved_flags); } /** * 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. */ Loading Loading @@ -4098,6 +4145,7 @@ public class MainActivity extends AppCompatActivity implements PreferenceFragmen } 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 Loading app/src/main/java/net/sourceforge/opencamera/preview/Preview.java +24 −2 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ package net.sourceforge.opencamera.preview; import net.sourceforge.opencamera.HDRProcessor; import net.sourceforge.opencamera.JavaImageFunctions; import net.sourceforge.opencamera.JavaImageProcessing; import net.sourceforge.opencamera.MainActivity; import net.sourceforge.opencamera.cameracontroller.RawImage; //import net.sourceforge.opencamera.MainActivity; import net.sourceforge.opencamera.MyDebug; import net.sourceforge.opencamera.R; import net.sourceforge.opencamera.ScriptC_histogram_compute; Loading Loading @@ -3873,6 +3873,21 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu return optimalSize; } private static CameraController.Size getClosestSizeForFullScreen(List<CameraController.Size> 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<CameraController.Size> sizes) { if( MyDebug.LOG ) Log.d(TAG, "getOptimalPreviewSize()"); Loading Loading @@ -3908,6 +3923,7 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu Log.d(TAG, "swapped display_size to: " + 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 ) { Loading Loading @@ -3937,8 +3953,12 @@ 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"); 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); Log.d(TAG, "optimalSize ratio: " + ((double)optimalSize.width / optimalSize.height)); Loading Loading @@ -4786,6 +4806,7 @@ 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 ) { Loading @@ -4794,6 +4815,7 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu Log.d(TAG, "wait until photo taken"); } else { ((MainActivity)getContext()).setDecorFitsSystemWindows(true); this.is_video = true; } } Loading Loading
app/src/main/java/net/sourceforge/opencamera/MainActivity.java +48 −0 Original line number Diff line number Diff line Loading @@ -763,10 +763,39 @@ public class MainActivity extends AppCompatActivity implements PreferenceFragmen 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()); } /** Whether to use codepaths that are compatible with scoped storage. Loading Loading @@ -3631,7 +3660,13 @@ public class MainActivity extends AppCompatActivity implements PreferenceFragmen } } /** * 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; } Loading Loading @@ -3904,6 +3939,18 @@ public class MainActivity extends AppCompatActivity implements PreferenceFragmen getWindow().getDecorView().setSystemUiVisibility(saved_flags); } /** * 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. */ Loading Loading @@ -4098,6 +4145,7 @@ public class MainActivity extends AppCompatActivity implements PreferenceFragmen } 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 Loading
app/src/main/java/net/sourceforge/opencamera/preview/Preview.java +24 −2 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ package net.sourceforge.opencamera.preview; import net.sourceforge.opencamera.HDRProcessor; import net.sourceforge.opencamera.JavaImageFunctions; import net.sourceforge.opencamera.JavaImageProcessing; import net.sourceforge.opencamera.MainActivity; import net.sourceforge.opencamera.cameracontroller.RawImage; //import net.sourceforge.opencamera.MainActivity; import net.sourceforge.opencamera.MyDebug; import net.sourceforge.opencamera.R; import net.sourceforge.opencamera.ScriptC_histogram_compute; Loading Loading @@ -3873,6 +3873,21 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu return optimalSize; } private static CameraController.Size getClosestSizeForFullScreen(List<CameraController.Size> 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<CameraController.Size> sizes) { if( MyDebug.LOG ) Log.d(TAG, "getOptimalPreviewSize()"); Loading Loading @@ -3908,6 +3923,7 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu Log.d(TAG, "swapped display_size to: " + 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 ) { Loading Loading @@ -3937,8 +3953,12 @@ 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"); 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); Log.d(TAG, "optimalSize ratio: " + ((double)optimalSize.width / optimalSize.height)); Loading Loading @@ -4786,6 +4806,7 @@ 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 ) { Loading @@ -4794,6 +4815,7 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu Log.d(TAG, "wait until photo taken"); } else { ((MainActivity)getContext()).setDecorFitsSystemWindows(true); this.is_video = true; } } Loading