com.facebook.react.bridge.Arguments Java Examples

The following examples show how to use com.facebook.react.bridge.Arguments. 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: RNHceModule.java    From react-native-nfc-hce with Apache License 2.0 6 votes vote down vote up
private WritableMap supportNFC() {
    NfcManager manager = (NfcManager) this.reactContext.getSystemService(this.reactContext.NFC_SERVICE);
    NfcAdapter adapter = manager.getDefaultAdapter();
    WritableMap map = Arguments.createMap();
    if (adapter != null) {
        map.putBoolean("support", true);
        if (adapter.isEnabled()) {
            map.putBoolean("enabled", true);
        } else {
            map.putBoolean("enabled", false);
        }
    } else {
        map.putBoolean("support", false);
        map.putBoolean("enabled", false);
    }

    return map;
}
 
Example #2
Source File: FirestackStorage.java    From react-native-firestack with MIT License 6 votes vote down vote up
private WritableMap getDownloadData(final UploadTask.TaskSnapshot taskSnapshot) {
  Uri downloadUrl = taskSnapshot.getDownloadUrl();
  StorageMetadata d = taskSnapshot.getMetadata();

  WritableMap resp = Arguments.createMap();
  resp.putString("downloadUrl", downloadUrl.toString());
  resp.putString("fullPath", d.getPath());
  resp.putString("bucket", d.getBucket());
  resp.putString("name", d.getName());

  WritableMap metadataObj = Arguments.createMap();
  metadataObj.putString("cacheControl", d.getCacheControl());
  metadataObj.putString("contentDisposition", d.getContentDisposition());
  metadataObj.putString("contentType", d.getContentType());
  resp.putMap("metadata", metadataObj);

  return resp;
}
 
Example #3
Source File: ReactNativeUtilTest.java    From react-native-azurenotificationhub with MIT License 6 votes vote down vote up
@Test
public void testEmitIntent() {
    when(mReactApplicationContext.hasActiveCatalystInstance()).thenReturn(true);
    DeviceEventManagerModule.RCTDeviceEventEmitter emitter = PowerMockito.mock(
            DeviceEventManagerModule.RCTDeviceEventEmitter.class);
    when(mReactApplicationContext.getJSModule(any())).thenReturn(emitter);
    when(Arguments.createMap()).thenReturn(PowerMockito.mock(WritableMap.class));

    Intent intent = PowerMockito.mock(Intent.class);
    when(intent.getStringExtra(KEY_INTENT_EVENT_NAME)).thenReturn("event");
    when(intent.getStringExtra(KEY_INTENT_EVENT_TYPE)).thenReturn(INTENT_EVENT_TYPE_BUNDLE);
    when(intent.getExtras()).thenReturn(mBundle);
    emitIntent(mReactApplicationContext, intent);
    verify(mReactApplicationContext, times(1)).hasActiveCatalystInstance();
    verify(mReactApplicationContext, times(1)).getJSModule(any());
    verify(emitter, times(1)).emit(eq("event"), any(WritableMap.class));

    reset(intent);
    when(intent.getStringExtra(KEY_INTENT_EVENT_NAME)).thenReturn("event");
    when(intent.getStringExtra(KEY_INTENT_EVENT_TYPE)).thenReturn(INTENT_EVENT_TYPE_STRING);
    when(intent.getStringExtra(KEY_INTENT_EVENT_STRING_DATA)).thenReturn("data");
    emitIntent(mReactApplicationContext, intent);
    verify(mReactApplicationContext, times(2)).hasActiveCatalystInstance();
    verify(mReactApplicationContext, times(2)).getJSModule(any());
    verify(emitter, times(1)).emit("event", "data");
}
 
Example #4
Source File: UserProfileBridge.java    From react-native-lock with MIT License 6 votes vote down vote up
private void put(String key, List<?> list, WritableMap into) {
    if (list == null || list.isEmpty()) {
        return;
    }

    final WritableArray array = Arguments.createArray();
    for (Object item: list) {
        if (item instanceof String) {
            array.pushString((String) item);
        }
        if (item instanceof Integer) {
            array.pushInt((Integer) item);
        }
        if (item instanceof Boolean) {
            array.pushBoolean((Boolean) item);
        }
        if (item instanceof Double) {
            array.pushDouble((Double) item);
        }
        if (item instanceof Date) {
            array.pushString(formatter.format(item));
        }
    }
    into.putArray(key, array);
}
 
Example #5
Source File: OTSessionManager.java    From opentok-react-native with MIT License 6 votes vote down vote up
@Override
public void onVideoEnabled(SubscriberKit subscriber, String reason) {

    String streamId = Utils.getStreamIdBySubscriber(subscriber);
    if (streamId.length() > 0) {
        ConcurrentHashMap<String, Stream> streams = sharedState.getSubscriberStreams();
        Stream mStream = streams.get(streamId);
        WritableMap subscriberInfo = Arguments.createMap();
        if (mStream != null) {
            subscriberInfo.putMap("stream", EventUtils.prepareJSStreamMap(mStream, subscriber.getSession()));
        }
        subscriberInfo.putString("reason", reason);
        sendEventMap(this.getReactApplicationContext(), subscriberPreface + "onVideoEnabled", subscriberInfo);
    }
    printLogs("onVideoEnabled " + reason);
}
 
Example #6
Source File: GoogleFitManager.java    From react-native-google-fit with MIT License 6 votes vote down vote up
@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_OAUTH) {
        mAuthInProgress = false;
        if (resultCode == Activity.RESULT_OK) {
            // Make sure the app is not already connected or attempting to connect
            if (!mApiClient.isConnecting() && !mApiClient.isConnected()) {
                mApiClient.connect();
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            Log.e(TAG, "Authorization - Cancel");
            WritableMap map = Arguments.createMap();
            map.putString("message", "" + "Authorization cancelled");
            sendEvent(mReactContext, "GoogleFitAuthorizeFailure", map);
        }
    }
}
 
Example #7
Source File: QTalkLoaclSearch.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
 * 给rn返回搜索地址
 * @param msg
 * @param promise
 */
@ReactMethod
public void searchUrl(String msg,Promise promise){
    WritableMap map = Arguments.createMap();
    map.putBoolean("is_ok", true);

    map.putString("data", QtalkNavicationService.getInstance().getSearchurl());
    map.putString("Msg",msg);
    Logger.i("QTalkLoaclSearch->"+QtalkNavicationService.getInstance().getSearchurl());
    try {
        promise.resolve(map);
    }catch (Exception e){
        Logger.i("QTalkLoaclSearch-searchUrl>"+e.getLocalizedMessage());
        promise.reject("500",e.toString(),e);
    }
}
 
Example #8
Source File: OTSessionManager.java    From opentok-react-native with MIT License 6 votes vote down vote up
@Override
public void onError(SubscriberKit subscriberKit, OpentokError opentokError) {

    String streamId = Utils.getStreamIdBySubscriber(subscriberKit);
    if (streamId.length() > 0) {
        ConcurrentHashMap<String, Stream> streams = sharedState.getSubscriberStreams();
        Stream mStream = streams.get(streamId);
        WritableMap subscriberInfo = Arguments.createMap();
        if (mStream != null) {
            subscriberInfo.putMap("stream", EventUtils.prepareJSStreamMap(mStream, subscriberKit.getSession()));
        }
        subscriberInfo.putMap("error", EventUtils.prepareJSErrorMap(opentokError));
        sendEventMap(this.getReactApplicationContext(), subscriberPreface +  "onError", subscriberInfo);
    }
    printLogs("onError: "+opentokError.getErrorDomain() + " : " +
            opentokError.getErrorCode() +  " - "+opentokError.getMessage());

}
 
Example #9
Source File: OAuthManagerModule.java    From react-native-oauth with MIT License 6 votes vote down vote up
@ReactMethod
public void deauthorize(final String providerName, final Callback onComplete) {
  try {
    Log.i(TAG, "deauthorizing " + providerName);
    HashMap<String,Object> cfg = this.getConfiguration(providerName);
    final String authVersion = (String) cfg.get("auth_version");

    _credentialsStore.delete(providerName);

    WritableMap resp = Arguments.createMap();
    resp.putString("status", "ok");

    onComplete.invoke(null, resp);
  } catch (Exception ex) {
    exceptionCallback(ex, onComplete);
  }
}
 
Example #10
Source File: RNYandexMapKitView.java    From react-native-yandexmapkit with MIT License 6 votes vote down vote up
@Override
public boolean onFinishGeoCode(GeoCode geoCode) {
    if (geoCode != null) {
        WritableMap payload = Arguments.createMap();
        payload.putString("displayName", geoCode.getDisplayName());
        payload.putString("kind", geoCode.getKind());
        payload.putString("title", geoCode.getTitle());
        payload.putString("subtitle", geoCode.getSubtitle());
        WritableMap point = Arguments.createMap();
        GeoPoint geoPoint = geoCode.getGeoPoint();
        point.putDouble("latitude", geoPoint.getLat());
        point.putDouble("longitude", geoPoint.getLon());
        payload.putMap("point", point);

        ReactContext reactContext = (ReactContext) getContext();
        reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(this.getId(), GEOCODING_EVENT, payload);
    }
    return true;
}
 
Example #11
Source File: NearbyConnectionModule.java    From react-native-google-nearby-connection with MIT License 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
	if (getReactApplicationContext().hasActiveCatalystInstance()) {
		String serviceId = intent.getStringExtra("serviceId");
		String endpointId = intent.getStringExtra("endpointId");
		int payloadType = intent.getIntExtra("payloadType", -1);
		String payloadId = intent.getStringExtra("payloadId");

		WritableMap out = Arguments.createMap();
		out.putString("serviceId", serviceId);
		out.putString("endpointId", endpointId);
		out.putInt("payloadType", payloadType);
		out.putString("payloadId", payloadId);

		if (payloadType == Payload.Type.FILE) {
			long payloadSize = intent.getLongExtra("payloadSize", -1);
			out.putDouble("payloadSize", payloadSize);
		}

		sendEvent(getReactApplicationContext(), "receive_payload", out);
	}
}
 
Example #12
Source File: ReactExoplayerView.java    From react-native-video with MIT License 6 votes vote down vote up
private WritableArray getAudioTrackInfo() {
    WritableArray audioTracks = Arguments.createArray();

    MappingTrackSelector.MappedTrackInfo info = trackSelector.getCurrentMappedTrackInfo();
    int index = getTrackRendererIndex(C.TRACK_TYPE_AUDIO);
    if (info == null || index == C.INDEX_UNSET) {
        return audioTracks;
    }

    TrackGroupArray groups = info.getTrackGroups(index);
    for (int i = 0; i < groups.length; ++i) {
        Format format = groups.get(i).getFormat(0);
        WritableMap audioTrack = Arguments.createMap();
        audioTrack.putInt("index", i);
        audioTrack.putString("title", format.id != null ? format.id : "");
        audioTrack.putString("type", format.sampleMimeType);
        audioTrack.putString("language", format.language != null ? format.language : "");
        audioTrack.putString("bitrate", format.bitrate == Format.NO_VALUE ? ""
                                : String.format(Locale.US, "%.2fMbps", format.bitrate / 1000000f));
        audioTracks.pushMap(audioTrack);
    }
    return audioTracks;
}
 
Example #13
Source File: DBManager.java    From react-native-android-sqlite with MIT License 6 votes vote down vote up
@ReactMethod
public void query(final String sql, final ReadableArray values, final Callback callback) {
	new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
		@Override
		protected void doInBackgroundGuarded(Void ...params) {
			WritableArray data = Arguments.createArray();

			// FLog.w(ReactConstants.TAG, "dbmanager.query.sql=%s", sql);
			// FLog.w(ReactConstants.TAG, "dbmanager.query.values.size()=%d", values.size());

			try {
				data = mDb.query(sql, values);
			} catch(Exception e) {
				FLog.w(ReactConstants.TAG, "Exception in database query: ", e);
				callback.invoke(ErrorUtil.getError(null, e.getMessage()), null);
			}

			callback.invoke(null, data);
		}
	}.execute();
}
 
Example #14
Source File: TweetView.java    From react-native-twitterkit with MIT License 6 votes vote down vote up
private void handleError() {
  LogUtils.d(TAG, "handleError");
  if(tweetView != null) {
    tweetView.setVisibility(View.INVISIBLE);
  }

  WritableMap evt = Arguments.createMap();
  evt.putString("message", "Could not load tweet");

  ReactContext ctx = (ReactContext) getContext();
  ctx.getJSModule(RCTEventEmitter.class).receiveEvent(
          getId(),
          "onLoadError",
          evt);

}
 
Example #15
Source File: RNStripeTerminalModule.java    From react-native-stripe-terminal with MIT License 6 votes vote down vote up
@ReactMethod
public void abortInstallUpdate(){
    if(pendingInstallUpdate!=null && !pendingInstallUpdate.isCompleted()){
        pendingInstallUpdate.cancel(new Callback() {
            @Override
            public void onSuccess() {
                pendingInstallUpdate = null;
                sendEventWithName(EVENT_ABORT_INSTALL_COMPLETION,Arguments.createMap());
            }

            @Override
            public void onFailure(@Nonnull TerminalException e) {
                WritableMap errorMap = Arguments.createMap();
                errorMap.putString(ERROR,e.getErrorMessage());
                sendEventWithName(EVENT_ABORT_INSTALL_COMPLETION,errorMap);
            }
        });
    }else{
        sendEventWithName(EVENT_ABORT_INSTALL_COMPLETION,Arguments.createMap());
    }
}
 
Example #16
Source File: TelephonyModule.java    From react-native-telephony with MIT License 6 votes vote down vote up
@Override
public void phoneSignalStrengthsUpdated(SignalStrength signalStrength) {
    WritableMap map = Arguments.createMap();
    map.putInt("cdmaDbm", signalStrength.getCdmaDbm());
    map.putInt("cdmaEcio()", signalStrength.getCdmaEcio());
    map.putInt("evdoDbm", signalStrength.getEvdoDbm());
    map.putInt("evdoEcio", signalStrength.getEvdoEcio());
    map.putInt("evdoSnr", signalStrength.getEvdoSnr());
    map.putInt("gsmBitErrorRate", signalStrength.getGsmBitErrorRate());
    map.putInt("gsmSignalStrength", signalStrength.getGsmSignalStrength());
    map.putBoolean("gsm", signalStrength.isGsm());

    WritableMap result = Arguments.createMap();
    result.putString("type", "LISTEN_SIGNAL_STRENGTHS");
    result.putMap("data", map);

    sendEvent(PHONE_STATE_LISTENER, result);
}
 
Example #17
Source File: RNStripeTerminalModule.java    From react-native-stripe-terminal with MIT License 6 votes vote down vote up
@ReactMethod
public void collectPaymentMethod(){
    pendingCreatePaymentIntent = Terminal.getInstance().collectPaymentMethod(lastPaymentIntent, this, new PaymentIntentCallback() {
        @Override
        public void onSuccess(@Nonnull PaymentIntent paymentIntent) {
            pendingCreatePaymentIntent = null;
            lastPaymentIntent = paymentIntent;
            WritableMap collectPaymentMethodMap = Arguments.createMap();
            collectPaymentMethodMap.putMap(INTENT,serializePaymentIntent(paymentIntent,lastCurrency));
            sendEventWithName(EVENT_PAYMENT_METHOD_COLLECTION,collectPaymentMethodMap);
        }

        @Override
        public void onFailure(@Nonnull TerminalException e) {
            pendingCreatePaymentIntent = null;
            WritableMap errorMap = Arguments.createMap();
            errorMap.putString(ERROR,e.getErrorMessage());
            errorMap.putInt(CODE,e.getErrorCode().ordinal());
            errorMap.putMap(INTENT,serializePaymentIntent(lastPaymentIntent,lastCurrency));
            sendEventWithName(EVENT_PAYMENT_METHOD_COLLECTION,errorMap);
        }
    });
}
 
Example #18
Source File: SocketsModule.java    From react-native-sockets with MIT License 6 votes vote down vote up
@ReactMethod
public void getIpAddress(Callback successCallback, Callback errorCallback) {
    WritableArray ipList = Arguments.createArray();
    try {
        Enumeration<NetworkInterface> enumNetworkInterfaces = NetworkInterface.getNetworkInterfaces();
        while (enumNetworkInterfaces.hasMoreElements()) {
            NetworkInterface networkInterface = enumNetworkInterfaces.nextElement();
            Enumeration<InetAddress> enumInetAddress = networkInterface.getInetAddresses();
            while (enumInetAddress.hasMoreElements()) {
                InetAddress inetAddress = enumInetAddress.nextElement();
                if (inetAddress.isSiteLocalAddress()) {
                    ipList.pushString(inetAddress.getHostAddress());
                }
            }
        }
    } catch (SocketException e) {
        Log.e(eTag, "getIpAddress SocketException", e);
        errorCallback.invoke(e.getMessage());
    }
    successCallback.invoke(ipList);
}
 
Example #19
Source File: RNStripeTerminalModule.java    From react-native-stripe-terminal with MIT License 6 votes vote down vote up
WritableMap serializeReader(Reader reader) {
    WritableMap writableMap = Arguments.createMap();
    if(reader!=null) {
        double batteryLevel = 0;
        if(reader.getBatteryLevel()!=null)
            batteryLevel = (double) reader.getBatteryLevel();
        writableMap.putDouble(BATTERY_LEVEL, batteryLevel);

        int readerType = 0;
        if(reader.getDeviceType()!=null)
            readerType = reader.getDeviceType().ordinal();
        writableMap.putInt(DEVICE_TYPE, readerType);

        String serial = "";

        if(reader.getSerialNumber()!=null)
            serial = reader.getSerialNumber();
        writableMap.putString(SERIAL_NUMBER, serial);

        String softwareVersion = "";
        if(reader.getSoftwareVersion()!=null)
            softwareVersion = reader.getSoftwareVersion();
        writableMap.putString(DEVICE_SOFTWARE_VERSION, softwareVersion);
    }
    return writableMap;
}
 
Example #20
Source File: ReactNativeUtilTest.java    From react-native-azurenotificationhub with MIT License 6 votes vote down vote up
@Test
public void testConvertBundleToMapNullArgument() {
    WritableMap expectedMap = PowerMockito.mock(WritableMap.class);
    when(Arguments.createMap()).thenReturn(expectedMap);

    WritableMap map = convertBundleToMap(null);

    Assert.assertEquals(map, expectedMap);
    verify(expectedMap, times(0)).putNull(anyString());
    verify(expectedMap, times(0)).putMap(anyString(), any());
    verify(expectedMap, times(0)).putString(anyString(), anyString());
    verify(expectedMap, times(0)).putDouble(anyString(), anyDouble());
    verify(expectedMap, times(0)).putDouble(anyString(), anyFloat());
    verify(expectedMap, times(0)).putInt(anyString(), anyInt());
    verify(expectedMap, times(0)).putBoolean(anyString(), anyBoolean());
    verify(expectedMap, times(0)).putNull(anyString());
}
 
Example #21
Source File: EscPosModule.java    From react-native-esc-pos with MIT License 6 votes vote down vote up
@ReactMethod
public void scanDevices() {
    scanManager.registerCallback(new ScanManager.OnBluetoothScanListener() {
        @Override
        public void deviceFound(BluetoothDevice bluetoothDevice) {
            WritableMap deviceInfoParams = Arguments.createMap();
            deviceInfoParams.putString("name", bluetoothDevice.getName());
            deviceInfoParams.putString("macAddress", bluetoothDevice.getAddress());

            // put deviceInfoParams into callbackParams
            WritableMap callbackParams = Arguments.createMap();
            callbackParams.putMap("deviceInfo", deviceInfoParams);
            callbackParams.putString("state", BluetoothEvent.DEVICE_FOUND.name());

            // emit callback to RN code
            reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                    .emit("bluetoothDeviceFound", callbackParams);
        }
    });
    scanManager.startScan();
}
 
Example #22
Source File: OrientationModule.java    From react-native-orientation-locker with MIT License 6 votes vote down vote up
@ReactMethod
public void lockToLandscapeLeft() {
    final Activity activity = getCurrentActivity();
    if (activity == null) return;
    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    isLocked = true;

    // force send an UI orientation event
    lastOrientationValue = "LANDSCAPE-LEFT";
    WritableMap params = Arguments.createMap();
    params.putString("orientation", lastOrientationValue);
    if (ctx.hasActiveCatalystInstance()) {
        ctx
        .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
        .emit("orientationDidChange", params);
    }

    // send a locked event
    WritableMap lockParams = Arguments.createMap();
    lockParams.putString("orientation", lastOrientationValue);
    if (ctx.hasActiveCatalystInstance()) {
        ctx
        .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
        .emit("lockDidChange", lockParams);
    }
}
 
Example #23
Source File: ShareModule.java    From react-native-GPay with MIT License 5 votes vote down vote up
/**
 * Open a chooser dialog to send text content to other apps.
 *
 * Refer http://developer.android.com/intl/ko/training/sharing/send.html
 *
 * @param content the data to send
 * @param dialogTitle the title of the chooser dialog
 */
@ReactMethod
public void share(ReadableMap content, String dialogTitle, Promise promise) {
  if (content == null) {
    promise.reject(ERROR_INVALID_CONTENT, "Content cannot be null");
    return;
  }

  try {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setTypeAndNormalize("text/plain");

    if (content.hasKey("title")) {
      intent.putExtra(Intent.EXTRA_SUBJECT, content.getString("title"));
    }

    if (content.hasKey("message")) {
      intent.putExtra(Intent.EXTRA_TEXT, content.getString("message"));
    }

    Intent chooser = Intent.createChooser(intent, dialogTitle);
    chooser.addCategory(Intent.CATEGORY_DEFAULT);

    Activity currentActivity = getCurrentActivity();
    if (currentActivity != null) {
      currentActivity.startActivity(chooser);
    } else {
      getReactApplicationContext().startActivity(chooser);
    }
    WritableMap result = Arguments.createMap();
    result.putString("action", ACTION_SHARED);
    promise.resolve(result);
  } catch (Exception e) {
    promise.reject(ERROR_UNABLE_TO_OPEN_DIALOG, "Failed to open share dialog");
  }
}
 
Example #24
Source File: ReactVideoView.java    From react-native-video with MIT License 5 votes vote down vote up
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {

    WritableMap error = Arguments.createMap();
    error.putInt(EVENT_PROP_WHAT, what);
    error.putInt(EVENT_PROP_EXTRA, extra);
    WritableMap event = Arguments.createMap();
    event.putMap(EVENT_PROP_ERROR, error);
    mEventEmitter.receiveEvent(getId(), Events.EVENT_ERROR.toString(), event);
    return true;
}
 
Example #25
Source File: NearbyConnectionModule.java    From react-native-google-nearby-connection with MIT License 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
	if (getReactApplicationContext().hasActiveCatalystInstance()) {
		String endpointId = intent.getStringExtra("endpointId");
		String endpointName = intent.getStringExtra("endpointName");
		String serviceId = intent.getStringExtra("serviceId");

		WritableMap out = Arguments.createMap();
		out.putString("endpointId", endpointId);
		out.putString("endpointName", endpointName);
		out.putString("serviceId", serviceId);

		sendEvent(getReactApplicationContext(), "endpoint_discovered", out);
	}
}
 
Example #26
Source File: RNStripeTerminalModule.java    From react-native-stripe-terminal with MIT License 5 votes vote down vote up
@Override
public void onReportReaderEvent(@Nonnull ReaderEvent event) {
    lastReaderEvent = event;
    WritableMap readerEventReportMap = Arguments.createMap();
    readerEventReportMap.putInt(EVENT,event.ordinal());
    readerEventReportMap.putMap(INFO,Arguments.createMap());
    sendEventWithName(EVENT_DID_REPORT_READER_EVENT, readerEventReportMap);
}
 
Example #27
Source File: RCTConvert.java    From react-native-twilio-ip-messaging with MIT License 5 votes vote down vote up
public static WritableMap Message(Message message) {
    WritableMap map = Arguments.createMap();

    map.putString("sid", message.getSid());
    map.putInt("index", (int) message.getMessageIndex());
    map.putString("author", message.getAuthor());
    map.putString("body", message.getMessageBody());
    map.putString("timestamp", message.getTimeStamp());
    map.putMap("attributes", jsonToWritableMap(message.getAttributes()));
    return map;
}
 
Example #28
Source File: FIRMessagingModule.java    From react-native-fcm with MIT License 5 votes vote down vote up
private void registerMessageHandler() {
    IntentFilter intentFilter = new IntentFilter("com.evollu.react.fcm.ReceiveNotification");

    LocalBroadcastManager.getInstance(getReactApplicationContext()).registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (getReactApplicationContext().hasActiveCatalystInstance()) {
                RemoteMessage message = intent.getParcelableExtra("data");
                WritableMap params = Arguments.createMap();
                WritableMap fcmData = Arguments.createMap();

                if (message.getNotification() != null) {
                    Notification notification = message.getNotification();
                    fcmData.putString("title", notification.getTitle());
                    fcmData.putString("body", notification.getBody());
                    fcmData.putString("color", notification.getColor());
                    fcmData.putString("icon", notification.getIcon());
                    fcmData.putString("tag", notification.getTag());
                    fcmData.putString("action", notification.getClickAction());
                }
                params.putMap("fcm", fcmData);
                params.putString("collapse_key", message.getCollapseKey());
                params.putString("from", message.getFrom());
                params.putString("google.message_id", message.getMessageId());
                params.putDouble("google.sent_time", message.getSentTime());

                if(message.getData() != null){
                    Map<String, String> data = message.getData();
                    Set<String> keysIterator = data.keySet();
                    for(String key: keysIterator){
                        params.putString(key, data.get(key));
                    }
                }
                sendEvent("FCMNotificationReceived", params);

            }
        }
    }, intentFilter);
}
 
Example #29
Source File: ReactAztecSelectionChangeEvent.java    From react-native-aztec with GNU General Public License v2.0 5 votes vote down vote up
private WritableMap serializeEventData() {
    WritableMap eventData = Arguments.createMap();
    eventData.putInt("target", getViewTag());
    eventData.putString("text", mText);
    eventData.putInt("selectionStart", mSelectionStart);
    eventData.putInt("selectionEnd", mSelectionEnd);
    return eventData;
}
 
Example #30
Source File: RCTConvert.java    From react-native-twilio-ip-messaging with MIT License 5 votes vote down vote up
private static WritableMap mapToWritableMap(Map<String,String> map) {
    if (map == null) {
        return null;
    }
    WritableMap writableMap = Arguments.createMap();
    for (String key : map.keySet()) {
        writableMap.putString(key, map.get(key));
    }
    return writableMap;
}