Better camera preview rotation
This commit is contained in:
parent
ed53b8b62e
commit
a2d010cfcc
2 changed files with 25 additions and 16 deletions
|
@ -267,7 +267,7 @@ public class DialerActivity extends Activity implements LinphoneGuiListener {
|
|||
if (mCamera == null) {
|
||||
mCamera = Camera.open(mCurrentCameraId);
|
||||
}
|
||||
mVideoCaptureView.setCamera(mCamera);
|
||||
mVideoCaptureView.setCamera(mCamera, mCurrentCameraId);
|
||||
mCamera.startPreview();
|
||||
}
|
||||
|
||||
|
@ -281,10 +281,10 @@ public class DialerActivity extends Activity implements LinphoneGuiListener {
|
|||
public void onClick(View v) {
|
||||
mCurrentCameraId = (mCurrentCameraId + 1) % numberOfCameras;
|
||||
mCamera.release();
|
||||
mVideoCaptureView.setCamera(null);
|
||||
mVideoCaptureView.setCamera(null, -1);
|
||||
|
||||
mCamera = Camera.open(mCurrentCameraId);
|
||||
mVideoCaptureView.switchCamera(mCamera);
|
||||
mVideoCaptureView.switchCamera(mCamera, mCurrentCameraId);
|
||||
mCamera.startPreview();
|
||||
}
|
||||
});
|
||||
|
@ -315,7 +315,7 @@ public class DialerActivity extends Activity implements LinphoneGuiListener {
|
|||
|
||||
if (mCamera != null) {
|
||||
mCamera.release();
|
||||
mVideoCaptureView.setCamera(null);
|
||||
mVideoCaptureView.setCamera(null, -1);
|
||||
mCamera = null;
|
||||
}
|
||||
}
|
||||
|
@ -448,7 +448,7 @@ public class DialerActivity extends Activity implements LinphoneGuiListener {
|
|||
if (mVideoCaptureView != null && mCamera == null && !LinphoneManager.getLc().isIncall())
|
||||
{
|
||||
mCamera = Camera.open(mCurrentCameraId);
|
||||
mVideoCaptureView.switchCamera(mCamera);
|
||||
mVideoCaptureView.switchCamera(mCamera, mCurrentCameraId);
|
||||
mCamera.startPreview();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,9 @@ package org.linphone.ui;
|
|||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.linphone.core.Log;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.Camera;
|
||||
import android.hardware.Camera.CameraInfo;
|
||||
import android.hardware.Camera.Size;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Display;
|
||||
|
@ -46,17 +45,19 @@ public class CameraView extends ViewGroup implements SurfaceHolder.Callback {
|
|||
Size mPreviewSize;
|
||||
List<Size> mSupportedSizes;
|
||||
Camera mCamera;
|
||||
int mCameraId;
|
||||
|
||||
public void setCamera(Camera camera) {
|
||||
public void setCamera(Camera camera, int id) {
|
||||
mCamera = camera;
|
||||
mCameraId = id;
|
||||
if (mCamera != null) {
|
||||
mSupportedSizes = mCamera.getParameters().getSupportedPreviewSizes();
|
||||
requestLayout();
|
||||
}
|
||||
}
|
||||
|
||||
public void switchCamera(Camera camera) {
|
||||
setCamera(camera);
|
||||
public void switchCamera(Camera camera, int id) {
|
||||
setCamera(camera, id);
|
||||
try {
|
||||
camera.setPreviewDisplay(mHolder);
|
||||
} catch (IOException exception) {
|
||||
|
@ -77,13 +78,12 @@ public class CameraView extends ViewGroup implements SurfaceHolder.Callback {
|
|||
if (mSupportedSizes != null) {
|
||||
mPreviewSize = getOptimalPreviewSize(mSupportedSizes, width, height);
|
||||
}
|
||||
|
||||
Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
|
||||
if (display.getRotation() == Surface.ROTATION_90 || display.getRotation() == Surface.ROTATION_270) {
|
||||
Size tempSize = mPreviewSize;
|
||||
mPreviewSize.width = tempSize.height;
|
||||
mPreviewSize.height = tempSize.width;
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,17 +166,26 @@ public class CameraView extends ViewGroup implements SurfaceHolder.Callback {
|
|||
Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
|
||||
Camera.Parameters parameters = mCamera.getParameters();
|
||||
|
||||
int rotation = 0;
|
||||
if(display.getRotation() == Surface.ROTATION_90) {
|
||||
mCamera.setDisplayOrientation(270);
|
||||
rotation = 90;
|
||||
}
|
||||
else if(display.getRotation() == Surface.ROTATION_270) {
|
||||
mCamera.setDisplayOrientation(90);
|
||||
rotation = 270;
|
||||
}
|
||||
else if (display.getRotation() == Surface.ROTATION_180) {
|
||||
mCamera.setDisplayOrientation(180);
|
||||
rotation = 180;
|
||||
}
|
||||
requestLayout();
|
||||
|
||||
CameraInfo cameraInfo = new CameraInfo();
|
||||
Camera.getCameraInfo(mCameraId, cameraInfo);
|
||||
if (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) {
|
||||
mCamera.setDisplayOrientation((cameraInfo.orientation - rotation + 360) % 360);
|
||||
} else {
|
||||
mCamera.setDisplayOrientation((cameraInfo.orientation + rotation) % 360);
|
||||
}
|
||||
|
||||
requestLayout();
|
||||
mCamera.setParameters(parameters);
|
||||
mCamera.startPreview();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue