Skip to content

Commit

Permalink
Merge pull request google#22 from dataticket/master
Browse files Browse the repository at this point in the history
fix NPE crash with onMeasure when previewSize is null
  • Loading branch information
Dylan McIntyre committed Mar 10, 2017
2 parents 6d65d6f + e04fb36 commit c92c4e8
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions camerakit/src/main/java/com/flurgle/camerakit/CameraView.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,28 @@ protected void onDetachedFromWindow() {
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (mAdjustViewBounds) {
Size previewSize = getPreviewSize();
if (getLayoutParams().width == LayoutParams.WRAP_CONTENT) {
int height = MeasureSpec.getSize(heightMeasureSpec);
float ratio = (float) height / (float) previewSize.getWidth();
int width = (int) (previewSize.getHeight() * ratio);
super.onMeasure(
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
heightMeasureSpec
);
return;
} else if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) {
int width = MeasureSpec.getSize(widthMeasureSpec);
float ratio = (float) width / (float) previewSize.getHeight();
int height = (int) (previewSize.getWidth() * ratio);
super.onMeasure(
widthMeasureSpec,
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
);
if(previewSize != null) {
if (getLayoutParams().width == LayoutParams.WRAP_CONTENT) {
int height = MeasureSpec.getSize(heightMeasureSpec);
float ratio = (float) height / (float) previewSize.getWidth();
int width = (int) (previewSize.getHeight() * ratio);
super.onMeasure(
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
heightMeasureSpec
);
return;
} else if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) {
int width = MeasureSpec.getSize(widthMeasureSpec);
float ratio = (float) width / (float) previewSize.getHeight();
int height = (int) (previewSize.getWidth() * ratio);
super.onMeasure(
widthMeasureSpec,
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
);
return;
}
}else{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
return;
}
}
Expand Down

0 comments on commit c92c4e8

Please sign in to comment.