mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-01-24 04:10:51 +01:00
move some more code in utils
This commit is contained in:
parent
0223867412
commit
e8cb8d1464
@ -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<Camera.Size> 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();
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user