Search in sources :

Example 6 with JSObject

use of com.getcapacitor.JSObject in project capacitor-video-player by jepiqueau.

the class CapacitorVideoPlayerPlugin method echo.

@PluginMethod
public void echo(PluginCall call) {
    String value = call.getString("value");
    JSObject ret = new JSObject();
    ret.put("value", implementation.echo(value));
    call.resolve(ret);
}
Also used : JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 7 with JSObject

use of com.getcapacitor.JSObject in project capacitor-video-player by jepiqueau.

the class CapacitorVideoPlayerPlugin method play.

@PluginMethod
public void play(final PluginCall call) {
    this.call = call;
    JSObject ret = new JSObject();
    ret.put("method", "play");
    String playerId = call.getString("playerId");
    if (playerId == null) {
        ret.put("result", false);
        ret.put("message", "Must provide a PlayerId");
        call.resolve(ret);
        return;
    }
    if ("fullscreen".equals(mode) && fsPlayerId.equals(playerId)) {
        bridge.getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                JSObject ret = new JSObject();
                ret.put("method", "play");
                if (fsFragment != null) {
                    fsFragment.play();
                    boolean playing = fsFragment.isPlaying();
                    ret.put("result", true);
                    ret.put("value", true);
                    call.resolve(ret);
                } else {
                    ret.put("result", false);
                    ret.put("message", "Fullscreen fragment is not defined");
                    call.resolve(ret);
                }
            }
        });
    } else {
        ret.put("result", false);
        ret.put("message", "player is not defined");
        call.resolve(ret);
    }
}
Also used : MyRunnable(com.jeep.plugin.capacitor.capacitorvideoplayer.Notifications.MyRunnable) JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 8 with JSObject

use of com.getcapacitor.JSObject in project capacitor-video-player by jepiqueau.

the class CapacitorVideoPlayerPlugin method AddObserversToNotificationCenter.

private void AddObserversToNotificationCenter() {
    NotificationCenter.defaultCenter().addMethodForNotification("playerItemPlay", new MyRunnable() {

        @Override
        public void run() {
            JSObject data = new JSObject();
            data.put("fromPlayerId", this.getInfo().get("fromPlayerId"));
            data.put("currentTime", this.getInfo().get("currentTime"));
            notifyListeners("jeepCapVideoPlayerPlay", data);
            return;
        }
    });
    NotificationCenter.defaultCenter().addMethodForNotification("playerItemPause", new MyRunnable() {

        @Override
        public void run() {
            JSObject data = new JSObject();
            data.put("fromPlayerId", this.getInfo().get("fromPlayerId"));
            data.put("currentTime", this.getInfo().get("currentTime"));
            notifyListeners("jeepCapVideoPlayerPause", data);
            return;
        }
    });
    NotificationCenter.defaultCenter().addMethodForNotification("playerItemReady", new MyRunnable() {

        @Override
        public void run() {
            JSObject data = new JSObject();
            data.put("fromPlayerId", this.getInfo().get("fromPlayerId"));
            data.put("currentTime", this.getInfo().get("currentTime"));
            notifyListeners("jeepCapVideoPlayerReady", data);
            return;
        }
    });
    NotificationCenter.defaultCenter().addMethodForNotification("playerItemEnd", new MyRunnable() {

        @Override
        public void run() {
            final JSObject data = new JSObject();
            data.put("fromPlayerId", this.getInfo().get("fromPlayerId"));
            data.put("currentTime", this.getInfo().get("currentTime"));
            bridge.getActivity().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    FrameLayout frameLayoutView = getBridge().getActivity().findViewById(frameLayoutViewId);
                    if (frameLayoutView != null) {
                        ((ViewGroup) getBridge().getWebView().getParent()).removeView(frameLayoutView);
                        fragmentUtils.removeFragment(fsFragment);
                    }
                    fsFragment = null;
                    NotificationCenter.defaultCenter().removeAllNotifications();
                    notifyListeners("jeepCapVideoPlayerEnded", data);
                }
            });
        }
    });
    NotificationCenter.defaultCenter().addMethodForNotification("playerFullscreenDismiss", new MyRunnable() {

        @Override
        public void run() {
            boolean ret = false;
            final JSObject data = new JSObject();
            if (Integer.valueOf((String) this.getInfo().get("dismiss")) == 1)
                ret = true;
            data.put("dismiss", ret);
            bridge.getActivity().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    FrameLayout frameLayoutView = getBridge().getActivity().findViewById(frameLayoutViewId);
                    if (frameLayoutView != null) {
                        ((ViewGroup) getBridge().getWebView().getParent()).removeView(frameLayoutView);
                        fragmentUtils.removeFragment(fsFragment);
                    }
                    fsFragment = null;
                    NotificationCenter.defaultCenter().removeAllNotifications();
                    notifyListeners("jeepCapVideoPlayerExit", data);
                }
            });
        }
    });
    NotificationCenter.defaultCenter().addMethodForNotification("videoPathInternalReady", new MyRunnable() {

        @Override
        public void run() {
            long videoId = (Long) this.getInfo().get("videoId");
            // Get the previously saved call
            FrameLayout pickerLayoutView = getBridge().getActivity().findViewById(pickerLayoutViewId);
            if (pickerLayoutView != null) {
                ((ViewGroup) getBridge().getWebView().getParent()).removeView(pickerLayoutView);
                fragmentUtils.removeFragment(pkFragment);
            }
            pkFragment = null;
            if (videoId != -1) {
                createFullScreenFragment(call, videoPath, videoRate, exitOnEnd, loopOnEnd, pipEnabled, null, null, null, isTV, fsPlayerId, true, videoId);
            } else {
                Toast.makeText(context, "No Video files found ", Toast.LENGTH_SHORT).show();
                Map<String, Object> info = new HashMap<String, Object>() {

                    {
                        put("dismiss", "1");
                    }
                };
                NotificationCenter.defaultCenter().postNotification("playerFullscreenDismiss", info);
            }
        }
    });
}
Also used : MyRunnable(com.jeep.plugin.capacitor.capacitorvideoplayer.Notifications.MyRunnable) ViewGroup(android.view.ViewGroup) MyRunnable(com.jeep.plugin.capacitor.capacitorvideoplayer.Notifications.MyRunnable) FrameLayout(android.widget.FrameLayout) JSObject(com.getcapacitor.JSObject) JSObject(com.getcapacitor.JSObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with JSObject

use of com.getcapacitor.JSObject in project capacitor-app-update by robingenz.

the class AppUpdatePlugin method readyForUpdate.

private boolean readyForUpdate(PluginCall call, int appUpdateType) {
    JSObject ret = new JSObject();
    if (this.appUpdateInfo == null) {
        ret.put("code", UPDATE_INFO_MISSING);
        call.resolve(ret);
        return false;
    }
    if (this.appUpdateInfo.updateAvailability() != UpdateAvailability.UPDATE_AVAILABLE) {
        ret.put("code", UPDATE_NOT_AVAILABLE);
        call.resolve(ret);
        return false;
    }
    if (!this.appUpdateInfo.isUpdateTypeAllowed(appUpdateType)) {
        ret.put("code", UPDATE_NOT_ALLOWED);
        call.resolve(ret);
        return false;
    }
    return true;
}
Also used : JSObject(com.getcapacitor.JSObject)

Example 10 with JSObject

use of com.getcapacitor.JSObject in project capacitor-app-update by robingenz.

the class AppUpdatePlugin method getAppUpdateInfo.

@PluginMethod
public void getAppUpdateInfo(PluginCall call) {
    Task<AppUpdateInfo> appUpdateInfoTask = this.appUpdateManager.getAppUpdateInfo();
    appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
        this.appUpdateInfo = appUpdateInfo;
        PackageInfo pInfo;
        try {
            pInfo = this.getPackageInfo();
        } catch (PackageManager.NameNotFoundException e) {
            call.reject(ERROR_GET_APP_INFO_FAILED);
            return;
        }
        JSObject ret = new JSObject();
        ret.put("currentVersion", String.valueOf(pInfo.versionCode));
        ret.put("availableVersion", String.valueOf(appUpdateInfo.availableVersionCode()));
        ret.put("updateAvailability", appUpdateInfo.updateAvailability());
        ret.put("updatePriority", appUpdateInfo.updatePriority());
        ret.put("immediateUpdateAllowed", appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE));
        ret.put("flexibleUpdateAllowed", appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE));
        Integer clientVersionStalenessDays = appUpdateInfo.clientVersionStalenessDays();
        if (clientVersionStalenessDays != null) {
            ret.put("clientVersionStalenessDays", clientVersionStalenessDays);
        }
        ret.put("installStatus", appUpdateInfo.installStatus());
        call.resolve(ret);
    });
    appUpdateInfoTask.addOnFailureListener(failure -> {
        String message = failure.getMessage();
        call.reject(message);
    });
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) JSObject(com.getcapacitor.JSObject) AppUpdateInfo(com.google.android.play.core.appupdate.AppUpdateInfo) PluginMethod(com.getcapacitor.PluginMethod)

Aggregations

JSObject (com.getcapacitor.JSObject)169 PluginMethod (com.getcapacitor.PluginMethod)93 JSONException (org.json.JSONException)28 JSONObject (org.json.JSONObject)20 MyRunnable (com.jeep.plugin.capacitor.capacitorvideoplayer.Notifications.MyRunnable)16 JSArray (com.getcapacitor.JSArray)14 Radar (io.radar.sdk.Radar)12 Uri (android.net.Uri)11 Location (android.location.Location)9 JSONArray (org.json.JSONArray)7 ArrayList (java.util.ArrayList)6 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)6 ParseException (java.text.ParseException)5 Intent (android.content.Intent)4 FirebaseUser (com.google.firebase.auth.FirebaseUser)4 Gson (com.google.gson.Gson)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4