com.facebook.react.bridge.Callback Java Examples

The following examples show how to use com.facebook.react.bridge.Callback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImageEditingManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
private CropTask(
    ReactContext context,
    String uri,
    int x,
    int y,
    int width,
    int height,
    Callback success,
    Callback error) {
  super(context);
  if (x < 0 || y < 0 || width <= 0 || height <= 0) {
    throw new JSApplicationIllegalArgumentException(String.format(
        "Invalid crop rectangle: [%d, %d, %d, %d]", x, y, width, height));
  }
  mContext = context;
  mUri = uri;
  mX = x;
  mY = y;
  mWidth = width;
  mHeight = height;
  mSuccess = success;
  mError = error;
}
 
Example #2
Source File: OTSessionManager.java    From opentok-react-native with MIT License 6 votes vote down vote up
@ReactMethod
public void sendSignal(String sessionId, ReadableMap signal, Callback callback) {
    ConcurrentHashMap<String, Session> mSessions = sharedState.getSessions();
    Session mSession = mSessions.get(sessionId);
    ConcurrentHashMap<String, Connection> mConnections = sharedState.getConnections();
    String connectionId = signal.getString("to");
    Connection mConnection = null;
    if (connectionId != null) {
        mConnection = mConnections.get(connectionId);
    }
    if (mConnection != null && mSession != null) {
        mSession.sendSignal(signal.getString("type"), signal.getString("data"), mConnection);
        callback.invoke();
    } else if (mSession != null) {
        mSession.sendSignal(signal.getString("type"), signal.getString("data"));
        callback.invoke();
    } else {
        WritableMap errorInfo = EventUtils.createError("There was an error sending the signal. The native session instance could not be found.");
        callback.invoke(errorInfo);
    }

}
 
Example #3
Source File: AsyncStorageModule.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * Clears the database.
 */
@ReactMethod
public void clear(final Callback callback) {
  new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
    @Override
    protected void doInBackgroundGuarded(Void... params) {
      if (!mReactDatabaseSupplier.ensureDatabase()) {
        callback.invoke(AsyncStorageErrorUtil.getDBError(null));
        return;
      }
      try {
        mReactDatabaseSupplier.clear();
        callback.invoke();
      } catch (Exception e) {
        FLog.w(ReactConstants.TAG, e.getMessage(), e);
        callback.invoke(AsyncStorageErrorUtil.getError(null, e.getMessage()));
      }
    }
  }.executeOnExecutor(executor);
}
 
Example #4
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
@ReactMethod
public void selectUserNotInStartContacts(String key, Callback callback) {
    List<Nick> list = IMDatabaseManager.getInstance().selectUserNotInStartContacts(key);
    WritableNativeArray array = new WritableNativeArray();
    for (int i = 0; i < list.size(); i++) {
        Nick nick = list.get(i);
        WritableNativeMap map = new WritableNativeMap();
        map.putString("Name", TextUtils.isEmpty(nick.getName()) ? nick.getXmppId() : nick.getName());
        map.putString("XmppId", nick.getXmppId());
        map.putString("HeaderUri", TextUtils.isEmpty(nick.getHeaderSrc()) ? defaultUserImage : nick.getHeaderSrc());
        array.pushMap(map);

    }
    WritableNativeMap re = new WritableNativeMap();
    re.putArray("users", array);
    callback.invoke(re);
}
 
Example #5
Source File: SamsungHealthModule.java    From rn-samsung-health with The Unlicense 6 votes vote down vote up
@ReactMethod
    public void readHeight(double startDate, double endDate, Callback error, Callback success) {
     HealthDataResolver resolver = new HealthDataResolver(mStore, null);
        Filter filter = Filter.and(
            Filter.greaterThanEquals(HealthConstants.Height.START_TIME, (long)startDate),
            Filter.lessThanEquals(HealthConstants.Height.START_TIME, (long)endDate)
        );
        HealthDataResolver.ReadRequest request = new ReadRequest.Builder()
                .setDataType(HealthConstants.Height.HEALTH_DATA_TYPE)
                .setProperties(new String[]{
                        HealthConstants.Height.HEIGHT,
                        HealthConstants.Height.START_TIME,  
                        HealthConstants.Height.TIME_OFFSET,
                        HealthConstants.Height.DEVICE_UUID 
                })
                .setFilter(filter)
                .build();

        try {
            resolver.read(request).setResultListener(new HealthDataResultListener(this, error, success));
        } catch (Exception e) {
            Log.e(REACT_MODULE, e.getClass().getName() + " - " + e.getMessage());
            Log.e(REACT_MODULE, "Getting Height fails.");
            error.invoke("Getting Height fails.");
        }
}
 
Example #6
Source File: ForwardingCookieHandler.java    From react-native-GPay with MIT License 6 votes vote down vote up
public void clearCookies(final Callback callback) {
  if (USES_LEGACY_STORE) {
    new GuardedResultAsyncTask<Boolean>(mContext) {
      @Override
      protected Boolean doInBackgroundGuarded() {
        getCookieManager().removeAllCookie();
        mCookieSaver.onCookiesModified();
        return true;
      }

      @Override
      protected void onPostExecuteGuarded(Boolean result) {
        callback.invoke(result);
      }
    }.execute();
  } else {
    clearCookiesAsync(callback);
  }
}
 
Example #7
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
@ReactMethod
public void selectStarOrBlackContacts(String pkey, Callback callback) {
    List<Nick> list = IMDatabaseManager.getInstance().selectStarOrBlackContactsAsNick(pkey);
    WritableNativeArray array = new WritableNativeArray();
    for (int i = 0; i < list.size(); i++) {
        Nick nick = list.get(i);
        WritableNativeMap map = new WritableNativeMap();
        map.putString("Name", TextUtils.isEmpty(nick.getName()) ? nick.getXmppId() : nick.getName());
        map.putString("XmppId", nick.getXmppId());
        map.putString("HeaderUri", TextUtils.isEmpty(nick.getHeaderSrc()) ? defaultUserImage : nick.getHeaderSrc());
        array.pushMap(map);

    }
    WritableNativeMap re = new WritableNativeMap();
    re.putArray("data", array);
    callback.invoke(re);
}
 
Example #8
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
 * 查询不在星标联系人的好友
 *
 * @param callback
 */
@ReactMethod
public void selectFriendsNotInStarContacts(Callback callback) {
    List<Nick> list = IMDatabaseManager.getInstance().selectFriendsNotInStarContacts();
    WritableNativeArray array = new WritableNativeArray();
    for (int i = 0; i < list.size(); i++) {
        Nick nick = list.get(i);
        WritableNativeMap map = new WritableNativeMap();
        map.putString("Name", TextUtils.isEmpty(nick.getName()) ? nick.getXmppId() : nick.getName());
        map.putString("XmppId", nick.getXmppId());
        map.putString("HeaderUri", TextUtils.isEmpty(nick.getHeaderSrc()) ? defaultUserImage : nick.getHeaderSrc());
        array.pushMap(map);

    }
    WritableNativeMap re = new WritableNativeMap();
    re.putArray("contacts", array);
    callback.invoke(re);
}
 
Example #9
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
     * 同步群置顶信息
     *
     * @param groupId
     * @param callback
     */
    @ReactMethod
    public void syncGroupStickyState(String groupId, Callback callback) {
//        RecentConversation rc = new RecentConversation();
//        rc.setId(groupId);
//        rc.setRealUser(groupId);
//        rc = ConnectionUtil.getInstance().SelectConversationByRC(rc);
        UserConfigData userConfigData = new UserConfigData();
        userConfigData.setSubkey(groupId + "<>" + groupId);
        userConfigData.setKey(CacheDataType.kStickJidDic);
        UserConfigData ucd = ConnectionUtil.getInstance().selectUserConfigValueForKey(userConfigData);
//        recentConvDataModel.selectRecentConvById(rc);
//        panelView.setTop(rc.getTop()>0);
        WritableNativeMap map = new WritableNativeMap();
        map.putBoolean("state", ucd != null);
        callback.invoke(map);
    }
 
Example #10
Source File: QtalkPlugin.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
     * 进行网络请求
     */
    @ReactMethod
    public void getSearchInfo(String url, ReadableMap params, ReadableMap cookie, Callback callback1, final Callback callback2) {
        final WritableNativeMap map = new WritableNativeMap();

        HttpUtil.PostUrl(url, params.toHashMap(), cookie.toHashMap(), new ProtocolCallback.UnitCallback<String>() {
            @Override
            public void onCompleted(String s) {
                map.putBoolean("isOk", true);
                map.putString("responseJson", s);
                callback2.invoke(map);
            }

            @Override
            public void onFailure(String errMsg) {
                map.putBoolean("isOk", false);
                map.putString("message", errMsg);
                callback2.invoke(map);
            }
        });


//
    }
 
Example #11
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
 * 群踢人
 *
 * @param params
 */
@ReactMethod
public void kickGroupMember(ReadableMap params, Callback callback) {
    final String groupId = params.getString("groupId");
    ReadableMap map = params.getMap("members");
    ReadableMapKeySetIterator keySet = map.keySetIterator();
    Map<String, String> memberMap = new HashMap<>();
    while (keySet.hasNextKey()) {
        ReadableMap item = map.getMap(keySet.nextKey());
        String userId = item.getString("xmppId");
        String name = item.getString("name");
        memberMap.put(name, userId);
    }
    if (TextUtils.isEmpty(groupId) || memberMap.size() == 0) {
        return;
    }
    ConnectionUtil.getInstance().delGroupMember(groupId, memberMap);
    sendEvent("closeKickMembers", new WritableNativeMap());
    toast("成员已移除");
}
 
Example #12
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
@ReactMethod
public void setServiceState(final ReadableMap map, final Callback callback) {
    if (map == null) {
        return;
    }
    final String st = map.getString("state");
    final String sid = map.getString("sid");

    ThirdProviderAPI.setServiceStatus(CurrentPreference.getInstance().getUserid(), st, sid, new ProtocolCallback.UnitCallback<Boolean>() {
        @Override
        public void onCompleted(Boolean aBoolean) {
            WritableNativeMap writableNativeMap = new WritableNativeMap();
            writableNativeMap.putBoolean("result", aBoolean);
            callback.invoke(writableNativeMap);
        }

        @Override
        public void onFailure(String errMsg) {
        }
    });
}
 
Example #13
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
@ReactMethod
public void selectGroupMemberForKick(ReadableMap params, Callback callback) {
    String groupId = params.getString("groupId");
    List<Nick> userList = ConnectionUtil.getInstance().selectGroupMemberForKick(groupId);
    WritableNativeArray array = new WritableNativeArray();
    for (int i = 0; i < userList.size(); i++) {
        Nick nick = userList.get(i);
        WritableNativeMap map = new WritableNativeMap();
        map.putString("name", TextUtils.isEmpty(nick.getName()) ? nick.getXmppId() : nick.getName());
        map.putString("xmppId", nick.getXmppId());
        map.putString("headerUri", TextUtils.isEmpty(nick.getHeaderSrc()) ? defaultUserImage : nick.getHeaderSrc());
        array.pushMap(map);

    }
    WritableNativeMap re = new WritableNativeMap();
    re.putArray("UserList", array);
    re.putBoolean("ok", true);
    callback.invoke(re);
}
 
Example #14
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
 * 根据文字搜索联系人
 *
 * @param params
 * @param callback
 */
@ReactMethod
public void selectUserListByText(ReadableMap params, Callback callback) {
    String groupId = params.getString("groupId");
    String searchText = params.getString("searchText");
    List<Nick> userList = ConnectionUtil.getInstance().SelectUserListBySearchText(groupId, searchText);
    WritableNativeArray array = new WritableNativeArray();

    for (int i = 0; i < userList.size(); i++) {
        Nick nick = userList.get(i);
        WritableNativeMap map = new WritableNativeMap();
        map.putString("name", TextUtils.isEmpty(nick.getName()) ? nick.getXmppId() : nick.getName());
        map.putString("xmppId", nick.getXmppId());
        map.putString("headerUri", TextUtils.isEmpty(nick.getHeaderSrc()) ? defaultUserImage : nick.getHeaderSrc());
        map.putBoolean("hasInGroup", nick.isInGroup());
        map.putString("desc",nick.getDescInfo());
        array.pushMap(map);

    }
    WritableNativeMap re = new WritableNativeMap();
    re.putArray("UserList", array);
    re.putBoolean("ok", true);
    callback.invoke(re);
}
 
Example #15
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
 * 获取用户信息
 *
 * @param userId
 * @param callback
 */
@ReactMethod
public void getUserInfo(final String userId, final Callback callback) {

    ConnectionUtil.getInstance().getUserCard(userId, new IMLogicManager.NickCallBack() {
        @Override
        public void onNickCallBack(Nick nick) {
            WritableMap hm = new WritableNativeMap();

            hm.putString("Name", nick.getName());
            hm.putString("Remarks", nick.getMark());
            hm.putString("HeaderUri", nick.getHeaderSrc());
            hm.putString("Department", nick.getDescInfo());
            hm.putString("UserId", nick.getXmppId());
            WritableNativeMap map = new WritableNativeMap();
            map.putMap("UserInfo", hm);
            callback.invoke(map);
        }
    }, false, true);
}
 
Example #16
Source File: SamsungHealthModule.java    From rn-samsung-health with The Unlicense 6 votes vote down vote up
@ReactMethod
    public void readSleep(double startDate, double endDate, Callback error, Callback success) {
    HealthDataResolver resolver = new HealthDataResolver(mStore, null);
        Filter filter = Filter.and(
            Filter.greaterThanEquals(HealthConstants.Sleep.START_TIME, (long)startDate),
            Filter.lessThanEquals(HealthConstants.Sleep.END_TIME, (long)endDate)
        );
        HealthDataResolver.ReadRequest request = new ReadRequest.Builder()
                .setDataType(HealthConstants.Sleep.HEALTH_DATA_TYPE) 
                .setProperties(new String[]{
                        HealthConstants.Sleep.START_TIME,
                        HealthConstants.Sleep.END_TIME,
                        HealthConstants.Sleep.TIME_OFFSET,
                        HealthConstants.Sleep.DEVICE_UUID
                })
                .setFilter(filter)
                .build();

        try {
            resolver.read(request).setResultListener(new HealthDataResultListener(this, error, success));
        } catch (Exception e) {
            Log.e(REACT_MODULE, e.getClass().getName() + " - " + e.getMessage());
            Log.e(REACT_MODULE, "Getting Sleep fails.");
            error.invoke("Getting Sleep fails.");
        }
}
 
Example #17
Source File: QimRNBModule.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
     * 同步在线通知状态
     *
     * @param callback
     */
    @ReactMethod
    public void syncOnLineNotifyState(Callback callback) {
//        CurrentPreference.ProFile proFile = CurrentPreference.getInstance().getProFile();
//        WritableMap map = new WritableNativeMap();
////        WritableMap params = new WritableNativeMap();
////        params.putBoolean("syncOnLineNotifyState",proFile.isOfflinePush());
//        map.putBoolean("state", proFile.isOfflinePush());
//        callback.invoke(map);


        WritableMap map = new WritableNativeMap();
        boolean state = ConnectionUtil.getInstance().getPushStateBy(PushSettinsStatus.PUSH_ONLINE);
        map.putBoolean("state", state);
        callback.invoke(map);

    }
 
Example #18
Source File: NativeAnimatedNodeTraversalTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Test
public void testNodeValueListenerIfListening() {
  int nodeId = 1;

  createSimpleAnimatedViewWithOpacity(1000, 0d);
  JavaOnlyArray frames = JavaOnlyArray.of(0d, 0.2d, 0.4d, 0.6d, 0.8d, 1d);

  Callback animationCallback = mock(Callback.class);
  AnimatedNodeValueListener valueListener = mock(AnimatedNodeValueListener.class);

  mNativeAnimatedNodesManager.startListeningToAnimatedNodeValue(nodeId, valueListener);
  mNativeAnimatedNodesManager.startAnimatingNode(
    1,
    nodeId,
    JavaOnlyMap.of("type", "frames", "frames", frames, "toValue", 1d),
    animationCallback);

  for (int i = 0; i < frames.size(); i++) {
    reset(valueListener);
    mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
    verify(valueListener).onValueUpdate(eq(frames.getDouble(i)));
  }

  reset(valueListener);
  mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
  verifyNoMoreInteractions(valueListener);
}
 
Example #19
Source File: QimRNBModule.java    From imsdk-android with MIT License 5 votes vote down vote up
public void getGroupMemberFromDB(String groupId, Callback callback) {
    List<GroupMember> groupMemberList = ConnectionUtil.getInstance().SelectGroupMemberByGroupId(groupId);
    if (ListUtil.isEmpty(groupMemberList)) {
        return;
    }
    WritableNativeArray array = new WritableNativeArray();
    int per = 2;
    for (int i = 0; i < groupMemberList.size(); i++) {
        GroupMember gm = groupMemberList.get(i);
        WritableNativeMap map = new WritableNativeMap();
        String affiliation = gm.getAffiliation();
        map.putString("affiliation", affiliation);
        map.putString("headerUri", TextUtils.isEmpty(gm.getHeaderSrc()) ? defaultUserImage : gm.getHeaderSrc());
        String xmppid = gm.getMemberId();
        if (CurrentPreference.getInstance().getPreferenceUserId().equals(xmppid)) {
            if (!TextUtils.isEmpty(affiliation)) {
                per = Integer.parseInt(affiliation);
            }
        }
        map.putString("xmppjid", xmppid);
        map.putString("jid", gm.getGroupId());
        map.putString("name", gm.getName());
        array.pushMap(map);

    }
    WritableNativeMap re = new WritableNativeMap();
    re.putArray("GroupMembers", array);
    re.putBoolean("ok", true);
    re.putString("GroupId", groupId);
    re.putInt("permissions", per);
    if (callback != null) {
        callback.invoke(re);
    } else {
        sendEvent("updateGroupMember", re);
    }
}
 
Example #20
Source File: LocationModule.java    From react-native-GPay with MIT License 5 votes vote down vote up
private SingleUpdateRequest(
    LocationManager locationManager,
    String provider,
    long timeout,
    Callback success,
    Callback error) {
  mLocationManager = locationManager;
  mProvider = provider;
  mTimeout = timeout;
  mSuccess = success;
  mError = error;
}
 
Example #21
Source File: QimRNBModule.java    From imsdk-android with MIT License 5 votes vote down vote up
/**
     * 更新通知声音状态
     *
     * @param notifySoundState
     * @param callback
     */
    @ReactMethod
    public void updateNotifySoundState(boolean notifySoundState, final Callback callback) {

//        boolean state = notifySoundState;
//        CurrentPreference.getInstance().setTurnOnMsgSound(state);
//        IMDatabaseManager.getInstance().updateConfig();
//        WritableMap map = new WritableNativeMap();
//        map.putBoolean("ok", true);
//        callback.invoke(map);

        final boolean state = notifySoundState;

        final WritableMap map = new WritableNativeMap();
        HttpUtil.setPushMsgSettings(PushSettinsStatus.SOUND_INAPP, state ? 1 : 0, new ProtocolCallback.UnitCallback<Boolean>() {
            @Override
            public void onCompleted(Boolean aBoolean) {
                ConnectionUtil.getInstance().setPushState(PushSettinsStatus.SOUND_INAPP, state ? 1 : 0);
                com.qunar.im.protobuf.common.CurrentPreference.getInstance().setTurnOnMsgSound(ConnectionUtil.getInstance().getPushStateBy(PushSettinsStatus.SOUND_INAPP));
                map.putBoolean("ok", true);
                callback.invoke(map);
            }

            @Override
            public void onFailure(String errMsg) {
                map.putBoolean("ok", false);
                callback.invoke(map);
            }
        });
    }
 
Example #22
Source File: ReactNativeAPKModule.java    From react-native-apk with MIT License 5 votes vote down vote up
@ReactMethod
public void getApps(Callback cb) {
  List<PackageInfo> packages = this.reactContext.getPackageManager().getInstalledPackages(0);

  List<String> ret = new ArrayList<>();
  for (final PackageInfo p : packages) {
    ret.add(p.packageName);
  }
  cb.invoke(ret);
}
 
Example #23
Source File: QimRNBModule.java    From imsdk-android with MIT License 5 votes vote down vote up
/**
     * 获取用户是否开启推送
     *
     * @param callback
     */
    @ReactMethod
    public void getStartPushState(Callback callback) {
//        CurrentPreference.ProFile proFile = CurrentPreference.getInstance().getProFile();
//        WritableMap map = new WritableNativeMap();
////        WritableMap params = new WritableNativeMap();
////        params.putBoolean("getNotifySoundState",proFile.isTurnOnMsgSound());
//        map.putBoolean("state", proFile.isTurnOnPsuh());
//        callback.invoke(map);

        WritableMap map = new WritableNativeMap();
        boolean state = ConnectionUtil.getInstance().getPushStateBy(PushSettinsStatus.PUSH_SWITCH);
        map.putBoolean("state", state);
        callback.invoke(map);
    }
 
Example #24
Source File: UIImplementation.java    From react-native-GPay with MIT License 5 votes vote down vote up
/**
 *  Check if the first shadow node is the descendant of the second shadow node
 */
public void viewIsDescendantOf(
    final int reactTag,
    final int ancestorReactTag,
    final Callback callback) {
  ReactShadowNode node = mShadowNodeRegistry.getNode(reactTag);
  ReactShadowNode ancestorNode = mShadowNodeRegistry.getNode(ancestorReactTag);
  if (node == null || ancestorNode == null) {
    callback.invoke(false);
    return;
  }
  callback.invoke(node.isDescendantOf(ancestorNode));
}
 
Example #25
Source File: UIViewOperationQueue.java    From react-native-GPay with MIT License 5 votes vote down vote up
private FindTargetForTouchOperation(
    final int reactTag,
    final float targetX,
    final float targetY,
    final Callback callback) {
  super();
  mReactTag = reactTag;
  mTargetX = targetX;
  mTargetY = targetY;
  mCallback = callback;
}
 
Example #26
Source File: QimRNBModule.java    From imsdk-android with MIT License 5 votes vote down vote up
/**
 * 获取客户端版本号
 *
 * @param callback
 */
@ReactMethod
public void getAppVersion(Callback callback) {
    String version = "" + QunarIMApp.getQunarIMApp().getVersion();
    WritableMap map = new WritableNativeMap();
    map.putString("AppVersion", version);
    callback.invoke(map);
}
 
Example #27
Source File: SingleLocationUpdate.java    From react-native-geolocation-service with MIT License 5 votes vote down vote up
public SingleLocationUpdate(
  FusedLocationProviderClient fusedLocationProviderClient,
  LocationRequest locationRequest,
  long timeout,
  Callback success,
  Callback error
) {
  mFusedProviderClient = fusedLocationProviderClient;
  mLocationRequest = locationRequest;
  mTimeout = timeout;
  mSuccessCallback = success;
  mErrorCallback = error;
}
 
Example #28
Source File: RNVoiceRecorderModule.java    From react-native-voice-recorder with Apache License 2.0 5 votes vote down vote up
@ReactMethod
public void Record(final ReadableMap props, final Callback onDone, final Callback onCancel) {

  _onDone = onDone;
  _onCancel = onCancel;

  Dexter.withActivity(getCurrentActivity())
          .withPermissions(
                  Manifest.permission.WRITE_EXTERNAL_STORAGE,
                  Manifest.permission.RECORD_AUDIO
          ).withListener(new MultiplePermissionsListener() {
    @Override public void onPermissionsChecked(MultiplePermissionsReport report) {/* ... */

      String filePath = Environment.getExternalStorageDirectory() + "/recorded_audio.wav";

      int color = Color.parseColor("#165297");

      int requestCode = 0;
      AndroidAudioRecorder.with(getCurrentActivity())
              // Required
              .setFilePath(filePath)
              .setColor(color)
              .setRequestCode(requestCode)

              // Optional
              .setSource(AudioSource.CAMCORDER.MIC)
              .setChannel(AudioChannel.STEREO)
              .setSampleRate(AudioSampleRate.HZ_48000)
              .setAutoStart(true)
              .setKeepDisplayOn(true)

              // Start recording
              .record();
    }
    @Override public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions, PermissionToken token) {/* ... */}
  }).check();
}
 
Example #29
Source File: LocationModule.java    From react-native-GPay with MIT License 5 votes vote down vote up
/**
 * Get the current position. This can return almost immediately if the location is cached or
 * request an update, which might take a while.
 *
 * @param options map containing optional arguments: timeout (millis), maximumAge (millis) and
 *        highAccuracy (boolean)
 */
@ReactMethod
public void getCurrentPosition(
    ReadableMap options,
    final Callback success,
    Callback error) {
  LocationOptions locationOptions = LocationOptions.fromReactMap(options);

  try {
    LocationManager locationManager =
        (LocationManager) getReactApplicationContext().getSystemService(Context.LOCATION_SERVICE);
    String provider = getValidProvider(locationManager, locationOptions.highAccuracy);
    if (provider == null) {
      error.invoke(
          PositionError.buildError(
              PositionError.POSITION_UNAVAILABLE, "No location provider available."));
      return;
    }
    Location location = locationManager.getLastKnownLocation(provider);
    if (location != null && (SystemClock.currentTimeMillis() - location.getTime()) < locationOptions.maximumAge) {
      success.invoke(locationToMap(location));
      return;
    }

    new SingleUpdateRequest(locationManager, provider, locationOptions.timeout, success, error)
        .invoke(location);
  } catch (SecurityException e) {
    throwLocationPermissionMissing(e);
  }
}
 
Example #30
Source File: NativeAnimatedNodeTraversalTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Test
public void testAnimationCallbackFinish() {
  createSimpleAnimatedViewWithOpacity(1000, 0d);

  JavaOnlyArray frames = JavaOnlyArray.of(0d, 1d);
  Callback animationCallback = mock(Callback.class);
  mNativeAnimatedNodesManager.startAnimatingNode(
    1,
    1,
    JavaOnlyMap.of("type", "frames", "frames", frames, "toValue", 1d),
    animationCallback);

  ArgumentCaptor<ReadableMap> callbackResponseCaptor = ArgumentCaptor.forClass(ReadableMap.class);

  reset(animationCallback);
  mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
  verifyNoMoreInteractions(animationCallback);

  reset(animationCallback);
  mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
  verify(animationCallback).invoke(callbackResponseCaptor.capture());

  assertThat(callbackResponseCaptor.getValue().hasKey("finished")).isTrue();
  assertThat(callbackResponseCaptor.getValue().getBoolean("finished")).isTrue();

  reset(animationCallback);
  mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
  verifyNoMoreInteractions(animationCallback);
}