Fix Android Studio preview error using isInEditMode.

pull/1/head
Antonio Nicolás Pina 8 years ago
parent 4c2d2a271a
commit 5eff7e0eb4
  1. 58
      camerakit/src/main/java/com/flurgle/camerakit/CameraView.java

@ -110,43 +110,49 @@ public class CameraView extends FrameLayout {
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;
}
});
}
} }
@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