Search in sources :

Example 1 with Size

use of com.google.android.cameraview.Size in project react-native-camera by lwansbrough.

the class CameraModule method getAvailablePictureSizes.

@ReactMethod
public void getAvailablePictureSizes(final String ratio, final int viewTag, final Promise promise) {
    final ReactApplicationContext context = getReactApplicationContext();
    UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {

        @Override
        public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
            final RNCameraView cameraView;
            try {
                cameraView = (RNCameraView) nativeViewHierarchyManager.resolveView(viewTag);
                WritableArray result = Arguments.createArray();
                if (cameraView.isCameraOpened()) {
                    SortedSet<Size> sizes = cameraView.getAvailablePictureSizes(AspectRatio.parse(ratio));
                    for (Size size : sizes) {
                        result.pushString(size.toString());
                    }
                    promise.resolve(result);
                } else {
                    promise.reject("E_CAMERA_UNAVAILABLE", "Camera is not running");
                }
            } catch (Exception e) {
                promise.reject("E_CAMERA_BAD_VIEWTAG", "getAvailablePictureSizesAsync: Expected a Camera component");
            }
        }
    });
}
Also used : UIBlock(com.facebook.react.uimanager.UIBlock) UIManagerModule(com.facebook.react.uimanager.UIManagerModule) Size(com.google.android.cameraview.Size) SortedSet(java.util.SortedSet) NativeViewHierarchyManager(com.facebook.react.uimanager.NativeViewHierarchyManager)

Example 2 with Size

use of com.google.android.cameraview.Size in project react-native-camera by react-native-community.

the class CameraModule method getAvailablePictureSizes.

@ReactMethod
public void getAvailablePictureSizes(final String ratio, final int viewTag, final Promise promise) {
    final ReactApplicationContext context = getReactApplicationContext();
    UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {

        @Override
        public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
            final RNCameraView cameraView;
            try {
                cameraView = (RNCameraView) nativeViewHierarchyManager.resolveView(viewTag);
                WritableArray result = Arguments.createArray();
                if (cameraView.isCameraOpened()) {
                    SortedSet<Size> sizes = cameraView.getAvailablePictureSizes(AspectRatio.parse(ratio));
                    for (Size size : sizes) {
                        result.pushString(size.toString());
                    }
                    promise.resolve(result);
                } else {
                    promise.reject("E_CAMERA_UNAVAILABLE", "Camera is not running");
                }
            } catch (Exception e) {
                promise.reject("E_CAMERA_BAD_VIEWTAG", "getAvailablePictureSizesAsync: Expected a Camera component");
            }
        }
    });
}
Also used : UIBlock(com.facebook.react.uimanager.UIBlock) UIManagerModule(com.facebook.react.uimanager.UIManagerModule) Size(com.google.android.cameraview.Size) SortedSet(java.util.SortedSet) NativeViewHierarchyManager(com.facebook.react.uimanager.NativeViewHierarchyManager)

Aggregations

NativeViewHierarchyManager (com.facebook.react.uimanager.NativeViewHierarchyManager)2 UIBlock (com.facebook.react.uimanager.UIBlock)2 UIManagerModule (com.facebook.react.uimanager.UIManagerModule)2 Size (com.google.android.cameraview.Size)2 SortedSet (java.util.SortedSet)2