List of usage examples for com.facebook.react.bridge Callback invoke
public void invoke(Object... args);
From source file:com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.java
@ReactMethod public void getLog(final Callback success, final Callback failure) { TSCallback callback = new TSCallback() { public void success(Object log) { success.invoke((String) log); }/*from w w w . j av a 2 s . co m*/ public void error(Object error) { failure.invoke((String) error); } }; getAdapter().getLog(callback); }
From source file:com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.java
private void setEnabled(boolean value) { Log.i(TAG, "- setEnabled: " + value + ", current value: " + Settings.getEnabled()); BackgroundGeolocation adapter = getAdapter(); if (value) {/* w ww .j ava2 s . c o m*/ TSCallback callback = new TSCallback() { public void success(Object state) { if (startCallback != null) { Callback success = startCallback.get("success"); success.invoke(getState()); startCallback = null; } } public void error(Object error) { startCallback = null; } }; adapter.start(callback); } }
From source file:com.zenome.bundlebus.BundleBusNativeModule.java
License:Open Source License
@ReactMethod public boolean checkUpdate(String aAppKey, final Callback aSuccCallback, final Callback aFailedCallback) { return mBundleBus.checkForUpdates(aAppKey, new ICheckUpdateListener() { @Override/*from w ww .j av a2 s . c om*/ public void onCheckUpdateSuccess(String aActionType) { aSuccCallback.invoke(aActionType); } @Override public void onCheckUpdateFailed(int aErrorCode, String aReason) { aFailedCallback.invoke(aErrorCode, aReason); } }); }
From source file:com.zenome.bundlebus.BundleBusNativeModule.java
License:Open Source License
@ReactMethod public boolean update(String aAppKey, final Callback aSuccCallback, final Callback aFailedCallback) { return mBundleBus.update(aAppKey, new IUpdateListener() { @Override//from w w w . j a va 2 s .co m public void onUpdateSuccess(String aActionType) { aSuccCallback.invoke(aActionType); } @Override public void onUpdateFailed(int aErrorCode, String aReason) { aFailedCallback.invoke(aErrorCode, aReason); } }); }
From source file:com.zenome.bundlebus.BundleBusNativeModule.java
License:Open Source License
@ReactMethod public void silentUpdate(String aAppKey, final Callback aSuccCallback, final Callback aFailedCallback) { mBundleBus.silentUpdate(aAppKey, new IUpdateListener() { @Override//from www. j a v a 2 s. c o m public void onUpdateSuccess(String aActionType) { aSuccCallback.invoke(aActionType); } @Override public void onUpdateFailed(int aErrorCode, String aReason) { aFailedCallback.invoke(aErrorCode, aReason); } }); }
From source file:org.th317erd.react.DynamicFontsModule.java
License:Open Source License
@ReactMethod public void loadFontFromFile(final ReadableMap options, final Callback callback) { Activity currentActivity = getCurrentActivity(); if (currentActivity == null) { callback.invoke("Invalid activity"); return;/*from w ww .j av a2s . com*/ } String filePath = options.hasKey("filePath") ? options.getString("filePath") : null, name = (options.hasKey("name")) ? options.getString("name") : null; if (filePath == null || filePath.length() == 0) { callback.invoke("filePath property empty"); return; } File f = new File(filePath); if (f.exists() && f.canRead()) { boolean wasLoaded = false; try { Typeface typeface = Typeface.createFromFile(f); //Cache the font for react ReactFontManager.getInstance().setTypeface(name, typeface.getStyle(), typeface); wasLoaded = true; } catch (Throwable e) { callback.invoke(e.getMessage()); } finally { if (wasLoaded) { callback.invoke(null, name); } } } else { callback.invoke("invalid file"); } }
From source file:org.th317erd.react.DynamicFontsModule.java
License:Open Source License
@ReactMethod public void loadFont(final ReadableMap options, final Callback callback) throws Exception { Activity currentActivity = getCurrentActivity(); if (currentActivity == null) { callback.invoke("Invalid activity"); return;//from w ww . jav a 2 s.co m } String name = (options.hasKey("name")) ? options.getString("name") : null, data = (options.hasKey("data")) ? options.getString("data") : null, type = null; if (name == null || name.length() == 0) { callback.invoke("Name property empty"); return; } if (data == null || data.length() == 0) { callback.invoke("Data property empty"); return; } if (("data:").equalsIgnoreCase(data.substring(0, 5))) { Integer pos = data.indexOf(','); if (pos > 0) { String[] encodingParams = data.substring(5, pos).split(";"); String mimeType = encodingParams[0]; data = data.substring(pos + 1); if (("application/x-font-ttf").equalsIgnoreCase(mimeType) || ("application/x-font-truetype").equalsIgnoreCase(mimeType) || ("font/ttf").equalsIgnoreCase(mimeType)) { type = "ttf"; } else if (("application/x-font-opentype").equalsIgnoreCase(mimeType) || ("font/opentype").equalsIgnoreCase(mimeType)) { type = "otf"; } } } if (options.hasKey("type")) type = options.getString("type"); if (type == null) type = "ttf"; try { byte[] decodedBytes = Base64.decode(data, Base64.DEFAULT); File cacheFile = new File(currentActivity.getCacheDir(), "tempFont" + (tempNameCounter++) + type); FileOutputStream stream = new FileOutputStream(cacheFile); try { stream.write(decodedBytes); } finally { stream.close(); } //Load the font from the temporary file we just created Typeface typeface = Typeface.createFromFile(cacheFile); //Cache the font for react ReactFontManager.getInstance().setTypeface(name, typeface.getStyle(), typeface); cacheFile.delete(); } catch (Exception e) { callback.invoke(e.getMessage()); } finally { callback.invoke(null, name); } }
From source file:ph.com.globe.connect.Amax.java
License:Open Source License
/** * Send rewards request./*from ww w . j a v a2s. c o m*/ * * @param rewardsToken rewards token * @param address subscriber address * @param promo defined promo * @param success * @param error * @return void * @throws HttpRequestException http request exception * @throws HttpResponseException http response exception */ public void sendRewardRequest(String rewardsToken, String address, String promo, final Callback success, final Callback error) throws HttpRequestException, HttpResponseException { // set url String url = this.AMAX_URL; // set base data Map<String, Object> data = new HashMap<>(); // set outbound reward reqeuest data Map<String, Object> orr = new HashMap<>(); // set app id orr.put("app_id", this.appId); // set app secret orr.put("app_secret", this.appSecret); // set rewards token orr.put("rewards_token", rewardsToken); // set address orr.put("address", address); // set promo orr.put("promo", promo); // set outbound reward request data data.put("outboundRewardRequest", new org.json.JSONObject(orr)); // send request new HttpRequest() // set url .setUrl(url) // set data .setData(data) // set async handler .setAsyncHandler(new AsyncHandler() { @Override public void response(HttpResponse response) throws HttpResponseException { // try parsing try { // send response success.invoke(response.convertJsonToMap(response.getJsonResponse())); } catch (HttpResponseException e) { error.invoke(e.getMessage()); } } }) // execute async post .execute("post"); }
From source file:ph.com.globe.connect.Authentication.java
License:Open Source License
/** * Returns the Oauth dialog url./*w w w . ja v a 2 s . co m*/ * * @param success * @param error * @throws ApiException api exception */ @ReactMethod public void getDialogUrl(Callback success, Callback error) throws ApiException { // try parsing url try { // build url String url = this.API_HOST + this.DIALOG_URL; // initialize url builder URIBuilder builder = new URIBuilder(url); // set app_id parameter builder.setParameter("app_id", this.appId); // build the url url = builder.build().toString(); success.invoke(url); } catch (URISyntaxException e) { error.invoke(e.getMessage()); } }
From source file:ph.com.globe.connect.Authentication.java
License:Open Source License
/** * Get access token request./* w w w . j a v a 2 s . com*/ * * @param code access code * @param success * @param error * @return void * @throws HttpRequestException http request exception * @throws HttpResponseException http response excetion */ @ReactMethod public void getAccessToken(String code, final Callback success, final Callback error) throws HttpRequestException, HttpResponseException { // create data key value Map<String, Object> data = new HashMap<>(); // set app id data.put("app_id", this.appId); // set app secret data.put("app_secret", this.appSecret); // set app code data.put("code", code); // send request new HttpRequest() // set url .setUrl(this.getAccessUrl()) // set data .setData(data) // set async handler .setAsyncHandler(new AsyncHandler() { @Override public void response(HttpResponse response) throws HttpResponseException { // try parsing try { // send response success.invoke(response.convertJsonToMap(response.getJsonResponse())); } catch (HttpResponseException e) { error.invoke(e.getMessage()); } } }) // execute async post .execute("post"); }