lets use portrait mode

This commit is contained in:
tibbi 2016-04-16 14:32:22 +02:00
parent 9e584ee2d0
commit 9cf240691d
3 changed files with 11 additions and 10 deletions

View File

@ -17,7 +17,7 @@
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:screenOrientation="landscape"> android:screenOrientation="portrait">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>

View File

@ -62,6 +62,7 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback {
final Camera.Parameters params = camera.getParameters(); final Camera.Parameters params = camera.getParameters();
params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
camera.setParameters(params); 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) { protected void onLayout(boolean changed, int l, int t, int r, int b) {
} }
private Camera.Size getOptimalPreviewSize(List<Camera.Size> sizes, int w, int h) { private Camera.Size getOptimalPreviewSize(List<Camera.Size> sizes, int height, int width) {
final double ASPECT_TOLERANCE = 0.1; final double ASPECT_TOLERANCE = 0.1;
double targetRatio = (double) h / w; double targetRatio = (double) height / width;
if (sizes == null) if (sizes == null)
return null; return null;
@ -205,18 +206,18 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback {
double ratio = (double) size.width / size.height; double ratio = (double) size.width / size.height;
if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)
continue; continue;
if (Math.abs(size.height - h) < minDiff) { if (Math.abs(size.height - height) < minDiff) {
optimalSize = size; optimalSize = size;
minDiff = Math.abs(size.height - h); minDiff = Math.abs(size.height - height);
} }
} }
if (optimalSize == null) { if (optimalSize == null) {
minDiff = Double.MAX_VALUE; minDiff = Double.MAX_VALUE;
for (Camera.Size size : sizes) { for (Camera.Size size : sizes) {
if (Math.abs(size.height - h) < minDiff) { if (Math.abs(size.height - height) < minDiff) {
optimalSize = size; optimalSize = size;
minDiff = Math.abs(size.height - h); minDiff = Math.abs(size.height - height);
} }
} }
} }

View File

@ -14,9 +14,9 @@
android:id="@+id/shutter" android:id="@+id/shutter"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true" android:layout_alignParentBottom="true"
android:layout_centerVertical="true" android:layout_centerHorizontal="true"
android:layout_marginRight="@dimen/preview_btn_margin" android:layout_marginBottom="@dimen/preview_btn_margin"
android:src="@mipmap/ic_launcher"/> android:src="@mipmap/ic_launcher"/>
</RelativeLayout> </RelativeLayout>