mirror of
https://github.com/status-im/react-native-camera.git
synced 2025-02-24 17:58:20 +00:00
Set the device orientation before instantiating RCTCamera (#368)
This commit is contained in:
parent
14836aef58
commit
1e581d7c97
@ -13,8 +13,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class RCTCamera {
|
public class RCTCamera {
|
||||||
|
private static RCTCamera ourInstance;
|
||||||
private static final RCTCamera ourInstance = new RCTCamera();
|
|
||||||
private final HashMap<Integer, CameraInfoWrapper> _cameraInfos;
|
private final HashMap<Integer, CameraInfoWrapper> _cameraInfos;
|
||||||
private final HashMap<Integer, Integer> _cameraTypeToIndex;
|
private final HashMap<Integer, Integer> _cameraTypeToIndex;
|
||||||
private final Map<Number, Camera> _cameras;
|
private final Map<Number, Camera> _cameras;
|
||||||
@ -25,6 +24,10 @@ public class RCTCamera {
|
|||||||
public static RCTCamera getInstance() {
|
public static RCTCamera getInstance() {
|
||||||
return ourInstance;
|
return ourInstance;
|
||||||
}
|
}
|
||||||
|
public static void createInstance(int deviceOrientation) {
|
||||||
|
ourInstance = new RCTCamera(deviceOrientation);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public Camera acquireCameraInstance(int type) {
|
public Camera acquireCameraInstance(int type) {
|
||||||
if (null == _cameras.get(type) && null != _cameraTypeToIndex.get(type)) {
|
if (null == _cameras.get(type) && null != _cameraTypeToIndex.get(type)) {
|
||||||
@ -333,11 +336,13 @@ public class RCTCamera {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private RCTCamera() {
|
private RCTCamera(int deviceOrientation) {
|
||||||
_cameras = new HashMap<>();
|
_cameras = new HashMap<>();
|
||||||
_cameraInfos = new HashMap<>();
|
_cameraInfos = new HashMap<>();
|
||||||
_cameraTypeToIndex = new HashMap<>();
|
_cameraTypeToIndex = new HashMap<>();
|
||||||
|
|
||||||
|
_actualDeviceOrientation = deviceOrientation;
|
||||||
|
|
||||||
// map camera types to camera indexes and collect cameras properties
|
// map camera types to camera indexes and collect cameras properties
|
||||||
for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
|
for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
|
||||||
Camera.CameraInfo info = new Camera.CameraInfo();
|
Camera.CameraInfo info = new Camera.CameraInfo();
|
||||||
|
@ -24,7 +24,7 @@ public class RCTCameraView extends ViewGroup {
|
|||||||
public RCTCameraView(Context context) {
|
public RCTCameraView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
this._context = context;
|
this._context = context;
|
||||||
setActualDeviceOrientation(context);
|
RCTCamera.createInstance(getDeviceOrientation(context));
|
||||||
|
|
||||||
_orientationListener = new OrientationEventListener(context, SensorManager.SENSOR_DELAY_NORMAL) {
|
_orientationListener = new OrientationEventListener(context, SensorManager.SENSOR_DELAY_NORMAL) {
|
||||||
@Override
|
@Override
|
||||||
@ -106,7 +106,7 @@ public class RCTCameraView extends ViewGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean setActualDeviceOrientation(Context context) {
|
private boolean setActualDeviceOrientation(Context context) {
|
||||||
int actualDeviceOrientation = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getOrientation();
|
int actualDeviceOrientation = getDeviceOrientation(context);
|
||||||
if (_actualDeviceOrientation != actualDeviceOrientation) {
|
if (_actualDeviceOrientation != actualDeviceOrientation) {
|
||||||
_actualDeviceOrientation = actualDeviceOrientation;
|
_actualDeviceOrientation = actualDeviceOrientation;
|
||||||
RCTCamera.getInstance().setActualDeviceOrientation(_actualDeviceOrientation);
|
RCTCamera.getInstance().setActualDeviceOrientation(_actualDeviceOrientation);
|
||||||
@ -116,6 +116,10 @@ public class RCTCameraView extends ViewGroup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getDeviceOrientation(Context context) {
|
||||||
|
return ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getOrientation();
|
||||||
|
}
|
||||||
|
|
||||||
private void layoutViewFinder() {
|
private void layoutViewFinder() {
|
||||||
layoutViewFinder(this.getLeft(), this.getTop(), this.getRight(), this.getBottom());
|
layoutViewFinder(this.getLeft(), this.getTop(), this.getRight(), this.getBottom());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user