Merge pull request #22 from dataticket/master

fix NPE crash with onMeasure when previewSize is null
pull/1/head
Dylan McIntyre 8 years ago committed by GitHub
commit c92c4e8a61
  1. 39
      camerakit/src/main/java/com/flurgle/camerakit/CameraView.java

@ -122,23 +122,28 @@ public class CameraView extends FrameLayout {
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (mAdjustViewBounds) { if (mAdjustViewBounds) {
Size previewSize = getPreviewSize(); Size previewSize = getPreviewSize();
if (getLayoutParams().width == LayoutParams.WRAP_CONTENT) { if(previewSize != null) {
int height = MeasureSpec.getSize(heightMeasureSpec); if (getLayoutParams().width == LayoutParams.WRAP_CONTENT) {
float ratio = (float) height / (float) previewSize.getWidth(); int height = MeasureSpec.getSize(heightMeasureSpec);
int width = (int) (previewSize.getHeight() * ratio); float ratio = (float) height / (float) previewSize.getWidth();
super.onMeasure( int width = (int) (previewSize.getHeight() * ratio);
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), super.onMeasure(
heightMeasureSpec MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
); heightMeasureSpec
return; );
} else if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) { return;
int width = MeasureSpec.getSize(widthMeasureSpec); } else if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) {
float ratio = (float) width / (float) previewSize.getHeight(); int width = MeasureSpec.getSize(widthMeasureSpec);
int height = (int) (previewSize.getWidth() * ratio); float ratio = (float) width / (float) previewSize.getHeight();
super.onMeasure( int height = (int) (previewSize.getWidth() * ratio);
widthMeasureSpec, super.onMeasure(
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY) widthMeasureSpec,
); MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
);
return;
}
}else{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
return; return;
} }
} }

Loading…
Cancel
Save