Search in sources :

Example 1 with WritableMap

use of com.facebook.react.bridge.WritableMap in project gl-react-native by ProjectSeptemberInc.

the class GLCanvas method capture.

private void capture() {
    Bitmap capture = createSnapshot();
    ReactContext reactContext = (ReactContext) getContext();
    RCTEventEmitter eventEmitter = reactContext.getJSModule(RCTEventEmitter.class);
    for (CaptureConfig config : captureConfigs) {
        String result = null, error = null;
        boolean isPng = config.type.equals("png");
        boolean isJpeg = !isPng && (config.type.equals("jpg") || config.type.equals("jpeg"));
        boolean isWebm = !isPng && !isJpeg && config.type.equals("webm");
        boolean isBase64 = config.format.equals("base64");
        boolean isFile = !isBase64 && config.format.equals("file");
        Bitmap.CompressFormat compressFormat = isPng ? Bitmap.CompressFormat.PNG : isJpeg ? Bitmap.CompressFormat.JPEG : isWebm ? Bitmap.CompressFormat.WEBP : null;
        int quality = (int) (100 * config.quality);
        if (compressFormat == null) {
            error = "Unsupported capture type '" + config.type + "'";
        } else if (isBase64) {
            try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                capture.compress(compressFormat, quality, baos);
                String frame = "data:image/png;base64," + Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT);
                baos.close();
                result = frame;
            } catch (Exception e) {
                e.printStackTrace();
                error = "Could not capture as base64: " + e.getMessage();
            }
        } else if (isFile) {
            try {
                FileOutputStream fileOutputStream = new FileOutputStream(config.filePath);
                capture.compress(compressFormat, quality, fileOutputStream);
                fileOutputStream.close();
                result = "file://" + config.filePath;
            } catch (Exception e) {
                e.printStackTrace();
                error = "Could not write file: " + e.getMessage();
            }
        } else {
            error = "Unsupported capture format '" + config.format + "'";
        }
        WritableMap response = Arguments.createMap();
        response.putMap("config", config.toMap());
        if (error != null)
            response.putString("error", error);
        if (result != null)
            response.putString("result", result);
        eventEmitter.receiveEvent(getId(), "captureFrame", response);
    }
    captureConfigs = new ArrayList<>();
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) RCTEventEmitter(com.facebook.react.uimanager.events.RCTEventEmitter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GLException(android.opengl.GLException) Bitmap(android.graphics.Bitmap) ReactContext(com.facebook.react.bridge.ReactContext) ThemedReactContext(com.facebook.react.uimanager.ThemedReactContext) FileOutputStream(java.io.FileOutputStream)

Example 2 with WritableMap

use of com.facebook.react.bridge.WritableMap in project gl-react-native by ProjectSeptemberInc.

the class GLCanvas method dispatchOnLoad.

private void dispatchOnLoad() {
    WritableMap event = Arguments.createMap();
    ReactContext reactContext = (ReactContext) getContext();
    reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "load", event);
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) ReactContext(com.facebook.react.bridge.ReactContext) ThemedReactContext(com.facebook.react.uimanager.ThemedReactContext) RCTEventEmitter(com.facebook.react.uimanager.events.RCTEventEmitter)

Example 3 with WritableMap

use of com.facebook.react.bridge.WritableMap in project gl-react-native by ProjectSeptemberInc.

the class GLCanvas method dispatchOnProgress.

private void dispatchOnProgress(double progress, int loaded, int total) {
    WritableMap event = Arguments.createMap();
    event.putDouble("progress", Double.isNaN(progress) ? 0.0 : progress);
    event.putInt("loaded", loaded);
    event.putInt("total", total);
    ReactContext reactContext = (ReactContext) getContext();
    reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "progress", event);
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) ReactContext(com.facebook.react.bridge.ReactContext) ThemedReactContext(com.facebook.react.uimanager.ThemedReactContext) RCTEventEmitter(com.facebook.react.uimanager.events.RCTEventEmitter)

Example 4 with WritableMap

use of com.facebook.react.bridge.WritableMap in project gl-react-native by ProjectSeptemberInc.

the class CaptureConfig method toMap.

public WritableMap toMap() {
    WritableMap map = Arguments.createMap();
    map.putString("format", format);
    map.putString("type", type);
    map.putString("filePath", filePath);
    map.putDouble("quality", quality);
    return map;
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap)

Example 5 with WritableMap

use of com.facebook.react.bridge.WritableMap in project native-navigation by airbnb.

the class NativeFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_native, container, false);
    final int count = getArguments().getInt(ARG_COUNT);
    Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
    toolbar.setTitle("Fragment " + count);
    toolbar.setNavigationIcon(R.drawable.n2_ic_arrow_back_white);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().onBackPressed();
        }
    });
    view.findViewById(R.id.push).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getScreenCoordinator().pushScreen(newInstance(count + 1));
        }
    });
    view.findViewById(R.id.present).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Promise promise = new PromiseImpl(new Callback() {

                @Override
                public void invoke(Object... args) {
                    WritableMap map = (WritableMap) args[0];
                    ReadableMap payload = map.getMap("payload");
                    if (payload != null) {
                        String text = "Result: " + payload.getString(RESULT_TEXT);
                        Toast.makeText(getContext(), text, Toast.LENGTH_LONG).show();
                    }
                }
            }, new Callback() {

                @Override
                public void invoke(Object... args) {
                    Toast.makeText(getContext(), "Promise was rejected.", Toast.LENGTH_LONG).show();
                }
            });
            getScreenCoordinator().presentScreen(newInstance(0), promise);
        }
    });
    view.findViewById(R.id.push_rn).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getScreenCoordinator().pushScreen("ScreenOne");
        }
    });
    view.findViewById(R.id.present_rn).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getScreenCoordinator().presentScreen("ScreenOne");
        }
    });
    view.findViewById(R.id.pop).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getScreenCoordinator().pop();
        }
    });
    final EditText editText = (EditText) view.findViewById(R.id.payload);
    view.findViewById(R.id.dismiss).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Map<String, Object> payload = new HashMap<>();
            payload.put(RESULT_TEXT, editText.getText().toString());
            getScreenCoordinator().dismiss(Activity.RESULT_OK, payload);
        }
    });
    return view;
}
Also used : EditText(android.widget.EditText) WritableMap(com.facebook.react.bridge.WritableMap) AppCompatActivity(android.support.v7.app.AppCompatActivity) View(android.view.View) PromiseImpl(com.facebook.react.bridge.PromiseImpl) Promise(com.facebook.react.bridge.Promise) Callback(com.facebook.react.bridge.Callback) ReadableMap(com.facebook.react.bridge.ReadableMap) ReadableMap(com.facebook.react.bridge.ReadableMap) HashMap(java.util.HashMap) Map(java.util.Map) WritableMap(com.facebook.react.bridge.WritableMap) Toolbar(android.support.v7.widget.Toolbar) Nullable(android.support.annotation.Nullable)

Aggregations

WritableMap (com.facebook.react.bridge.WritableMap)46 ReactContext (com.facebook.react.bridge.ReactContext)5 ThemedReactContext (com.facebook.react.uimanager.ThemedReactContext)4 RCTEventEmitter (com.facebook.react.uimanager.events.RCTEventEmitter)3 Intent (android.content.Intent)2 MediaMetadataRetriever (android.media.MediaMetadataRetriever)2 View (android.view.View)2 Callback (com.facebook.react.bridge.Callback)2 WritableNativeMap (com.facebook.react.bridge.WritableNativeMap)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Activity (android.app.Activity)1 BroadcastReceiver (android.content.BroadcastReceiver)1 ContentValues (android.content.ContentValues)1 Context (android.content.Context)1 IntentFilter (android.content.IntentFilter)1 AssetFileDescriptor (android.content.res.AssetFileDescriptor)1 Bitmap (android.graphics.Bitmap)1 Camera (android.hardware.Camera)1 Uri (android.net.Uri)1