List of usage examples for com.facebook.react.bridge WritableNativeMap WritableNativeMap
public WritableNativeMap()
From source file:by.iba.gomel.avkhonia.MFReactNativeBind.GenericSecurityCheckChallengeHandler.java
License:Apache License
public void login(JSONObject credentials) { Log.d("IBATimesheet", "Try to login"); if (isChallenged) { submitChallengeAnswer(credentials); } else {//from ww w . j a v a 2s. co m WLAuthorizationManager.getInstance().login(Constants.SECURITY_CHECK, credentials, new WLLoginResponseListener() { @Override public void onSuccess() { reactApplicationContext .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class); Log.d("IBATimesheet", "login - LOGIN_SUCCESS event"); sendEvent(reactApplicationContext, "LOGIN_SUCCESS", null); } @Override public void onFailure(WLFailResponse wlFailResponse) { WritableMap params = new WritableNativeMap(); params.putString("errorMsg", wlFailResponse.getErrorMsg()); Log.d("IBATimesheet", "Connection failure: " + wlFailResponse.getErrorCode().getDescription() + ": " + wlFailResponse.getErrorMsg()); sendEvent(reactApplicationContext, "CONNECTION_ERROR", params); } }); } }
From source file:by.iba.gomel.avkhonia.MFReactNativeBind.GenericSecurityCheckChallengeHandler.java
License:Apache License
public void logout() { Log.d("IBATimesheet", "Try to logout"); WLAuthorizationManager.getInstance().logout(Constants.SECURITY_CHECK, new WLLogoutResponseListener() { @Override//from w w w . j a va 2 s .c o m public void onSuccess() { reactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class); sendEvent(reactApplicationContext, "LOGOUT_SUCCESS", null); } @Override public void onFailure(WLFailResponse wlFailResponse) { WritableMap params = new WritableNativeMap(); params.putString("errorMsg", wlFailResponse.getErrorMsg()); reactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class); sendEvent(reactApplicationContext, "LOGOUT_FAILURE", null); } }); }
From source file:com.boundlessgeo.spatialconnect.jsbridge.SCBridge.java
License:Apache License
private static WritableMap convertJsonToMap(JSONObject jsonObject) throws JSONException { WritableMap map = new WritableNativeMap(); Iterator<String> iterator = jsonObject.keys(); while (iterator.hasNext()) { String key = iterator.next(); Object value = jsonObject.get(key); if (value instanceof JSONObject) { map.putMap(key, convertJsonToMap((JSONObject) value)); } else if (value instanceof JSONArray) { map.putArray(key, convertJsonToArray((JSONArray) value)); } else if (value instanceof Boolean) { map.putBoolean(key, (Boolean) value); } else if (value instanceof Integer) { map.putInt(key, (Integer) value); } else if (value instanceof Double) { map.putDouble(key, (Double) value); } else if (value instanceof String) { map.putString(key, (String) value); } else {/*from w ww .j av a 2s . c o m*/ map.putString(key, value.toString()); } } return map; }
From source file:com.dylanvann.cameraroll.CameraRollManager.java
License:Open Source License
private static void putAlbums(ContentResolver resolver, Cursor cursor, WritableMap response) { WritableArray albums = new WritableNativeArray(); int bucketIdIndex = cursor.getColumnIndex(Video.VideoColumns.BUCKET_ID); int bucketNameIndex = cursor.getColumnIndex(Video.VideoColumns.BUCKET_DISPLAY_NAME); int idIndex = cursor.getColumnIndex(FileColumns._ID); int mimeTypeIndex = cursor.getColumnIndex(FileColumns.MIME_TYPE); int mediaTypeIndex = cursor.getColumnIndex(FileColumns.MEDIA_TYPE); int dateModifiedIndex = cursor.getColumnIndex(FileColumns.DATE_MODIFIED); int widthIndex = IS_JELLY_BEAN_OR_LATER ? cursor.getColumnIndex(FileColumns.WIDTH) : -1; int heightIndex = IS_JELLY_BEAN_OR_LATER ? cursor.getColumnIndex(FileColumns.HEIGHT) : -1; HashMap<String, WritableMap> albumsMap = new HashMap<>(); String assetCountKey = "assetCount"; if (cursor.moveToFirst()) { {/* w w w.j a v a 2 s . c om*/ WritableMap album = new WritableNativeMap(); album.putInt(assetCountKey, cursor.getCount()); WritableArray previewAssets = new WritableNativeArray(); WritableMap asset = new WritableNativeMap(); putAssetInfo(resolver, cursor, asset, mediaTypeIndex, idIndex, widthIndex, heightIndex, mimeTypeIndex, dateModifiedIndex); previewAssets.pushMap(asset); album.putArray("previewAssets", previewAssets); albumsMap.put("-1", album); } while (cursor.moveToNext()) { String albumId = cursor.getString(bucketIdIndex); if (!albumsMap.containsKey(albumId)) { WritableMap album = new WritableNativeMap(); String albumName = cursor.getString(bucketNameIndex); album.putString("id", albumId); album.putString("title", albumName); album.putInt(assetCountKey, 1); WritableArray previewAssets = new WritableNativeArray(); WritableMap asset = new WritableNativeMap(); putAssetInfo(resolver, cursor, asset, mediaTypeIndex, idIndex, widthIndex, heightIndex, mimeTypeIndex, dateModifiedIndex); previewAssets.pushMap(asset); album.putArray("previewAssets", previewAssets); albumsMap.put(albumId, album); } else { WritableMap album = albumsMap.get(albumId); int count = album.getInt(assetCountKey); album.putInt(assetCountKey, count + 1); } } Collection<WritableMap> albumsCollection = albumsMap.values(); for (WritableMap album : albumsCollection) { albums.pushMap(album); } } response.putArray("albums", albums); }
From source file:com.dylanvann.cameraroll.CameraRollManager.java
License:Open Source License
private static void putPageInfo(Cursor photos, WritableMap response, int limit) { WritableMap pageInfo = new WritableNativeMap(); pageInfo.putBoolean("has_next_page", limit < photos.getCount()); if (limit < photos.getCount()) { photos.moveToPosition(limit - 1); pageInfo.putString("end_cursor", photos.getString(photos.getColumnIndex(FileColumns.DATE_MODIFIED))); }/*from w w w.j a v a 2 s . co m*/ response.putMap("page_info", pageInfo); }
From source file:com.dylanvann.cameraroll.CameraRollManager.java
License:Open Source License
private static void putAssets(ContentResolver resolver, Cursor photos, WritableMap response, int limit) { WritableArray assets = new WritableNativeArray(); photos.moveToFirst();/* w w w. j a v a2 s . c o m*/ int idIndex = photos.getColumnIndex(FileColumns._ID); int mimeTypeIndex = photos.getColumnIndex(FileColumns.MIME_TYPE); int mediaTypeIndex = photos.getColumnIndex(FileColumns.MEDIA_TYPE); int dateModifiedIndex = photos.getColumnIndex(FileColumns.DATE_MODIFIED); int widthIndex = IS_JELLY_BEAN_OR_LATER ? photos.getColumnIndex(FileColumns.WIDTH) : -1; int heightIndex = IS_JELLY_BEAN_OR_LATER ? photos.getColumnIndex(FileColumns.HEIGHT) : -1; for (int i = 0; i < limit && !photos.isAfterLast(); i++) { WritableMap asset = new WritableNativeMap(); boolean imageInfoSuccess = putAssetInfo(resolver, photos, asset, mediaTypeIndex, idIndex, widthIndex, heightIndex, mimeTypeIndex, dateModifiedIndex); if (imageInfoSuccess) { assets.pushMap(asset); } else { // we skipped an image because we couldn't get its details (e.g. width/height), so we // decrement i in order to correctly reach the limit, if the cursor has enough rows i--; } photos.moveToNext(); } response.putArray("assets", assets); }
From source file:com.hijridatepicker.HijriDatePickerAndroidModule.java
License:Open Source License
/** * @param milliseconds your gregorian date in milliseconds * @return hijri date at the format of "dd-MM-yyyy" *///from w w w. j av a2 s .c o m @ReactMethod public void convertMillisecondsToHijriDate(double milliseconds, Promise promise) { try { UmmalquraCalendar ummalquraCalendar = new UmmalquraCalendar(); ummalquraCalendar.setTimeInMillis((long) milliseconds); WritableMap result = new WritableNativeMap(); result.putInt("year", ummalquraCalendar.get(Calendar.YEAR)); result.putInt("month", ummalquraCalendar.get(Calendar.MONTH)); result.putInt("day", ummalquraCalendar.get(Calendar.DAY_OF_MONTH)); promise.resolve(result); } catch (Exception e) { promise.reject(ERROR_CONVERT, "Exception while executing convertMillisecondsToHijriDate, Details: " + e.getMessage()); } }
From source file:com.ibatimesheet.RNJSONUtils.java
License:Apache License
public static WritableMap convertJsonToMap(JSONObject jsonObject) throws JSONException { WritableMap map = new WritableNativeMap(); Iterator<String> iterator = jsonObject.keys(); while (iterator.hasNext()) { String key = iterator.next(); Object value = jsonObject.get(key); if (value instanceof JSONObject) { map.putMap(key, convertJsonToMap((JSONObject) value)); } else if (value instanceof JSONArray) { map.putArray(key, convertJsonToArray((JSONArray) value)); } else if (value instanceof Boolean) { map.putBoolean(key, (Boolean) value); } else if (value instanceof Integer) { map.putInt(key, (Integer) value); } else if (value instanceof Double) { map.putDouble(key, (Double) value); } else if (value instanceof String) { map.putString(key, (String) value); } else {/*from ww w . j a v a 2s . c o m*/ map.putString(key, value.toString()); } } return map; }
From source file:com.microsoft.appcenter.reactnative.auth.AppCenterReactNativeAuthModule.java
License:Open Source License
@ReactMethod public void signIn(final Promise promise) { Auth.signIn().thenAccept(new AppCenterConsumer<SignInResult>() { @Override// w w w . j a va 2s. c o m public void accept(SignInResult signInResult) { WritableMap writableMap = new WritableNativeMap(); if (signInResult.getException() == null) { /* Sign-in succeeded, convert Java result to a JavaScript result. */ UserInformation userInformation = signInResult.getUserInformation(); writableMap.putString(ACCESS_TOKEN_KEY, userInformation.getAccessToken()); writableMap.putString(ACCOUNT_ID_KEY, userInformation.getAccountId()); writableMap.putString(ID_TOKEN_KEY, userInformation.getIdToken()); promise.resolve(writableMap); } else { Exception signInFailureException = signInResult.getException(); promise.reject("Sign-in failed", signInFailureException); } } }); }
From source file:com.microsoft.c3p.reactnative.C3PReactModule.java
License:Open Source License
private static WritableNativeMap convertObjectResult(JavaScriptValue objectResult) { WritableNativeMap convertedResult = new WritableNativeMap(); for (Map.Entry<String, JavaScriptValue> entry : objectResult.getObjectEntries()) { String key = entry.getKey(); JavaScriptValue value = entry.getValue(); switch (value.getType()) { case Null: convertedResult.putNull(key); break; case Boolean: convertedResult.putBoolean(key, value.getBoolean()); break; case Number: convertedResult.putDouble(key, value.getDouble()); break; case String: convertedResult.putString(key, value.getString()); break; case Object: convertedResult.putMap(key, C3PReactModule.convertObjectResult(value)); break; case Array: convertedResult.putArray(key, C3PReactModule.convertArrayResult(value)); break; }//from w w w.j ava 2 s . com } return convertedResult; }