Example usage for org.apache.cordova PluginResult setKeepCallback

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

Introduction

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

Prototype

public void setKeepCallback(boolean b) 

Source Link

Usage

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

License:Open Source License

public void onAdLoaded() {
    Log.d(LOG_TAG, "onAdLoaded");

    if (admob.bannerAdPreload) {
        PluginResult pr = new PluginResult(PluginResult.Status.OK, "onBannerAdPreloaded");
        pr.setKeepCallback(true);
        admob.bannerViewCC.sendPluginResult(pr);
        //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
        //pr.setKeepCallback(true);
        //admob.bannerViewCC.sendPluginResult(pr);
    }/*from   w  ww .  j  a v a  2  s.c om*/

    PluginResult pr = new PluginResult(PluginResult.Status.OK, "onBannerAdLoaded");
    //pr.setKeepCallback(true);
    admob.bannerViewCC.sendPluginResult(pr);
    //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
    //pr.setKeepCallback(true);
    //admob.bannerViewCC.sendPluginResult(pr);
}

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

License:Open Source License

public void onAdLoaded() {
    Log.d(LOG_TAG, "onAdLoaded");

    if (admob.fullScreenAdPreload) {
        PluginResult pr = new PluginResult(PluginResult.Status.OK, "onFullScreenAdPreloaded");
        pr.setKeepCallback(true);
        admob.interstitialViewCC.sendPluginResult(pr);
        //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
        //pr.setKeepCallback(true);
        //admob.interstitialViewCC.sendPluginResult(pr);
    }//from ww w  .j  a  va 2 s. c  o m

    PluginResult pr = new PluginResult(PluginResult.Status.OK, "onFullScreenAdLoaded");
    pr.setKeepCallback(true);
    admob.interstitialViewCC.sendPluginResult(pr);
    //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
    //pr.setKeepCallback(true);
    //admob.interstitialViewCC.sendPluginResult(pr);      

    if (!admob.fullScreenAdPreload) {
        interstitialView.show();
    }
}

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

License:Open Source License

public void onAdOpened() {
    Log.d(LOG_TAG, "onAdOpened");

    PluginResult pr = new PluginResult(PluginResult.Status.OK, "onFullScreenAdShown");
    pr.setKeepCallback(true);
    admob.interstitialViewCC.sendPluginResult(pr);
    //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
    //pr.setKeepCallback(true);
    //admob.interstitialViewCC.sendPluginResult(pr);      
}

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

License:Open Source License

public void _showBannerAd(String position, String size) {

    if (bannerIsShowingOverlap() && position.equals(bannerPreviousPosition)
            && size.equals(bannerPreviousSize)) {
        return;//from   www . jav  a  2 s  . c  o  m
    }

    this.bannerPreviousPosition = position;
    this.bannerPreviousSize = size;

    if (bannerAdPreload) {
        bannerAdPreload = false;
    } else {
        _hideBannerAd();

        loadBannerAd();
    }

    addBannerViewOverlap(position, size);

    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);         
}

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

License:Open Source License

public void _hideBannerAd() {
    removeBannerViewOverlap();//from  ww w.jav a 2  s. com

    PluginResult pr = new PluginResult(PluginResult.Status.OK, "onBannerAdHidden");
    pr.setKeepCallback(true);
    plugin.getCallbackContextKeepCallback().sendPluginResult(pr);
    //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
    //pr.setKeepCallback(true);
    //plugin.getCallbackContextKeepCallback().sendPluginResult(pr);      
}

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

License:Open Source License

public void _hideBannerAd() {
    removeBannerViewOverlap();//from  ww w  . j a  v  a 2s . c  om

    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;/*  www. ja  va2  s.co 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.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();// w  ww  . j a v a2 s.  co m

            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.doylestowncoder.plugin.mobileaccessibility.MobileAccessibility.java

License:Apache License

protected void sendMobileAccessibilityStatusChangedCallback() {
    if (this.mCallbackContext != null) {
        PluginResult result = new PluginResult(PluginResult.Status.OK, getMobileAccessibilityStatus());
        result.setKeepCallback(true);
        this.mCallbackContext.sendPluginResult(result);
    }// w  w w . j a  v  a2s. co m
}

From source file:com.dtworkshop.inappcrossbrowser.WebViewBrowser.java

License:Apache License

/**
 * Executes the request and returns PluginResult.
 *
 * @param action        The action to execute.
 * @param args          JSONArry of arguments for the plugin.
 * @return              A PluginResult object with a status and message.
 *///from  w w w . j a  v a2 s. co  m
public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext)
        throws JSONException {
    if (action.equals("open")) {
        this.callbackContext = callbackContext;
        final String url = args.getString(0);
        String t = args.optString(1);
        if (t == null || t.equals("") || t.equals(NULL)) {
            t = SELF;
        }
        final String target = t;
        final HashMap<String, Boolean> features = parseFeature(args.optString(2));

        Log.d(LOG_TAG, "target = " + target);

        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                String result = "";
                // SELF
                if (SELF.equals(target)) {
                    Log.d(LOG_TAG, "in self");
                    /* This code exists for compatibility between 3.x and 4.x versions of Cordova.
                     * Previously the Config class had a static method, isUrlWhitelisted(). That
                     * responsibility has been moved to the plugins, with an aggregating method in
                     * PluginManager.
                     */
                    Boolean shouldAllowNavigation = null;
                    if (url.startsWith("javascript:")) {
                        shouldAllowNavigation = true;
                    }
                    if (shouldAllowNavigation == null) {
                        try {
                            Method iuw = Config.class.getMethod("isUrlWhiteListed", String.class);
                            shouldAllowNavigation = (Boolean) iuw.invoke(null, url);
                        } catch (NoSuchMethodException e) {
                        } catch (IllegalAccessException e) {
                        } catch (InvocationTargetException e) {
                        }
                    }
                    if (shouldAllowNavigation == null) {
                        try {
                            Method gpm = webView.getClass().getMethod("getPluginManager");
                            PluginManager pm = (PluginManager) gpm.invoke(webView);
                            Method san = pm.getClass().getMethod("shouldAllowNavigation", String.class);
                            shouldAllowNavigation = (Boolean) san.invoke(pm, url);
                        } catch (NoSuchMethodException e) {
                        } catch (IllegalAccessException e) {
                        } catch (InvocationTargetException e) {
                        }
                    }
                    // load in webview
                    if (Boolean.TRUE.equals(shouldAllowNavigation)) {
                        Log.d(LOG_TAG, "loading in webview");
                        webView.loadUrl(url);
                    }
                    //Load the dialer
                    else if (url.startsWith(WebView.SCHEME_TEL)) {
                        try {
                            Log.d(LOG_TAG, "loading in dialer");
                            Intent intent = new Intent(Intent.ACTION_DIAL);
                            intent.setData(Uri.parse(url));
                            cordova.getActivity().startActivity(intent);
                        } catch (android.content.ActivityNotFoundException e) {
                            LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString());
                        }
                    }
                    // load in InAppBrowser
                    else {
                        Log.d(LOG_TAG, "loading in InAppBrowser");
                        result = showWebPage(url, features);
                    }
                }
                // SYSTEM
                else if (SYSTEM.equals(target)) {
                    Log.d(LOG_TAG, "in system");
                    result = openExternal(url);
                }
                // perso a3d HORIZONTAL
                else if (BLANKH.equals(target)) {
                    Log.d(LOG_TAG, "in blank horizontal");
                    result = showWebPage(url, features);
                }
                // BLANK - or anything else
                else {
                    Log.d(LOG_TAG, "in blank");
                    result = showWebPage(url, features);
                }

                PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, result);
                pluginResult.setKeepCallback(true);
                callbackContext.sendPluginResult(pluginResult);
            }
        });
    } else if (action.equals("close")) {
        closeDialog();
    } else if (action.equals("injectScriptCode")) {
        String jsWrapper = null;
        if (args.getBoolean(1)) {
            jsWrapper = String.format("prompt(JSON.stringify([eval(%%s)]), 'gap-iab://%s')",
                    callbackContext.getCallbackId());
        }
        injectDeferredObject(args.getString(0), jsWrapper);
    } else if (action.equals("injectScriptFile")) {
        String jsWrapper;
        if (args.getBoolean(1)) {
            jsWrapper = String.format(
                    "(function(d) { var c = d.createElement('script'); c.src = %%s; c.onload = function() { prompt('', 'gap-iab://%s'); }; d.body.appendChild(c); })(document)",
                    callbackContext.getCallbackId());
        } else {
            jsWrapper = "(function(d) { var c = d.createElement('script'); c.src = %s; d.body.appendChild(c); })(document)";
        }
        injectDeferredObject(args.getString(0), jsWrapper);
    } else if (action.equals("injectStyleCode")) {
        String jsWrapper;
        if (args.getBoolean(1)) {
            jsWrapper = String.format(
                    "(function(d) { var c = d.createElement('style'); c.innerHTML = %%s; d.body.appendChild(c); prompt('', 'gap-iab://%s');})(document)",
                    callbackContext.getCallbackId());
        } else {
            jsWrapper = "(function(d) { var c = d.createElement('style'); c.innerHTML = %s; d.body.appendChild(c); })(document)";
        }
        injectDeferredObject(args.getString(0), jsWrapper);
    } else if (action.equals("injectStyleFile")) {
        String jsWrapper;
        if (args.getBoolean(1)) {
            jsWrapper = String.format(
                    "(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %%s; d.head.appendChild(c); prompt('', 'gap-iab://%s');})(document)",
                    callbackContext.getCallbackId());
        } else {
            jsWrapper = "(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %s; d.head.appendChild(c); })(document)";
        }
        injectDeferredObject(args.getString(0), jsWrapper);
    } else if (action.equals("show")) {
        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                dialog.show();
            }
        });
        PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
        pluginResult.setKeepCallback(true);
        this.callbackContext.sendPluginResult(pluginResult);
    } else {
        return false;
    }
    return true;
}