Merge pull request #24 from dataticket/master

fix CalledFromWrongThreadException in setTruePreviewSize(80)
pull/1/head
Dylan McIntyre 8 years ago committed by GitHub
commit 3eb3c72811
  1. 42
      camerakit/src/main/base/com/flurgle/camerakit/PreviewImpl.java

@ -61,28 +61,32 @@ abstract class PreviewImpl {
return mHeight;
}
void setTruePreviewSize(int width, int height) {
void setTruePreviewSize(final int width, final int height) {
this.mTrueWidth = width;
this.mTrueHeight = height;
if (width != 0 && height != 0) {
AspectRatio aspectRatio = AspectRatio.of(width, height);
int targetHeight = (int) (getView().getWidth() * aspectRatio.toFloat());
float scaleY;
if (getView().getHeight() > 0) {
scaleY = (float) targetHeight / (float) getView().getHeight();
} else {
scaleY = 1;
}
if (scaleY > 1) {
getView().setScaleX(1);
getView().setScaleY(scaleY);
} else {
getView().setScaleX(1 / scaleY);
getView().setScaleY(1);
getView().post(new Runnable() {
@Override
public void run() {
if (width != 0 && height != 0) {
AspectRatio aspectRatio = AspectRatio.of(width, height);
int targetHeight = (int) (getView().getWidth() * aspectRatio.toFloat());
float scaleY;
if (getView().getHeight() > 0) {
scaleY = (float) targetHeight / (float) getView().getHeight();
} else {
scaleY = 1;
}
if (scaleY > 1) {
getView().setScaleX(1);
getView().setScaleY(scaleY);
} else {
getView().setScaleX(1 / scaleY);
getView().setScaleY(1);
}
}
}
}
});
}
int getTrueWidth() {

Loading…
Cancel
Save