com.facebook.react.bridge.ReadableArray Java Examples

The following examples show how to use com.facebook.react.bridge.ReadableArray. 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: Utils.java    From photo-viewer with Apache License 2.0 6 votes vote down vote up
private static JSONArray convertArrayToJson(ReadableArray readableArray) throws JSONException {
    JSONArray array = new JSONArray();
    for (int i = 0; i < readableArray.size(); i++) {
        switch (readableArray.getType(i)) {
            case Null:
                break;
            case Boolean:
                array.put(readableArray.getBoolean(i));
                break;
            case Number:
                array.put(readableArray.getDouble(i));
                break;
            case String:
                array.put(readableArray.getString(i));
                break;
            case Map:
                array.put(readableMapToJson(readableArray.getMap(i)));
                break;
            case Array:
                array.put(convertArrayToJson(readableArray.getArray(i)));
                break;
        }
    }
    return array;
}
 
Example #2
Source File: RNDocViewerModule.java    From react-native-doc-viewer with MIT License 6 votes vote down vote up
@ReactMethod
public void openDocBinaryinUrl(ReadableArray args, Callback callback) {
    final ReadableMap arg_object = args.getMap(0);
    try {
      if (arg_object.getString("url") != null && arg_object.getString("fileName") != null && arg_object.getString("fileType") != null) {
          // parameter parsing
          final String url = arg_object.getString("url");
          final String fileName =arg_object.getString("fileName");
          final String fileType =arg_object.getString("fileType");
          final Boolean cache =arg_object.getBoolean("cache");
          final byte[] bytesData = new byte[0];
          // Begin the Download Task
          new FileDownloaderAsyncTask(callback, url, cache, fileName, fileType, bytesData).execute();
      }else{
          callback.invoke(false);
      }
     } catch (Exception e) {
          callback.invoke(e.getMessage());
     }
}
 
Example #3
Source File: RNArcGISMapViewManager.java    From react-native-arcgis-mapview with MIT License 6 votes vote down vote up
@Override
public void receiveCommand(RNAGSMapView mapView, int command, ReadableArray args) {
    Assertions.assertNotNull(mapView);
    Assertions.assertNotNull(args);
    switch (command) {
        case SHOW_CALLOUT: mapView.showCallout(args.getMap(0));return;
        case CENTER_MAP: mapView.centerMap(args.getArray(0));return;
        case ADD_GRAPHICS_OVERLAY: mapView.addGraphicsOverlay(args.getMap(0));return;
        case REMOVE_GRAPHICS_OVERLAY: mapView.removeGraphicsOverlay(args.getString(0));return;
        case ADD_POINTS_TO_OVERLAY: mapView.addPointsToOverlay(args.getMap(0));return;
        case REMOVE_POINTS_FROM_OVERLAY: mapView.removePointsFromOverlay(args.getMap(0));return;
        case UPDATE_POINTS_IN_GRAPHICS_OVERLAY: mapView.updatePointsInGraphicsOverlay(args.getMap(0));return;
        case ROUTE_GRAPHICS_OVERLAY: mapView.routeGraphicsOverlay(args.getMap(0));return;
        case SET_ROUTE_IS_VISIBLE: mapView.setRouteIsVisible(args.getBoolean(0));return;
        case DISPOSE: mapView.onHostDestroy();
    }
}
 
Example #4
Source File: BleManager.java    From react-native-ble-manager with Apache License 2.0 6 votes vote down vote up
@ReactMethod
public void scan(ReadableArray serviceUUIDs, final int scanSeconds, boolean allowDuplicates, ReadableMap options,
		Callback callback) {
	Log.d(LOG_TAG, "scan");
	if (getBluetoothAdapter() == null) {
		Log.d(LOG_TAG, "No bluetooth support");
		callback.invoke("No bluetooth support");
		return;
	}
	if (!getBluetoothAdapter().isEnabled()) {
		return;
	}

	synchronized (peripherals) {
		for (Iterator<Map.Entry<String, Peripheral>> iterator = peripherals.entrySet().iterator(); iterator
				.hasNext();) {
			Map.Entry<String, Peripheral> entry = iterator.next();
			if (!entry.getValue().isConnected()) {
				iterator.remove();
			}
		}
	}

	if (scanManager != null)
		scanManager.scan(serviceUUIDs, scanSeconds, options, callback);
}
 
Example #5
Source File: RNJWPlayerViewManager.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@Override
public void receiveCommand(RNJWPlayerView root, int commandId, @Nullable ReadableArray args) {
  super.receiveCommand(root, commandId, args);

  switch (commandId) {
    case COMMAND_PLAY:
      play(root);
      break;
    case COMMAND_PAUSE:
      pause(root);
      break;
    case COMMAND_STOP:
      stop(root);
      break;
    case COMMAND_TOGGLE_SPEED:
      toggleSpeed(root);
      break;
    default:
      //do nothing!!!!
  }
}
 
Example #6
Source File: DBManager.java    From react-native-android-sqlite with MIT License 6 votes vote down vote up
@ReactMethod
public void exec(final String sql, final ReadableArray values, final Callback callback) {
	new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
		@Override
		protected void doInBackgroundGuarded(Void ...params) {
			try {
				mDb.exec(sql, values);
			} catch(Exception e) {
				FLog.w(ReactConstants.TAG, "Exception in database exec: ", e);
				callback.invoke(ErrorUtil.getError(null, e.getMessage()), null);
			}

			callback.invoke();
		}
	}.execute();
}
 
Example #7
Source File: RNInstabugBugReportingModule.java    From Instabug-React-Native with MIT License 6 votes vote down vote up
/**
 * Sets the enabled report types to be shown in the prompt. Bug or Feedback or both.
 * @param types
 * @see BugReporting.ReportType
 */
@SuppressLint("WrongConstant")
@ReactMethod
public void setReportTypes(ReadableArray types) {
    Object[] objectArray = ArrayUtil.toArray(types);
    String[] stringArray = Arrays.copyOf(objectArray, objectArray.length, String[].class);
    final int[] parsedReportTypes = new int[stringArray.length];
    for (int i = 0; i < stringArray.length; i++) {
        parsedReportTypes[i] = (int) ArgsRegistry.getRawValue(stringArray[i]);
    }
    MainThreadHandler.runOnMainThread(new Runnable() {
        @Override
        public void run() {
            try {
                BugReporting.setReportTypes(parsedReportTypes);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
 
Example #8
Source File: BaseViewManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@ReactProp(name = PROP_ACCESSIBILITY_STATES)
public void setViewStates(T view, ReadableArray accessibilityStates) {
  view.setSelected(false);
  view.setEnabled(true);
  if (accessibilityStates == null) {
    return;
  }
  for (int i = 0; i < accessibilityStates.size(); i++) {
    String state = accessibilityStates.getString(i);
    if (state.equals("selected")) {
      view.setSelected(true);
    } else if (state.equals("disabled")) {
      view.setEnabled(false);
    }
  }
}
 
Example #9
Source File: RNInstabugBugReportingModule.java    From Instabug-React-Native with MIT License 6 votes vote down vote up
/**
 * Sets the options for the features in the SDK
 *
 * @param optionValues the invocation option value
 */
@ReactMethod
public void setOptions(final ReadableArray optionValues) {
    MainThreadHandler.runOnMainThread(new Runnable() {
        @Override
        public void run() {
            try {
                Object[] objectArray = ArrayUtil.toArray(optionValues);
                String[] stringArray = Arrays.copyOf(objectArray, objectArray.length, String[].class);
                for (String option : stringArray) {
                    BugReporting.setOptions((int) ArgsRegistry.getRawValue(option));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
 
Example #10
Source File: CheckoutModule.java    From react-native-square-reader-sdk with Apache License 2.0 6 votes vote down vote up
static private Set<AdditionalPaymentType> buildAdditionalPaymentTypes(ReadableArray additionalPaymentTypes) {
    Set<AdditionalPaymentType> types = new LinkedHashSet<>();
    if (additionalPaymentTypes != null) {
        for (int i = 0; i < additionalPaymentTypes.size(); i++) {
            String typeName = additionalPaymentTypes.getString(i);
            switch (typeName) {
                case "cash":
                    types.add(AdditionalPaymentType.CASH);
                    break;
                case "manual_card_entry":
                    types.add(AdditionalPaymentType.MANUAL_CARD_ENTRY);
                    break;
                case "other":
                    types.add(AdditionalPaymentType.OTHER);
                    break;
                default:
                    throw new RuntimeException("Unexpected payment type: " + typeName);
            }
        }
    }
    return types;
}
 
Example #11
Source File: CatalystNativeJSToJavaParametersTestCase.java    From react-native-GPay with MIT License 6 votes vote down vote up
public void testIntOutOfRangeThrown() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnArrayWithLargeInts();
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapWithLargeInts();
  waitForBridgeAndUIIdle();

  assertEquals(1, mRecordingTestModule.getArrayCalls().size());
  assertEquals(1, mRecordingTestModule.getMapCalls().size());

  ReadableArray array = mRecordingTestModule.getArrayCalls().get(0);
  assertNotNull(array);

  ReadableMap map = mRecordingTestModule.getMapCalls().get(0);
  assertNotNull(map);

  assertEquals(ReadableType.Number, array.getType(0));
  assertUnexpectedTypeExceptionThrown(array, 0, "int");
  assertEquals(ReadableType.Number, array.getType(1));
  assertUnexpectedTypeExceptionThrown(array, 1, "int");

  assertEquals(ReadableType.Number, map.getType("first"));
  assertUnexpectedTypeExceptionThrown(map, "first", "int");
  assertEquals(ReadableType.Number, map.getType("second"));
  assertUnexpectedTypeExceptionThrown(map, "second", "int");
}
 
Example #12
Source File: RNInstabugReactnativeModule.java    From Instabug-React-Native with MIT License 6 votes vote down vote up
@ReactMethod
public void hideView(final ReadableArray ids) {
    MainThreadHandler.runOnMainThread(new Runnable() {
        @Override
        public void run() {
            UIManagerModule uiManagerModule = getReactApplicationContext().getNativeModule(UIManagerModule.class);
            uiManagerModule.prependUIBlock(new UIBlock() {
                @Override
                public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
                    final View[] arrayOfViews = new View[ids.size()];
                    for (int i = 0; i < ids.size(); i++) {
                        int viewId = (int) ids.getDouble(i);
                        try {
                            arrayOfViews[i] = nativeViewHierarchyManager.resolveView(viewId);
                        } catch(Exception e) {
                            e.printStackTrace();
                        }
                    }
                    Instabug.setViewsAsPrivate(arrayOfViews);
                }
            });
        }
    });
}
 
Example #13
Source File: RNSketchViewManager.java    From react-native-sketch-view with MIT License 6 votes vote down vote up
@Override
public void receiveCommand(SketchViewContainer root, int commandId, @Nullable ReadableArray args) {
  Assertions.assertNotNull(root);

  switch (commandId) {
    case COMMAND_CLEAR_SKETCH:
      root.sketchView.clear();
      return;
    case COMMAND_CHANGE_TOOL:
      Assertions.assertNotNull(args);
      int toolId = args.getInt(0);
      root.sketchView.setToolType(toolId);
      return;
    case COMMAND_SAVE_SKETCH:
      try {
        SketchFile sketchFile = root.saveToLocalCache();
        onSaveSketch(root, sketchFile);
        return;
      } catch (IOException e) {
        e.printStackTrace();
      }
    default:
      throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Unsupported command %d.", commandId));
  }
}
 
Example #14
Source File: RNKakaoLinkModule.java    From react-native-kakao-links with MIT License 6 votes vote down vote up
private LocationTemplate createLocationTemplate(ReadableMap options) {
  LocationTemplate.Builder locationTemplate = LocationTemplate.newBuilder(
    options.getString("address"),
    createContentObject(options.getMap("content"))
  );

  String addressTitle = options.getString("addressTitle");
  if (addressTitle != null) {
    locationTemplate.setAddressTitle(addressTitle);
  }

  ReadableMap social = options.getMap("social");
  if (social != null) {
    locationTemplate.setSocial(createSocialObject(social));
  }

  ReadableArray buttons = options.getArray("buttons");
  if (buttons != null) {
    for (int i = 0; i < buttons.size(); i++) {
      locationTemplate.addButton(createButtonObject(buttons.getMap(i)));
    }
  }
  return locationTemplate.build();

}
 
Example #15
Source File: FirestackDatabase.java    From react-native-firestack with MIT License 6 votes vote down vote up
@ReactMethod
public void on(final String path,
               final ReadableArray modifiers,
               final String name,
               final Callback callback) {
  FirestackDBReference ref = this.getDBHandle(path);

  WritableMap resp = Arguments.createMap();

  if (name.equals("value")) {
    ref.addValueEventListener(name, modifiers);
  } else {
    ref.addChildEventListener(name, modifiers);
  }

  this.saveDBHandle(path, ref);
  resp.putString("result", "success");
  Log.d(TAG, "Added listener " + name + " for " + ref);
  
  resp.putString("handle", path);
  callback.invoke(null, resp);
}
 
Example #16
Source File: ReactToolbar.java    From react-native-GPay with MIT License 6 votes vote down vote up
void setActions(@Nullable ReadableArray actions) {
  Menu menu = getMenu();
  menu.clear();
  mActionsHolder.clear();
  if (actions != null) {
    for (int i = 0; i < actions.size(); i++) {
      ReadableMap action = actions.getMap(i);

      MenuItem item = menu.add(Menu.NONE, Menu.NONE, i, action.getString(PROP_ACTION_TITLE));

      if (action.hasKey(PROP_ACTION_ICON)) {
        setMenuItemIcon(item, action.getMap(PROP_ACTION_ICON));
      }

      int showAsAction = action.hasKey(PROP_ACTION_SHOW)
          ? action.getInt(PROP_ACTION_SHOW)
          : MenuItem.SHOW_AS_ACTION_NEVER;
      if (action.hasKey(PROP_ACTION_SHOW_WITH_TEXT) &&
          action.getBoolean(PROP_ACTION_SHOW_WITH_TEXT)) {
        showAsAction = showAsAction | MenuItem.SHOW_AS_ACTION_WITH_TEXT;
      }
      item.setShowAsAction(showAsAction);
    }
  }
}
 
Example #17
Source File: NetworkRecordingModuleMock.java    From react-native-GPay with MIT License 6 votes vote down vote up
@ReactMethod
public final void sendRequest(
    String method,
    String url,
    int requestId,
    ReadableArray headers,
    ReadableMap data,
    final String responseType,
    boolean incrementalUpdates,
    int timeout,
    boolean withCredentials) {
  mLastRequestId = requestId;
  mRequestCount++;
  mRequestMethod = method;
  mRequestURL = url;
  mRequestHeaders = headers;
  mRequestData = data;
  if (mRequestListener != null) {
    mRequestListener.onRequest(method, url, headers, data);
  }
  if (mCompleteRequest) {
    onResponseReceived(requestId, mResponseCode, null);
    onDataReceived(requestId, mResponseBody);
    onRequestComplete(requestId, null);
  }
}
 
Example #18
Source File: GPay.java    From react-native-GPay with MIT License 5 votes vote down vote up
/**
 * An object describing accepted forms of payment by your app, used to determine a viewer's
 * readiness to pay
 *
 * @return API version and payment methods supported by the app
 * @see <a
 * href="https://developers.google.com/pay/api/android/reference/object#IsReadyToPayRequest">IsReadyToPayRequest</a>
 */
private static JSONObject getIsReadyToPayRequest(ReadableArray cardNetworks) {
    try {
        JSONObject isReadyToPayRequest = GPay.getBaseRequest();
        isReadyToPayRequest.put(
                "allowedPaymentMethods", new JSONArray().put(getBaseCardPaymentMethod(cardNetworks)));
        return isReadyToPayRequest;
    } catch (JSONException e) {
        Log.e("getIsReadyToPayRequest", e.toString());
        return null;
    }
}
 
Example #19
Source File: CatalystNativeJSToJavaParametersTestCase.java    From react-native-GPay with MIT License 5 votes vote down vote up
public void testNestedArray() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnNestedArray();
  waitForBridgeAndUIIdle();

  List<ReadableArray> calls = mRecordingTestModule.getArrayCalls();
  assertEquals(1, calls.size());
  ReadableArray array = calls.get(0);
  assertNotNull(array);
  assertEquals(2, array.size());
  assertEquals("we", array.getString(0));

  assertFalse(array.isNull(1));
  ReadableArray subArray = array.getArray(1);
  assertEquals(2, subArray.size());
  assertEquals("have", subArray.getString(0));

  subArray = subArray.getArray(1);
  assertEquals(2, subArray.size());
  assertEquals("to", subArray.getString(0));

  subArray = subArray.getArray(1);
  assertEquals(2, subArray.size());
  assertEquals("go", subArray.getString(0));

  subArray = subArray.getArray(1);
  assertEquals(1, subArray.size());
  assertEquals("deeper", subArray.getString(0));
}
 
Example #20
Source File: FirestackUtils.java    From react-native-firestack with MIT License 5 votes vote down vote up
public static List<Object> recursivelyDeconstructReadableArray(ReadableArray readableArray) {
    List<Object> deconstructedList = new ArrayList<>(readableArray.size());
    for (int i = 0; i < readableArray.size(); i++) {
        ReadableType indexType = readableArray.getType(i);
        switch(indexType) {
            case Null:
                deconstructedList.add(i, null);
                break;
            case Boolean:
                deconstructedList.add(i, readableArray.getBoolean(i));
                break;
            case Number:
                deconstructedList.add(i, readableArray.getDouble(i));
                break;
            case String:
                deconstructedList.add(i, readableArray.getString(i));
                break;
            case Map:
                deconstructedList.add(i, FirestackUtils.recursivelyDeconstructReadableMap(readableArray.getMap(i)));
                break;
            case Array:
                deconstructedList.add(i, FirestackUtils.recursivelyDeconstructReadableArray(readableArray.getArray(i)));
                break;
            default:
                throw new IllegalArgumentException("Could not convert object at index " + i + ".");
        }
    }
    return deconstructedList;
}
 
Example #21
Source File: SQLitePlugin.java    From react-native-sqlite-storage with MIT License 5 votes vote down vote up
DBQuery(String[] myqueries, String[] qids, ReadableArray[] params, CallbackContext c) {
    this.stop = false;
    this.close = false;
    this.delete = false;
    this.queries = myqueries;
    this.queryIDs = qids;
    this.queryParams = params;
    this.cbc = c;
}
 
Example #22
Source File: RNBottomSheet.java    From react-native-bottom-sheet with MIT License 5 votes vote down vote up
@ReactMethod
public void showBottomSheetWithOptions(ReadableMap options, final Callback onSelect) {
    ReadableArray optionArray = options.getArray("options");
    final Integer cancelButtonIndex = options.getInt("cancelButtonIndex");

    final BottomSheet.Builder builder = new BottomSheet.Builder(this.getCurrentActivity());

    // create options
    Integer size = optionArray.size();
    for (int i = 0; i < size; i++) {
        builder.sheet(i, optionArray.getString(i));
    }

    builder.listener(new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == cancelButtonIndex) {
                dialog.dismiss();
            } else {
                onSelect.invoke(which);
            }
        }
    });

    UiThreadUtil.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            builder.build().show();
        }
    });
}
 
Example #23
Source File: Utils.java    From react-native-update with MIT License 5 votes vote down vote up
public static JSONArray convertReadableToJsonArray(ReadableArray arr) {
    JSONArray jsonArr = new JSONArray();
    for (int i=0; i<arr.size(); i++) {
        ReadableType type = arr.getType(i);
        switch (type) {
            case Map:
                jsonArr.put(convertReadableToJsonObject(arr.getMap(i)));
                break;
            case Array:
                jsonArr.put(convertReadableToJsonArray(arr.getArray(i)));
                break;
            case String:
                jsonArr.put(arr.getString(i));
                break;
            case Number:
                Double number = arr.getDouble(i);
                if ((number == Math.floor(number)) && !Double.isInfinite(number)) {
                    // This is a whole number.
                    jsonArr.put(number.longValue());
                } else {
                    try {
                        jsonArr.put(number.doubleValue());
                    } catch (JSONException jsonException) {
                        throw new RuntimeException("Unable to put value " + arr.getDouble(i) + " in JSONArray");
                    }
                }
                break;
            case Boolean:
                jsonArr.put(arr.getBoolean(i));
                break;
            case Null:
                jsonArr.put(null);
                break;
        }
    }

    return jsonArr;
}
 
Example #24
Source File: CatalystNativeJSToJavaParametersTestCase.java    From react-native-GPay with MIT License 5 votes vote down vote up
public void testStringWithMultibyteUTF8Characters() {
  TestJSToJavaParametersModule jsModule =
      mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class);
  jsModule.returnMapWithMultibyteUTF8CharacterString();
  jsModule.returnArrayWithMultibyteUTF8CharacterString();
  waitForBridgeAndUIIdle();

  List<ReadableMap> maps = mRecordingTestModule.getMapCalls();
  assertEquals(1, maps.size());

  ReadableMap map = maps.get(0);
  assertEquals("a", map.getString("one-byte"));
  assertEquals("\u00A2", map.getString("two-bytes"));
  assertEquals("\u20AC", map.getString("three-bytes"));
  assertEquals("\uD83D\uDE1C", map.getString("four-bytes"));
  assertEquals(
      "\u017C\u00F3\u0142\u0107 g\u0119\u015Bl\u0105 \u6211 \uD83D\uDE0E ja\u017A\u0107",
      map.getString("mixed"));

  List<ReadableArray> arrays = mRecordingTestModule.getArrayCalls();
  assertEquals(1, arrays.size());

  ReadableArray array = arrays.get(0);
  assertEquals("a", array.getString(0));
  assertEquals("\u00A2", array.getString(1));
  assertEquals("\u20AC", array.getString(2));
  assertEquals("\uD83D\uDE1C", array.getString(3));
  assertEquals(
      "\u017C\u00F3\u0142\u0107 g\u0119\u015Bl\u0105 \u6211 \uD83D\uDE0E ja\u017A\u0107",
      array.getString(4));
}
 
Example #25
Source File: RNKakaoLinkModule.java    From react-native-kakao-links with MIT License 5 votes vote down vote up
private CommerceTemplate createCommerceTemplate(ReadableMap options) {
  CommerceTemplate.Builder commerceTemplate = CommerceTemplate.newBuilder(
    createContentObject(options.getMap("content")),
    createCommerceDetailObject(options.getMap("commerce"))
  );

  //add buttons
  ReadableArray buttons = options.getArray("buttons");
  if (buttons != null) {
    for (int i = 0; i < buttons.size(); i++) {
      commerceTemplate.addButton(createButtonObject(buttons.getMap(i)));
    }
  }
  return commerceTemplate.build();
}
 
Example #26
Source File: MidtransModule.java    From react-native-payment-gateway with MIT License 5 votes vote down vote up
/**
 * required for Mandiri Bill and BCA klikPay, Optional for other payment
 * @param itemDetails ReadableArray, holds information about item purchased by user TransactionRequest takes an array list of item details
 * @param transactionRequest object to request payment
 */
private void setItemDetail(ReadableArray itemDetails, TransactionRequest transactionRequest){
    ArrayList<ItemDetails> itemDetailsList = new ArrayList<>();
    for(int a=0; a < itemDetails.size(); a++){
        ReadableMap rmItem = itemDetails.getMap(a);
        String id = rmItem.getString("id");
        int price = rmItem.getInt("price");
        int qty = rmItem.getInt("qty");
        String name = rmItem.getString("name");
        itemDetailsList.add(new ItemDetails(id, price, qty, name));
    }
    transactionRequest.setItemDetails(itemDetailsList);
}
 
Example #27
Source File: RNTScratchViewManager.java    From react-native-scratch with MIT License 5 votes vote down vote up
@Override
public void receiveCommand(ScratchView view, int commandId, @javax.annotation.Nullable ReadableArray args) {
    super.receiveCommand(view, commandId, args);
    if (commandId == 0) {
        view.reset();
    }
}
 
Example #28
Source File: SamsungHealthModule.java    From react-native-samsung-health with The Unlicense 5 votes vote down vote up
@ReactMethod
public void connect(ReadableArray permissions, Callback error, Callback success)
{
    // Add permission
    ConnectionListener listener = new ConnectionListener(this, error, success);
    for (int i = 0; i < permissions.size(); i++) {
        listener.addReadPermission(permissions.getString(i));
    }

    // Create a HealthDataStore instance and set its listener
    mStore = new HealthDataStore(getReactApplicationContext(), listener);
    // Request the connection to the health data store
    mStore.connectService();
}
 
Example #29
Source File: RNNodeModule.java    From react-native-node with MIT License 5 votes vote down vote up
@ReactMethod
public void start(ReadableArray args) {
    Log.d(TAG, "Launching an intent for RNNodeService...");
    Intent intent = new Intent(_reactContext, RNNodeService.class);
    intent.putExtra("args", this.toStringArrayList(args));
    _reactContext.startService(intent);
}
 
Example #30
Source File: RNUtils.java    From react-native-batch-push with MIT License 5 votes vote down vote up
@Nullable
public static BatchEventData convertSerializedEventDataToEventData(@Nullable ReadableMap serializedEventData) {
    if (serializedEventData == null) {
        return null;
    }

    BatchEventData batchEventData = new BatchEventData();
    ReadableArray tags = serializedEventData.getArray("tags");

    for (int i = 0; i < tags.size(); i++) {
        batchEventData.addTag(tags.getString(i));
    }

    ReadableMap attributes = serializedEventData.getMap("attributes");
    ReadableMapKeySetIterator iterator = attributes.keySetIterator();

    while (iterator.hasNextKey()) {
        String key = iterator.nextKey();
        ReadableMap valueMap = attributes.getMap(key);

        String type = valueMap.getString("type");
        if ("string".equals(type)) {
            batchEventData.put(key, valueMap.getString("value"));
        } else if ("boolean".equals(type)) {
            batchEventData.put(key, valueMap.getBoolean("value"));
        } else if ("integer".equals(type)) {
            batchEventData.put(key, valueMap.getDouble("value"));
        } else if ("float".equals(type)) {
            batchEventData.put(key, valueMap.getDouble("value"));
        } else {
            Log.e("RNBatchPush", "Invalid parameter : Unknown event_data.attributes type (" + type + ")");
        }
    }

    return batchEventData;
}