Skip to content

Commit

Permalink
Aspect ratio change invokes layout
Browse files Browse the repository at this point in the history
Calling setAspectRatio now requests layout if necessary (google#20).

Change-Id: Ie4f7be899be6f222850d89f2593988aa5d312f89
  • Loading branch information
yaraki committed Dec 15, 2016
1 parent 061e4a3 commit aa7dcf6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,22 @@ Set<AspectRatio> getSupportedAspectRatios() {
}

@Override
void setAspectRatio(AspectRatio ratio) {
boolean setAspectRatio(AspectRatio ratio) {
if (mAspectRatio == null || !isCameraOpened()) {
// Handle this later when camera is opened
mAspectRatio = ratio;
return true;
} else if (!mAspectRatio.equals(ratio)) {
final Set<Size> sizes = mPreviewSizes.sizes(ratio);
if (sizes == null) {
throw new UnsupportedOperationException(ratio + " is not supported");
} else {
mAspectRatio = ratio;
adjustCameraParameters();
return true;
}
}
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,19 @@ Set<AspectRatio> getSupportedAspectRatios() {
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ View getView() {

abstract Set<AspectRatio> getSupportedAspectRatios();

abstract void setAspectRatio(AspectRatio ratio);
/**
* @return {@code true} if the aspect ratio was changed.
*/
abstract boolean setAspectRatio(AspectRatio ratio);

abstract AspectRatio getAspectRatio();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,9 @@ public Set<AspectRatio> getSupportedAspectRatios() {
* @param ratio The {@link AspectRatio} to be set.
*/
public void setAspectRatio(@NonNull AspectRatio ratio) {
mImpl.setAspectRatio(ratio);
if (mImpl.setAspectRatio(ratio)) {
requestLayout();
}
}

/**
Expand Down

0 comments on commit aa7dcf6

Please sign in to comment.