CameraCallbacks tests

pull/37/head
Mattia Iavarone 8 years ago
parent 64a02a9d33
commit bd6d8cdaa5
  1. 37
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/BaseTest.java
  2. 301
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraCallbacksTest.java
  3. 2
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewTest.java
  4. 42
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/CropHelperTest.java
  5. 5
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/MockPreview.java
  6. 22
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/PinchGestureLayoutTest.java
  7. 4
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/PreviewTest.java
  8. 9
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/ScrollGestureLayoutTest.java
  9. 10
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/TapGestureLayoutTest.java
  10. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  11. 16
      cameraview/src/main/utils/com/otaliastudios/cameraview/Task.java

@ -2,6 +2,9 @@ package com.otaliastudios.cameraview;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.YuvImage;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
@ -11,6 +14,16 @@ import android.view.View;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class BaseTest { public class BaseTest {
@ -38,4 +51,28 @@ public class BaseTest {
public static void waitUi() { public static void waitUi() {
InstrumentationRegistry.getInstrumentation().waitForIdleSync(); InstrumentationRegistry.getInstrumentation().waitForIdleSync();
} }
public static byte[] mockJpeg(int width, int height) {
Bitmap source = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
ByteArrayOutputStream os = new ByteArrayOutputStream();
source.compress(Bitmap.CompressFormat.JPEG, 100, os);
return os.toByteArray();
}
public static YuvImage mockYuv(int width, int height) {
YuvImage y = mock(YuvImage.class);
when(y.getWidth()).thenReturn(width);
when(y.getHeight()).thenReturn(height);
when(y.compressToJpeg(any(Rect.class), anyInt(), any(OutputStream.class))).thenAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
Rect rect = (Rect) invocation.getArguments()[0];
OutputStream stream = (OutputStream) invocation.getArguments()[2];
stream.write(mockJpeg(rect.width(), rect.height()));
return true;
}
});
return y;
}
} }

@ -0,0 +1,301 @@
package com.otaliastudios.cameraview;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.YuvImage;
import android.support.test.filters.MediumTest;
import android.support.test.runner.AndroidJUnit4;
import android.view.ViewGroup;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyFloat;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(AndroidJUnit4.class)
@MediumTest
public class CameraCallbacksTest extends BaseTest {
private CameraView camera;
private CameraView.CameraCallbacks callbacks;
private CameraListener listener;
private MockCameraController mockController;
private MockPreview mockPreview;
private Task<Boolean> task;
@Before
public void setUp() {
ui(new Runnable() {
@Override
public void run() {
Context context = context();
listener = mock(CameraListener.class);
camera = new CameraView(context) {
@Override
protected CameraController instantiateCameraController(CameraCallbacks callbacks, Preview preview) {
mockController = new MockCameraController(callbacks, preview);
return mockController;
}
@Override
protected Preview instantiatePreview(Context context, ViewGroup container) {
mockPreview = new MockPreview(context, container);
return mockPreview;
}
@Override
protected boolean checkPermissions(SessionType sessionType) {
return true;
}
};
camera.addCameraListener(listener);
callbacks = camera.mCameraCallbacks;
task = new Task<>();
task.listen();
}
});
}
@After
public void tearDown() {
camera.removeCameraListener(listener);
camera = null;
mockController = null;
mockPreview = null;
callbacks = null;
listener = null;
}
// Completes our task.
private Answer completeTask() {
return new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
task.end(true);
return null;
}
};
}
@Test
public void testDontDispatchIfRemoved() {
camera.removeCameraListener(listener);
doAnswer(completeTask()).when(listener).onCameraOpened(null);
callbacks.dispatchOnCameraOpened(null);
assertNull(task.await(200));
verify(listener, never()).onCameraOpened(null);
}
@Test
public void testDontDispatchIfCleared() {
camera.clearCameraListeners();
doAnswer(completeTask()).when(listener).onCameraOpened(null);
callbacks.dispatchOnCameraOpened(null);
assertNull(task.await(200));
verify(listener, never()).onCameraOpened(null);
}
@Test
public void testDispatchOnCameraOpened() {
doAnswer(completeTask()).when(listener).onCameraOpened(null);
callbacks.dispatchOnCameraOpened(null);
assertNotNull(task.await(200));
verify(listener, times(1)).onCameraOpened(null);
}
@Test
public void testDispatchOnCameraClosed() {
doAnswer(completeTask()).when(listener).onCameraClosed();
callbacks.dispatchOnCameraClosed();
assertNotNull(task.await(200));
verify(listener, times(1)).onCameraClosed();
}
@Test
public void testDispatchOnVideoTaken() {
doAnswer(completeTask()).when(listener).onVideoTaken(null);
callbacks.dispatchOnVideoTaken(null);
assertNotNull(task.await(200));
verify(listener, times(1)).onVideoTaken(null);
}
@Test
public void testDispatchOnZoomChanged() {
doAnswer(completeTask()).when(listener).onZoomChanged(anyFloat(), any(float[].class), any(PointF[].class));
callbacks.dispatchOnZoomChanged(0f, null);
assertNotNull(task.await(200));
verify(listener, times(1)).onZoomChanged(anyFloat(), any(float[].class), any(PointF[].class));
}
@Test
public void testDispatchOnExposureCorrectionChanged() {
doAnswer(completeTask()).when(listener).onExposureCorrectionChanged(0f, null, null);
callbacks.dispatchOnExposureCorrectionChanged(0f, null, null);
assertNotNull(task.await(200));
verify(listener, times(1)).onExposureCorrectionChanged(0f, null, null);
}
@Test
public void testDispatchOnFocusStart() {
// Enable tap gesture.
// Can't mock package protected. camera.mTapGestureLayout = mock(TapGestureLayout.class);
camera.mapGesture(Gesture.TAP, GestureAction.FOCUS_WITH_MARKER);
PointF point = new PointF();
doAnswer(completeTask()).when(listener).onFocusStart(point);
callbacks.dispatchOnFocusStart(Gesture.TAP, point);
assertNotNull(task.await(200));
verify(listener, times(1)).onFocusStart(point);
// Can't mock package protected. verify(camera.mTapGestureLayout, times(1)).onFocusStart(point);
}
@Test
public void testDispatchOnFocusEnd() {
// Enable tap gesture.
// Can't mock package protected. camera.mTapGestureLayout = mock(TapGestureLayout.class);
camera.mapGesture(Gesture.TAP, GestureAction.FOCUS_WITH_MARKER);
PointF point = new PointF();
boolean success = true;
doAnswer(completeTask()).when(listener).onFocusEnd(success, point);
callbacks.dispatchOnFocusEnd(Gesture.TAP, success, point);
assertNotNull(task.await(200));
verify(listener, times(1)).onFocusEnd(success, point);
// Can't mock package protected. verify(camera.mTapGestureLayout, times(1)).onFocusEnd(success);
}
@Test
public void testOrientationCallbacks_deviceOnly() {
doAnswer(completeTask()).when(listener).onOrientationChanged(anyInt());
// Assert not called. Both methods must be called.
callbacks.onDeviceOrientationChanged(0);
assertNull(task.await(200));
verify(listener, never()).onOrientationChanged(anyInt());
}
@Test
public void testOrientationCallbacks_displayOnly() {
doAnswer(completeTask()).when(listener).onOrientationChanged(anyInt());
// Assert not called. Both methods must be called.
callbacks.onDisplayOffsetChanged(0);
assertNull(task.await(200));
verify(listener, never()).onOrientationChanged(anyInt());
}
@Test
public void testOrientationCallbacks_both() {
doAnswer(completeTask()).when(listener).onOrientationChanged(anyInt());
// Assert called.
callbacks.onDisplayOffsetChanged(0);
callbacks.onDeviceOrientationChanged(90);
assertNotNull(task.await(200));
verify(listener, times(1)).onOrientationChanged(anyInt());
}
@Test
public void testProcessJpeg() {
int[] viewDim = new int[]{ 200, 200 };
int[] imageDim = new int[]{ 1000, 1600 };
// With crop flag: expect a 1:1 ratio.
int[] output = testProcessImage(true, true, viewDim, imageDim);
assertEquals(output[0], 1000);
assertEquals(output[1], 1000);
// Without crop flag: expect original ratio.
output = testProcessImage(true, false, viewDim, imageDim);
assertEquals(output[0], imageDim[0]);
assertEquals(output[1], imageDim[1]);
}
@Test
public void testProcessYuv() {
int[] viewDim = new int[]{ 200, 200 };
int[] imageDim = new int[]{ 1000, 1600 };
// With crop flag: expect a 1:1 ratio.
int[] output = testProcessImage(false, true, viewDim, imageDim);
assertEquals(output[0], 1000);
assertEquals(output[1], 1000);
// Without crop flag: expect original ratio.
output = testProcessImage(false, false, viewDim, imageDim);
assertEquals(output[0], imageDim[0]);
assertEquals(output[1], imageDim[1]);
}
private int[] testProcessImage(boolean jpeg, boolean crop, int[] viewDim, int[] imageDim) {
// End our task when onPictureTaken is called. Take note of the result.
final Task<byte[]> jpegTask = new Task<>();
jpegTask.listen();
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
jpegTask.end((byte[]) invocation.getArguments()[0]);
return null;
}
}).when(listener).onPictureTaken(any(byte[].class));
// Fake our own dimensions.
camera.setTop(0);
camera.setBottom(viewDim[1]);
camera.setLeft(0);
camera.setRight(viewDim[0]);
// Ensure the image will (not) be cropped.
camera.setCropOutput(crop);
mockPreview.setIsCropping(crop);
// Create fake JPEG array and trigger the process.
if (jpeg) {
callbacks.processImage(mockJpeg(imageDim[0], imageDim[1]), true, false);
} else {
callbacks.processSnapshot(mockYuv(imageDim[0], imageDim[1]), true, false);
}
// Wait for result and get out dimensions.
byte[] result = jpegTask.await(800);
assertNotNull(result);
Bitmap bitmap = BitmapFactory.decodeByteArray(result, 0, result.length);
return new int[]{ bitmap.getWidth(), bitmap.getHeight() };
}
}

@ -40,7 +40,7 @@ public class CameraViewTest extends BaseTest {
ui(new Runnable() { ui(new Runnable() {
@Override @Override
public void run() { public void run() {
Context context = InstrumentationRegistry.getContext(); Context context = context();
cameraView = new CameraView(context) { cameraView = new CameraView(context) {
@Override @Override
protected CameraController instantiateCameraController(CameraCallbacks callbacks, Preview preview) { protected CameraController instantiateCameraController(CameraCallbacks callbacks, Preview preview) {

@ -30,7 +30,7 @@ import static org.mockito.Mockito.when;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@SmallTest @SmallTest
public class CropHelperTest { public class CropHelperTest extends BaseTest {
@Test @Test
public void testCropFromYuv() { public void testCropFromYuv() {
@ -38,46 +38,30 @@ public class CropHelperTest {
testCropFromYuv(1600, 1600, AspectRatio.of(9, 16)); testCropFromYuv(1600, 1600, AspectRatio.of(9, 16));
} }
@Test
public void testCropFromJpeg() {
testCropFromJpeg(1600, 1600, AspectRatio.of(16, 9));
testCropFromJpeg(1600, 1600, AspectRatio.of(9, 16));
}
private void testCropFromYuv(final int w, final int h, final AspectRatio target) { private void testCropFromYuv(final int w, final int h, final AspectRatio target) {
final boolean wider = target.toFloat() > ((float) w / (float) h); final boolean wider = target.toFloat() > ((float) w / (float) h);
byte[] b = CropHelper.cropToJpeg(mockYuv(w, h), target, 100);
// Not sure how to test YuvImages... Bitmap result = BitmapFactory.decodeByteArray(b, 0, b.length);
YuvImage i = mock(YuvImage.class);
when(i.getWidth()).thenReturn(w);
when(i.getHeight()).thenReturn(h);
when(i.compressToJpeg(any(Rect.class), anyInt(), any(OutputStream.class))).thenAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock iom) throws Throwable {
Object[] args = iom.getArguments();
Rect rect = (Rect) args[0];
// Assert. // Assert.
AspectRatio ratio = AspectRatio.of(rect.width(), rect.height()); AspectRatio ratio = AspectRatio.of(result.getWidth(), result.getHeight());
assertEquals(target, ratio); assertEquals(target, ratio);
if (wider) { // width must match. if (wider) { // width must match.
assertEquals(rect.width(), w); assertEquals(result.getWidth(), w);
} else { } else {
assertEquals(rect.height(), h); assertEquals(result.getHeight(), h);
}
return true;
} }
});
CropHelper.cropToJpeg(i, target, 100);
}
@Test
public void testCropFromJpeg() {
testCropFromJpeg(1600, 1600, AspectRatio.of(16, 9));
testCropFromJpeg(1600, 1600, AspectRatio.of(9, 16));
} }
private void testCropFromJpeg(int w, int h, AspectRatio target) { private void testCropFromJpeg(int w, int h, AspectRatio target) {
final boolean wider = target.toFloat() > ((float) w / (float) h); final boolean wider = target.toFloat() > ((float) w / (float) h);
byte[] b = CropHelper.cropToJpeg(mockJpeg(w, h), target, 100);
Bitmap source = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
ByteArrayOutputStream os = new ByteArrayOutputStream();
source.compress(Bitmap.CompressFormat.JPEG, 100, os);
byte[] b = CropHelper.cropToJpeg(os.toByteArray(), target, 100);
Bitmap result = BitmapFactory.decodeByteArray(b, 0, b.length); Bitmap result = BitmapFactory.decodeByteArray(b, 0, b.length);
// Assert. // Assert.

@ -13,6 +13,11 @@ public class MockPreview extends Preview<View, Void> {
super(context, parent, null); super(context, parent, null);
} }
public void setIsCropping(boolean crop) {
getView().setScaleX(crop ? 2 : 1);
getView().setScaleY(crop ? 2 : 1);
}
@NonNull @NonNull
@Override @Override
protected View onCreateView(Context context, ViewGroup parent) { protected View onCreateView(Context context, ViewGroup parent) {

@ -2,33 +2,13 @@ package com.otaliastudios.cameraview;
import android.content.Context; import android.content.Context;
import android.support.test.espresso.Espresso;
import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction; import android.support.test.espresso.ViewAction;
import android.support.test.espresso.action.CoordinatesProvider;
import android.support.test.espresso.action.GeneralLocation;
import android.support.test.espresso.action.GeneralSwipeAction;
import android.support.test.espresso.action.MotionEvents;
import android.support.test.espresso.action.PrecisionDescriber;
import android.support.test.espresso.action.Press;
import android.support.test.espresso.action.Swipe;
import android.support.test.espresso.action.ViewActions;
import android.support.test.espresso.assertion.ViewAssertions;
import android.support.test.espresso.matcher.ViewMatchers;
import android.support.test.filters.SmallTest; import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4; import android.support.test.runner.AndroidJUnit4;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import java.util.concurrent.TimeUnit;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.withId; import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@ -69,7 +49,7 @@ public class PinchGestureLayoutTest extends GestureLayoutTest<PinchGestureLayout
touch.listen(); touch.listen();
touch.start(); touch.start();
onLayout().perform(action); onLayout().perform(action);
Gesture found = touch.await(10000, TimeUnit.MILLISECONDS); Gesture found = touch.await(10000);
assertNotNull(found); assertNotNull(found);
// How will this move our parameter? // How will this move our parameter?

@ -13,8 +13,6 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
@ -57,7 +55,7 @@ public abstract class PreviewTest extends BaseTest {
// Wait for surface to be available. // Wait for surface to be available.
protected void ensureAvailable() { protected void ensureAvailable() {
assertNotNull(availability.await(2, TimeUnit.SECONDS)); assertNotNull(availability.await(2000));
} }
// Trigger a destroy. // Trigger a destroy.

@ -3,17 +3,12 @@ package com.otaliastudios.cameraview;
import android.content.Context; import android.content.Context;
import android.support.test.espresso.ViewAction; import android.support.test.espresso.ViewAction;
import android.support.test.espresso.assertion.ViewAssertions;
import android.support.test.filters.SmallTest; import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4; import android.support.test.runner.AndroidJUnit4;
import org.hamcrest.Matchers;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import java.util.concurrent.TimeUnit;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.swipeDown; import static android.support.test.espresso.action.ViewActions.swipeDown;
import static android.support.test.espresso.action.ViewActions.swipeLeft; import static android.support.test.espresso.action.ViewActions.swipeLeft;
@ -50,7 +45,7 @@ public class ScrollGestureLayoutTest extends GestureLayoutTest<ScrollGestureLayo
touch.listen(); touch.listen();
touch.start(); touch.start();
onLayout().perform(swipeUp()); onLayout().perform(swipeUp());
Gesture found = touch.await(500, TimeUnit.MILLISECONDS); Gesture found = touch.await(500);
assertNull(found); assertNull(found);
} }
@ -58,7 +53,7 @@ public class ScrollGestureLayoutTest extends GestureLayoutTest<ScrollGestureLayo
touch.listen(); touch.listen();
touch.start(); touch.start();
onLayout().perform(scroll); onLayout().perform(scroll);
Gesture found = touch.await(500, TimeUnit.MILLISECONDS); Gesture found = touch.await(500);
assertEquals(found, expected); assertEquals(found, expected);
// How will this move our parameter? // How will this move our parameter?

@ -14,10 +14,6 @@ import android.view.MotionEvent;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import java.util.concurrent.TimeUnit;
import static android.support.test.espresso.Espresso.*;
import static android.support.test.espresso.matcher.ViewMatchers.*;
import static android.support.test.espresso.action.ViewActions.*; import static android.support.test.espresso.action.ViewActions.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -46,7 +42,7 @@ public class TapGestureLayoutTest extends GestureLayoutTest<TapGestureLayout> {
Tap.SINGLE, GeneralLocation.CENTER, Press.FINGER, Tap.SINGLE, GeneralLocation.CENTER, Press.FINGER,
InputDevice.SOURCE_UNKNOWN, MotionEvent.BUTTON_PRIMARY); InputDevice.SOURCE_UNKNOWN, MotionEvent.BUTTON_PRIMARY);
onLayout().perform(a); onLayout().perform(a);
Gesture found = touch.await(500, TimeUnit.MILLISECONDS); Gesture found = touch.await(500);
assertEquals(found, Gesture.TAP); assertEquals(found, Gesture.TAP);
Size size = rule.getActivity().getContentSize(); Size size = rule.getActivity().getContentSize();
@ -60,7 +56,7 @@ public class TapGestureLayoutTest extends GestureLayoutTest<TapGestureLayout> {
touch.listen(); touch.listen();
touch.start(); touch.start();
onLayout().perform(click()); onLayout().perform(click());
Gesture found = touch.await(500, TimeUnit.MILLISECONDS); Gesture found = touch.await(500);
assertNull(found); assertNull(found);
} }
@ -72,7 +68,7 @@ public class TapGestureLayoutTest extends GestureLayoutTest<TapGestureLayout> {
Tap.LONG, GeneralLocation.CENTER, Press.FINGER, Tap.LONG, GeneralLocation.CENTER, Press.FINGER,
InputDevice.SOURCE_UNKNOWN, MotionEvent.BUTTON_PRIMARY); InputDevice.SOURCE_UNKNOWN, MotionEvent.BUTTON_PRIMARY);
onLayout().perform(a); onLayout().perform(a);
Gesture found = touch.await(500, TimeUnit.MILLISECONDS); Gesture found = touch.await(500);
assertEquals(found, Gesture.LONG_TAP); assertEquals(found, Gesture.LONG_TAP);
Size size = rule.getActivity().getContentSize(); Size size = rule.getActivity().getContentSize();
assertEquals(layout.getPoints()[0].x, (size.getWidth() / 2f), 1f); assertEquals(layout.getPoints()[0].x, (size.getWidth() / 2f), 1f);

@ -59,7 +59,7 @@ public class CameraView extends FrameLayout {
private HashMap<Gesture, GestureAction> mGestureMap = new HashMap<>(4); private HashMap<Gesture, GestureAction> mGestureMap = new HashMap<>(4);
// Components // Components
private CameraCallbacks mCameraCallbacks; CameraCallbacks mCameraCallbacks;
private OrientationHelper mOrientationHelper; private OrientationHelper mOrientationHelper;
private CameraController mCameraController; private CameraController mCameraController;
private Preview mPreviewImpl; private Preview mPreviewImpl;

@ -44,19 +44,15 @@ class Task<T> {
} }
} }
T await() { T await(long millis) {
try { return await(millis, TimeUnit.MILLISECONDS);
mLatch.await();
} catch (Exception e) {
e.printStackTrace();
} }
T result = mResult;
mResult = null; T await() {
mLatch = null; return await(1, TimeUnit.MINUTES);
return result;
} }
T await(long time, @NonNull TimeUnit unit) { private T await(long time, @NonNull TimeUnit unit) {
try { try {
mLatch.await(time, unit); mLatch.await(time, unit);
} catch (Exception e) { } catch (Exception e) {

Loading…
Cancel
Save