main
Matthew 8 months ago
parent d82d8a7540
commit 280f0055f6

@ -18,6 +18,7 @@ package com.xypower.mppreview;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.TextureView;
/**
@ -52,11 +53,15 @@ public class AutoFitTextureView extends TextureView {
if (width < 0 || height < 0) {
throw new IllegalArgumentException("Size cannot be negative.");
}
Log.i("AutoFit", "setAspectRatio Width=" + width + " Height=" + height);
if (mRatioWidth == width && mRatioHeight == height) {
return;
}
mRatioWidth = width;
mRatioHeight = height;
requestLayout();
}
@ -65,12 +70,17 @@ public class AutoFitTextureView extends TextureView {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
if (0 == mRatioWidth || 0 == mRatioHeight) {
Log.i("AutoFit", "0 Width=" + width + " Height=" + height);
setMeasuredDimension(width, height);
} else {
if (width < height * mRatioWidth / mRatioHeight) {
Log.i("AutoFit", "Width=" + width + " Height=" + ((int)(width * mRatioHeight / mRatioWidth)));
setMeasuredDimension(width, width * mRatioHeight / mRatioWidth);
} else {
Log.i("AutoFit", "Width=" + ((int)height * mRatioWidth / mRatioHeight) + " Height=" + height);
setMeasuredDimension(height * mRatioWidth / mRatioHeight, height);
}
}

@ -177,7 +177,7 @@ public class Camera2RawFragment extends Fragment
/**
* Tag for the {@link Log}.
*/
private static final String TAG = "Camera2RawFragment";
private static final String TAG = "MpPreview";
/**
* Camera state: Device is closed.
@ -626,6 +626,7 @@ public class Camera2RawFragment extends Fragment
} else {
mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
}
if (mOrientationListener != null && mOrientationListener.canDetectOrientation()) {
mOrientationListener.enable();
}
@ -1033,7 +1034,7 @@ public class Camera2RawFragment extends Fragment
// Swap the view dimensions for calculation as needed if they are rotated relative to
// the sensor.
boolean swappedDimensions = totalRotation == 90 || totalRotation == 270;
final boolean swappedDimensions = totalRotation == 90 || totalRotation == 270;
int rotatedViewWidth = viewWidth;
int rotatedViewHeight = viewHeight;
int maxPreviewWidth = displaySize.x;
@ -1056,10 +1057,13 @@ public class Camera2RawFragment extends Fragment
}
// Find the best preview size for these view dimensions and configured JPEG size.
Size previewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class),
final Size previewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class),
rotatedViewWidth, rotatedViewHeight, maxPreviewWidth, maxPreviewHeight,
largestJpeg);
mMessageHandler.postDelayed(new Runnable() {
@Override
public void run() {
if (swappedDimensions) {
mTextureView.setAspectRatio(
previewSize.getHeight(), previewSize.getWidth());
@ -1067,6 +1071,10 @@ public class Camera2RawFragment extends Fragment
mTextureView.setAspectRatio(
previewSize.getWidth(), previewSize.getHeight());
}
}
}, 0);
// Find rotation of device in degrees (reverse device orientation for front-facing
// cameras).

@ -19,19 +19,20 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000" >
<com.xypower.mppreview.AutoFitTextureView
android:id="@+id/texture"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</FrameLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#504285f4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
@ -39,12 +40,13 @@
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
android:scaleType="fitXY"
app:layout_constraintBottom_toTopOf="@+id/backMain"
android:alpha="0.5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.5"
app:layout_constraintEnd_toStartOf="@id/backMain"
app:layout_constraintHorizontal_bias="0.5"
app:srcCompat="@drawable/ic_take_photo"
/>
@ -53,15 +55,12 @@
android:layout_width="48dp"
android:layout_height="48dp"
android:scaleType="fitXY"
app:layout_constraintStart_toStartOf="parent"
android:alpha="0.5"
app:layout_constraintStart_toEndOf="@id/picture"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/picture"
app:srcCompat="@drawable/ic_back"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Loading…
Cancel
Save