Java Code Examples for com.facebook.react.bridge.ReadableMap.getInt()

The following are Jave code examples for showing how to use getInt() of the com.facebook.react.bridge.ReadableMap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: react-native-camera-face-detector   File: RCTCameraModule.java   Source Code and License Vote up 6 votes
@ReactMethod
public void capture(final ReadableMap options, final Promise promise) {
    int orientation = options.hasKey("orientation") ? options.getInt("orientation") : RCTCamera.getInstance().getOrientation();
    if (orientation == RCT_CAMERA_ORIENTATION_AUTO) {
        _sensorOrientationChecker.onResume();
        _sensorOrientationChecker.registerOrientationListener(new RCTSensorOrientationListener() {
            @Override
            public void orientationEvent() {
                int deviceOrientation = _sensorOrientationChecker.getOrientation();
                _sensorOrientationChecker.unregisterOrientationListener();
                _sensorOrientationChecker.onPause();
                captureWithOrientation(options, promise, deviceOrientation);
            }
        });
    } else {
        captureWithOrientation(options, promise, orientation);
    }
}
 
Example 2
Project: RNLearn_Project1   File: CatalystNativeJSToJavaParametersTestCase.java   Source Code and License Vote up 6 votes
private void mapGetByType(ReadableMap map, String key, String typeToAskFor) {
  if (typeToAskFor.equals("double")) {
    map.getDouble(key);
  } else if (typeToAskFor.equals("int")) {
    map.getInt(key);
  } else if (typeToAskFor.equals("string")) {
    map.getString(key);
  } else if (typeToAskFor.equals("array")) {
    map.getArray(key);
  } else if (typeToAskFor.equals("map")) {
    map.getMap(key);
  } else if (typeToAskFor.equals("boolean")) {
    map.getBoolean(key);
  } else {
    throw new RuntimeException("Unknown type: " + typeToAskFor);
  }
}
 
Example 3
Project: react-native-webrtc   File: WebRTCModule.java   Source Code and License Vote up 6 votes
@ReactMethod
public void peerConnectionAddICECandidate(ReadableMap candidateMap, final int id, final Callback callback) {
    boolean result = false;
    PeerConnection peerConnection = getPeerConnection(id);
    Log.d(TAG, "peerConnectionAddICECandidate() start");
    if (peerConnection != null) {
        IceCandidate candidate = new IceCandidate(
            candidateMap.getString("sdpMid"),
            candidateMap.getInt("sdpMLineIndex"),
            candidateMap.getString("candidate")
        );
        result = peerConnection.addIceCandidate(candidate);
    } else {
        Log.d(TAG, "peerConnectionAddICECandidate() peerConnection is null");
    }
    callback.invoke(result);
    Log.d(TAG, "peerConnectionAddICECandidate() end");
}
 
Example 4
Project: RNLearn_Project1   File: CameraRollManager.java   Source Code and License Vote up 6 votes
/**
 * Get photos from {@link MediaStore.Images}, most recent first.
 *
 * @param params a map containing the following keys:
 *        <ul>
 *          <li>first (mandatory): a number representing the number of photos to fetch</li>
 *          <li>
 *            after (optional): a cursor that matches page_info[end_cursor] returned by a
 *            previous call to {@link #getPhotos}
 *          </li>
 *          <li>groupName (optional): an album name</li>
 *          <li>
 *            mimeType (optional): restrict returned images to a specific mimetype (e.g.
 *            image/jpeg)
 *          </li>
 *        </ul>
 * @param promise the Promise to be resolved when the photos are loaded; for a format of the
 *        parameters passed to this callback, see {@code getPhotosReturnChecker} in CameraRoll.js
 */
@ReactMethod
public void getPhotos(final ReadableMap params, final Promise promise) {
  int first = params.getInt("first");
  String after = params.hasKey("after") ? params.getString("after") : null;
  String groupName = params.hasKey("groupName") ? params.getString("groupName") : null;
  ReadableArray mimeTypes = params.hasKey("mimeTypes")
      ? params.getArray("mimeTypes")
      : null;
  if (params.hasKey("groupTypes")) {
    throw new JSApplicationIllegalArgumentException("groupTypes is not supported on Android");
  }

  new GetPhotosTask(
        getReactApplicationContext(),
        first,
        after,
        groupName,
        mimeTypes,
        promise)
        .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
 
Example 5
Project: react-native-android-piliplayer   File: PLVideoTextureViewManager.java   Source Code and License Vote up 6 votes
/**
 * 设置source属性,包括是否是直播流,解码类型,准备时长,是否有缓存等
 *
 * @param plVideoTextureView
 * @param source
 */
@ReactProp(name = "source")
public void setSource(PLVideoTextureView plVideoTextureView, ReadableMap source) {
    AVOptions avOptions = new AVOptions();
     uri = source.getString("uri");//视频连接地址
    //得到解码类型
    int mediaCodec = source.hasKey("mediaCodec") ? source.getInt("mediaCodec") : AVOptions.MEDIA_CODEC_SW_DECODE;
    //得到视频准备时间
    int timeout = source.hasKey("timeout") ? source.getInt("timeout") : 10 * 1000;
    //得到是否是直播流
    boolean liveStreaming = source.hasKey("liveStreaming") ? source.getBoolean("liveStreaming") : false;
    //得到是否应用缓存
    boolean cache = source.hasKey("cache") ? source.getBoolean("cache") : false;
    boolean started=source.hasKey("started")?source.getBoolean("started"):true;
    avOptions.setInteger(AVOptions.KEY_MEDIACODEC, mediaCodec);
    avOptions.setInteger(AVOptions.KEY_PREPARE_TIMEOUT, timeout);
    avOptions.setInteger(AVOptions.KEY_LIVE_STREAMING, liveStreaming ? 1 : 0);
    if (!liveStreaming && cache) {
        avOptions.setString(AVOptions.KEY_CACHE_DIR, Config.DEFAULT_CACHE_DIR);
    }
    plVideoTextureView.setAVOptions(avOptions);
    //MediaController mediaController = new MediaController(themedReactContext, !liveStreaming, liveStreaming);
   // plVideoTextureView.setMediaController(mediaController);
    plVideoTextureView.setVideoPath(uri);
}
 
Example 6
Project: RNLearn_Project1   File: CameraRollManager.java   Source Code and License Vote up 6 votes
/**
 * Get photos from {@link MediaStore.Images}, most recent first.
 *
 * @param params a map containing the following keys:
 *        <ul>
 *          <li>first (mandatory): a number representing the number of photos to fetch</li>
 *          <li>
 *            after (optional): a cursor that matches page_info[end_cursor] returned by a
 *            previous call to {@link #getPhotos}
 *          </li>
 *          <li>groupName (optional): an album name</li>
 *          <li>
 *            mimeType (optional): restrict returned images to a specific mimetype (e.g.
 *            image/jpeg)
 *          </li>
 *        </ul>
 * @param promise the Promise to be resolved when the photos are loaded; for a format of the
 *        parameters passed to this callback, see {@code getPhotosReturnChecker} in CameraRoll.js
 */
@ReactMethod
public void getPhotos(final ReadableMap params, final Promise promise) {
  int first = params.getInt("first");
  String after = params.hasKey("after") ? params.getString("after") : null;
  String groupName = params.hasKey("groupName") ? params.getString("groupName") : null;
  ReadableArray mimeTypes = params.hasKey("mimeTypes")
      ? params.getArray("mimeTypes")
      : null;
  if (params.hasKey("groupTypes")) {
    throw new JSApplicationIllegalArgumentException("groupTypes is not supported on Android");
  }

  new GetPhotosTask(
        getReactApplicationContext(),
        first,
        after,
        groupName,
        mimeTypes,
        promise)
        .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
 
Example 7
Project: pili-react-native   File: PiliStreamingViewManager.java   Source Code and License Vote up 6 votes
@ReactProp(name = "profile")
public void setProfile(AspectFrameLayout view, @Nullable ReadableMap profile) {
    ReadableMap video = profile.getMap("video");
    ReadableMap audio = profile.getMap("audio");
    int encodingSize = profile.getInt("encodingSize");

    StreamingProfile.AudioProfile aProfile =
            new StreamingProfile.AudioProfile(audio.getInt("rate"), audio.getInt("bitrate")); //audio sample rate, audio bitrate
    StreamingProfile.VideoProfile vProfile =
            new StreamingProfile.VideoProfile(video.getInt("fps"), video.getInt("bps"), video.getInt("maxFrameInterval"));//fps bps maxFrameInterval
    StreamingProfile.AVProfile avProfile = new StreamingProfile.AVProfile(vProfile, aProfile);
    mProfile.setAVProfile(avProfile);
    mProfile.setEncodingSizeLevel(encodingSize);
    mMediaStreamingManager.setStreamingProfile(mProfile);

}
 
Example 8
Project: react-native-camera   File: RCTCameraModule.java   Source Code and License Vote up 6 votes
@ReactMethod
public void capture(final ReadableMap options, final Promise promise) {
    int orientation = options.hasKey("orientation") ? options.getInt("orientation") : RCTCamera.getInstance().getOrientation();
    if (orientation == RCT_CAMERA_ORIENTATION_AUTO) {
        _sensorOrientationChecker.onResume();
        _sensorOrientationChecker.registerOrientationListener(new RCTSensorOrientationListener() {
            @Override
            public void orientationEvent() {
                int deviceOrientation = _sensorOrientationChecker.getOrientation();
                _sensorOrientationChecker.unregisterOrientationListener();
                _sensorOrientationChecker.onPause();
                captureWithOrientation(options, promise, deviceOrientation);
            }
        });
    } else {
        captureWithOrientation(options, promise, orientation);
    }
}
 
Example 9
Project: react-native-sockets   File: SocketClient.java   Source Code and License Vote up 6 votes
SocketClient(ReadableMap params, ReactContext reactContext) {
    //String addr, int port, boolean autoReconnect
    mReactContext = reactContext;
    dstAddress = params.getString("address");
    dstPort = params.getInt("port");
    if (params.hasKey("reconnect")) {
        reconnectOnClose = params.getBoolean("reconnect");
    }
    if (params.hasKey("maxReconnectAttempts")) {
        maxReconnectAttempts = params.getInt("maxReconnectAttempts");
    }
    if (params.hasKey("reconnectDelay")) {
        reconnectDelay = params.getInt("reconnectDelay");
    }

    Thread socketClientThread = new Thread(new SocketClientThread());
    socketClientThread.start();
}
 
Example 10
Project: RNLearn_Project1   File: StackTraceHelper.java   Source Code and License Vote up 6 votes
/**
 * Convert a JavaScript stack trace (see {@code parseErrorStack} JS module) to an array of
 * {@link StackFrame}s.
 */
public static StackFrame[] convertJsStackTrace(@Nullable ReadableArray stack) {
  int size = stack != null ? stack.size() : 0;
  StackFrame[] result = new StackFrame[size];
  for (int i = 0; i < size; i++) {
    ReadableMap frame = stack.getMap(i);
    String methodName = frame.getString("methodName");
    String fileName = frame.getString("file");
    int lineNumber = -1;
    if (frame.hasKey(LINE_NUMBER_KEY) && !frame.isNull(LINE_NUMBER_KEY)) {
      lineNumber = frame.getInt(LINE_NUMBER_KEY);
    }
    int columnNumber = -1;
    if (frame.hasKey(COLUMN_KEY) && !frame.isNull(COLUMN_KEY)) {
      columnNumber = frame.getInt(COLUMN_KEY);
    }
    result[i] = new StackFrameImpl(fileName, methodName, lineNumber, columnNumber);
  }
  return result;
}
 
Example 11
Project: RNLearn_Project1   File: StackTraceHelper.java   Source Code and License Vote up 6 votes
/**
 * Convert a JavaScript stack trace (see {@code parseErrorStack} JS module) to an array of
 * {@link StackFrame}s.
 */
public static StackFrame[] convertJsStackTrace(@Nullable ReadableArray stack) {
  int size = stack != null ? stack.size() : 0;
  StackFrame[] result = new StackFrame[size];
  for (int i = 0; i < size; i++) {
    ReadableMap frame = stack.getMap(i);
    String methodName = frame.getString("methodName");
    String fileName = frame.getString("file");
    int lineNumber = -1;
    if (frame.hasKey(LINE_NUMBER_KEY) && !frame.isNull(LINE_NUMBER_KEY)) {
      lineNumber = frame.getInt(LINE_NUMBER_KEY);
    }
    int columnNumber = -1;
    if (frame.hasKey(COLUMN_KEY) && !frame.isNull(COLUMN_KEY)) {
      columnNumber = frame.getInt(COLUMN_KEY);
    }
    result[i] = new StackFrameImpl(fileName, methodName, lineNumber, columnNumber);
  }
  return result;
}
 
Example 12
Project: react-native-pili-live   File: PiliStreamingViewManager.java   Source Code and License Vote up 6 votes
@ReactProp(name = "profile")
public void setProfile(AspectFrameLayout view, @Nullable ReadableMap profile) {
    ReadableMap video = profile.getMap("video");
    ReadableMap audio = profile.getMap("audio");
    int encodingSize = profile.getInt("encodingSize");

    StreamingProfile.AudioProfile aProfile =
            new StreamingProfile.AudioProfile(audio.getInt("rate"), audio.getInt("bitrate")); //audio sample rate, audio bitrate
    StreamingProfile.VideoProfile vProfile =
            new StreamingProfile.VideoProfile(video.getInt("fps"), video.getInt("bps"), video.getInt("maxFrameInterval"));//fps bps maxFrameInterval
    StreamingProfile.AVProfile avProfile = new StreamingProfile.AVProfile(vProfile, aProfile);
    mProfile.setAVProfile(avProfile);
    mProfile.setEncodingSizeLevel(encodingSize);
    mMediaStreamingManager.setStreamingProfile(mProfile);

}
 
Example 13
Project: react-native-background-task   File: BackgroundTaskModule.java   Source Code and License Vote up 5 votes
/**
 * Main point of interaction from JS users - allows them to specify the scheduling etc for the
 * background task.
 *
 * Default values are specified in JS (more accessible for the average user).
 *
 * @param config the config options passed in from JS:
 *      - period (required): how frequently to carry out the task in seconds
 *      - timeout (required): after how many seconds should the task be auto-killed
 */
@ReactMethod
public void schedule(final ReadableMap config) {
    Log.d(TAG, "@ReactMethod BackgroundTask.schedule");

    // Period can't be below 15m
    int period = config.getInt("period");
    if (period < 900) { period = 900; }

    // Flex must be between 5m and 15m
    int flex = config.getInt("flex");
    if (flex < 300) { flex = 300; }
    if (flex > 900) { flex = 900; }

    // Extra info to store with the JobRequest
    PersistableBundleCompat extras = new PersistableBundleCompat();
    extras.putInt("timeout", config.getInt("timeout"));

    mJobRequest = new JobRequest.Builder(RNJob.JOB_TAG)
            .setPeriodic(TimeUnit.SECONDS.toMillis(period), TimeUnit.SECONDS.toMillis(flex))
            .setPersisted(true)
            .setExtras(extras)
            .build();

    if (!mForeground) {
        commitSchedule();
    }
}
 
Example 14
Project: react-native-pili-player   File: PiliLiveViewManager.java   Source Code and License Vote up 5 votes
@ReactProp(name = "source")
    public void setSource(PLVideoView mVideoView, ReadableMap source) {
        AVOptions options = new AVOptions();
        String uri = source.getString("uri");
        boolean mediaController = source.hasKey("controller") && source.getBoolean("controller");
        int avFrameTimeout = source.hasKey("timeout") ? source.getInt("timeout") : -1;        //10 * 1000 ms
        //boolean liveStreaming = source.hasKey("live") && source.getBoolean("live");  //1 or 0 // 1 -> live
        boolean codec = source.hasKey("hardCodec") && source.getBoolean("hardCodec");  //1 or 0  // 1 -> hw codec enable, 0 -> disable [recommended]
        // the unit of timeout is ms
        if (avFrameTimeout >= 0) {
            options.setInteger(AVOptions.KEY_PREPARE_TIMEOUT, avFrameTimeout);
        }
        // Some optimization with buffering mechanism when be set to 1
        options.setInteger(AVOptions.KEY_LIVE_STREAMING, 1);
//        }

        // 1 -> hw codec enable, 0 -> disable [recommended]
        if (codec) {
            options.setInteger(AVOptions.KEY_MEDIACODEC, 1);
        } else {
            options.setInteger(AVOptions.KEY_MEDIACODEC, 0);
        }

        mVideoView.setAVOptions(options);

        // After setVideoPath, the play will start automatically
        // mVideoView.start() is not required

        mVideoView.setVideoPath(uri);

//        if (mediaController) {
//            // You can also use a custom `MediaController` widget
//            MediaController mMediaController = new MediaController(reactContext, false, isLiveStreaming(uri));
//            mVideoView.setMediaController(mMediaController);
//        }

    }
 
Example 15
Project: RNLearn_Project1   File: NativeAnimatedNodesManager.java   Source Code and License Vote up 5 votes
public void addAnimatedEventToView(int viewTag, String eventName, ReadableMap eventMapping) {
  int nodeTag = eventMapping.getInt("animatedValueTag");
  AnimatedNode node = mAnimatedNodes.get(nodeTag);
  if (node == null) {
    throw new JSApplicationIllegalArgumentException("Animated node with tag " + nodeTag +
      " does not exists");
  }
  if (!(node instanceof ValueAnimatedNode)) {
    throw new JSApplicationIllegalArgumentException("Animated node connected to event should be" +
      "of type " + ValueAnimatedNode.class.getName());
  }

  ReadableArray path = eventMapping.getArray("nativeEventPath");
  List<String> pathList = new ArrayList<>(path.size());
  for (int i = 0; i < path.size(); i++) {
    pathList.add(path.getString(i));
  }

  EventAnimationDriver event = new EventAnimationDriver(pathList, (ValueAnimatedNode) node);
  String key = viewTag + eventName;
  if (mEventDrivers.containsKey(key)) {
    mEventDrivers.get(key).add(event);
  } else {
    List<EventAnimationDriver> drivers = new ArrayList<>(1);
    drivers.add(event);
    mEventDrivers.put(key, drivers);
  }
}
 
Example 16
Project: RNNavitiaSDK   File: RNNavitiaSDK.java   Source Code and License Vote up 5 votes
private Object extractMapValue(ReadableMap params, HashMap<String, Object> paramsMap, String key) {
    Object mapValue;
    if (ReadableType.Number == params.getType(key)) {
        try {
            mapValue = params.getInt(key);
        } catch (UnexpectedNativeTypeException e) {
            mapValue = params.getDouble(key);
        }
    } else {
        mapValue = paramsMap.get(key);
    }

    return mapValue;
}
 
Example 17
Project: react-native-event-bridge   File: SecondActivity.java   Source Code and License Vote up 5 votes
@Override
public void onEventCallback(final String name, final ReadableMap info, final MSREventBridgeReceiverCallback callback) {
    Log.d(ReactConstants.TAG, this.getClass().getName() + ": Received event  with callback: ".concat(name));

    final String activityClassName = this.getClass().getSimpleName();

    // Example how to load some async data
    if (name.equals(LoadDataEventName)) {
        final int count = info.getInt("count");

        // Simulate some data loading delay
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                WritableArray array = new WritableNativeArray();
                for (int i = 0; i < count; i++) {
                    // getSimpleName() does not work here for some reason
                    String className = this.getClass().getName();
                    array.pushString("Row " + i + " - " + activityClassName);
                }

                callback.onSuccess(array);
            }
        }, 2000);

        return;
    }

    // Emit callback
    WritableMap map = new WritableNativeMap();
    map.putString("key", "value");
    callback.onSuccess(map);
}
 
Example 18
Project: RNLearn_Project1   File: SpringAnimation.java   Source Code and License Vote up 5 votes
SpringAnimation(ReadableMap config) {
  mSpringFriction = config.getDouble("friction");
  mSpringTension = config.getDouble("tension");
  mCurrentState.velocity = config.getDouble("initialVelocity");
  mEndValue = config.getDouble("toValue");
  mRestSpeedThreshold = config.getDouble("restSpeedThreshold");
  mDisplacementFromRestThreshold = config.getDouble("restDisplacementThreshold");
  mOvershootClampingEnabled = config.getBoolean("overshootClamping");
  mIterations = config.hasKey("iterations") ? config.getInt("iterations") : 1;
  mHasFinished = mIterations == 0;
}
 
Example 19
Project: pili-react-native   File: PiliPlayerViewManager.java   Source Code and License Vote up 4 votes
@ReactProp(name = "source")
    public void setSource(PLVideoView mVideoView, ReadableMap source) {
        AVOptions options = new AVOptions();
        String uri = source.getString("uri");
        boolean mediaController = source.hasKey("controller") && source.getBoolean("controller");
        int avFrameTimeout = source.hasKey("timeout") ? source.getInt("timeout") : -1;        //10 * 1000 ms
        boolean liveStreaming = source.hasKey("live") && source.getBoolean("live");  //1 or 0 // 1 -> live
        boolean codec = source.hasKey("hardCodec") && source.getBoolean("hardCodec");  //1 or 0  // 1 -> hw codec enable, 0 -> disable [recommended]
        // the unit of timeout is ms
        if (avFrameTimeout >= 0) {
            options.setInteger(AVOptions.KEY_GET_AV_FRAME_TIMEOUT, avFrameTimeout);
        }
        // Some optimization with buffering mechanism when be set to 1
        if (liveStreaming) {
            options.setInteger(AVOptions.KEY_LIVE_STREAMING, 1);
        } else {
            options.setInteger(AVOptions.KEY_LIVE_STREAMING, 0);
        }
//        }

        // 1 -> hw codec enable, 0 -> disable [recommended]
        if (codec) {
            options.setInteger(AVOptions.KEY_MEDIACODEC, 1);
        } else {
            options.setInteger(AVOptions.KEY_MEDIACODEC, 0);
        }

        mVideoView.setAVOptions(options);

        // After setVideoPath, the play will start automatically
        // mVideoView.start() is not required

        mVideoView.setVideoPath(uri);

//        if (mediaController) {
//            // You can also use a custom `MediaController` widget
//            MediaController mMediaController = new MediaController(reactContext, false, isLiveStreaming(uri));
//            mVideoView.setMediaController(mMediaController);
//        }

    }
 
Example 20
Project: rnrecord   File: DeleteCommand.java   Source Code and License Vote up 4 votes
public void delete(String tableName, ReadableMap props, Promise promise) {
    int id = props.getInt("id");
    executeDbCallsAsync(tableName, promise, id);
}