Search in sources :

Example 11 with ServiceCommandError

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

the class NetcastTVService method sendCommand.

@Override
public void sendCommand(final ServiceCommand<?> mCommand) {
    Util.runInBackground(new Runnable() {

        @SuppressWarnings("unchecked")
        @Override
        public void run() {
            final ServiceCommand<ResponseListener<Object>> command = (ServiceCommand<ResponseListener<Object>>) mCommand;
            Object payload = command.getPayload();
            try {
                HttpConnection connection = HttpConnection.newInstance(URI.create(command.getTarget()));
                connection.setHeader(HttpMessage.USER_AGENT, HttpMessage.UDAP_USER_AGENT);
                connection.setHeader(HttpMessage.CONTENT_TYPE_HEADER, HttpMessage.CONTENT_TYPE_TEXT_XML);
                if (payload != null && command.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_POST)) {
                    connection.setMethod(HttpConnection.Method.POST);
                    connection.setPayload(payload.toString());
                }
                connection.execute();
                int code = connection.getResponseCode();
                Log.d("", "RESP " + code);
                if (code == 200) {
                    Util.postSuccess(command.getResponseListener(), connection.getResponseString());
                } else {
                    Util.postError(command.getResponseListener(), ServiceCommandError.getError(code));
                }
            } catch (IOException e) {
                e.printStackTrace();
                Util.postError(command.getResponseListener(), new ServiceCommandError(0, e.getMessage(), null));
            }
        }
    });
}
Also used : HttpConnection(com.connectsdk.etc.helper.HttpConnection) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) IOException(java.io.IOException) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 12 with ServiceCommandError

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

the class NetcastTVService method getVolumeStatus.

private void getVolumeStatus(final VolumeStatusListener listener) {
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            String strObj = (String) response;
            JSONObject volumeStatus = parseVolumeXmlToJSON(strObj);
            try {
                boolean isMute = (Boolean) volumeStatus.get("mute");
                int volume = (Integer) volumeStatus.get("level");
                Util.postSuccess(listener, new VolumeStatus(isMute, volume));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    String requestURL = getUDAPRequestURL(UDAP_PATH_DATA, TARGET_VOLUME_INFO);
    ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, requestURL, null, responseListener);
    request.setHttpMethod(ServiceCommand.TYPE_GET);
    request.send();
}
Also used : JSONException(org.json.JSONException) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 13 with ServiceCommandError

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

the class WebOSTVService method launchInputPicker.

@Override
public void launchInputPicker(final AppLaunchListener listener) {
    final AppInfo appInfo = new AppInfo() {

        {
            setId("com.webos.app.inputpicker");
            setName("InputPicker");
        }
    };
    launchAppWithInfo(appInfo, null, new AppLaunchListener() {

        @Override
        public void onSuccess(LaunchSession object) {
            listener.onSuccess(object);
        }

        @Override
        public void onError(ServiceCommandError error) {
            appInfo.setId("com.webos.app.inputmgr");
            launchAppWithInfo(appInfo, null, listener);
        }
    });
}
Also used : LaunchSession(com.connectsdk.service.sessions.LaunchSession) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) AppInfo(com.connectsdk.core.AppInfo)

Example 14 with ServiceCommandError

use of com.connectsdk.service.command.ServiceCommandError 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 15 with ServiceCommandError

use of com.connectsdk.service.command.ServiceCommandError 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)

Aggregations

ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)84 JSONObject (org.json.JSONObject)70 ResponseListener (com.connectsdk.service.capability.listeners.ResponseListener)65 ServiceCommand (com.connectsdk.service.command.ServiceCommand)55 JSONException (org.json.JSONException)47 URLServiceSubscription (com.connectsdk.service.command.URLServiceSubscription)13 IOException (java.io.IOException)13 LaunchSession (com.connectsdk.service.sessions.LaunchSession)12 AppInfo (com.connectsdk.core.AppInfo)11 SuppressLint (android.annotation.SuppressLint)8 JSONArray (org.json.JSONArray)7 WebOSWebAppSession (com.connectsdk.service.sessions.WebOSWebAppSession)6 ChannelInfo (com.connectsdk.core.ChannelInfo)5 HttpConnection (com.connectsdk.etc.helper.HttpConnection)4 WebAppSession (com.connectsdk.service.sessions.WebAppSession)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 MediaInfo (com.connectsdk.core.MediaInfo)3 MediaPlayer (com.connectsdk.service.capability.MediaPlayer)3