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.commontime.plugin.LocationManager.java

License:Apache License

private void stopRangingBeaconsInRegion(final JSONObject arguments, CallbackContext callbackContext) {
    _handleCallSafely(callbackContext, new ILocationManagerCommand() {

        @Override// w  w  w  . j  a v a 2s.c  om
        public PluginResult run() {

            try {
                Region region = parseRegion(arguments);
                iBeaconManager.stopRangingBeaconsInRegion(region);

                PluginResult result = new PluginResult(PluginResult.Status.OK);
                result.setKeepCallback(true);
                return result;

            } catch (RemoteException e) {
                Log.e(TAG, "'stopRangingBeaconsInRegion' service error: " + e.getCause());
                return new PluginResult(PluginResult.Status.ERROR, e.getMessage());
            } catch (Exception e) {
                Log.e(TAG, "'stopRangingBeaconsInRegion' exception " + e.getCause());
                return new PluginResult(PluginResult.Status.ERROR, e.getMessage());
            }
        }
    });

}

From source file:com.commontime.plugin.LocationManager.java

License:Apache License

private void requestWhenInUseAuthorization(CallbackContext callbackContext) {
    _handleCallSafely(callbackContext, new ILocationManagerCommand() {

        @Override/* w  w w  .  jav a2s .  c om*/
        public PluginResult run() {
            return new PluginResult(PluginResult.Status.OK);
        }
    });
}

From source file:com.commontime.plugin.LocationManager.java

License:Apache License

private void requestAlwaysAuthorization(CallbackContext callbackContext) {
    _handleCallSafely(callbackContext, new ILocationManagerCommand() {

        @Override//from w  w  w .  ja v  a 2 s .c o  m
        public PluginResult run() {
            return new PluginResult(PluginResult.Status.OK);
        }
    });
}

From source file:com.commontime.plugin.LocationManager.java

License:Apache License

private void registerDelegateCallbackId(JSONObject arguments, final CallbackContext callbackContext) {

    _handleCallSafely(callbackContext, new ILocationManagerCommand() {

        @Override/*from  www. j av a 2  s  .co  m*/
        public PluginResult run() {
            debugLog("Registering delegate callback ID: " + callbackContext.getCallbackId());
            //delegateCallbackId = callbackContext.getCallbackId();

            createMonitorCallbacks(callbackContext);
            createRangingCallbacks(callbackContext);
            createManagerCallbacks(callbackContext);

            PluginResult result = new PluginResult(PluginResult.Status.OK);
            result.setKeepCallback(true);
            return result;
        }
    });

}

From source file:com.connectsdk.cordova.ConnectableDeviceWrapper.java

License:Apache License

public void setCallbackContext(CallbackContext callbackContext) {
    if (this.callbackContext != null && this.callbackContext != callbackContext) {
        PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT);
        this.callbackContext.sendPluginResult(result);
    }/*from w  w w. j  a v  a2  s  .  c  om*/

    this.callbackContext = callbackContext;

    setActive(callbackContext != null);
}

From source file:com.connectsdk.cordova.DiscoveryManagerWrapper.java

License:Apache License

public void setCallbackContext(CallbackContext callbackContext) {
    if (this.callbackContext != null && this.callbackContext != callbackContext) {
        PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT);
        this.callbackContext.sendPluginResult(result);
    }/*ww  w  .  j a  va  2 s  . c  om*/

    this.callbackContext = callbackContext;
}

From source file:com.contentecontent.cordova.plugins.share.Share.java

License:Open Source License

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    try {/*from www.j a v  a 2s.c om*/
        JSONObject jo = args.getJSONObject(0);
        doSendIntent(jo.getString("subject"), jo.getString("text"), jo.getString("imagePath"),
                jo.getString("mimeType"));
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
        return true;
    } catch (JSONException e) {
        Log.e("PhoneGapLog", "Share Plugin: Error: " + PluginResult.Status.JSON_EXCEPTION);
        e.printStackTrace();
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
        return false;
    }
}

From source file:com.cooee.cordova.plugins.camera.CameraLauncher.java

License:Apache License

/**
 * Executes the request and returns PluginResult.
 *
 * @param action          The action to execute.
 * @param args            JSONArry of arguments for the plugin.
 * @param callbackContext The callback id used when calling back into JavaScript.
 * @return A PluginResult object with a status and message.
 */// w  w  w  .ja v a  2 s  .c om
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    this.callbackContext = callbackContext;

    if (action.equals("takePicture")) {
        int srcType = CAMERA;
        int destType = FILE_URI;
        this.saveToPhotoAlbum = false;
        this.targetHeight = 0;
        this.targetWidth = 0;
        this.encodingType = JPEG;
        this.mediaType = PICTURE;
        this.mQuality = 80;

        this.mQuality = args.getInt(0);
        destType = args.getInt(1);
        srcType = args.getInt(2);
        this.targetWidth = args.getInt(3);
        this.targetHeight = args.getInt(4);
        this.encodingType = args.getInt(5);
        this.mediaType = args.getInt(6);
        this.allowEdit = args.getBoolean(7);
        this.correctOrientation = args.getBoolean(8);
        this.saveToPhotoAlbum = args.getBoolean(9);

        // If the user specifies a 0 or smaller width/height
        // make it -1 so later comparisons succeed
        if (this.targetWidth < 1) {
            this.targetWidth = -1;
        }
        if (this.targetHeight < 1) {
            this.targetHeight = -1;
        }

        try {
            if (srcType == CAMERA) {
                this.takePicture(destType, encodingType);
            } else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
                this.getImage(srcType, destType, encodingType);
            }
        } catch (IllegalArgumentException e) {
            callbackContext.error("Illegal Argument Exception");
            PluginResult r = new PluginResult(PluginResult.Status.ERROR);
            callbackContext.sendPluginResult(r);
            return true;
        }

        PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
        r.setKeepCallback(true);
        callbackContext.sendPluginResult(r);

        return true;
    }
    return false;
}

From source file:com.cordova.plugins.startapp.StartApp.java

License:MIT License

/**
 * Executes the request and returns PluginResult.
 *
 * @param action/*from www  .  ja  v a2 s. co m*/
 *          Action to perform.
 * @param args
 *          Arguments to the action.
 * @param callbackId
 *          JavaScript callback ID.
 * @return A PluginResult object with a status and message.
 */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    try {
        if (action.equals("startApp")) {
            if (args.length() != 2) {
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION));
                return false;
            }
            packageName = args.getString(0);
            mainActivity = args.getString(1);

            startActivity(packageName + "/" + mainActivity);
            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
            return true;
        }
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION));
        return false;
    } catch (JSONException e) {
        e.printStackTrace();
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
        return false;
    }
}

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  a  2 s  . c  om*/

    //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();
        //webView
        //
        final String position = args.getString(0);
        Log.d(LOG_TAG, position);
        final String size = args.getString(1);
        Log.d(LOG_TAG, size);

        //
        boolean bannerIsShowing = false;
        if (isOverlap) {
            if (bannerView != null) {
                //if banner is showing
                RelativeLayout bannerViewLayout = (RelativeLayout) bannerView.getParent();
                if (bannerViewLayout != null) {
                    bannerIsShowing = true;
                }
            }
        } else {
            if (bannerView != null) {
                //if banner is showing
                ViewGroup parentView = (ViewGroup) bannerView.getParent();
                if (parentView != null) {
                    bannerIsShowing = true;
                }
            }
        }
        if (bannerIsShowing && position.equals(this.position) && size.equals(this.size)) {
            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;
        }

        bannerViewCC = callbackContext;

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

        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.
}