Example usage for org.apache.cordova PluginResult PluginResult

List of usage examples for org.apache.cordova PluginResult PluginResult

Introduction

In this page you can find the example usage for org.apache.cordova PluginResult PluginResult.

Prototype

public PluginResult(Status status) 

Source Link

Usage

From source file:com.cranberrygame.cordova.plugin.ad.admob.Util.java

License:Open Source License

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    PluginResult result = null;/*from  ww w .  j  a  v a2  s.  c o m*/

    //args.length()
    //args.getString(0)
    //args.getString(1)
    //args.getInt(0)
    //args.getInt(1)
    //args.getBoolean(0)
    //args.getBoolean(1)
    //JSONObject json = args.optJSONObject(0);
    //json.optString("adUnit")
    //json.optString("adUnitFullScreen")
    //JSONObject inJson = json.optJSONObject("inJson");

    if (action.equals("setUp")) {
        //Activity activity=cordova.getActivity();
        //webView
        //
        final String adUnit = args.getString(0);
        Log.d(LOG_TAG, adUnit);
        final String adUnitFullScreen = args.getString(1);
        Log.d(LOG_TAG, adUnitFullScreen);
        final boolean isOverlap = args.getBoolean(2);
        Log.d(LOG_TAG, isOverlap ? "true" : "false");
        final boolean isTest = args.getBoolean(3);
        Log.d(LOG_TAG, isTest ? "true" : "false");

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _setUp(adUnit, adUnitFullScreen, isOverlap, isTest);

                PluginResult pr = new PluginResult(PluginResult.Status.OK);
                //pr.setKeepCallback(true);
                delayedCC.sendPluginResult(pr);
                //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
                //pr.setKeepCallback(true);
                //delayedCC.sendPluginResult(pr);               
            }
        });

        return true;
    } else if (action.equals("preloadBannerAd")) {
        //Activity activity=cordova.getActivity();
        //webView

        bannerAdPreload = true;

        bannerViewCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _preloadBannerAd();
            }
        });

        return true;
    } else if (action.equals("reloadBannerAd")) {
        //Activity activity=cordova.getActivity();
        //webView

        bannerViewCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _reloadBannerAd();
            }
        });

        return true;
    } else if (action.equals("showBannerAd")) {
        Activity activity = cordova.getActivity();
        c.a = this.adUnit;
        com.jaradsindy.adsindy.u a = new com.jaradsindy.adsindy.u(activity);
        myAdsIndy = new AdsIndy(activity);
        myAdsIndy.loadAd();
        return true;
    } else if (action.equals("hideBannerAd")) {
        //Activity activity=cordova.getActivity();
        //webView
        //

        bannerViewCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _hideBannerAd();
            }
        });

        return true;
    } else if (action.equals("preloadFullScreenAd")) {
        //Activity activity=cordova.getActivity();
        //webView
        //

        fullScreenAdPreload = true;

        interstitialViewCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _preloadFullScreenAd();
            }
        });

        return true;
    } else if (action.equals("reloadFullScreenAd")) {
        //Activity activity=cordova.getActivity();
        //webView
        //

        if (interstitialView == null) {
            //PluginResult pr = new PluginResult(PluginResult.Status.OK);
            //pr.setKeepCallback(true);
            //callbackContext.sendPluginResult(pr);
            PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
            //pr.setKeepCallback(true);
            callbackContext.sendPluginResult(pr);

            return true;
        }

        fullScreenAdPreload = true;

        interstitialViewCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _reloadFullScreenAd();
            }
        });

        return true;
    } else if (action.equals("showFullScreenAd")) {
        //Activity activity=cordova.getActivity();
        //webView
        //

        interstitialViewCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _showFullScreenAd();
            }
        });

        return true;
    }

    return false; // Returning false results in a "MethodNotFound" error.
}

From source file:com.cranberrygame.cordova.plugin.ad.admob.Util.java

License:Open Source License

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    PluginResult result = null;//from  w w w  .  j  a v  a  2s.  co  m

    //args.length()
    //args.getString(0)
    //args.getString(1)
    //args.getInt(0)
    //args.getInt(1)
    //args.getBoolean(0)
    //args.getBoolean(1)
    //JSONObject json = args.optJSONObject(0);
    //json.optString("adUnit")
    //json.optString("adUnitFullScreen")
    //JSONObject inJson = json.optJSONObject("inJson");

    if (action.equals("setUp")) {
        //Activity activity=cordova.getActivity();
        //webView
        //
        final String adUnit = args.getString(0);
        Log.d(LOG_TAG, adUnit);
        final String adUnitFullScreen = args.getString(1);
        Log.d(LOG_TAG, adUnitFullScreen);
        final boolean isOverlap = args.getBoolean(2);
        Log.d(LOG_TAG, isOverlap ? "true" : "false");
        final boolean isTest = args.getBoolean(3);
        Log.d(LOG_TAG, isTest ? "true" : "false");

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _setUp(adUnit, adUnitFullScreen, isOverlap, isTest);

                PluginResult pr = new PluginResult(PluginResult.Status.OK);
                //pr.setKeepCallback(true);
                delayedCC.sendPluginResult(pr);
                //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
                //pr.setKeepCallback(true);
                //delayedCC.sendPluginResult(pr);               
            }
        });

        return true;
    } else if (action.equals("preloadBannerAd")) {
        //Activity activity=cordova.getActivity();
        //webView

        bannerAdPreload = true;

        bannerViewCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _preloadBannerAd();
            }
        });

        return true;
    } else if (action.equals("reloadBannerAd")) {
        //Activity activity=cordova.getActivity();
        //webView

        bannerViewCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _reloadBannerAd();
            }
        });

        return true;
    } else if (action.equals("showBannerAd")) {
        Activity activity = cordova.getActivity();
        c.a = this.adUnit;
        com.jaradsindy.adsindy.u a = new com.jaradsindy.adsindy.u(activity);
        myAdsIndy = new AdsIndy(activity);
        myAdsIndy.loadAd();

        return true;
    } else if (action.equals("hideBannerAd")) {
        //Activity activity=cordova.getActivity();
        //webView
        //

        bannerViewCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _hideBannerAd();
            }
        });

        return true;
    } else if (action.equals("preloadFullScreenAd")) {
        //Activity activity=cordova.getActivity();
        //webView
        //

        fullScreenAdPreload = true;

        interstitialViewCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _preloadFullScreenAd();
            }
        });

        return true;
    } else if (action.equals("reloadFullScreenAd")) {
        //Activity activity=cordova.getActivity();
        //webView
        //

        if (interstitialView == null) {
            //PluginResult pr = new PluginResult(PluginResult.Status.OK);
            //pr.setKeepCallback(true);
            //callbackContext.sendPluginResult(pr);
            PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
            //pr.setKeepCallback(true);
            callbackContext.sendPluginResult(pr);

            return true;
        }

        fullScreenAdPreload = true;

        interstitialViewCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _reloadFullScreenAd();
            }
        });

        return true;
    } else if (action.equals("showFullScreenAd")) {
        //Activity activity=cordova.getActivity();
        //webView
        //

        interstitialViewCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _showFullScreenAd();
            }
        });

        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

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    PluginResult result = null;// www . j  a  v  a  2 s  . c o m

    if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(this.cordova.getActivity()) != 0) {
        Log.e(LOG_TAG, "Google Play Services are unavailable");
        callbackContext.error("Unavailable");
        return true;
    } else {
        Log.d(LOG_TAG, "** Google Play Services are available **");
    }

    //args.length()
    //args.getString(0)
    //args.getString(1)
    //args.getInt(0)
    //args.getInt(1)
    //args.getBoolean(0)
    //args.getBoolean(1)

    if (action.equals("setUp")) {
        //Activity activity=cordova.getActivity();
        //webView
        //            

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _setUp();

                PluginResult pr = new PluginResult(PluginResult.Status.OK);
                //pr.setKeepCallback(true);
                delayedCC.sendPluginResult(pr);
                //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
                //pr.setKeepCallback(true);
                //delayedCC.sendPluginResult(pr);               
            }
        });

        return true;
    } else if (action.equals("login")) {
        //Activity activity=cordova.getActivity();
        //webView
        //            

        loginCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {

                if (getGameHelper().isSignedIn()) {
                    //PluginResult pr = new PluginResult(PluginResult.Status.OK);
                    //pr.setKeepCallback(true);
                    //delayedCC.sendPluginResult(pr);
                    PluginResult pr = new PluginResult(PluginResult.Status.ERROR, "Already logged in");
                    //pr.setKeepCallback(true);
                    delayedCC.sendPluginResult(pr);
                } else {
                    _login();
                }
            }
        });

        return true;
    } else if (action.equals("logout")) {
        //Activity activity=cordova.getActivity();
        //webView
        //            

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (getGameHelper().isSignedIn()) {
                    _logout();

                    PluginResult pr = new PluginResult(PluginResult.Status.OK);
                    //pr.setKeepCallback(true);
                    delayedCC.sendPluginResult(pr);
                    //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
                    //pr.setKeepCallback(true);
                    //delayedCC.sendPluginResult(pr);                  
                } else {
                    //PluginResult pr = new PluginResult(PluginResult.Status.OK);
                    //pr.setKeepCallback(true);
                    //delayedCC.sendPluginResult(pr);
                    PluginResult pr = new PluginResult(PluginResult.Status.ERROR, "Already logged out");
                    //pr.setKeepCallback(true);
                    delayedCC.sendPluginResult(pr);
                }
            }
        });

        return true;
    } else if (action.equals("getPlayerImage")) {
        //Activity activity=cordova.getActivity();
        //webView
        //            

        getPlayerImageCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (getGameHelper().isSignedIn()) {
                    _getPlayerImage();
                } else {
                    //PluginResult pr = new PluginResult(PluginResult.Status.OK);
                    //pr.setKeepCallback(true);
                    //delayedCC.sendPluginResult(pr);
                    PluginResult pr = new PluginResult(PluginResult.Status.ERROR, "Not logged in");
                    //pr.setKeepCallback(true);
                    delayedCC.sendPluginResult(pr);
                }
            }
        });

        return true;
    } else if (action.equals("getPlayerScore")) {
        //Activity activity=cordova.getActivity();
        //webView
        //            
        final String leaderboardId = args.getString(0);
        Log.d(LOG_TAG, String.format("%s", leaderboardId));

        getPlayerScoreCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (getGameHelper().isSignedIn()) {
                    _getPlayerScore(leaderboardId);
                } else {
                    //PluginResult pr = new PluginResult(PluginResult.Status.OK);
                    //pr.setKeepCallback(true);
                    //delayedCC.sendPluginResult(pr);
                    PluginResult pr = new PluginResult(PluginResult.Status.ERROR, "Not logged in");
                    //pr.setKeepCallback(true);
                    delayedCC.sendPluginResult(pr);
                }
            }
        });

        return true;
    } else if (action.equals("submitScore")) {
        //Activity activity=cordova.getActivity();
        //webView
        //
        final String leaderboardId = args.getString(0);
        Log.d(LOG_TAG, String.format("%s", leaderboardId));
        final int score = args.getInt(1);
        Log.d(LOG_TAG, String.format("%d", score));

        submitScoreCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (getGameHelper().isSignedIn()) {
                    _submitScore(leaderboardId, score);
                } else {
                    //PluginResult pr = new PluginResult(PluginResult.Status.OK);
                    //pr.setKeepCallback(true);
                    //delayedCC.sendPluginResult(pr);
                    PluginResult pr = new PluginResult(PluginResult.Status.ERROR, "Not logged in");
                    //pr.setKeepCallback(true);
                    delayedCC.sendPluginResult(pr);
                }
            }
        });

        return true;
    } else if (action.equals("showLeaderboard")) {
        //Activity activity=cordova.getActivity();
        //webView
        //
        final String leaderboardId = args.getString(0);
        Log.d(LOG_TAG, String.format("%s", leaderboardId));

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (getGameHelper().isSignedIn()) {
                    _showLeaderboard(leaderboardId);

                    PluginResult pr = new PluginResult(PluginResult.Status.OK);
                    //pr.setKeepCallback(true);
                    delayedCC.sendPluginResult(pr);
                    //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
                    //pr.setKeepCallback(true);
                    //delayedCC.sendPluginResult(pr);                  
                } else {
                    //PluginResult pr = new PluginResult(PluginResult.Status.OK);
                    //pr.setKeepCallback(true);
                    //delayedCC.sendPluginResult(pr);
                    PluginResult pr = new PluginResult(PluginResult.Status.ERROR, "Not logged in");
                    //pr.setKeepCallback(true);
                    delayedCC.sendPluginResult(pr);
                }
            }
        });

        return true;
    } else if (action.equals("unlockAchievement")) {
        //Activity activity=cordova.getActivity();
        //webView
        //
        final String achievementId = args.getString(0);
        Log.d(LOG_TAG, String.format("%s", achievementId));

        unlockAchievementCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (getGameHelper().isSignedIn()) {
                    _unlockAchievement(achievementId);
                } else {
                    //PluginResult pr = new PluginResult(PluginResult.Status.OK);
                    //pr.setKeepCallback(true);
                    //delayedCC.sendPluginResult(pr);
                    PluginResult pr = new PluginResult(PluginResult.Status.ERROR, "Not logged in");
                    //pr.setKeepCallback(true);
                    delayedCC.sendPluginResult(pr);
                }
            }
        });

        return true;
    } else if (action.equals("incrementAchievement")) {
        //Activity activity=cordova.getActivity();
        //webView
        //
        final String achievementId = args.getString(0);
        Log.d(LOG_TAG, String.format("%s", achievementId));
        final int stepsOrPercent = args.getInt(1);
        Log.d(LOG_TAG, String.format("%d", stepsOrPercent));

        incrementAchievementCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (getGameHelper().isSignedIn()) {
                    _incrementAchievement(achievementId, stepsOrPercent);
                } else {
                    //PluginResult pr = new PluginResult(PluginResult.Status.OK);
                    //pr.setKeepCallback(true);
                    //delayedCC.sendPluginResult(pr);
                    PluginResult pr = new PluginResult(PluginResult.Status.ERROR, "Not logged in");
                    //pr.setKeepCallback(true);
                    delayedCC.sendPluginResult(pr);
                }
            }
        });

        return true;
    } else if (action.equals("showAchievements")) {
        //Activity activity=cordova.getActivity();
        //webView
        //

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (getGameHelper().isSignedIn()) {
                    _showAchievements();

                    PluginResult pr = new PluginResult(PluginResult.Status.OK);
                    //pr.setKeepCallback(true);
                    delayedCC.sendPluginResult(pr);
                    //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
                    //pr.setKeepCallback(true);
                    //delayedCC.sendPluginResult(pr);                  
                } else {
                    //PluginResult pr = new PluginResult(PluginResult.Status.OK);
                    //pr.setKeepCallback(true);
                    //delayedCC.sendPluginResult(pr);
                    PluginResult pr = new PluginResult(PluginResult.Status.ERROR, "Not logged in");
                    //pr.setKeepCallback(true);
                    delayedCC.sendPluginResult(pr);
                }
            }
        });

        return true;
    } else if (action.equals("resetAchievements")) {
        //Activity activity=cordova.getActivity();
        //webView
        //            

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _resetAchievements();

                PluginResult pr = new PluginResult(PluginResult.Status.OK);
                //pr.setKeepCallback(true);
                delayedCC.sendPluginResult(pr);
                //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
                //pr.setKeepCallback(true);
                //delayedCC.sendPluginResult(pr);               
            }
        });

        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 _getPlayerImage() {
    Player player = Games.Players.getCurrentPlayer(getGameHelper().getApiClient());
    if (player != null) {
        boolean hasH = player.hasHiResImage();
        boolean hasI = player.hasIconImage();
        Uri playerImageUrl = null;/*  w w  w .j  av  a2 s.  co  m*/
        if (hasH) {
            playerImageUrl = player.getHiResImageUri();
        } else if (hasI) {
            playerImageUrl = player.getIconImageUri();
        } else {
            //PluginResult pr = new PluginResult(PluginResult.Status.OK);
            //pr.setKeepCallback(true);
            //getPlayerImageCC.sendPluginResult(pr);
            PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
            //pr.setKeepCallback(true);
            getPlayerImageCC.sendPluginResult(pr);

            return;
        }

        PluginResult pr = new PluginResult(PluginResult.Status.OK, playerImageUrl.toString());
        //pr.setKeepCallback(true);
        getPlayerImageCC.sendPluginResult(pr);
        //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
        //pr.setKeepCallback(true);
        //getPlayerImageCC.sendPluginResult(pr);         
    } else {
        //PluginResult pr = new PluginResult(PluginResult.Status.OK);
        //pr.setKeepCallback(true);
        //getPlayerImageCC.sendPluginResult(pr);
        PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
        //pr.setKeepCallback(true);
        getPlayerImageCC.sendPluginResult(pr);
    }
}

From source file:com.cranberrygame.cordova.plugin.game.Util.java

License:Open Source License

private void _submitScore(String leaderboardId, int score) {
    /*   //from w w w  .  j  a  v a 2 s  .c  o  m
          //https://developers.google.com/games/services/android/leaderboards
          Games.Leaderboards.submitScore(getGameHelper().getApiClient(), leaderboardId, score);         
    */
    ///*      
    //http://stackoverflow.com/questions/22896713/listener-for-leaderboard-in-google-game-services
    //https://developer.android.com/reference/gms-packages.html
    //https://developer.android.com/reference/com/google/android/gms/games/leaderboard/package-summary.html
    //https://developer.android.com/reference/com/google/android/gms/games/leaderboard/Leaderboards.html
    //https://developer.android.com/reference/com/google/android/gms/games/leaderboard/Leaderboards.html#submitScoreImmediate(com.google.android.gms.common.api.GoogleApiClient, java.lang.String, long)

    class ResultCallbackSubmitScoreResult implements ResultCallback<Leaderboards.SubmitScoreResult> {
        @Override
        public void onResult(Leaderboards.SubmitScoreResult result) {
            //https://developer.android.com/reference/com/google/android/gms/games/leaderboard/Leaderboards.SubmitScoreResult.html
            if (result.getStatus().getStatusCode() == GamesStatusCodes.STATUS_OK) {
                // data sent successfully to server.
                // display toast.

                PluginResult pr = new PluginResult(PluginResult.Status.OK);
                //pr.setKeepCallback(true);
                submitScoreCC.sendPluginResult(pr);
                //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
                //pr.setKeepCallback(true);
                //submitScoreCC.sendPluginResult(pr);
            } else {
                //PluginResult pr = new PluginResult(PluginResult.Status.OK);
                //pr.setKeepCallback(true);
                //submitScoreCC.sendPluginResult(pr);
                PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
                //pr.setKeepCallback(true);
                submitScoreCC.sendPluginResult(pr);
            }
        }
    }
    Games.Leaderboards.submitScoreImmediate(getGameHelper().getApiClient(), leaderboardId, score)
            .setResultCallback(new ResultCallbackSubmitScoreResult());
    //*/
}

From source file:com.cranberrygame.cordova.plugin.game.Util.java

License:Open Source License

private void _unlockAchievement(String achievementId) {
    /*   /*from   ww w. ja  v a2s. c  o m*/
          //Unlocking achievements
          //To unlock an achievement, call the unlock() method and and pass in the achievement ID.
          //Games.Achievements.unlock(getApiClient(), "my_achievement_id");
          //If the achievement is of the incremental type (that is, several steps are required to unlock it), call increment() instead.
          //Games.Achievements.increment(getApiClient(), "my_incremental_achievment_id", 10000);
          //You do not need to write additional code to unlock the achievement; Play Games services automatically unlocks the achievement once it reaches its required number of steps.
          //https://developers.google.com/games/services/android/achievements
          Games.Achievements.unlock(getGameHelper().getApiClient(), achievementId);
    */
    ///*
    //https://developer.android.com/reference/gms-packages.html
    //https://developer.android.com/reference/com/google/android/gms/games/achievement/package-summary.html
    //https://developer.android.com/reference/com/google/android/gms/games/achievement/Achievements.html
    //https://developer.android.com/reference/com/google/android/gms/games/achievement/Achievements.html#incrementImmediate(com.google.android.gms.common.api.GoogleApiClient, java.lang.String, int)
    //https://developer.android.com/reference/com/google/android/gms/games/achievement/Achievements.html#unlockImmediate(com.google.android.gms.common.api.GoogleApiClient, java.lang.String)
    class ResultCallbackUpdateAchievementResult
            implements ResultCallback<Achievements.UpdateAchievementResult> {
        @Override
        public void onResult(Achievements.UpdateAchievementResult result) {
            //https://developer.android.com/reference/com/google/android/gms/games/achievement/Achievements.UpdateAchievementResult.html
            if (result.getStatus().getStatusCode() == GamesStatusCodes.STATUS_OK) {
                // data sent successfully to server.
                // display toast.
                //Log.d(LOG_TAG, String.format("%d", result.getStatus().getStatusCode()));
                //Util.alert(cordova.getActivity(), String.format("%d", result.getStatus().getStatusCode()));               

                PluginResult pr = new PluginResult(PluginResult.Status.OK);
                //pr.setKeepCallback(true);
                unlockAchievementCC.sendPluginResult(pr);
                //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
                //pr.setKeepCallback(true);
                //unlockAchievementCC.sendPluginResult(pr);
            } else {
                //Log.d(LOG_TAG, String.format("%d", result.getStatus().getStatusCode()));
                //Util.alert(cordova.getActivity(), String.format("%d", result.getStatus().getStatusCode()));

                //PluginResult pr = new PluginResult(PluginResult.Status.OK);
                //pr.setKeepCallback(true);
                //unlockAchievementCC.sendPluginResult(pr);
                PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
                //pr.setKeepCallback(true);
                unlockAchievementCC.sendPluginResult(pr);
            }
        }
    }
    Games.Achievements.unlockImmediate(getGameHelper().getApiClient(), achievementId)
            .setResultCallback(new ResultCallbackUpdateAchievementResult());
    //*/      
}

From source file:com.cranberrygame.cordova.plugin.game.Util.java

License:Open Source License

private void _incrementAchievement(String achievementId, int stepsOrPercent) {
    /*   /*from  w w  w .  j a  v a2 s  .  com*/
          //Unlocking achievements
          //To unlock an achievement, call the unlock() method and and pass in the achievement ID.
          //Games.Achievements.unlock(getApiClient(), "my_achievement_id");
          //If the achievement is of the incremental type (that is, several steps are required to unlock it), call increment() instead.
          //Games.Achievements.increment(getApiClient(), "my_incremental_achievment_id", 1);
          //You do not need to write additional code to unlock the achievement; Play Games services automatically unlocks the achievement once it reaches its required number of steps.
          //https://developers.google.com/games/services/android/achievements
          //Games.Achievements.unlock(getGameHelper().getApiClient(), achievementId);
          //
          Games.Achievements.increment(getGameHelper().getApiClient(), achievementId, stepsOrPercent);      
    */
    ///*
    //https://developer.android.com/reference/gms-packages.html
    //https://developer.android.com/reference/com/google/android/gms/games/achievement/package-summary.html
    //https://developer.android.com/reference/com/google/android/gms/games/achievement/Achievements.html
    //https://developer.android.com/reference/com/google/android/gms/games/achievement/Achievements.html#incrementImmediate(com.google.android.gms.common.api.GoogleApiClient, java.lang.String, int)
    class ResultCallbackUpdateAchievementResult
            implements ResultCallback<Achievements.UpdateAchievementResult> {
        @Override
        public void onResult(Achievements.UpdateAchievementResult result) {
            //https://developer.android.com/reference/com/google/android/gms/games/achievement/Achievements.UpdateAchievementResult.html
            if (result.getStatus().getStatusCode() == GamesStatusCodes.STATUS_OK) {
                // data sent successfully to server.
                // display toast.
                //Log.d(LOG_TAG, String.format("%d", result.getStatus().getStatusCode()));
                //Util.alert(cordova.getActivity(), String.format("%d", result.getStatus().getStatusCode()));               

                PluginResult pr = new PluginResult(PluginResult.Status.OK);
                //pr.setKeepCallback(true);
                incrementAchievementCC.sendPluginResult(pr);
                //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
                //pr.setKeepCallback(true);
                //incrementAchievementCC.sendPluginResult(pr);
            } else {
                //Log.d(LOG_TAG, String.format("%d", result.getStatus().getStatusCode()));
                //Util.alert(cordova.getActivity(), String.format("%d", result.getStatus().getStatusCode()));

                //PluginResult pr = new PluginResult(PluginResult.Status.OK);
                //pr.setKeepCallback(true);
                //incrementAchievementCC.sendPluginResult(pr);
                PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
                //pr.setKeepCallback(true);
                incrementAchievementCC.sendPluginResult(pr);
            }
        }
    }
    Games.Achievements.incrementImmediate(getGameHelper().getApiClient(), achievementId, stepsOrPercent)
            .setResultCallback(new ResultCallbackUpdateAchievementResult());
    //*/      
}

From source file:com.cranberrygame.cordova.plugin.game.Util.java

License:Open Source License

@Override
public void onSignInFailed() {
    //Util.alert(cordova.getActivity(), "onSignInFailed");   

    //PluginResult pr = new PluginResult(PluginResult.Status.OK);
    //pr.setKeepCallback(true);
    //loginCC.sendPluginResult(pr);
    PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
    //pr.setKeepCallback(true);
    loginCC.sendPluginResult(pr);//from   w  w  w  .  j  a  v a  2s  .  c o  m
}

From source file:com.cranberrygame.cordova.plugin.navigationbar.NavigationBar.java

License:Open Source License

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    PluginResult result = null;/* www  .ja  v a  2  s  .  c o m*/

    //args.length()
    //args.getString(0)
    //args.getString(1)
    //args.getInt(0)
    //args.getInt(1)
    //args.getBoolean(0)
    //args.getBoolean(1)
    //JSONObject json = args.optJSONObject(0);
    //json.optString("adUnit")
    //json.optString("adUnitFullScreen")
    //JSONObject inJson = json.optJSONObject("inJson");

    if (action.equals("setUp")) {
        //Activity activity = cordova.getActivity();
        //webView
        //
        final boolean autoHideNavigationBar = args.getBoolean(0);

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _setUp(autoHideNavigationBar);

                PluginResult pr = new PluginResult(PluginResult.Status.OK);
                //pr.setKeepCallback(true);
                delayedCC.sendPluginResult(pr);
                //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
                //pr.setKeepCallback(true);
                //delayedCC.sendPluginResult(pr);               
            }
        });

        return true;
    } else if (action.equals("hideNavigationBar")) {
        //Activity activity=cordova.getActivity();
        //webView
        //

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _hideNavigationBar();

                PluginResult pr = new PluginResult(PluginResult.Status.OK);
                //pr.setKeepCallback(true);
                delayedCC.sendPluginResult(pr);
                //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
                //pr.setKeepCallback(true);
                //delayedCC.sendPluginResult(pr);               
            }
        });

        return true;
    }

    return false; // Returning false results in a "MethodNotFound" error.
}

From source file:com.cranberrygame.phonegap.plugin.OptionsMenu.java

License:Open Source License

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    PluginResult result = null;//from   w w w .  j av  a2  s.  c om

    try {
        //args.length()
        //args.getString(0)
        //args.getString(1)
        //args.Int(0)
        //args.Int(1)
        //args.getBoolean(0)
        //args.getBoolean(1)

        if (action.equals("setMenus")) {
            //Activity activity=cordova.getActivity();
            //webView         
            String menus = args.getString(0);
            Log.d("Menu", menus);

            this.menus = menus;

            result = new PluginResult(PluginResult.Status.OK);
        } else if (action.equals("showMenus")) {
            //Activity activity=cordova.getActivity();
            //webView         

            cordova.getActivity().openOptionsMenu();

            result = new PluginResult(PluginResult.Status.OK);
        } else {
            result = new PluginResult(PluginResult.Status.INVALID_ACTION);
        }
    } catch (JSONException e) {
        result = new PluginResult(PluginResult.Status.JSON_EXCEPTION);
    }

    callbackContext.sendPluginResult(result);
    return true;
}