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, List<PluginResult> multipartMessages) 

Source Link

Usage

From source file:com.simplec.phonegap.plugins.videoplayer.VideoPlayer.java

License:BSD License

public boolean pause() {
    if (this.player != null) {
        this.player.pause();

        JSONObject event = new JSONObject();
        try {/*from w w  w .ja  v  a 2 s  .c  o  m*/
            event.put("type", "paused");
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        PluginResult eventResult = new PluginResult(PluginResult.Status.OK, event);
        eventResult.setKeepCallback(true);
        callbackContext.sendPluginResult(eventResult);

        return true;
    }
    return false;
}

From source file:com.simplec.phonegap.plugins.videoplayer.VideoPlayer.java

License:BSD License

public boolean resume() {
    if (this.player != null) {
        videoView.resume();// www  .  j av  a2s .c o m
        this.player.start();

        JSONObject event = new JSONObject();
        try {
            event.put("type", "playing");
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        PluginResult eventResult = new PluginResult(PluginResult.Status.OK, event);
        eventResult.setKeepCallback(true);
        callbackContext.sendPluginResult(eventResult);

        return true;
    }
    return false;
}

From source file:com.simplec.phonegap.plugins.videoplayer.VideoPlayer.java

License:BSD License

public boolean stop() {
    if (player != null) {
        JSONObject event = new JSONObject();
        try {//from w  ww  .j  av a 2 s. co m
            event.put("type", "completed");
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        PluginResult errorResult = new PluginResult(PluginResult.Status.OK, event);
        errorResult.setKeepCallback(false);
        callbackContext.sendPluginResult(errorResult);

        if (player != null) {
            player.stop();
            player.release();
            player = null;
        }
        if (dialog != null) {
            dialog.dismiss();
            dialog = null;
        }

        prepared = false;
        videoView = null;
        detector = null;
        callbackContext = null;

        return true;
    }
    return false;
}

From source file:com.sldev.cordova.locale.LocalizationPlugin.java

License:Apache License

private void initLocaleChangeReceiver() {
    if (localeChangeReceiver != null) {
        return;/*www. j ava  2 s. c  o m*/
    }
    localeChangeIntent = new IntentFilter(Intent.ACTION_LOCALE_CHANGED);
    localeChangeReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            // update stored strings
            Iterator<String> jsonKeys = stringMap.keys();
            while (jsonKeys.hasNext()) {
                String key = jsonKeys.next();
                try {
                    stringMap.put(key, getFromResource(key));
                } catch (JSONException e) {
                    //            Log.e(TAG, "Can't update string with key: "+key);
                }
            }
            if (!localeChangeListeners.isEmpty()) {
                PluginResult result = new PluginResult(PluginResult.Status.OK, getLocale());
                result.setKeepCallback(true);
                for (CallbackContext listener : localeChangeListeners.values()) {
                    listener.sendPluginResult(result);
                }
                //          localeChangeCallback.success(Locale.getDefault().getDisplayLanguage());
            }
        }
    };
}

From source file:com.sldev.cordova.locale.LocalizationPlugin.java

License:Apache License

@Override
public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException {
    if (action.equals(ACTION_GET)) {
        String resourceId = args.getString(0);
        String resString = get(resourceId);
        if (resString != null) {
            callbackContext.success(resString);
        } else {//  w ww  .  j a va 2s . co m
            callbackContext.error("Resource not found: " + resourceId);
        }
    } else if (action.equals(ACTION_GET_ALL)) {
        LOG.d(TAG, args.toString());
        JSONArray resIds = null;
        try {
            resIds = args.getJSONArray(0);
        } catch (JSONException je) {
            // no res ids
            callbackContext.error("Resource ID Error: " + je.getLocalizedMessage());
        }
        Log.d(TAG, "getAll: " + resIds);
        String resString = getAll(resIds);
        if (resString != null) {
            callbackContext.success(resString);
        } else {
            callbackContext.error("GETALL: Resource not found: " + resIds);
        }
    } else if (action.equals(ACTION_REGISTER_CALLBACK)) {
        localeChangeListeners.put(callbackContext.getCallbackId(), callbackContext);
        PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT, callbackContext.getCallbackId());
        result.setKeepCallback(true);
        callbackContext.sendPluginResult(result);
    } else if (action.equals(ACTION_UNREGISTER_CALLBACK)) {
        String callbackId = args.getString(0);
        if (callbackId != null && localeChangeListeners.containsKey(callbackId)) {
            localeChangeListeners.remove(callbackId);
        } else {
            callbackContext.error("Callback ID invalid.");
        }
    } else if (action.equals((ACTION_GET_LOCALE))) {
        callbackContext.success(getLocale());
    } else {
        callbackContext.error("Invalid action: " + action);
    }
    return true;
}

From source file:com.snipme.record.Record.java

License:Apache License

/**
 * Called when the video view exits./*from   ww  w.j a v a2 s  . c  o m*/
 *
 * @param requestCode       The request code originally supplied to startActivityForResult(),
 *                          allowing you to identify who this result came from.
 * @param resultCode        The integer result code returned by the child activity through its setResult().
 * @param intent            An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
 * @throws JSONException
 */
public void onActivityResult(int requestCode, int resultCode, final Intent intent) {
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == CAPTURE_VIDEO) {
            Log.i(TAG, "onActivityResult: Video Capture success");
            final Record that = this;
            Runnable captureVideo = new Runnable() {

                @Override
                public void run() {

                    Uri data = null;

                    if (intent != null) {
                        // Get the uri of the video clip
                        data = intent.getData();
                        Log.i(TAG, "onActivityResult: Uri: " + data);
                        Log.i(TAG, "Uri of the video file recorded");
                    }

                    if (data == null) {
                        File movie = new File(getTempDirectoryPath(), "Capture.avi");
                        data = Uri.fromFile(movie);
                    }

                    // create a file object from the uri
                    if (data == null) {
                        that.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Error: data is null"));
                    } else {
                        results.put(createMediaFile(data));

                        if (results.length() >= 1) {
                            // Send Uri back to JavaScript for viewing video
                            that.callbackContext
                                    .sendPluginResult(new PluginResult(PluginResult.Status.OK, results));
                        } else {
                            // still need to capture more video clips
                            //captureVideo(duration);
                        }
                    }
                }
            };
            this.cordova.getThreadPool().execute(captureVideo);
        }
    } else if (resultCode == Activity.RESULT_CANCELED) {

    }

}