simply test

pull/386/head
Mevin Dhunnooa 7 years ago
parent e268d968e9
commit 91e1159aaf
  1. 18
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/IntegrationTest.java
  2. 19
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java

@ -88,6 +88,15 @@ public class IntegrationTest extends BaseTest {
controller.mCrashHandler = crashThread.get();
}
@Test
public void testPreviewOrientationOnRotation(){
waitForOpen(true);
controller.setDeviceOrientation(270);
assertEquals(controller.getCameraOrientation(), 0);
controller.setDeviceOrientation(0);
assertEquals(controller.getCameraOrientation(), 90);
}
@After
public void tearDown() throws Exception {
camera.stopVideo();
@ -158,14 +167,7 @@ public class IntegrationTest extends BaseTest {
//region test open/close
@Test
public void testPreviewSizeOnOrientationChange() {
waitForOpen(true);
controller.setDeviceOrientation(90);
assertTrue(controller.mPreviewSize.getWidth() > controller.mPreviewSize.getHeight());
controller.setDeviceOrientation(0);
assertTrue(controller.mPreviewSize.getWidth() < controller.mPreviewSize.getHeight());
}
@Test
public void testOpenClose() throws Exception {

@ -165,15 +165,22 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
void setDeviceOrientation(int deviceOrientation) {
super.setDeviceOrientation(deviceOrientation);
if (mCamera != null && mPreview != null) {
if (this.getDeviceOrientation() == 270)
mCamera.setDisplayOrientation(0);
else if (this.getDeviceOrientation() == 90)
mCamera.setDisplayOrientation(180);
else if (this.getDeviceOrientation() == 0)
mCamera.setDisplayOrientation(90);
int cameraOrientation = getCameraOrientation();
mCamera.setDisplayOrientation(cameraOrientation);
}
}
public int getCameraOrientation(){
if (this.getDeviceOrientation() == 270)
return 0;
else if (this.getDeviceOrientation() == 90)
return 180;
else if (this.getDeviceOrientation() == 0)
return 90;
return 270;
}
// To be called when the preview size is setup or changed.
private void startPreview(String log) {
LOG.i(log, "Dispatching onCameraPreviewSizeChanged.");

Loading…
Cancel
Save