Skip to content

Commit

Permalink
Fix app:aspectRatio not working at Camera2 google#177
Browse files Browse the repository at this point in the history
  • Loading branch information
luowei committed Jul 9, 2018
1 parent b63f8a6 commit f9928ee
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions library/src/main/api21/com/google/android/cameraview/Camera2.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import android.util.Log;
import android.util.SparseIntArray;
import android.view.Surface;

import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Set;
Expand Down Expand Up @@ -263,11 +262,20 @@ Set<AspectRatio> getSupportedAspectRatios() {

@Override
boolean setAspectRatio(AspectRatio ratio) {
if (ratio == null || ratio.equals(mAspectRatio) ||
!mPreviewSizes.ratios().contains(ratio)) {
if (ratio == null || ratio.equals(mAspectRatio)) {
// TODO: Better error handling
return false;
}

if (!mPreviewSizes.ratios().contains(ratio)) {
if (mPreviewSizes.ratios().size() <= 0) {
// may be initialized from layout xml
mAspectRatio = ratio;
return true;
}
return false;
}

mAspectRatio = ratio;
prepareImageReader();
if (mCaptureSession != null) {
Expand Down Expand Up @@ -640,8 +648,8 @@ void captureStillPicture() {
new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session,
@NonNull CaptureRequest request,
@NonNull TotalCaptureResult result) {
@NonNull CaptureRequest request,
@NonNull TotalCaptureResult result) {
unlockFocus();
}
}, null);
Expand Down Expand Up @@ -695,13 +703,13 @@ void setState(int state) {

@Override
public void onCaptureProgressed(@NonNull CameraCaptureSession session,
@NonNull CaptureRequest request, @NonNull CaptureResult partialResult) {
@NonNull CaptureRequest request, @NonNull CaptureResult partialResult) {
process(partialResult);
}

@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session,
@NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
@NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
process(result);
}

Expand Down

0 comments on commit f9928ee

Please sign in to comment.