List of usage examples for org.apache.cordova PluginResult PluginResult
public PluginResult(Status status, List<PluginResult> multipartMessages)
From source file:com.android.plugins.GyroscopeListener.java
License:Open Source License
private void win() { // Success return object PluginResult result = new PluginResult(PluginResult.Status.OK, this.getOrientationJSON()); result.setKeepCallback(true);/* w ww. ja v a 2 s . co m*/ callbackContext.sendPluginResult(result); }
From source file:com.android.plugins.MagnetometerListener.java
License:Open Source License
/** * Executes the request.//w w w .j a va 2 s . c o m * * @param action The action to execute. * @param args The exec() arguments. * @param callbackId The callback id used when calling back into JavaScript. * @return Whether the action was valid. */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { if (action.equals("start")) { this.callbackContext = callbackContext; if (this.status != MagnetometerListener.RUNNING) { // If not running, then this is an async call, so don't worry about waiting // We drop the callback onto our stack, call start, and let start and the sensor callback fire off the callback down the road this.start(); } } else if (action.equals("stop")) { if (this.status == MagnetometerListener.RUNNING) { this.stop(); } } else { // Unsupported action return false; } PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT, ""); result.setKeepCallback(true); callbackContext.sendPluginResult(result); return true; }
From source file:com.appfeel.cordova.admob.AdMobAds.java
License:Open Source License
/** * Parses the show ad input parameters and runs the show ad action on the UI thread. * /*from w ww.jav a 2 s . c o m*/ * @param inputs The JSONArray representing input parameters. This function expects the first object in the array to be a JSONObject with the input * parameters. * @return A PluginResult representing whether or not an ad was requested succcessfully. Listen for onReceiveAd() and onFailedToReceiveAd() callbacks to see * if an ad was successfully retrieved. */ private PluginResult executeShowBannerAd(final boolean show, final CallbackContext callbackContext) { if (adView == null) { return new PluginResult(Status.ERROR, "adView is null, call createBannerView first."); } cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { if (show == isBannerVisible) { // no change } else if (show) { if (adView.getParent() != null) { ((ViewGroup) adView.getParent()).removeView(adView); } if (isBannerOverlap) { RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); if (isOffsetStatusBar) { int titleBarHeight = 0; Rect rectangle = new Rect(); Window window = AdMobAds.this.cordova.getActivity().getWindow(); window.getDecorView().getWindowVisibleDisplayFrame(rectangle); if (isBannerAtTop) { if (rectangle.top == 0) { int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop(); titleBarHeight = contentViewTop - rectangle.top; } params2.topMargin = titleBarHeight; } else { if (rectangle.top > 0) { int contentViewBottom = window.findViewById(Window.ID_ANDROID_CONTENT) .getBottom(); titleBarHeight = contentViewBottom - rectangle.bottom; } params2.bottomMargin = titleBarHeight; } } else if (isBannerAtTop) { params2.addRule(RelativeLayout.ALIGN_PARENT_TOP); } else { params2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); } if (adViewLayout == null) { adViewLayout = new RelativeLayout(cordova.getActivity()); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); if (CORDOVA_4) { ((ViewGroup) webView.getView().getParent()).addView(adViewLayout, params); } else { ((ViewGroup) webView).addView(adViewLayout, params); } } adViewLayout.addView(adView, params2); adViewLayout.bringToFront(); } else { if (CORDOVA_4) { ViewGroup wvParentView = (ViewGroup) webView.getView().getParent(); if (parentView == null) { parentView = new LinearLayout(webView.getContext()); } if (wvParentView != null && wvParentView != parentView) { wvParentView.removeView(webView.getView()); ((LinearLayout) parentView).setOrientation(LinearLayout.VERTICAL); parentView.setLayoutParams( new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 0.0F)); webView.getView().setLayoutParams( new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1.0F)); parentView.addView(webView.getView()); cordova.getActivity().setContentView(parentView); } } else { parentView = (ViewGroup) ((ViewGroup) webView).getParent(); } if (isBannerAtTop) { parentView.addView(adView, 0); } else { parentView.addView(adView); } parentView.bringToFront(); parentView.requestLayout(); } adView.setVisibility(View.VISIBLE); isBannerVisible = true; } else { adView.setVisibility(View.GONE); isBannerVisible = false; } if (callbackContext != null) { callbackContext.success(); } } }); return null; }
From source file:com.appfeel.cordova.admob.AdMobAds.java
License:Open Source License
protected PluginResult showInterstitialAd(final CallbackContext callbackContext) { if (interstitialAd == null) { return new PluginResult(Status.ERROR, "interstitialAd is null, call createInterstitialView first."); }//from www. j ava2 s . c o m cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { if (interstitialAd.isLoaded()) { isInterstitialRequested = false; interstitialAd.show(); } if (callbackContext != null) { callbackContext.success(); } } }); return null; }
From source file:com.appfeel.cordova.analytics.CPGoogleAnalytics.java
License:Open Source License
private PluginResult execStartTracker(String id, CallbackContext callbackContext) { PluginResult result = new PluginResult(Status.ERROR, "Invalid tracker"); if (null != id && id.length() > 0) { tracker = GoogleAnalytics.getInstance(this.cordova.getActivity()).newTracker(id); GoogleAnalytics.getInstance(this.cordova.getActivity()).setLocalDispatchPeriod(30); GoogleAnalytics.getInstance(this.cordova.getActivity()).getLogger().setLogLevel(LogLevel.ERROR); result = new PluginResult(Status.OK); }// ww w . jav a 2s. c om return result; }
From source file:com.appfeel.cordova.analytics.CPGoogleAnalytics.java
License:Open Source License
private PluginResult execSetDispatchPeriod(Integer period, CallbackContext callbackContext) { PluginResult result = new PluginResult(Status.ERROR, "Missing dispatch period value"); if (null != period) { GoogleAnalytics.getInstance(this.cordova.getActivity()).setLocalDispatchPeriod(period); result = new PluginResult(Status.OK); }//from w w w.ja v a 2s . c o m return result; }
From source file:com.appfeel.cordova.analytics.CPGoogleAnalytics.java
License:Open Source License
private PluginResult execTrackView(JSONObject options, CallbackContext callbackContext) { PluginResult result = new PluginResult(Status.ERROR, "Missing screen name"); if (tracker == null) { result = new PluginResult(Status.ERROR, "Tracker not started. Call startTrackerWithId('UA-XXXXXX'); first."); } else if (options.has(OPT_SCREEN_NAME)) { HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder(); prepareBuilder(builder, options); actualScreen = options.optString(OPT_SCREEN_NAME); tracker.setScreenName(actualScreen); tracker.send(builder.build());/*from w ww . ja va2 s .co m*/ result = new PluginResult(Status.OK); } return result; }
From source file:com.appfeel.cordova.analytics.CPGoogleAnalytics.java
License:Open Source License
private PluginResult execTrackEvent(JSONObject options, CallbackContext callbackContext) { PluginResult result = new PluginResult(Status.ERROR, "Missing category or action"); if (tracker == null) { result = new PluginResult(Status.ERROR, "Tracker not started. Call startTrackerWithId('UA-XXXXXX'); first."); } else if (options.has(OPT_CATEGORY) && options.has(OPT_ACTION)) { HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder(); prepareBuilder(builder, options); builder.setCategory(options.optString(OPT_CATEGORY)); builder.setAction(options.optString(OPT_ACTION)); if (options.has(OPT_LABEL)) { builder.setLabel(options.optString(OPT_LABEL)); }/* w w w. j av a2s .c o m*/ if (options.has(OPT_VALUE)) { builder.setValue(options.optLong(OPT_VALUE)); } tracker.send(builder.build()); result = new PluginResult(Status.OK); } return result; }
From source file:com.appfeel.cordova.analytics.CPGoogleAnalytics.java
License:Open Source License
private PluginResult execTrackTiming(JSONObject options, CallbackContext callbackContext) { PluginResult result = new PluginResult(Status.ERROR, "Missing category, variable to measure or value"); if (tracker == null) { result = new PluginResult(Status.ERROR, "Tracker not started. Call startTrackerWithId('UA-XXXXXX'); first."); } else if (options.has(OPT_CATEGORY) && options.has(OPT_VARIABLE) && options.has(OPT_VALUE)) { HitBuilders.TimingBuilder builder = new HitBuilders.TimingBuilder(); prepareBuilder(builder, options); builder.setCategory(options.optString(OPT_CATEGORY)); builder.setVariable(options.optString(OPT_VARIABLE)); builder.setValue(options.optLong(OPT_VALUE)); if (options.has(OPT_LABEL)) { builder.setLabel(options.optString(OPT_LABEL)); }//from w ww. j a va2 s . c om tracker.send(builder.build()); result = new PluginResult(Status.OK); } return result; }
From source file:com.appfeel.cordova.analytics.CPGoogleAnalytics.java
License:Open Source License
private PluginResult execTrackEcommerce(JSONObject options, CallbackContext callbackContext) { PluginResult result = new PluginResult(Status.ERROR, "Missing arguments"); if (tracker == null) { result = new PluginResult(Status.ERROR, "Tracker not started. Call startTrackerWithId('UA-XXXXXX'); first."); } else {/*from www.ja v a 2 s . co m*/ Product product = createProduct(options); Product relatedProduct = createRelatedProduct(options); ProductAction productAction = createProductAction(options); String productList = ""; String productListSource = ""; if (options.has(OPT_PRODUCT_LIST)) { productList = options.optString(OPT_PRODUCT_LIST); } if (options.has(OPT_PRODUCT_LIST_SOURCE)) { productListSource = options.optString(OPT_PRODUCT_LIST_SOURCE); } if (options.has(OPT_PRODUCT_SCREEN_NAME)) { tracker.setScreenName(options.optString(OPT_PRODUCT_SCREEN_NAME)); } // THIS IS VERY UGLY AS HitBuilders.HitBuilder INTERFACE IS NOT VISIBLE if (options.has(OPT_CATEGORY) && options.has(OPT_ACTION)) { HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder(); prepareBuilder(builder, options); builder.setCategory(options.optString(OPT_CATEGORY)); builder.setAction(options.optString(OPT_ACTION)); if (options.has(OPT_LABEL)) { builder.setLabel(options.optString(OPT_LABEL)); } if (options.has(OPT_VALUE)) { builder.setValue(options.optLong(OPT_VALUE)); } /// <-- REPEATED CODE FOR SCREEN VIEWS (modifications here, copy paste below) if (productAction == null && product != null && productList.length() > 0) { builder.addImpression(product, productList); } else if (productAction != null) { builder.setProductAction(productAction); if (product != null) { // Could be a refund builder.addProduct(product); } if (relatedProduct != null && productList.length() > 0) { builder.addImpression(relatedProduct, productList); } else if (productList.length() > 0) { productAction.setProductActionList(productList); } if (productListSource.length() > 0) { productAction.setProductListSource(productListSource); } } else { builder = null; } if (builder != null) { tracker.send(builder.build()); result = new PluginResult(Status.OK); } /// REPEATED CODE FOR SCREEN VIEWS --> } else { HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder(); prepareBuilder(builder, options); /// <-- REPEATED CODE FOR EVENTS (do not modify here, modify previous block) if (productAction == null && product != null && productList.length() > 0) { builder.addImpression(product, productList); } else if (productAction != null) { builder.setProductAction(productAction); if (product != null) { // Could be a refund builder.addProduct(product); } if (relatedProduct != null && productList.length() > 0) { builder.addImpression(relatedProduct, productList); } else if (productList.length() > 0) { productAction.setProductActionList(productList); } if (productListSource.length() > 0) { productAction.setProductListSource(productListSource); } } else { builder = null; } if (builder != null) { tracker.send(builder.build()); result = new PluginResult(Status.OK); } /// REPEATED CODE FOR EVENTS --> } tracker.setScreenName(actualScreen); } return result; }