move some more code in utils

This commit is contained in:
tibbi
2016-11-24 21:03:45 +01:00
parent 0223867412
commit e8cb8d1464
2 changed files with 22 additions and 27 deletions

View File

@@ -305,20 +305,6 @@ public class Preview extends ViewGroup
return maxRes == 0 || size.width * size.height < maxRes; 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) { private boolean isProperRatio(Camera.Size size) {
final float currRatio = (float) size.height / size.width; final float currRatio = (float) size.height / size.width;
float wantedRatio = (float) 3 / 4; float wantedRatio = (float) 3 / 4;
@@ -330,7 +316,7 @@ public class Preview extends ViewGroup
} }
private Camera.Size getOptimalVideoSize() { private Camera.Size getOptimalVideoSize() {
final int maxResolution = getMaxVideoResolution(); final int maxResolution = Utils.Companion.getMaxVideoResolution(mConfig);
final List<Camera.Size> sizes = getSupportedVideoSizes(); final List<Camera.Size> sizes = getSupportedVideoSizes();
Collections.sort(sizes, new SizesComparator()); Collections.sort(sizes, new SizesComparator());
Camera.Size maxSize = sizes.get(0); 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) { private void focusArea(final boolean takePictureAfter) {
if (mCamera == null) if (mCamera == null)
return; return;
@@ -616,15 +596,14 @@ public class Preview extends ViewGroup
mRecorder.setProfile(cpHigh); mRecorder.setProfile(cpHigh);
if (Utils.Companion.needsStupidWritePermissions(getContext(), mCurrVideoPath)) { if (Utils.Companion.needsStupidWritePermissions(getContext(), mCurrVideoPath)) {
final Config config = Config.Companion.newInstance(getContext()); if (mConfig.getTreeUri().isEmpty()) {
if (config.getTreeUri().isEmpty()) {
Utils.Companion.showToast(mContext, R.string.save_error_internal_storage); Utils.Companion.showToast(mContext, R.string.save_error_internal_storage);
config.setSavePhotosFolder(Environment.getExternalStorageDirectory().toString()); mConfig.setSavePhotosFolder(Environment.getExternalStorageDirectory().toString());
releaseCamera(); releaseCamera();
return false; return false;
} }
try { 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)); document = document.createFile("", mCurrVideoPath.substring(mCurrVideoPath.lastIndexOf('/') + 1));
final Uri uri = document.getUri(); final Uri uri = document.getUri();
final ParcelFileDescriptor fileDescriptor = getContext().getContentResolver().openFileDescriptor(uri, "rw"); final ParcelFileDescriptor fileDescriptor = getContext().getContentResolver().openFileDescriptor(uri, "rw");
@@ -637,7 +616,7 @@ public class Preview extends ViewGroup
} }
mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
int rotation = getFinalRotation(); int rotation = Utils.Companion.getFinalRotation(mActivity, mCurrCameraId, mCallback.getCurrentOrientation());
mInitVideoRotation = rotation; mInitVideoRotation = rotation;
mRecorder.setOrientationHint(rotation); mRecorder.setOrientationHint(rotation);
@@ -667,7 +646,7 @@ public class Preview extends ViewGroup
} }
private void startRecording() { private void startRecording() {
if (mInitVideoRotation != getFinalRotation()) { if (mInitVideoRotation != Utils.Companion.getFinalRotation(mActivity, mCurrCameraId, mCallback.getCurrentOrientation())) {
cleanupRecorder(); cleanupRecorder();
initRecorder(); initRecorder();
} }

View File

@@ -150,5 +150,21 @@ class Utils {
} }
return degrees 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
}
}
} }
} }