Java Code Examples for org.apache.cordova.CordovaArgs#getString()

The following examples show how to use org.apache.cordova.CordovaArgs#getString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CodePush.java    From reacteu-app with MIT License 6 votes vote down vote up
private boolean execIsFirstRun(CordovaArgs args, CallbackContext callbackContext) {
    try {
        boolean isFirstRun = false;
        String packageHash = args.getString(0);
        CodePushPackageMetadata currentPackageMetadata = codePushPackageManager.getCurrentPackageMetadata();
        if (null != currentPackageMetadata) {
            /* This is the first run for a package if we just updated, and the current package hash matches the one provided. */
            isFirstRun = (null != packageHash
                    && !packageHash.isEmpty()
                    && packageHash.equals(currentPackageMetadata.packageHash)
                    && didUpdate);
        }
        callbackContext.success(isFirstRun ? 1 : 0);
    } catch (JSONException e) {
        callbackContext.error("Invalid package hash. " + e.getMessage());
    }
    return true;
}
 
Example 2
Source File: CodePush.java    From reacteu-app with MIT License 6 votes vote down vote up
private boolean execPreInstall(CordovaArgs args, CallbackContext callbackContext) {
/* check if package is valid */
    try {
        final String startLocation = args.getString(0);
        File startPage = this.getStartPageForPackage(startLocation);
        if (startPage != null) {
            /* start page exists */
            callbackContext.success();
        } else {
            callbackContext.error("Could not get the package start page");
        }
    } catch (Exception e) {
        callbackContext.error("Could not get the package start page");
    }
    return true;
}
 
Example 3
Source File: AndroidWearPlugin.java    From cordova-androidwear with Apache License 2.0 6 votes vote down vote up
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());
	}
}
 
Example 4
Source File: CodePush.java    From reacteu-app with MIT License 5 votes vote down vote up
private boolean execIsFailedUpdate(CordovaArgs args, CallbackContext callbackContext) {
    try {
        final String packageHash = args.getString(0);
        boolean isFailedUpdate = this.codePushPackageManager.isFailedUpdate(packageHash);
        callbackContext.success(isFailedUpdate ? 1 : 0);
    } catch (JSONException e) {
        callbackContext.error("Could not read the package hash: " + e.getMessage());
    }
    return true;
}
 
Example 5
Source File: CodePush.java    From reacteu-app with MIT License 5 votes vote down vote up
private boolean execInstall(CordovaArgs args, CallbackContext callbackContext) {
    try {
        final String startLocation = args.getString(0);
        final InstallMode installMode = InstallMode.fromValue(args.optInt(1));
        final int minimumBackgroundDuration = args.optInt(2);

        File startPage = this.getStartPageForPackage(startLocation);
        if (startPage != null) {
            /* start page file exists */
            /* navigate to the start page */
            if (InstallMode.IMMEDIATE.equals(installMode)) {
                this.navigateToFile(startPage);
                markUpdate();
            } else {
                InstallOptions pendingInstall = new InstallOptions(installMode, minimumBackgroundDuration);
                this.codePushPackageManager.savePendingInstall(pendingInstall);
            }

            callbackContext.success();
        } else {
            callbackContext.error("Could not find the package start page.");
        }
    } catch (Exception e) {
        callbackContext.error("Cound not read webview URL: " + e.getMessage());
    }
    return true;
}
 
Example 6
Source File: AndroidWearPlugin.java    From cordova-androidwear with Apache License 2.0 5 votes vote down vote up
private void onDataReceived(final CordovaArgs args,
							final CallbackContext callbackContext) throws JSONException {
	Log.d(TAG, "onDataReceived");

	String connectionId = args.getString(0);
	WearConnection connection = connections.get(connectionId);
	if (connection != null) {
		connection.addDataListener(callbackContext);
	} else {
		callbackContext.error("Invalid connection handle");
	}
}
 
Example 7
Source File: AndroidWearPlugin.java    From cordova-androidwear with Apache License 2.0 5 votes vote down vote up
private void onError(final CordovaArgs args,
					 final CallbackContext callbackContext) throws JSONException {
	Log.d(TAG, "onError");

	String connectionId = args.getString(0);
	WearConnection connection = connections.get(connectionId);
	if (connection != null) {
		connection.addErrorListener(callbackContext);
	} else {
		callbackContext.error("Invalid connection handle");
	}
}
 
Example 8
Source File: VideoPlayer.java    From cordova-plugin-videoplayer with MIT License 4 votes vote down vote up
/**
 * Executes the request and returns PluginResult.
 *
 * @param action        The action to execute.
 * @param args          JSONArray of arguments for the plugin.
 * @param callbackId    The callback id used when calling back into JavaScript.
 * @return              A PluginResult object with a status and message.
 */
public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException {
    if (action.equals("play")) {
        this.callbackContext = callbackContext;

        CordovaResourceApi resourceApi = webView.getResourceApi();
        String target = args.getString(0);
        final JSONObject options = args.getJSONObject(1);

        String fileUriStr;
        try {
            Uri targetUri = resourceApi.remapUri(Uri.parse(target));
            fileUriStr = targetUri.toString();
        } catch (IllegalArgumentException e) {
            fileUriStr = target;
        }

        Log.v(LOG_TAG, fileUriStr);

        final String path = stripFileProtocol(fileUriStr);

        // Create dialog in new thread
        cordova.getActivity().runOnUiThread(new Runnable() {
            public void run() {
                openVideoDialog(path, options);
            }
        });

        // Don't return any result now
        PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
        pluginResult.setKeepCallback(true);
        callbackContext.sendPluginResult(pluginResult);
        callbackContext = null;

        return true;
    }
    else if (action.equals("close")) {
        if (dialog != null) {
            if(player.isPlaying()) {
                player.stop();
            }
            player.release();
            dialog.dismiss();
        }

        if (callbackContext != null) {
            PluginResult result = new PluginResult(PluginResult.Status.OK);
            result.setKeepCallback(false); // release status callback in JS side
            callbackContext.sendPluginResult(result);
            callbackContext = null;
        }

        return true;
    }
    return false;
}