Search in sources :

Example 6 with URLServiceSubscription

use of com.connectsdk.service.command.URLServiceSubscription in project butter-android by butterproject.

the class WebOSTVKeyboardInput method connect.

public URLServiceSubscription<TextInputStatusListener> connect(final TextInputStatusListener listener) {
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            JSONObject jsonObj = (JSONObject) response;
            TextInputStatusInfo keyboard = parseRawKeyboardData(jsonObj);
            Util.postSuccess(listener, keyboard);
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    URLServiceSubscription<TextInputStatusListener> subscription = new URLServiceSubscription<TextInputStatusListener>(service, KEYBOARD_INPUT, null, true, responseListener);
    subscription.send();
    return subscription;
}
Also used : JSONObject(org.json.JSONObject) URLServiceSubscription(com.connectsdk.service.command.URLServiceSubscription) TextInputStatusListener(com.connectsdk.service.capability.TextInputControl.TextInputStatusListener) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) TextInputStatusInfo(com.connectsdk.core.TextInputStatusInfo)

Example 7 with URLServiceSubscription

use of com.connectsdk.service.command.URLServiceSubscription in project butter-android by butterproject.

the class WebOSTVService method getRunningApp.

private ServiceCommand<AppInfoListener> getRunningApp(boolean isSubscription, final AppInfoListener listener) {
    ServiceCommand<AppInfoListener> request;
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            final JSONObject jsonObj = (JSONObject) response;
            AppInfo app = new AppInfo() {

                {
                    setId(jsonObj.optString("appId"));
                    setName(jsonObj.optString("appName"));
                    setRawData(jsonObj);
                }
            };
            Util.postSuccess(listener, app);
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    if (isSubscription)
        request = new URLServiceSubscription<AppInfoListener>(this, FOREGROUND_APP, null, true, responseListener);
    else
        request = new ServiceCommand<AppInfoListener>(this, FOREGROUND_APP, null, true, responseListener);
    request.send();
    return request;
}
Also used : JSONObject(org.json.JSONObject) URLServiceSubscription(com.connectsdk.service.command.URLServiceSubscription) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand) AppInfo(com.connectsdk.core.AppInfo)

Example 8 with URLServiceSubscription

use of com.connectsdk.service.command.URLServiceSubscription in project butter-android by butterproject.

the class WebOSTVService method getVolumeStatus.

private ServiceCommand<ResponseListener<Object>> getVolumeStatus(boolean isSubscription, final VolumeStatusListener listener) {
    ServiceCommand<ResponseListener<Object>> request;
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            try {
                JSONObject jsonObj = (JSONObject) response;
                boolean isMute = (Boolean) jsonObj.get("mute");
                int iVolume = jsonObj.getInt("volume");
                float fVolume = (float) (iVolume / 100.0);
                Util.postSuccess(listener, new VolumeStatus(isMute, fVolume));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    if (isSubscription)
        request = new URLServiceSubscription<ResponseListener<Object>>(this, VOLUME_STATUS, null, true, responseListener);
    else
        request = new ServiceCommand<ResponseListener<Object>>(this, VOLUME_STATUS, null, true, responseListener);
    request.send();
    return request;
}
Also used : JSONException(org.json.JSONException) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) SuppressLint(android.annotation.SuppressLint) JSONObject(org.json.JSONObject) URLServiceSubscription(com.connectsdk.service.command.URLServiceSubscription) JSONObject(org.json.JSONObject) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 9 with URLServiceSubscription

use of com.connectsdk.service.command.URLServiceSubscription in project butter-android by butterproject.

the class WebOSTVService method isWebAppPinned.

private ServiceCommand<WebAppPinStatusListener> isWebAppPinned(boolean isSubscription, String webAppId, final WebAppPinStatusListener listener) {
    if (webAppId == null || webAppId.length() == 0) {
        if (listener != null) {
            listener.onError(new ServiceCommandError(-1, "You must provide a valid web app id", null));
        }
        return null;
    }
    String uri = "ssap://webapp/isWebAppPinned";
    JSONObject payload = new JSONObject();
    try {
        payload.put("webAppId", webAppId);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(final Object response) {
            JSONObject obj = (JSONObject) response;
            boolean status = obj.optBoolean("pinned");
            if (listener != null) {
                listener.onSuccess(status);
            }
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    ServiceCommand<WebAppPinStatusListener> request;
    if (isSubscription)
        request = new URLServiceSubscription<WebAppPinStatusListener>(this, uri, payload, true, responseListener);
    else
        request = new ServiceCommand<WebAppPinStatusListener>(this, uri, payload, true, responseListener);
    request.send();
    return request;
}
Also used : WebAppPinStatusListener(com.connectsdk.service.sessions.WebAppSession.WebAppPinStatusListener) JSONObject(org.json.JSONObject) URLServiceSubscription(com.connectsdk.service.command.URLServiceSubscription) JSONException(org.json.JSONException) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) JSONObject(org.json.JSONObject) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 10 with URLServiceSubscription

use of com.connectsdk.service.command.URLServiceSubscription in project butter-android by butterproject.

the class WebOSTVService method getMuteStatus.

private ServiceCommand<ResponseListener<Object>> getMuteStatus(boolean isSubscription, final MuteListener listener) {
    ServiceCommand<ResponseListener<Object>> request;
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            try {
                JSONObject jsonObj = (JSONObject) response;
                boolean isMute = (Boolean) jsonObj.get("mute");
                Util.postSuccess(listener, isMute);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    if (isSubscription)
        request = new URLServiceSubscription<ResponseListener<Object>>(this, MUTE, null, true, responseListener);
    else
        request = new ServiceCommand<ResponseListener<Object>>(this, MUTE, null, true, responseListener);
    request.send();
    return request;
}
Also used : JSONObject(org.json.JSONObject) URLServiceSubscription(com.connectsdk.service.command.URLServiceSubscription) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Aggregations

ResponseListener (com.connectsdk.service.capability.listeners.ResponseListener)14 URLServiceSubscription (com.connectsdk.service.command.URLServiceSubscription)14 JSONObject (org.json.JSONObject)14 ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)13 JSONException (org.json.JSONException)11 ServiceCommand (com.connectsdk.service.command.ServiceCommand)9 SuppressLint (android.annotation.SuppressLint)4 ChannelInfo (com.connectsdk.core.ChannelInfo)3 TextInputStatusInfo (com.connectsdk.core.TextInputStatusInfo)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 JSONArray (org.json.JSONArray)2 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 AppInfo (com.connectsdk.core.AppInfo)1 ProgramInfo (com.connectsdk.core.ProgramInfo)1 ProgramList (com.connectsdk.core.ProgramList)1 TextInputStatusListener (com.connectsdk.service.capability.TextInputControl.TextInputStatusListener)1 WebOSTVServiceConfig (com.connectsdk.service.config.WebOSTVServiceConfig)1 WebAppPinStatusListener (com.connectsdk.service.sessions.WebAppSession.WebAppPinStatusListener)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1