From 9cf240691d16b6f401bb12c6b0d59d09082410cb Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 16 Apr 2016 14:32:22 +0200 Subject: [PATCH] lets use portrait mode --- app/src/main/AndroidManifest.xml | 2 +- .../java/com/simplemobiletools/camera/Preview.java | 13 +++++++------ app/src/main/res/layout/activity_main.xml | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 50635591..9fb86dd1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,7 +17,7 @@ android:theme="@style/AppTheme"> + android:screenOrientation="portrait"> diff --git a/app/src/main/java/com/simplemobiletools/camera/Preview.java b/app/src/main/java/com/simplemobiletools/camera/Preview.java index 2d04bb9b..f7d2b0ab 100644 --- a/app/src/main/java/com/simplemobiletools/camera/Preview.java +++ b/app/src/main/java/com/simplemobiletools/camera/Preview.java @@ -62,6 +62,7 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback { final Camera.Parameters params = camera.getParameters(); params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); camera.setParameters(params); + camera.setDisplayOrientation(90); } } @@ -191,9 +192,9 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback { protected void onLayout(boolean changed, int l, int t, int r, int b) { } - private Camera.Size getOptimalPreviewSize(List sizes, int w, int h) { + private Camera.Size getOptimalPreviewSize(List sizes, int height, int width) { final double ASPECT_TOLERANCE = 0.1; - double targetRatio = (double) h / w; + double targetRatio = (double) height / width; if (sizes == null) return null; @@ -205,18 +206,18 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback { double ratio = (double) size.width / size.height; if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue; - if (Math.abs(size.height - h) < minDiff) { + if (Math.abs(size.height - height) < minDiff) { optimalSize = size; - minDiff = Math.abs(size.height - h); + minDiff = Math.abs(size.height - height); } } if (optimalSize == null) { minDiff = Double.MAX_VALUE; for (Camera.Size size : sizes) { - if (Math.abs(size.height - h) < minDiff) { + if (Math.abs(size.height - height) < minDiff) { optimalSize = size; - minDiff = Math.abs(size.height - h); + minDiff = Math.abs(size.height - height); } } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 19303894..8c232969 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -14,9 +14,9 @@ android:id="@+id/shutter" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_alignParentRight="true" - android:layout_centerVertical="true" - android:layout_marginRight="@dimen/preview_btn_margin" + android:layout_alignParentBottom="true" + android:layout_centerHorizontal="true" + android:layout_marginBottom="@dimen/preview_btn_margin" android:src="@mipmap/ic_launcher"/>