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.appfeel.cordova.analytics.CPGoogleAnalytics.java

License:Open Source License

private PluginResult execSetAppParams(JSONObject options, CallbackContext callbackContext) {
    if (options.has(OPT_APP_ID)) {
        tracker.setAppId(options.optString(OPT_APP_ID));
    }/*  w  w  w .jav a2s  . c o  m*/
    if (options.has(OPT_APP_INSTALLER_ID)) {
        tracker.setAppInstallerId(options.optString(OPT_APP_INSTALLER_ID));
    }
    if (options.has(OPT_APP_NAME)) {
        tracker.setAppName(options.optString(OPT_APP_NAME));
    }
    if (options.has(OPT_APP_VERSION)) {
        tracker.setAppVersion(options.optString(OPT_APP_VERSION));
    }

    return new PluginResult(Status.OK);
}

From source file:com.appfeel.cordova.analytics.CPGoogleAnalytics.java

License:Open Source License

private PluginResult execSetCustomParams(JSONObject options, CallbackContext callbackContext) {
    int i;//from  w  ww .  ja va  2  s  .  c o m
    if (options != null) {
        JSONArray names = options.names();

        for (i = 0; i < names.length(); i += 1) {
            tracker.set(names.optString(i), options.optString(names.optString(i)));
        }
    }

    return new PluginResult(Status.OK);
}

From source file:com.appfeel.cordova.analytics.CPGoogleAnalytics.java

License:Open Source License

private PluginResult execSetDebugMode(CallbackContext callbackContext) {
    GoogleAnalytics.getInstance(this.cordova.getActivity()).getLogger().setLogLevel(LogLevel.VERBOSE);
    return new PluginResult(Status.OK);
}

From source file:com.blockertech.SMSRetriever.java

public boolean execute(String action, JSONArray inputs, CallbackContext callbackContext) throws JSONException {
    cordova.requestPermissions(this, 0, Manifest.permission.READ_SMS);
    PluginResult result = null;//from  ww w .  ja va2  s .c  o  m
    if (ACTION_SET_OPTIONS.equals(action)) {
        JSONObject options = inputs.optJSONObject(0);
        this.setOptions(options);
        result = new PluginResult(PluginResult.Status.OK);
    } else if (ACTION_START_WATCH.equals(action)) {
        result = this.startWatch(callbackContext);
    } else if (ACTION_ENABLE_INTERCEPT.equals(action)) {
        boolean on_off = inputs.optBoolean(0);
        result = this.enableIntercept(on_off, callbackContext);
    } else if (ACTION_LIST_SMS.equals(action)) {
        JSONObject filters = inputs.optJSONObject(0);
        result = this.listSMS(filters, callbackContext);
    } else {
        Log.d(LOGTAG, String.format("Invalid action passed: %s", action));
        result = new PluginResult(PluginResult.Status.INVALID_ACTION);
    }
    if (result != null) {
        callbackContext.sendPluginResult(result);
    }
    return true;
}

From source file:com.cem.echo.Echo.java

protected boolean getCertificateList(CallbackContext callbackContext) {
    System.out.println("-----getcertlist: entrance deneme");

    List<String> certs = new ArrayList<String>();

    try {//w w  w  .j  a va  2 s  .  c o  m
        /*            InputStream lisansStream = cordova.getActivity().getResources().openRawResource(cordova.getActivity().getResources().getIdentifier("lisans", "raw", cordova.getActivity().getPackageName()));
                    LicenseUtil.setLicenseXml(lisansStream);
                    lisansStream.close();*/

        Resources activityRes = cordova.getActivity().getResources();
        int lisansid = activityRes.getIdentifier("lisans", "raw", cordova.getActivity().getPackageName());
        InputStream lisansStream = activityRes.openRawResource(lisansid);
        LicenseUtil.setLicenseXml(lisansStream);
        lisansStream.close();

        System.out.println("-----getcertlist: lisans aldik");

        mTerminalHandler = new SCDTerminalHandler(cordova.getActivity());

        mAPDUSmartCard = new APDUSmartCard(mTerminalHandler);
        mAPDUSmartCard.setDisableSecureMessaging(true);

        CardTerminal[] terminalList = mAPDUSmartCard.getTerminalList();

        CardTerminal cardTerminal = terminalList[0];

        //System.out.println("hehehe " + terminalList[0]);

        mAPDUSmartCard.openSession(cardTerminal);
        String readerName = cardTerminal.getName();
        List<byte[]> signCertValueList = mAPDUSmartCard.getSignatureCertificates();

        certificateList = new ArrayList<ECertificate>();

        for (byte[] signCertValue : signCertValueList) {
            ECertificate signCert = new ECertificate(signCertValue);
            //Sadece nitelikli sertifikalar ekiliyor.
            //Kanuni geerlilii olmayan sertifikalarla imza atlmak istenirse bu kontrol kaldrlabilir.
            //  if(signCert.isQualifiedCertificate()){
            certificateList.add(signCert);
            System.out.println("Sertifika Sahibi :" + signCert.getSubject().getCommonNameAttribute());
            certs.add(signCert.getSubject().getCommonNameAttribute());
            //}
        }
    } catch (Exception e) {
        e.printStackTrace();
        PluginResult pluginResult = new PluginResult(PluginResult.Status.ERROR);
        pluginResult.setKeepCallback(true);
        callbackContext.sendPluginResult(pluginResult);
        //callbackContext.error("Sertifikalar alrken bir hata olutu.");
        return false;
    }

    String[] res = new String[certs.size()];
    certs.toArray(res);

    PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, new JSONArray(certs));
    pluginResult.setKeepCallback(true);
    callbackContext.sendPluginResult(pluginResult);
    //callbackContext.success(new JSONArray(certs));
    return true;
}

From source file:com.cem.echo.Echo.java

protected boolean sign(int _certIndex, String _password, String _sourceFilePath, String _destFilePath,
        CallbackContext _callbackContext) {
    final int certIndex = _certIndex;
    final String password = _password;
    final String sourceFilePath = _sourceFilePath.replaceAll("file://", "");
    final String destFilePath = _destFilePath.replaceAll("file://", "");

    final CallbackContext callbackContext = _callbackContext;

    System.out.println("-----sign: entrance: " + certIndex + " " + password + " " + sourceFilePath);
    cordova.getActivity().runOnUiThread(new Runnable() {
        public void run() {
            try {

                mAPDUSmartCard.login(password);

                ECertificate signCert = certificateList.get(certIndex);

                BaseSigner signer = mAPDUSmartCard.getSigner(signCert.asX509Certificate(),
                        Algorithms.SIGNATURE_RSA_SHA1);
                BaseSignedData bsd = new BaseSignedData();

                System.out.println("--------------LOGIN BASARILI------------");

                /*File tempFile = new File("cem1.txt");
                System.out.println("---temp file: " + tempFile.getAbsolutePath());
                        /*from w w  w. jav a2 s  . c  om*/
                CordovaResourceApi resourceApi = webView.getResourceApi();
                Uri sourceUri = resourceApi.remapUri(Uri.fromFile(new File("cem2.txt")));
                System.out.println("---source uri: " + sourceUri);
                        
                tempFile = resourceApi.mapUriToFile(Uri.parse(sourceFilePath));
                System.out.println("sourcefilepath....");
                if(tempFile != null) {
                System.out.println(tempFile.getAbsolutePath());
                } else {
                System.out.println("null file");
                }
                        
                System.out.println("sourceuri...");
                tempFile = resourceApi.mapUriToFile(sourceUri);
                if(tempFile != null) {
                System.out.println(tempFile.getAbsolutePath());
                } else {
                System.out.println("null file");
                }*/

                ISignable content = new SignableFile(new File(sourceFilePath));
                bsd.addContent(content);
                //Since SigningTime attribute is optional,add it to optional attributes list
                List<IAttribute> optionalAttributes = new ArrayList<IAttribute>();
                optionalAttributes.add(new SigningTimeAttr(Calendar.getInstance()));
                HashMap<String, Object> params = new HashMap<String, Object>();

                params.put(EParameters.P_VALIDATE_CERTIFICATE_BEFORE_SIGNING, false);
                bsd.addSigner(ESignatureType.TYPE_BES, signCert, signer, optionalAttributes, params);
                byte[] signedDocument = bsd.getEncoded();
                System.out.println("mzalama ilemi tamamland. Dosyaya yazlacak. Imzali Veri ="
                        + (signedDocument.toString()));

                AsnIO.dosyayaz(signedDocument, destFilePath);

                mAPDUSmartCard.logout();
                mAPDUSmartCard.closeSession();
            } catch (Exception e) {
                e.printStackTrace();
                PluginResult pluginResult = new PluginResult(PluginResult.Status.ERROR);
                pluginResult.setKeepCallback(true);
                callbackContext.sendPluginResult(pluginResult);
                //callbackContext.error("mzalama srasnda bir hata olutu. Ltfen ifrenizi kontrol edip tekrar deneyiniz.");
                //return false;
            }

            PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
            pluginResult.setKeepCallback(true);
            callbackContext.sendPluginResult(pluginResult);
            //callbackContext.success();
            //return true;
        }
    });

    return true;

}

From source file:com.cloudant.sync.cordova.CloudantSyncPlugin.java

License:Open Source License

/**
 * Creates a new Replicator/*from   ww  w . j  a va2 s .c o  m*/
 * @param documentStoreName - The name of the DocumentStore
 * @param remoteURI - The remote database URI
 * @param type - The type of replication to be performed
 * @param token - The unique token id of the Replicator
 * @param callbackContext - The javascript callback to execute when complete or errored
 */
private void createReplicator(final String documentStoreName, final String remoteURI, final String type,
        final Integer token, final CallbackContext callbackContext) {
    cordova.getThreadPool().execute(new Runnable() {
        @Override
        public void run() {
            try {
                DocumentStore ds = getDocumentStore(documentStoreName);

                if (remoteURI == null || type == null || token == null) {
                    throw new Exception("Replicator uri, type, and token must not be null");
                }

                URI uri;
                try {
                    uri = new URI(remoteURI);
                } catch (URISyntaxException e) {
                    throw new Exception("Invalid uri: " + remoteURI);
                }

                Replicator replicator;
                final SyncPluginInterceptor interceptor = new SyncPluginInterceptor(callbackContext);
                if (type.equals("push")) {
                    replicator = ReplicatorBuilder.push().to(uri).from(ds)
                            .addRequestInterceptors((HttpConnectionRequestInterceptor) interceptor)
                            .addResponseInterceptors((HttpConnectionResponseInterceptor) interceptor).build();
                } else if (type.equals("pull")) {
                    replicator = ReplicatorBuilder.pull().from(uri).to(ds)
                            .addRequestInterceptors((HttpConnectionRequestInterceptor) interceptor)
                            .addResponseInterceptors((HttpConnectionResponseInterceptor) interceptor).build();
                } else {
                    throw new Exception("Replicator 'type' must be either 'push' or 'pull'. Received: " + type);
                }

                if (replicator == null) {
                    throw new Exception("Failed to create " + type + " Replicator. Builder returned null");
                }

                replicator.getEventBus().register(new SyncPluginListener(callbackContext));

                replicators.put(token, replicator);
                interceptors.put(token, interceptor);

                PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
                pluginResult.setKeepCallback(true);
                callbackContext.sendPluginResult(pluginResult);

            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }
        }
    });
}

From source file:com.cloudant.sync.cordova.CloudantSyncPlugin.java

License:Open Source License

private void resolveConflictsForDocument(final String documentStoreName, final String documentId,
        final CallbackContext callbackContext) {
    cordova.getThreadPool().execute(new Runnable() {
        @Override//from w w w. j  a v  a 2s .  co  m
        public void run() {
            try {
                DocumentStore ds = getDocumentStore(documentStoreName);

                ConflictResolverWrapper conflictResolver = new ConflictResolverWrapper(callbackContext);

                // Store the conflictResolver in a map indexed by a unique ID that can be passed around
                // to retrieve the conflictResolver from other callbacks. The callbackId is unique
                // to each invocation of this method so we'll use that.
                resolverMap.put(callbackContext.getCallbackId(), conflictResolver);
                ds.database().resolveConflicts(documentId, conflictResolver);
                PluginResult r = new PluginResult(PluginResult.Status.OK);
                callbackContext.sendPluginResult(r);

            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }
        }
    });
}

From source file:com.cloudant.sync.cordova.CloudantSyncPlugin.java

License:Open Source License

private void returnResolvedDocument(final JSONObject docRev, final String resolverId,
        final CallbackContext callbackContext) {
    cordova.getThreadPool().execute(new Runnable() {
        @Override/*from  www. j a  v a  2  s  .  c  o m*/
        public void run() {
            try {
                ConflictResolverWrapper conflictResolver = resolverMap.remove(resolverId);
                DocumentRevision revision = docRev == null ? null : buildDocRevision(docRev);
                conflictResolver.setRevision(revision);

                PluginResult r = new PluginResult(PluginResult.Status.OK);
                callbackContext.sendPluginResult(r);
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }
        }
    });
}

From source file:com.coloreight.plugin.clipboard.Clipboard.java

License:Open Source License

public void paste(final CallbackContext callbackContext) {
    cordova.getActivity().runOnUiThread(new Runnable() {
        public void run() {
            ClipboardManager clipboard = (ClipboardManager) cordova.getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);

            if (!clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.NO_RESULT));
            }/*from w w w.j av  a2 s.c o m*/

            try {
                ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
                String text = item.getText().toString();

                callbackContext.success(text);
            } catch (Exception e) {
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.toString()));
            }
        }
    });
}