diff --git a/app/src/main/java/com/simplemobiletools/camera/Preview.java b/app/src/main/java/com/simplemobiletools/camera/Preview.java index df8bfee6..a563fb9b 100644 --- a/app/src/main/java/com/simplemobiletools/camera/Preview.java +++ b/app/src/main/java/com/simplemobiletools/camera/Preview.java @@ -305,20 +305,6 @@ public class Preview extends ViewGroup return maxRes == 0 || size.width * size.height < maxRes; } - private int getMaxVideoResolution() { - final int maxRes = mConfig.getMaxVideoResolution(); - switch (maxRes) { - case 0: - return 400000; - case 1: - return 1000000; - case 2: - return 2100000; - default: - return 0; - } - } - private boolean isProperRatio(Camera.Size size) { final float currRatio = (float) size.height / size.width; float wantedRatio = (float) 3 / 4; @@ -330,7 +316,7 @@ public class Preview extends ViewGroup } private Camera.Size getOptimalVideoSize() { - final int maxResolution = getMaxVideoResolution(); + final int maxResolution = Utils.Companion.getMaxVideoResolution(mConfig); final List sizes = getSupportedVideoSizes(); Collections.sort(sizes, new SizesComparator()); Camera.Size maxSize = sizes.get(0); @@ -359,12 +345,6 @@ public class Preview extends ViewGroup } } - private int getFinalRotation() { - int rotation = Utils.Companion.getMediaRotation(mActivity, mCurrCameraId); - rotation += Utils.Companion.compensateDeviceRotation(mCurrCameraId, mCallback.getCurrentOrientation()); - return rotation % 360; - } - private void focusArea(final boolean takePictureAfter) { if (mCamera == null) return; @@ -616,15 +596,14 @@ public class Preview extends ViewGroup mRecorder.setProfile(cpHigh); if (Utils.Companion.needsStupidWritePermissions(getContext(), mCurrVideoPath)) { - final Config config = Config.Companion.newInstance(getContext()); - if (config.getTreeUri().isEmpty()) { + if (mConfig.getTreeUri().isEmpty()) { Utils.Companion.showToast(mContext, R.string.save_error_internal_storage); - config.setSavePhotosFolder(Environment.getExternalStorageDirectory().toString()); + mConfig.setSavePhotosFolder(Environment.getExternalStorageDirectory().toString()); releaseCamera(); return false; } try { - DocumentFile document = Utils.Companion.getFileDocument(getContext(), mCurrVideoPath, config.getTreeUri()); + DocumentFile document = Utils.Companion.getFileDocument(getContext(), mCurrVideoPath, mConfig.getTreeUri()); document = document.createFile("", mCurrVideoPath.substring(mCurrVideoPath.lastIndexOf('/') + 1)); final Uri uri = document.getUri(); final ParcelFileDescriptor fileDescriptor = getContext().getContentResolver().openFileDescriptor(uri, "rw"); @@ -637,7 +616,7 @@ public class Preview extends ViewGroup } mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); - int rotation = getFinalRotation(); + int rotation = Utils.Companion.getFinalRotation(mActivity, mCurrCameraId, mCallback.getCurrentOrientation()); mInitVideoRotation = rotation; mRecorder.setOrientationHint(rotation); @@ -667,7 +646,7 @@ public class Preview extends ViewGroup } private void startRecording() { - if (mInitVideoRotation != getFinalRotation()) { + if (mInitVideoRotation != Utils.Companion.getFinalRotation(mActivity, mCurrCameraId, mCallback.getCurrentOrientation())) { cleanupRecorder(); initRecorder(); } diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/Utils.kt b/app/src/main/kotlin/com/simplemobiletools/camera/Utils.kt index 436d973d..24797c41 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/Utils.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/Utils.kt @@ -150,5 +150,21 @@ class Utils { } return degrees } + + fun getFinalRotation(activity: Activity, currCameraId: Int, deviceOrientation: Int): Int { + var rotation = Utils.getMediaRotation(activity, currCameraId) + rotation += Utils.compensateDeviceRotation(currCameraId, deviceOrientation) + return rotation % 360 + } + + + fun getMaxVideoResolution(config: Config): Int { + return when (config.maxVideoResolution) { + 0 -> 400000 + 1 -> 1000000 + 2 -> 2100000 + else -> 0 + } + } } }