Java Code Examples for com.facebook.react.bridge.WritableMap.putString()

The following are Jave code examples for showing how to use putString() of the com.facebook.react.bridge.WritableMap 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: taplytics-react-native   File: TRNBroadcastReceiver.java   Source Code and License Vote up 6 votes
private WritableMap getIntentData(Intent intent) {
    WritableMap data = Arguments.createMap();
    JSONObject dataObject = new JSONObject();
    try {
        if (intent.hasExtra("tl_id")) {
            dataObject.put("tl_id", intent.getExtras().getString("tl_id"));
        }
        if (intent.hasExtra("custom_keys")) {
            dataObject.put("custom_keys", new JSONObject(intent.getExtras().getString("custom_keys")));
        }
    } catch (Throwable ignored) {
        //Ignore the bad JSON for now. Log here as you please.
    }
    data.putString("value", dataObject.toString());
    return data;
}
 
Example 2
Project: react-native-webrtc   File: DataChannelObserver.java   Source Code and License Vote up 6 votes
@Override
public void onMessage(DataChannel.Buffer buffer) {
    WritableMap params = Arguments.createMap();
    params.putInt("id", mId);
    params.putInt("peerConnectionId", peerConnectionId);

    byte[] bytes;
    if (buffer.data.hasArray()) {
        bytes = buffer.data.array();
    } else {
        bytes = new byte[buffer.data.remaining()];
        buffer.data.get(bytes);
    }

    if (buffer.binary) {
        params.putString("type", "binary");
        params.putString("data", Base64.encodeToString(bytes, Base64.NO_WRAP));
    } else {
        params.putString("type", "text");
        params.putString("data", new String(bytes, Charset.forName("UTF-8")));
    }

    webRTCModule.sendEvent("dataChannelReceiveMessage", params);
}
 
Example 3
Project: react-native-twilio-chat   File: RCTConvert.java   Source Code and License Vote up 6 votes
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());

    WritableMap attributes = Arguments.createMap();
    try {
        attributes = jsonToWritableMap(message.getAttributes());
    }
    catch (JSONException e) {}
    map.putMap("attributes", attributes);
    return map;
}
 
Example 4
Project: react-native-pgp   File: Module.java   Source Code and License Vote up 5 votes
@ReactMethod
public void generateKeyPair(final String userId, final int numBits, final String passphrase, Promise promise) {
  Log.d("ReactNativePGP", "generateKeyPair");
  try {
    WritableMap resultMap = Arguments.createMap();
    PGPKeyRingGenerator keyGenerator = PGPUtils.generateKeyRingGenerator(userId, numBits, passphrase.toCharArray());

    // public key
    PGPPublicKeyRing publicKeyRing              = keyGenerator.generatePublicKeyRing();
    ByteArrayOutputStream publicKeyOutputStream = new ByteArrayOutputStream();
    ArmoredOutputStream armoredPubOutputStream  = new ArmoredOutputStream(publicKeyOutputStream);

    publicKeyRing.encode(armoredPubOutputStream);
    armoredPubOutputStream.close();
    resultMap.putString("publicKey", publicKeyOutputStream.toString("UTF-8"));

    // private key
    PGPSecretKeyRing secretKeyRing               = keyGenerator.generateSecretKeyRing();
    ByteArrayOutputStream privateKeyOutputStream = new ByteArrayOutputStream();
    ArmoredOutputStream armoredPrivOutputStream  = new ArmoredOutputStream(privateKeyOutputStream);

    secretKeyRing.encode(armoredPrivOutputStream);
    armoredPrivOutputStream.close();
    resultMap.putString("privateKey", privateKeyOutputStream.toString("UTF-8"));
    resultMap.putString("fingerPrint", Utils.bytesToHex(secretKeyRing.getPublicKey().getFingerprint()));

    promise.resolve(resultMap);
  } catch(Exception e) {
    promise.reject(new Exception(e.getMessage()));
  }
}
 
Example 5
Project: react-native-twilio-chat   File: RCTConvert.java   Source Code and License Vote up 5 votes
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;
}
 
Example 6
Project: RNLearn_Project1   File: TimePickerDialogModule.java   Source Code and License Vote up 5 votes
@Override
public void onTimeSet(TimePicker view, int hour, int minute) {
  if (!mPromiseResolved && getReactApplicationContext().hasActiveCatalystInstance()) {
    WritableMap result = new WritableNativeMap();
    result.putString("action", ACTION_TIME_SET);
    result.putInt("hour", hour);
    result.putInt("minute", minute);
    mPromise.resolve(result);
    mPromiseResolved = true;
  }
}
 
Example 7
Project: react-native-ibeacons   File: BeaconsAndroidModule.java   Source Code and License Vote up 5 votes
@ReactMethod
public void getMonitoredRegions(Callback callback) {
    WritableArray array = new WritableNativeArray();
    for (Region region: mBeaconManager.getMonitoredRegions()) {
        WritableMap map = new WritableNativeMap();
        map.putString("identifier", region.getUniqueId());
        map.putString("uuid", region.getId1().toString());
        map.putInt("major", region.getId2() != null ? region.getId2().toInt() : 0);
        map.putInt("minor", region.getId3() != null ? region.getId3().toInt() : 0);
        array.pushMap(map);
    }
    callback.invoke(array);
}
 
Example 8
Project: react-native-android-text-to-speech   File: RNAndroidTextToSpeechModule.java   Source Code and License Vote up 5 votes
@ReactMethod
public void setDefaultSpeechRate(float speechRate, Promise promise) {
	if(notReady(promise)) return;

	int result = tts.setSpeechRate(speechRate);
	if(result == TextToSpeech.SUCCESS) {
		WritableMap map = Arguments.createMap();
		map.putString("status", "Success");
		map.putDouble("speechRate", (double)speechRate);
		promise.resolve(map);
	} else {
		promise.reject("error", "Unable to set speech rate");
	}
}
 
Example 9
Project: react-native-android-text-to-speech   File: RNAndroidTextToSpeechModule.java   Source Code and License Vote up 5 votes
@ReactMethod
public void setDefaultPitch(float pitch, Promise promise) {
	if(notReady(promise)) return;

	int result = tts.setPitch(pitch);
	if(result == TextToSpeech.SUCCESS) {
		WritableMap map = Arguments.createMap();
		map.putString("status", "Success");
		map.putDouble("pitch", (double)pitch);
		promise.resolve(map);
	} else {
		promise.reject("error", "Unable to set pitch");
	}
}
 
Example 10
Project: react-native-twilio-chat   File: RCTTwilioChatClient.java   Source Code and License Vote up 5 votes
@Override
public void onToastFailed(ErrorInfo errorInfo) {
    WritableMap map = Arguments.createMap();
    map.putString("error",errorInfo.getErrorText());
    map.putString("userInfo", errorInfo.toString());

    sendEvent("chatClient:toastFailed", map);
}
 
Example 11
Project: react-native-android-new-crosswalk   File: ErrorEvent.java   Source Code and License Vote up 5 votes
private WritableMap serializeEventData () {
    WritableMap eventData = Arguments.createMap();
    eventData.putInt("errorNumber", errorNumber);
    eventData.putString("errorMessage", errorMessage);
    eventData.putString("url", url);

    return eventData;
}
 
Example 12
Project: RNLearn_Project1   File: DatePickerDialogModule.java   Source Code and License Vote up 5 votes
@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
  if (!mPromiseResolved && getReactApplicationContext().hasActiveCatalystInstance()) {
    WritableMap result = new WritableNativeMap();
    result.putString("action", ACTION_DATE_SET);
    result.putInt("year", year);
    result.putInt("month", month);
    result.putInt("day", day);
    mPromise.resolve(result);
    mPromiseResolved = true;
  }
}
 
Example 13
Project: react-native-twilio-chat   File: RCTTwilioChatClient.java   Source Code and License Vote up 5 votes
@Override
public void onToastNotification(String channelSid, String messageSid) {
    WritableMap map = Arguments.createMap();
    map.putString("channelSid", channelSid);
    map.putString("messageSid", messageSid);

    sendEvent("chatClient:toastReceived", map);
}
 
Example 14
Project: React-Native-Music-Player   File: MusicPlayerModule.java   Source Code and License Vote up 5 votes
/**
 * Play Song and update UI
 * @param songURL
 * @param songName
 * @param AlbumArt
 */
@ReactMethod
public void playThisSong(String songURL, String songName, String AlbumArt) {
    if (IS_SONG_PAUSED) {
        DemoPlayer.getInstance().resume();
    } else {
        DemoPlayer.getInstance().play(songURL,
                MusicPlayerModule.this);
    }
    IS_SONG_PAUSED = false;

    //Update UI with new SOng Info
    WritableMap paramsUI = Arguments.createMap();
    paramsUI.putString(KEY_UPDATE_SONG_NAME, songName);
    paramsUI.putString(KEY_UPDATE_ALBUM_ART, AlbumArt);
    paramsUI.putString(KEY_UPDATE_DURATION, PlayerUtil.milliSecondsToTimer(DemoPlayer.getInstance().getPlayer()
            .getDuration()));
    paramsUI.putInt(KEY_UPDATE_SEEK_POSTION, DemoPlayer.getInstance().getProgress());
    sendEvent(reactAppContext, EVENT_SONG_CHANGED, paramsUI);

    //Start Progress bar update
    ((MainActivity) getCurrentActivity()).getSongProgressHandler().postDelayed(updateProgressTask, DELAY_MILLIS);
    WritableMap params = Arguments.createMap();
    params.putBoolean(KEY_SONG_PAUSED, IS_SONG_PAUSED);
    params.putInt(KEY_UPDATE_SEEK_POSTION, DemoPlayer.getInstance().getProgress());
    sendEvent(reactAppContext, EVENT_UPDATE_PROGRESS, params);
}
 
Example 15
Project: react-native-telephony   File: TelephonyModule.java   Source Code and License Vote up 5 votes
@Override
public void phoneDataConnectionStateUpdated(int direction) {
    WritableMap map = Arguments.createMap();
    map.putInt("direction", direction);

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

    sendEvent(PHONE_STATE_LISTENER, result);
}
 
Example 16
Project: react-native-blue-manager   File: Helper.java   Source Code and License Vote up 5 votes
public static WritableMap decodePermissions(BluetoothGattCharacteristic characteristic) {

		// NOTE: props strings need to be consistent across iOS and Android
		WritableMap props = Arguments.createMap();
		int permissions = characteristic.getPermissions();

		if ((permissions & BluetoothGattCharacteristic.PERMISSION_READ) != 0x0 ) {
			props.putString("Read", "Read");
		}

		if ((permissions & BluetoothGattCharacteristic.PERMISSION_WRITE) != 0x0 ) {
			props.putString("Write", "Write");
		}

		if ((permissions & BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED) != 0x0 ) {
			props.putString("ReadEncrypted", "ReadEncrypted");
		}

		if ((permissions & BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED) != 0x0 ) {
			props.putString("WriteEncrypted", "WriteEncrypted");
		}

		if ((permissions & BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED_MITM) != 0x0 ) {
			props.putString("ReadEncryptedMITM", "ReadEncryptedMITM");
		}

		if ((permissions & BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM) != 0x0 ) {
			props.putString("WriteEncryptedMITM", "WriteEncryptedMITM");
		}

		if ((permissions & BluetoothGattCharacteristic.PERMISSION_WRITE_SIGNED) != 0x0 ) {
			props.putString("WriteSigned", "WriteSigned");
		}

		if ((permissions & BluetoothGattCharacteristic.PERMISSION_WRITE_SIGNED_MITM) != 0x0 ) {
			props.putString("WriteSignedMITM", "WriteSignedMITM");
		}

		return props;
	}
 
Example 17
Project: react-native-twilio-chat   File: RCTTwilioChatClient.java   Source Code and License Vote up 5 votes
@Override
public void onChannelSynchronizationChange(Channel channel) {
    WritableMap map = Arguments.createMap();
    map.putString("channelSid",channel.getSid());
    map.putString("status", channel.getSynchronizationStatus().toString());

    sendEvent("chatClient:channel:synchronizationStatusChanged", map);
}
 
Example 18
Project: RNLearn_Project1   File: PositionError.java   Source Code and License Vote up 5 votes
public static WritableMap buildError(int code, String message) {
  WritableMap error = Arguments.createMap();
  error.putInt("code", code);
  if (message != null) {
    error.putString("message", message);
  }
  return error;
}
 
Example 19
Project: react-native-leancloud-sdk   File: RNPushNotificationJsDelivery.java   Source Code and License Vote up 4 votes
void notifyRemoteFetch(Bundle bundle) {
    String bundleString = convertJSON(bundle);
    WritableMap params = Arguments.createMap();
    params.putString("dataJSON", bundleString);
    sendEvent("remoteFetch", params);
}
 
Example 20
Project: RNLearn_Project1   File: ReactTextInputSubmitEditingEvent.java   Source Code and License Vote up 4 votes
private WritableMap serializeEventData() {
  WritableMap eventData = Arguments.createMap();
  eventData.putInt("target", getViewTag());
  eventData.putString("text", mText);
  return eventData;
}