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.moodstocks.phonegap.plugin.MoodstocksPlugin.java

License:Open Source License

@Override
public void onSyncProgress(int total, int current) {
    Log.d(TAG, "[SYNC] " + current + "/" + total);

    JSONObject obj = new JSONObject();

    try {// ww  w.j  av  a 2  s.  c  o  m
        obj.put(MESSAGE, "Sync is progressing.");
        obj.put(STATUS, 2);
        obj.put(PROGRESS, 100 * (current / total));
    } catch (JSONException e) {
        e.printStackTrace();
    }

    PluginResult r = new PluginResult(PluginResult.Status.OK, obj);
    r.setKeepCallback(true);
    this.syncCallback.sendPluginResult(r);
}

From source file:com.moodstocks.phonegap.plugin.MoodstocksScanActivity.java

License:Open Source License

@Override
public void onBackPressed() {
    if (backPressActivated) {
        session.pause();// www  .  ja v a 2  s  .com

        JSONObject obj = new JSONObject();
        try {
            obj.put(FORMAT, null);
            obj.put(VALUE, null);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        PluginResult r = new PluginResult(PluginResult.Status.OK, obj);
        r.setKeepCallback(false);

        MoodstocksPlugin.getScanCallback().sendPluginResult(r);

        // Remove the web view from web container when quitting
        webContainer.removeView(MoodstocksPlugin.getOverlay());
        super.onBackPressed();
    }
}

From source file:com.moodstocks.phonegap.plugin.MoodstocksScanActivity.java

License:Open Source License

@Override
public void onScanComplete(Result result) {
    if (result != null) {
        session.pause();/*www  .j  a v  a 2  s .  c  o m*/
        // result found, send to overlay
        JSONObject obj = new JSONObject();
        try {
            obj.put(FORMAT, result.getType());
            obj.put(VALUE, result.getValue());
        } catch (JSONException e) {
            e.printStackTrace();
        }

        PluginResult r = new PluginResult(PluginResult.Status.OK, obj);
        r.setKeepCallback(true);

        MoodstocksPlugin.getScanCallback().sendPluginResult(r);
    }
}

From source file:com.moodstocks.phonegap.plugin.MS4Plugin.java

License:Open Source License

public static void scanSuccess(Result result) {
    PluginResult scanResult = new PluginResult(PluginResult.Status.OK, result.getValue());
    scanResult.setKeepCallback(true);//from ww w . ja  v a2 s  .c  o  m
    scanCallbackContext.sendPluginResult(scanResult);
}

From source file:com.moodstocks.phonegap.plugin.MS4Plugin.java

License:Open Source License

public static void recognisePhotoSuccess(Result result) {
    PluginResult scanResult = new PluginResult(PluginResult.Status.OK, result.getValue());
    scanResult.setKeepCallback(false);/*from  w w w  . ja v  a2 s.  c o m*/
    recognisePhotoCallbackContext.sendPluginResult(scanResult);
}

From source file:com.moodstocks.phonegap.plugin.MS4Plugin.java

License:Open Source License

public static void recognisePhotoFail() {
    PluginResult scanResult = new PluginResult(PluginResult.Status.ERROR, "No Image Found");
    scanResult.setKeepCallback(false);//from   w  w  w  .j  a v  a2 s.  c o m
    recognisePhotoCallbackContext.sendPluginResult(scanResult);
}

From source file:com.moodstocks.phonegap.plugin.MS4Plugin.java

License:Open Source License

public static void scanNoResult() {
    PluginResult scanResult = new PluginResult(PluginResult.Status.ERROR, "No Image Found");
    scanResult.setKeepCallback(true);/*ww w . j a va  2  s .c  o m*/
    scanCallbackContext.sendPluginResult(scanResult);
}

From source file:com.moodstocks.phonegap.plugin.MS4Plugin.java

License:Open Source License

public static void syncFinished(int count) {
    PluginResult syncResult = new PluginResult(PluginResult.Status.OK, count);
    syncResult.setKeepCallback(false); // final sync callback -- doesn't need keeping
    syncCallbackContext.sendPluginResult(syncResult);
}

From source file:com.moodstocks.phonegap.plugin.MS4Plugin.java

License:Open Source License

public static void openFinished(Boolean bundleFlag) {
    PluginResult openResult = new PluginResult(PluginResult.Status.OK, bundleFlag);
    openResult.setKeepCallback(false); // final open callback -- doesn't need keeping
    openCallbackContext.sendPluginResult(openResult);
}

From source file:com.movistar.tvsindesco.cordova.plugin.VideoPlugin.java

@Override
public boolean execute(final String action, final JSONArray args, final CallbackContext callbackContext)
        throws JSONException {
    if (action.equals("playIP")) {
        cordova.getActivity().runOnUiThread(new Runnable() {
            public void run() {
                currentPlay = PLAYING_LIVE;
                codecMpeg123 = true;/*from w  w w  .ja va  2 s .c om*/
                String url = null;
                try {
                    url = args.getString(0);
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                urlPlaying = url;
                Log.i(LOGTAG, "url: " + url);
                player.init(url, MainActivity.getSurfaceView_live());
            }
        });

        return true;
        //        } else if (action.equals("playRtsp")) {
        //            cordova.getActivity().runOnUiThread(new Runnable() {
        //                public void run() {
        //                    Log.i(LOGTAG, "playingrtsp: ");
        //                    currentPlay = PLAYING_RTSP;
        //                    codecMpeg123 = true;
        //                    String url = null;
        //                    try {
        //                        url = args.getString(0);
        //                    } catch (JSONException e) {
        //                        e.printStackTrace();
        //                    }
        //                    urlPlaying = url;
        //                    if (player != null) {
        //                        if (player.getDvbSubsShown()) {
        //                            player.switchDvbSubs(false);
        //                            player.setSelectedTrack(DemoPlayer.TYPE_DVBSUBS, -1);
        //                        }
        //                        player.release();
        //                    }
        //                    player = new DemoPlayer(new RtspRendererBuilder(context, userAgent, url));
        //                    player.setSurface(surface_live);
        //
        //                    player.prepare();
        //                    player.setPlayWhenReady(true);
        //
        //                }
        //            });
        //
        //            return true;
    } else if (action.equals("state")) {
        callbackContext.success(stateVideo);
        return true;
    } else if (action.equals("playVOD")) {
        cordova.getActivity().runOnUiThread(new Runnable() {
            public void run() {
                currentPlay = PLAYING_VOD;
                codecMpeg123 = false;
                String url = null;
                try {
                    url = args.getString(0);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                urlPlaying = url;
                Log.i(LOGTAG, "url: " + url);
                if (player != null) {
                    player.release();
                }
                player.init(url, surfaceView_live);
            }
        });

        return true;
        //        } else if (action.equals("pauseVOD")) {
        //            player.getPlayerControl().pause();
        //
        //            return true;
        //        } else if (action.equals("ffRtsp")) {
        //            player.rtspFastForward(Integer.parseInt(args.getString(0)));
        //
        //            return true;
        //        } else if (action.equals("rewindRtsp")) {
        //            player.rtspRewind(Integer.parseInt(args.getString(0)));
        //
        //            return true;
        //        } else if (action.equals("resumeVOD")) {
        //            player.getPlayerControl().start();
        //
        //            return true;
        //        } else if (action.equals("playPositionVOD")) {
        //            if (player.getPlaybackState() == player.STATE_READY || player.getPlaybackState() == player.STATE_BUFFERING) {
        //                callbackContext.success(player.getPlayerControl().getCurrentPosition());
        //            } else {
        //                callbackContext.success(0);
        //            }
        //
        //            return true;
        //        } else if (action.equals("playTimeVOD")) {
        //            if (player.getPlaybackState() == player.STATE_READY || player.getPlaybackState() == player.STATE_BUFFERING) {
        //                callbackContext.success(player.getPlayerControl().getDuration());
        //            } else {
        //                callbackContext.success(0);
        //            }
        //
        //            return true;
        //        } else if (action.equals("playPositionAudio")) {
        //            if (playerAudio != null) {
        //                if (playerAudio.getPlaybackState() == playerAudio.STATE_READY) {
        //                    callbackContext.success(playerAudio.getPlayerControl().getCurrentPosition());
        //                } else {
        //                    callbackContext.success(0);
        //                }
        //            } else {
        //                callbackContext.success(0);
        //            }
        //            return true;
        //        } else if (action.equals("playTimeAudio")) {
        //
        //            if (playerAudio != null) {
        //                if (playerAudio.getPlaybackState() == playerAudio.STATE_READY) {
        //                    callbackContext.success(playerAudio.getPlayerControl().getDuration());
        //                } else {
        //                    callbackContext.success(0);
        //                }
        //            } else {
        //
        //                callbackContext.success(0);
        //            }
        //
        //            return true;
        //        } else if (action.equals("seekVOD")) {
        //            player.seekTo(Integer.parseInt(args.getString(0)));
        //
        //            return true;
        //        } else if (action.equals("seekRtsp")) {
        //            player.rtspPlay(Integer.parseInt(args.getString(0)));
        //
        //            return true;
    } else if (action.equals("playAudio")) {
        currentPlay = PLAYING_AUDIO;
        codecMpeg123 = false;
        final String url = args.getString(0);
        urlPlaying = url;
        if (player != null) {
            player.release();
        }
        player.init(url, surfaceView_live);
        return true;
        //        } else if (action.equals("pauseAudio")) {
        //            playerAudio.getPlayerControl().pause();
        //
        //            return true;
        //        } else if (action.equals("resumeAudio")) {
        //            playerAudio.getPlayerControl().start();
        //
        //            return true;
    } else if (action.equals("stopAudio")) {
        if (playerAudio != null) {
            playerAudio.stop();
        }

        return true;
        //        } else if (action.equals("seekAudio")) {
        //            if (playerAudio != null) {
        //                playerAudio.seekTo(Integer.parseInt(args.getString(0)));
        //            }
        //
        //            return true;
    } else if (action.equals("release")) {
        if (player != null) {
            player.stop();
        }

        return true;
    } else if (action.equals("setToken")) {
        Log.i(LOGTAG, "setToken");
        token = args.getString(0);
        Log.i(LOGTAG, "token: " + token);
        return true;
    } else if (action.equals("setLicense")) {
        Log.i(LOGTAG, "setLicense");
        LA_URL = args.getString(0);
        Log.i(LOGTAG, "LA_URL: " + LA_URL);

        return true;
        //        } else if (action.equals("playDrm")) {
        //            cordova.getActivity().runOnUiThread(new Runnable() {
        //                public void run() {
        //                    currentPlay = PLAYING_DRM;
        //                    codecMpeg123 = false;
        //
        //                    errorDRM = false;
        //                    String contentUri = null;
        //                    try {
        //                        contentUri = args.getString(0);
        //                        Log.i(LOGTAG, "url: " + contentUri);
        //                        urlPlaying = contentUri;
        //                    } catch (JSONException e) {
        //                        e.printStackTrace();
        //                    }
        //
        //                    if (player != null) {
        //                        player.release();
        //                    }
        //
        //                    player = new DemoPlayer(new SmoothStreamingRendererBuilder(context, userAgent, contentUri.toString(),
        //                            new SmoothStreamingTestMediaDrmCallback()));
        //                    player.setSurface(surface_live);
        //
        //                    eventLogger = new EventLogger();
        //                    eventLogger.startSession();
        //                    player.addListener(eventLogger);
        //                    player.setInfoListener(eventLogger);
        //
        //                    player.prepare();
        //                    player.setPlayWhenReady(true);
        //                }
        //            });
        //
        //            return true;
    } else if (action.equals("changeAudio")) {
        if (player.changeAudio(Integer.parseInt(args.getString(0)))) {
            callbackContext.success("1");
        } else {
            callbackContext.success("0");
        }
        return true;
    } else if (action.equals("getAudios")) {
        String audioinfo = player.getAudios();
        callbackContext.success(audioinfo.substring(1));
        return true;
    } else if (action.equals("getSubtitles")) {
        callbackContext.success(player.getSubtitles());
        return true;
    } else if (action.equals("changeSubtitle")) {
        if (player.changeSubtitle(Integer.parseInt(args.getString(0)))) {
            callbackContext.success("1");
        } else {
            callbackContext.success("0");
        }
        return true;
    } else if (action.equals("supportMulticast")) {
        File file = new File("/proc/net/igmp");
        if (file.exists()) {
            callbackContext.success("1");
        } else {
            callbackContext.success("0");
        }

        return true;
    } else if (action.equals("setVideoSize")) {
        float APP_WIDTH = 1280;
        float appWidth = webView.getWidth();
        float appHeight = webView.getHeight();
        final android.view.ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) surfaceView_live
                .getLayoutParams();
        if (args.getString(0).equals("1")) {
            float scale = APP_WIDTH / appWidth;
            Log.i(LOGTAG, "screenWidth: " + appWidth);
            Log.i(LOGTAG, "scale: " + scale);
            float width = Integer.parseInt(args.getString(1)) / scale;
            float height = Integer.parseInt(args.getString(2)) / scale;
            float bottomMargin = Integer.parseInt(args.getString(3)) / scale;
            float rightMargin = Integer.parseInt(args.getString(3)) / scale;
            lp.width = (int) width;
            lp.height = (int) height;
            lp.topMargin = (int) (appHeight - height - bottomMargin);
            lp.leftMargin = (int) (appWidth - width - rightMargin);
            cordova.getActivity().runOnUiThread(new Runnable() {
                public void run() {
                    surfaceView_live.setLayoutParams(lp);
                    //                        MainActivity.getVideoFrame().bringToFront();
                }
            });

        } else {
            lp.width = (int) appWidth;
            lp.height = (int) appHeight;
            lp.topMargin = 0;
            lp.leftMargin = 0;
            cordova.getActivity().runOnUiThread(new Runnable() {
                public void run() {
                    surfaceView_live.setLayoutParams(lp);
                    webView.bringToFront();
                }
            });
        }
        return true;
    } else if (action.equals("muteVideo")) {
        if (args.getString(0).equals("1")) {
            player.setVolume(0);
        } else {
            player.setVolume(0);
        }
        return true;
    } else if (action.equals("registerCallback")) {
        String event = args.getString(0);
        if (event.equals("OnStateChanged")) {
            onStateChangedCallbackContext = callbackContext;
            PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, "registered");
            pluginResult.setKeepCallback(true);
            onStateChangedCallbackContext.sendPluginResult(pluginResult);
        } else if (event.equals("OnError")) {
            onErrorCallbackContext = callbackContext;
            PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, "registered");
            pluginResult.setKeepCallback(true);
            onErrorCallbackContext.sendPluginResult(pluginResult);
        } else if (event.equals("OnTrackChanged")) {
            onTrackChangedCallbackContext = callbackContext;
            PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, "registered");
            pluginResult.setKeepCallback(true);
            onTrackChangedCallbackContext.sendPluginResult(pluginResult);
        } else {
            callbackContext.error("unknown event");
        }
    } else {
        return false;
    }
    return true;
}