org.apache.cordova.Whitelist#org.apache.cordova.CallbackContext源码实例Demo

下面列出了org.apache.cordova.Whitelist#org.apache.cordova.CallbackContext 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: AvI   文件: SplashScreen.java
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if (action.equals("hide")) {
        cordova.getActivity().runOnUiThread(new Runnable() {
            public void run() {
                webView.postMessage("splashscreen", "hide");
            }
        });
    } else if (action.equals("show")) {
        cordova.getActivity().runOnUiThread(new Runnable() {
            public void run() {
                webView.postMessage("splashscreen", "show");
            }
        });
    } else {
        return false;
    }

    callbackContext.success();
    return true;
}
 
源代码2 项目: L.TileLayer.Cordova   文件: FileTransfer.java
@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
    if (action.equals("upload") || action.equals("download")) {
        String source = args.getString(0);
        String target = args.getString(1);

        if (action.equals("upload")) {
            try {
                source = URLDecoder.decode(source, "UTF-8");
                upload(source, target, args, callbackContext);
            } catch (UnsupportedEncodingException e) {
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.MALFORMED_URL_EXCEPTION, "UTF-8 error."));
            }
        } else {
            download(source, target, args, callbackContext);
        }
        return true;
    } else if (action.equals("abort")) {
        String objectId = args.getString(0);
        abort(objectId);
        callbackContext.success();
        return true;
    }
    return false;
}
 
private boolean setColorEffect(String effect, CallbackContext callbackContext) {
  if(this.hasCamera(callbackContext) == false){
    return true;
  }

  Camera camera = fragment.getCamera();
  Camera.Parameters params = camera.getParameters();

  List<String> supportedColors;
  supportedColors = params.getSupportedColorEffects();

  if(supportedColors.contains(effect)){
    params.setColorEffect(effect);
    fragment.setCameraParameters(params);
    callbackContext.success(effect);
  }else{
    callbackContext.error("Color effect not supported" + effect);
    return true;
  }
  return true;
}
 
源代码4 项目: jpHolo   文件: NetworkManager.java
/**
 * 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                  True if the action was valid, false otherwise.
 */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    if (action.equals("getConnectionInfo")) {
        this.connectionCallbackContext = callbackContext;
        NetworkInfo info = sockMan.getActiveNetworkInfo();
        String connectionType = "";
        try {
            connectionType = this.getConnectionInfo(info).get("type").toString();
        } catch (JSONException e) { }

        PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, connectionType);
        pluginResult.setKeepCallback(true);
        callbackContext.sendPluginResult(pluginResult);
        return true;
    }
    return false;
}
 
private boolean setFocusMode(String focusMode, CallbackContext callbackContext) {
  if(this.hasCamera(callbackContext) == false){
    return true;
  }

  Camera camera = fragment.getCamera();
  Camera.Parameters params = camera.getParameters();

  List<String> supportedFocusModes;
  List<String> supportedAutoFocusModes = Arrays.asList("auto", "continuous-picture", "continuous-video","macro");
  supportedFocusModes = params.getSupportedFocusModes();
  if (supportedFocusModes.indexOf(focusMode) > -1) {
    params.setFocusMode(focusMode);
    fragment.setCameraParameters(params);
    callbackContext.success(focusMode);
    return true;
  } else {
    callbackContext.error("Focus mode not recognised: " + focusMode);
    return true;
  }
}
 
boolean printTextSizeAlign(CallbackContext callbackContext, String msg, Integer size, Integer align)
        throws IOException {
    try {
        // set unicode
        byte[] new_size = selFontSize(size);
        byte[] new_align = selAlignTitle(align);
        mmOutputStream.write(new_size);
        mmOutputStream.write(new_align);
        mmOutputStream.write(msg.getBytes("iso-8859-1"));
        resetDefaultFontAlign();
        Log.d(LOG_TAG, "PRINT TEXT SENT " + msg);
        callbackContext.success("PRINT TEXT SENT");
        return true;
    } catch (Exception e) {
        String errMsg = e.getMessage();
        Log.e(LOG_TAG, errMsg);
        e.printStackTrace();
        callbackContext.error(errMsg);
    }
    return false;
}
 
源代码7 项目: app-icon   文件: SplashScreen.java
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if (action.equals("hide")) {
        cordova.getActivity().runOnUiThread(new Runnable() {
            public void run() {
                webView.postMessage("splashscreen", "hide");
            }
        });
    } else if (action.equals("show")) {
        cordova.getActivity().runOnUiThread(new Runnable() {
            public void run() {
                webView.postMessage("splashscreen", "show");
            }
        });
    } else {
        return false;
    }

    callbackContext.success();
    return true;
}
 
public PluginResult requestAd(JSONObject options, CallbackContext callbackContext) {
    CordovaInterface cordova = plugin.cordova;

    plugin.config.setInterstitialOptions(options);

    if (interstitialAd == null) {
        callbackContext.error("interstitialAd is null, call createInterstitialView first");
        return null;
    }

    final CallbackContext delayCallback = callbackContext;
    cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (interstitialAd == null) {
                return;
            }
            interstitialAd.loadAd(plugin.buildAdRequest());

            delayCallback.success();
        }
    });

    return null;
}
 
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    try {
        if (action.equals("startAsync")) {
            startAsync(args, callbackContext);
            return true;
        }
        if (action.equals("stop")) {
            stop(args, callbackContext);
            return true;
        }
        return false; // invalid action
    } catch (Exception ex) {
        callbackContext.error(ex.getMessage());
    }
    return true;
}
 
源代码10 项目: phonenumber   文件: PhoneNumberPlugin.java
@Override
 public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {

     if (!GET_METHOD.equals(action)) {
         callbackContext.error("No such method: " + action);
         return (false);
     }

     try {
         TelephonyManager tMgr = (TelephonyManager)this.cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE);
         String number = tMgr.getLine1Number();
         if ((null == number) || (number.trim().length() <= 0))
	callbackContext.error("Phone number is not available on this device");

Log.i(TAG, "Number is " + number);
         callbackContext.success(number);
     } catch (Throwable t) {
         Log.e(TAG, "Getting phone number", t);
     }

     return (true);
 }
 
源代码11 项目: reader   文件: FileTransfer.java
@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
    if (action.equals("upload") || action.equals("download")) {
        String source = args.getString(0);
        String target = args.getString(1);

        if (action.equals("upload")) {
            upload(source, target, args, callbackContext);
        } else {
            download(source, target, args, callbackContext);
        }
        return true;
    } else if (action.equals("abort")) {
        String objectId = args.getString(0);
        abort(objectId);
        callbackContext.success();
        return true;
    }
    return false;
}
 
源代码12 项目: reacteu-app   文件: Device.java
/**
 * 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                  True if the action was valid, false if not.
 */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if ("getDeviceInfo".equals(action)) {
        JSONObject r = new JSONObject();
        r.put("uuid", Device.uuid);
        r.put("version", this.getOSVersion());
        r.put("platform", this.getPlatform());
        r.put("model", this.getModel());
        r.put("manufacturer", this.getManufacturer());
     r.put("isVirtual", this.isVirtual());
        r.put("serial", this.getSerialNumber());
        callbackContext.success(r);
    }
    else {
        return false;
    }
    return true;
}
 
源代码13 项目: cordova-androidwear   文件: AndroidWearPlugin.java
private void sendData(final CordovaArgs args,
					  final CallbackContext callbackContext) throws JSONException {
	Log.d(TAG, "sendData");

	String connectionId = args.getString(0);
	String data = args.getString(1);
	try {
		if (api != null) {
			api.sendData(connectionId, data);
			callbackContext.success();
		} else {
			callbackContext.error("Service not present");
		}
	} catch (RemoteException e) {
		callbackContext.error(e.getMessage());
	}
}
 
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    try {
        if (action.equals("get")) {
            TelephonyManager tm = (TelephonyManager) this.cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE);
            AccountManager am = AccountManager.get(this.cordova.getActivity());

            String result = getDetails(tm,am);
            if (result != null) {
                callbackContext.success(result);
                return true;
            }
        }
        callbackContext.error("Invalid action");
        return false;
    } catch (Exception e) {
        String s = "Exception: " + e.getMessage();

        System.err.println(s);
        callbackContext.error(s);

        return false;
    }
}
 
/**
 * Changes sound from earpiece to speaker and back
 *
 * @param mode Speaker Mode
 */
public void setSpeaker(final JSONArray arguments, final CallbackContext callbackContext) {
    cordova.getThreadPool().execute(new Runnable() {
        public void run() {
            String mode = arguments.optString(0);
            if (mode.equals("on")) {
                Log.d(TAG, "SPEAKER");
                audioManager.setMode(AudioManager.MODE_NORMAL);
                audioManager.setSpeakerphoneOn(true);
            } else {
                Log.d(TAG, "EARPIECE");
                audioManager.setMode(AudioManager.MODE_IN_CALL);
                audioManager.setSpeakerphoneOn(false);
            }
        }
    });
}
 
源代码16 项目: admob-plus   文件: RewardedVideoAd.java
public static boolean executeShowAction(Action action, CallbackContext callbackContext) {
    plugin.cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            RewardedVideoAd rewardedVideoAd = (RewardedVideoAd) action.getAd();
            if (rewardedVideoAd != null) {
                rewardedVideoAd.show();
            }

            PluginResult result = new PluginResult(PluginResult.Status.OK, "");
            callbackContext.sendPluginResult(result);
        }
    });

    return true;
}
 
源代码17 项目: admob-plus   文件: BannerAd.java
public static boolean executeShowAction(Action action, CallbackContext callbackContext) {
    plugin.cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            BannerAd bannerAd = (BannerAd) action.getAd();
            if (bannerAd == null) {
                bannerAd = new BannerAd(
                    action.optId(),
                    action.getAdUnitID(),
                    action.getAdSize(),
                    "top".equals(action.optPosition()) ? Gravity.TOP : Gravity.BOTTOM
                );
            }
            bannerAd.show(action.buildAdRequest());
            PluginResult result = new PluginResult(PluginResult.Status.OK, "");
            callbackContext.sendPluginResult(result);
        }
    });

    return true;
}
 
源代码18 项目: CordovaYoutubeVideoPlayer   文件: PluginManager.java
@Override
public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException {
    if ("startup".equals(action)) {
        // The onPageStarted event of CordovaWebViewClient resets the queue of messages to be returned to javascript in response
        // to exec calls. Since this event occurs on the UI thread and exec calls happen on the WebCore thread it is possible
        // that onPageStarted occurs after exec calls have started happening on a new page, which can cause the message queue
        // to be reset between the queuing of a new message and its retrieval by javascript. To avoid this from happening,
        // javascript always sends a "startup" exec upon loading a new page which causes all future exec calls to happen on the UI
        // thread (and hence after onPageStarted) until there are no more pending exec calls remaining.
        numPendingUiExecs.getAndIncrement();
        ctx.getActivity().runOnUiThread(new Runnable() {
            public void run() {
                numPendingUiExecs.getAndDecrement();
            }
        });
        return true;
    }
    return false;
}
 
源代码19 项目: reacteu-app   文件: CodePush.java
private boolean execUpdateSuccess(CallbackContext callbackContext) {
    if (this.codePushPackageManager.isFirstRun()) {
        this.codePushPackageManager.saveFirstRunFlag();
        /* save reporting status for first install */
        try {
            String appVersion = Utilities.getAppVersionName(cordova.getActivity());
            codePushReportingManager.reportStatus(CodePushReportingManager.Status.STORE_VERSION, null, appVersion, mainWebView.getPreferences().getString(DEPLOYMENT_KEY_PREFERENCE, null), this.mainWebView);
        } catch (PackageManager.NameNotFoundException e) {
            // Should not happen unless the appVersion is not specified, in which case we can't report anything anyway.
            e.printStackTrace();
        }
    }

    if (this.codePushPackageManager.installNeedsConfirmation()) {
        /* save reporting status */
        CodePushPackageMetadata currentMetadata = this.codePushPackageManager.getCurrentPackageMetadata();
        codePushReportingManager.reportStatus(CodePushReportingManager.Status.UPDATE_CONFIRMED, currentMetadata.label, currentMetadata.appVersion, currentMetadata.deploymentKey, this.mainWebView);
    }

    this.codePushPackageManager.clearInstallNeedsConfirmation();
    this.cleanOldPackageSilently();
    callbackContext.success();

    return true;
}
 
源代码20 项目: cordova-plugin-wizpurchase   文件: WizPurchase.java
/**
 * Restore all Inventory products and purchases
 *
 * @param callbackContext Instance
 **/
private void restoreAllPurchases(CallbackContext callbackContext) throws JSONException {
	// Check if the Inventory is available
	if (mInventory != null) {
		// Get the list of owned items
		List<Purchase> purchaseList = mInventory.getAllPurchases();
		setPurchasesAsPending(purchaseList);
		JSONArray jsonPurchaseList = convertToJSONArray(purchaseList);
		// Return result
		callbackContext.success(jsonPurchaseList);
	} else {
		// Initialise the Plug-In
		cordova.getThreadPool().execute(new Runnable() {
			public void run() {
				List<String> skus = new ArrayList<String>();
				init(skus);
			}
		});
		// Retain the callback and wait
		mRestoreAllCbContext = callbackContext;
		retainCallBack(mRestoreAllCbContext);
	}
}
 
/**
 * 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                  True if the action was valid, false otherwise.
 */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    if (action.equals("getConnectionInfo")) {
        this.connectionCallbackContext = callbackContext;
        NetworkInfo info = sockMan.getActiveNetworkInfo();
        String connectionType = "";
        try {
            connectionType = this.getConnectionInfo(info).get("type").toString();
        } catch (JSONException e) {
            LOG.d(LOG_TAG, e.getLocalizedMessage());
        }

        PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, connectionType);
        pluginResult.setKeepCallback(true);
        callbackContext.sendPluginResult(pluginResult);
        return true;
    }
    return false;
}
 
源代码22 项目: cordova-plugin-wizpurchase   文件: WizPurchase.java
/**
 * Get a list of purchases which have not been ended yet using finishPurchase
 *
 * @param callbackContext Instance
 **/
private void getPendingPurchases(CallbackContext callbackContext) throws JSONException {
	// Check if the Inventory is available
	if (mInventory != null) {
		// Get and return any previously purchased Items
		JSONArray jsonPurchaseList = new JSONArray();
		jsonPurchaseList = getPendingPurchases();
		// Return result
		callbackContext.success(jsonPurchaseList);
	} else {
		// Initialise the Plug-In
		cordova.getThreadPool().execute(new Runnable() {
			public void run() {
				List<String> skus = new ArrayList<String>();
				init(skus);
			}
		});
		// Retain the callback and wait
		mGetPendingCbContext = callbackContext;
		retainCallBack(mGetPendingCbContext);
	}
}
 
private boolean setZoom(int zoom, CallbackContext callbackContext) {
  if(this.hasCamera(callbackContext) == false){
    return true;
  }

  Camera camera = fragment.getCamera();
  Camera.Parameters params = camera.getParameters();

  if (camera.getParameters().isZoomSupported()) {
    params.setZoom(zoom);
    fragment.setCameraParameters(params);

    callbackContext.success(zoom);
  } else {
    callbackContext.error("Zoom not supported");
  }

  return true;
}
 
private boolean stopCamera(CallbackContext callbackContext) {
  if(webViewParent != null) {
    cordova.getActivity().runOnUiThread(new Runnable() {
      @Override
      public void run() {
        ((ViewGroup)webView.getView()).bringToFront();
        webViewParent = null;
      }
    });
  }

  if(this.hasView(callbackContext) == false){
    return true;
  }

  FragmentManager fragmentManager = cordova.getActivity().getFragmentManager();
  FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
  fragmentTransaction.remove(fragment);
  fragmentTransaction.commit();
  fragment = null;

  callbackContext.success();
  return true;
}
 
源代码25 项目: jpHolo   文件: Share.java
@Override
public boolean execute(final String action, final JSONArray args,
		final CallbackContext callbackContext) {
	cordova.getThreadPool().execute(new Runnable() {
		@Override
		public void run() {
			try {
				final JSONObject jo = args.getJSONObject(0);
				doSendIntent(jo.getString("subject"), jo.getString("text"));
				callbackContext.sendPluginResult(new PluginResult(
						PluginResult.Status.OK));
			} catch (final JSONException e) {
				Log.e(LOG_PROV, LOG_NAME + "Error: "
						+ PluginResult.Status.JSON_EXCEPTION);
				e.printStackTrace();
				callbackContext.sendPluginResult(new PluginResult(
						PluginResult.Status.JSON_EXCEPTION));
			}
		}
	});
	return true;
}
 
protected void setUp() throws Exception {
    super.setUp();
    activity = this.getActivity();
    cordovaWebView = activity.cordovaWebView;
    resourceApi = cordovaWebView.getResourceApi();
    resourceApi.setThreadCheckingEnabled(false);
    cordovaWebView.pluginManager.addService(new PluginEntry("CordovaResourceApiTestPlugin1", new CordovaPlugin() {
        @Override
        public Uri remapUri(Uri uri) {
            if (uri.getQuery() != null && uri.getQuery().contains("pluginRewrite")) {
                return cordovaWebView.getResourceApi().remapUri(
                        Uri.parse("data:text/plain;charset=utf-8,pass"));
            }
            return null;
        }
        public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
            synchronized (CordovaResourceApiTest.this) {
                execPayload = args.getString(0);
                execStatus = args.getInt(1);
                CordovaResourceApiTest.this.notify();
            }
            return true;
        }
    }));
}
 
源代码27 项目: cordova-plugin-foxitpdf   文件: FoxitPdf.java
static void onDocSave(String data) {
    CallbackContext callbackContext = mCallbackArrays.get(CALLBACK_FOR_OPENDOC);
    if (callbackContext != null) {
        try {
            JSONObject obj = new JSONObject();
            obj.put("type", RDK_DOCSAVED_EVENT);
            obj.put("info", data);

            PluginResult result = new PluginResult(PluginResult.Status.OK, obj);
            result.setKeepCallback(true);
            callbackContext.sendPluginResult(result);
        } catch (JSONException ex) {
            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
        }
    }
}
 
private boolean hasCamera(CallbackContext callbackContext) {
  if(this.hasView(callbackContext) == false){
    return false;
  }

  if(fragment.getCamera() == null) {
    callbackContext.error("No Camera");
    return false;
  }

  return true;
}
 
public CellLocationController(
        boolean isConnected,
        boolean returnSignalStrength,
        CordovaInterface cordova,
        CallbackContext callbackContext
){
    _isConnected = isConnected;
    _cordova = cordova;
    _callbackContext = callbackContext;
    _returnSignalStrength = returnSignalStrength;
}
 
源代码30 项目: reader   文件: ActivityIndicator.java
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
	if (action.equals("show")) {
		String text = args.getString(0);
		show(text);
		callbackContext.success();
		return true;
	} else if (action.equals("hide")) {
		hide();
		callbackContext.success();
		return true;
	}

	return false;
}