List of usage examples for org.apache.cordova PluginResult PluginResult
public PluginResult(Status status, List<PluginResult> multipartMessages)
From source file:com.cranberrygame.cordova.plugin.ad.appodeal.Util.java
License:Open Source License
public void _hideBannerAd() { removeBannerViewOverlap();/*from w w w . j ava 2s . c o m*/ PluginResult pr = new PluginResult(PluginResult.Status.OK, "onBannerAdHidden"); pr.setKeepCallback(true); callbackContextKeepCallback.sendPluginResult(pr); //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); //pr.setKeepCallback(true); //callbackContextKeepCallback.sendPluginResult(pr); }
From source file:com.cranberrygame.cordova.plugin.ad.revmob.Util.java
License:Open Source License
public void _showBannerAd(String position, String size) { if (bannerIsShowingOverlap() && position.equals(bannerPreviousPosition) && size.equals(bannerPreviousSize)) { return;//from w w w . j av a 2s .c o m } this.bannerPreviousPosition = position; this.bannerPreviousSize = size; if (bannerAdPreload) { bannerAdPreload = false; PluginResult pr = new PluginResult(PluginResult.Status.OK, "onBannerAdShown"); pr.setKeepCallback(true); plugin.getCallbackContextKeepCallback().sendPluginResult(pr); //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); //pr.setKeepCallback(true); //plugin.getCallbackContextKeepCallback().sendPluginResult(pr); } else { _hideBannerAd(); loadBannerAd(); } addBannerViewOverlap(position, size); }
From source file:com.cranberrygame.cordova.plugin.ad.unityads.Util.java
License:Open Source License
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("setLicenseKey")) { setLicenseKey(action, args, callbackContext); return true; } else if (action.equals("setUp")) { setUp(action, args, callbackContext); return true; } else if (action.equals("showVideoAd")) { showVideoAd(action, args, callbackContext); return true; } else if (action.equals("showRewardedVideoAd")) { showRewardedVideoAd(action, args, callbackContext); return true; } else if (action.equals("canShow")) { if (UnityAds.canShow() && UnityAds.canShowAds()) { PluginResult pr = new PluginResult(PluginResult.Status.OK, "YES"); callbackContext.sendPluginResult(pr); } else {/*www .j a v a 2 s . com*/ PluginResult pr = new PluginResult(PluginResult.Status.OK, "NO"); callbackContext.sendPluginResult(pr); } return true; } return false; // Returning false results in a "MethodNotFound" error. }
From source file:com.cranberrygame.cordova.plugin.exitappatsecond.ExitAppAtSecond.java
License:Open Source License
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { PluginResult result = null;/*from ww w . j ava2 s . c om*/ //args.length() //args.getString(0) //args.getString(1) //args.Int(0) //args.Int(1) //args.getBoolean(0) //args.getBoolean(1) if (action.equals("exitAppAtSecond")) { //Activity activity=cordova.getActivity(); //webView //String adUnit = args.getString(0); //Log.d("___PLUGIN_NAME___", adUnit); /* //back key exit method1 new AlertDialog.Builder(cordova.getActivity()) .setTitle("Exit") .setMessage("Do you want to exit?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { android.os.Process.killProcess(android.os.Process.myPid()); } }) .setNegativeButton("No", null) .setCancelable(false) .show(); */ //back key exit method2: back key twice //if (event.getDownTime() - lastPressedTime < PERIOD) { if (System.currentTimeMillis() - lastPressedTime < PERIOD) { PluginResult pr = new PluginResult(PluginResult.Status.OK, "onExitAppAtSecond"); //pr.setKeepCallback(true); callbackContext.sendPluginResult(pr); //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); //pr.setKeepCallback(true); //callbackContext.sendPluginResult(pr); //following code kill process completely //android.os.Process.killProcess(android.os.Process.myPid()); //following codes raise run time error: //https://apache.googlesource.com/cordova-android/+/2.9.x/framework/src/org/apache/cordova/App.java //webView.postMessage("exit", null); //cordova.getActivity().finish(); //webView.loadUrl("javascript:navigator.app.exitApp();"); } else { Toast.makeText(cordova.getActivity().getApplicationContext(), "press again to exit.", Toast.LENGTH_SHORT).show(); //lastPressedTime = event.getEventTime(); lastPressedTime = System.currentTimeMillis(); } return true; } return false; // Returning false results in a "MethodNotFound" error. }
From source file:com.cranberrygame.cordova.plugin.game.Util.java
License:Open Source License
private void _getPlayerScore(String leaderboardId) { class ResultCallbackSubmitScoreResult implements ResultCallback<Leaderboards.LoadPlayerScoreResult> { @Override/*ww w . j av a2 s .c o m*/ public void onResult(Leaderboards.LoadPlayerScoreResult result) { //https://developer.android.com/reference/com/google/android/gms/games/leaderboard/Leaderboards.LoadPlayerScoreResult.html if (result.getStatus().getStatusCode() == GamesStatusCodes.STATUS_OK) { //https://developer.android.com/reference/com/google/android/gms/games/leaderboard/LeaderboardScore.html LeaderboardScore ls = result.getScore(); long score = 0; if (ls != null) score = ls.getRawScore(); PluginResult pr = new PluginResult(PluginResult.Status.OK, score); //pr.setKeepCallback(true); getPlayerScoreCC.sendPluginResult(pr); //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); //pr.setKeepCallback(true); //getPlayerScoreCC.sendPluginResult(pr); } else { //PluginResult pr = new PluginResult(PluginResult.Status.OK); //pr.setKeepCallback(true); //getPlayerScoreCC.sendPluginResult(pr); PluginResult pr = new PluginResult(PluginResult.Status.ERROR); //pr.setKeepCallback(true); getPlayerScoreCC.sendPluginResult(pr); } } } //https://developer.android.com/reference/com/google/android/gms/games/leaderboard/Leaderboards.html //span: Time span to retrieve data for. Valid values are TIME_SPAN_DAILY, TIME_SPAN_WEEKLY, or TIME_SPAN_ALL_TIME. //leaderboardCollection: The leaderboard collection to retrieve scores for. Valid values are either COLLECTION_PUBLIC or COLLECTION_SOCIAL. //https://developer.android.com/reference/com/google/android/gms/games/leaderboard/Leaderboards.html#loadCurrentPlayerLeaderboardScore(com.google.android.gms.common.api.GoogleApiClient, java.lang.String, int, int) //https://developer.android.com/reference/com/google/android/gms/games/leaderboard/LeaderboardVariant.html#TIME_SPAN_DAILY //http://stackoverflow.com/questions/23248157/how-to-get-score-from-google-play-game-services-leaderboard-of-current-player Games.Leaderboards .loadCurrentPlayerLeaderboardScore(getGameHelper().getApiClient(), leaderboardId, LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC) .setResultCallback(new ResultCallbackSubmitScoreResult()); }
From source file:com.cranberrygame.cordova.plugin.game.Util.java
License:Open Source License
@Override public void onSignInSucceeded() { //Util.alert(cordova.getActivity(), "onSignInSucceeded"); //https://github.com/freshplanet/ANE-Google-Play-Game-Services/blob/master/android/src/com/freshplanet/googleplaygames/functions/AirGooglePlayGamesGetActivePlayerName.java //https://developer.android.com/reference/com/google/android/gms/games/Games.html#Players //https://developer.android.com/reference/com/google/android/gms/games/Players.html#getCurrentPlayer(com.google.android.gms.common.api.GoogleApiClient) //https://developer.android.com/reference/com/google/android/gms/games/Player.html Player player = Games.Players.getCurrentPlayer(getGameHelper().getApiClient()); JSONObject playerDetail = new JSONObject(); try {//from w w w .ja v a 2 s. c o m if (player != null) { String playerId = player.getPlayerId(); String displayName = player.getDisplayName(); //String title = player.getTitle(); playerDetail.put("playerId", playerId); playerDetail.put("playerDisplayName", displayName); } } catch (JSONException ex) { } PluginResult pr = new PluginResult(PluginResult.Status.OK, playerDetail); //pr.setKeepCallback(true); loginCC.sendPluginResult(pr); //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); //pr.setKeepCallback(true); //loginCC.sendPluginResult(pr); }
From source file:com.cranberrygame.cordova.plugin.InstallApp.java
License:Open Source License
private void _getInstalledApps(CallbackContext callbackContext) { //http://neverland.googlecode.com/svn/trunk/NeverLand/src/com/nearme/plugin/webview/client/cordova/AppLauncher.java final JSONArray installedApps = new JSONArray(); try {/*w w w . j ava2s.c om*/ final List<PackageInfo> apps = cordova.getActivity().getPackageManager() .getInstalledPackages(PackageManager.GET_SIGNATURES); for (PackageInfo packageInfo : apps) { if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) <= 0) { final JSONObject jsonObject = getJsonByPackageInfo(packageInfo); installedApps.put(jsonObject); } } PluginResult pr = new PluginResult(PluginResult.Status.OK, installedApps); //pr.setKeepCallback(true); callbackContext.sendPluginResult(pr); //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); //pr.setKeepCallback(true); //callbackContext.sendPluginResult(pr); } catch (JSONException ex) { //PluginResult pr = new PluginResult(PluginResult.Status.OK, installedApps); //pr.setKeepCallback(true); //callbackContext.sendPluginResult(pr); PluginResult pr = new PluginResult(PluginResult.Status.ERROR); //pr.setKeepCallback(true); callbackContext.sendPluginResult(pr); } }
From source file:com.cranberrygame.cordova.plugin.optionsmenu.OptionsMenu.java
License:Open Source License
@Override public Object onMessage(String id, Object data) { //https://github.com/dpogue/cordova-plugin-cambie/blob/master/src/android/Cambie.java //http://stackoverflow.com/questions/22403984/get-oncreateoptionsmenu-in-cordova-plugin //https://github.com/apache/cordova-android/blob/master/framework/src/org/apache/cordova/CordovaPlugin.java#L140 if (id.equals("onCreateOptionsMenu") || id.equals("onPrepareOptionsMenu")) { Menu menu = (Menu) data; if (this.menus != null) { menu.clear();//from w ww.j av a2s. com String[] _menus = this.menus.split(","); for (int i = 0; i < _menus.length; i++) { menu.add(0, i, 0, _menus[i]); } } } else if (id.equals("onOptionsItemSelected")) { MenuItem item = (MenuItem) data; //webView.loadUrl(String.format("javascript:cordova.fireDocumentEvent('onMenuSelected', {'menu': '%s'});", item.getTitle())); Log.d(LOG_TAG, "onOptionsItemSelected: " + item.getTitle()); JSONObject result = new JSONObject(); try { result.put("event", "onMenuSelected"); result.put("message", item.getTitle()); } catch (JSONException ex) { } //PluginResult pr = new PluginResult(PluginResult.Status.OK, "onMenuSelected"); PluginResult pr = new PluginResult(PluginResult.Status.OK, result); pr.setKeepCallback(true); callbackContextKeepCallback.sendPluginResult(pr); //PluginResult pr = new PluginResult(PluginResult.Status.ERROR); //pr.setKeepCallback(true); //callbackContextKeepCallback.sendPluginResult(pr); } return null; }
From source file:com.creare.notifications.Notifications.java
License:Apache License
/** * Builds and shows a native Android alert with given Strings * @param message The message the alert should display * @param title The title of the alert * @param buttonLabel The label of the button * @param callbackContext The callback context *//*from w ww . jav a 2s . c om*/ public synchronized void alert(final String message, final String title, final String buttonLabel, final CallbackContext callbackContext) { final CordovaInterface cordova = this.cordova; Runnable runnable = new Runnable() { public void run() { AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setMessage(message); dlg.setTitle(title); //dlg.setCanceledOnTouchOutside(false); // This is listed in the api (http://developer.android.com/reference/android/app/AlertDialog.html) but unavailable and unnecessary! dlg.setCancelable(false); dlg.setPositiveButton(buttonLabel, new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0)); } }); dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { public void onCancel(DialogInterface dialog) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0)); } }); changeTextDirection(dlg); }; }; this.cordova.getActivity().runOnUiThread(runnable); }
From source file:com.creare.notifications.Notifications.java
License:Apache License
/** * Builds and shows a native Android confirm dialog with given title, message, buttons. * This dialog only shows up to 3 buttons. Any labels after that will be ignored. * The index of the button pressed will be returned to the JavaScript callback identified by callbackId. * * @param message The message the dialog should display * @param title The title of the dialog * @param buttonLabels A comma separated list of button labels (Up to 3 buttons) * @param callbackContext The callback context. *//*from w w w . j a v a 2s .c o m*/ public synchronized void confirm(final String message, final String title, final JSONArray buttonLabels, final CallbackContext callbackContext) { final CordovaInterface cordova = this.cordova; Runnable runnable = new Runnable() { public void run() { AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setMessage(message); dlg.setTitle(title); dlg.setCancelable(false); // First button if (buttonLabels.length() > 0) { try { dlg.setNegativeButton(buttonLabels.getString(0), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 1)); } }); } catch (JSONException e) { } } // Second button if (buttonLabels.length() > 1) { try { dlg.setNeutralButton(buttonLabels.getString(1), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 2)); } }); } catch (JSONException e) { } } // Third button if (buttonLabels.length() > 2) { try { dlg.setPositiveButton(buttonLabels.getString(2), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 3)); } }); } catch (JSONException e) { } } dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { public void onCancel(DialogInterface dialog) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0)); } }); changeTextDirection(dlg); }; }; this.cordova.getActivity().runOnUiThread(runnable); }