Merge pull request #81 from ANPez/master

Fix Android Studio preview error using isInEditMode
pull/1/head
Dylan McIntyre 8 years ago committed by GitHub
commit 0affe235d9
  1. 58
      camerakit/src/main/java/com/flurgle/camerakit/CameraView.java

@ -151,44 +151,50 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
setPermissions(mPermissions); setPermissions(mPermissions);
setVideoQuality(mVideoQuality); setVideoQuality(mVideoQuality);
mDisplayOrientationDetector = new DisplayOrientationDetector(context) { if (!isInEditMode()) {
@Override mDisplayOrientationDetector = new DisplayOrientationDetector(context) {
public void onDisplayOrientationChanged(int displayOrientation) { @Override
mCameraImpl.setDisplayOrientation(displayOrientation); public void onDisplayOrientationChanged(int displayOrientation) {
mPreviewImpl.setDisplayOrientation(displayOrientation); mCameraImpl.setDisplayOrientation(displayOrientation);
} mPreviewImpl.setDisplayOrientation(displayOrientation);
};
final FocusMarkerLayout focusMarkerLayout = new FocusMarkerLayout(getContext());
addView(focusMarkerLayout);
focusMarkerLayout.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent motionEvent) {
int action = motionEvent.getAction();
if (motionEvent.getAction() == MotionEvent.ACTION_UP && mFocus == CameraKit.Constants.FOCUS_TAP_WITH_MARKER) {
focusMarkerLayout.focus(motionEvent.getX(), motionEvent.getY());
} }
};
mPreviewImpl.getView().dispatchTouchEvent(motionEvent); final FocusMarkerLayout focusMarkerLayout = new FocusMarkerLayout(getContext());
return true; addView(focusMarkerLayout);
} focusMarkerLayout.setOnTouchListener(new OnTouchListener() {
}); @Override
public boolean onTouch(View v, MotionEvent motionEvent) {
int action = motionEvent.getAction();
if (motionEvent.getAction() == MotionEvent.ACTION_UP && mFocus == CameraKit.Constants.FOCUS_TAP_WITH_MARKER) {
focusMarkerLayout.focus(motionEvent.getX(), motionEvent.getY());
}
mPreviewImpl.getView().dispatchTouchEvent(motionEvent);
return true;
}
});
}
mLifecycle = null; mLifecycle = null;
} }
@Override @Override
protected void onAttachedToWindow() { protected void onAttachedToWindow() {
super.onAttachedToWindow(); super.onAttachedToWindow();
mDisplayOrientationDetector.enable( if (!isInEditMode()) {
ViewCompat.isAttachedToWindow(this) mDisplayOrientationDetector.enable(
? DisplayManagerCompat.getInstance(getContext()).getDisplay(Display.DEFAULT_DISPLAY) ViewCompat.isAttachedToWindow(this)
: null ? DisplayManagerCompat.getInstance(getContext()).getDisplay(Display.DEFAULT_DISPLAY)
); : null
);
}
} }
@Override @Override
protected void onDetachedFromWindow() { protected void onDetachedFromWindow() {
mDisplayOrientationDetector.disable(); if (!isInEditMode()) {
mDisplayOrientationDetector.disable();
}
super.onDetachedFromWindow(); super.onDetachedFromWindow();
} }

Loading…
Cancel
Save