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">
<activity
android:name=".MainActivity"
android:screenOrientation="landscape">
android:screenOrientation="portrait">
<intent-filter>
<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();
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<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;
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);
}
}
}

View File

@ -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"/>
</RelativeLayout>