Search in sources :

Example 1 with URLServiceSubscription

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

the class WebOSTVService method getChannelList.

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

        @Override
        public void onSuccess(Object response) {
            try {
                JSONObject jsonObj = (JSONObject) response;
                ArrayList<ChannelInfo> list = new ArrayList<ChannelInfo>();
                JSONArray array = (JSONArray) jsonObj.get("channelList");
                for (int i = 0; i < array.length(); i++) {
                    JSONObject object = (JSONObject) array.get(i);
                    ChannelInfo channel = parseRawChannelData(object);
                    list.add(channel);
                }
                Util.postSuccess(listener, list);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    if (isSubscription)
        request = new URLServiceSubscription<ResponseListener<Object>>(this, CHANNEL_LIST, null, true, responseListener);
    else
        request = new ServiceCommand<ResponseListener<Object>>(this, CHANNEL_LIST, null, true, responseListener);
    request.send();
    return request;
}
Also used : ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) ChannelInfo(com.connectsdk.core.ChannelInfo) 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 2 with URLServiceSubscription

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

the class WebOSTVService method pinWebApp.

@Override
public void pinWebApp(String webAppId, final ResponseListener<Object> 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;
    }
    String uri = "ssap://webapp/pinWebApp";
    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;
            if (obj.has("pairingType")) {
                notifyPairingRequired();
            } else if (listener != null) {
                listener.onSuccess(response);
            }
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    ServiceCommand<ResponseListener<Object>> request = new URLServiceSubscription<ResponseListener<Object>>(this, uri, payload, true, responseListener);
    request.send();
}
Also used : 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)

Example 3 with URLServiceSubscription

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

the class WebOSTVService method getChannelCurrentProgramInfo.

private ServiceCommand<ResponseListener<Object>> getChannelCurrentProgramInfo(boolean isSubscription, final ProgramInfoListener listener) {
    String uri = "ssap://tv/getChannelCurrentProgramInfo";
    ServiceCommand<ResponseListener<Object>> request;
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            JSONObject jsonObj = (JSONObject) response;
            ProgramInfo programInfo = parseRawProgramInfo(jsonObj);
            Util.postSuccess(listener, programInfo);
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    if (isSubscription)
        request = new URLServiceSubscription<ResponseListener<Object>>(this, uri, null, true, responseListener);
    else
        request = new ServiceCommand<ResponseListener<Object>>(this, uri, null, true, responseListener);
    request.send();
    return request;
}
Also used : ProgramInfo(com.connectsdk.core.ProgramInfo) 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)

Example 4 with URLServiceSubscription

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

the class WebOSTVService method getProgramList.

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

        @Override
        public void onSuccess(Object response) {
            try {
                JSONObject jsonObj = (JSONObject) response;
                JSONObject jsonChannel = (JSONObject) jsonObj.get("channel");
                ChannelInfo channel = parseRawChannelData(jsonChannel);
                JSONArray programList = (JSONArray) jsonObj.get("programList");
                Util.postSuccess(listener, new ProgramList(channel, programList));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

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

Example 5 with URLServiceSubscription

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

the class WebOSTVService method getVolume.

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

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

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    if (isSubscription)
        request = new URLServiceSubscription<VolumeListener>(this, VOLUME, null, true, responseListener);
    else
        request = new ServiceCommand<VolumeListener>(this, VOLUME, 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)

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