Search in sources :

Example 51 with ResponseListener

use of com.connectsdk.service.capability.listeners.ResponseListener in project butter-android by butterproject.

the class NetcastTVService method launchAppStore.

@Override
public void launchAppStore(final String appId, final AppLaunchListener listener) {
    if (!serviceDescription.getModelNumber().equals("4.0")) {
        // TODO: this will not work in Korea, use Korean name instead
        launchApp("LG Smart World", listener);
        return;
    }
    String targetPath = getUDAPRequestURL(ROAP_PATH_APP_STORE);
    Map<String, String> params = new HashMap<String, String>();
    params.put("name", "SearchCMDPlaySDPContent");
    params.put("content_type", "4");
    params.put("conts_exec_type", "");
    params.put("conts_plex_type_flag", "");
    params.put("conts_search_id", "");
    params.put("conts_age", "12");
    params.put("exec_id", "");
    params.put("item_id", HttpMessage.encode(appId));
    params.put("app_type", "S");
    String httpMessage = getUDAPMessageBody(UDAP_API_COMMAND, params);
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            LaunchSession launchSession = LaunchSession.launchSessionForAppId(appId);
            // TODO: this will not work in Korea, use Korean name instead
            launchSession.setAppName("LG Smart World");
            launchSession.setService(NetcastTVService.this);
            launchSession.setSessionType(LaunchSessionType.App);
            Util.postSuccess(listener, launchSession);
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(this, targetPath, httpMessage, responseListener);
    command.send();
}
Also used : HashMap(java.util.HashMap) LaunchSession(com.connectsdk.service.sessions.LaunchSession) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 52 with ResponseListener

use of com.connectsdk.service.capability.listeners.ResponseListener in project butter-android by butterproject.

the class NetcastTVService method sendPairingKey.

@Override
public void sendPairingKey(final String pairingKey) {
    state = State.PAIRING;
    if (!(serviceConfig instanceof NetcastTVServiceConfig)) {
        serviceConfig = new NetcastTVServiceConfig(serviceConfig.getServiceUUID());
    }
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            state = State.PAIRED;
            ((NetcastTVServiceConfig) serviceConfig).setPairingKey(pairingKey);
            hConnectSuccess();
        }

        @Override
        public void onError(ServiceCommandError error) {
            state = State.INITIAL;
            if (listener != null)
                listener.onConnectionFailure(NetcastTVService.this, error);
        }
    };
    String requestURL = getUDAPRequestURL(UDAP_PATH_PAIRING);
    Map<String, String> params = new HashMap<String, String>();
    params.put("name", "hello");
    params.put("value", pairingKey);
    params.put("port", String.valueOf(serviceDescription.getPort()));
    String httpMessage = getUDAPMessageBody(UDAP_API_PAIRING, params);
    ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(this, requestURL, httpMessage, responseListener);
    command.send();
}
Also used : HashMap(java.util.HashMap) NetcastTVServiceConfig(com.connectsdk.service.config.NetcastTVServiceConfig) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 53 with ResponseListener

use of com.connectsdk.service.capability.listeners.ResponseListener in project butter-android by butterproject.

the class WebOSTVService method setMute.

@Override
public void setMute(boolean isMute, ResponseListener<Object> listener) {
    String uri = "ssap://audio/setMute";
    JSONObject payload = new JSONObject();
    try {
        payload.put("mute", isMute);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, uri, payload, true, listener);
    request.send();
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 54 with ResponseListener

use of com.connectsdk.service.capability.listeners.ResponseListener in project butter-android by butterproject.

the class WebOSTVService method getCurrentChannel.

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

        @Override
        public void onSuccess(Object response) {
            JSONObject jsonObj = (JSONObject) response;
            ChannelInfo channel = parseRawChannelData(jsonObj);
            Util.postSuccess(listener, channel);
        }

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

use of com.connectsdk.service.capability.listeners.ResponseListener 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)

Aggregations

ResponseListener (com.connectsdk.service.capability.listeners.ResponseListener)76 JSONObject (org.json.JSONObject)75 ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)65 ServiceCommand (com.connectsdk.service.command.ServiceCommand)64 JSONException (org.json.JSONException)54 URLServiceSubscription (com.connectsdk.service.command.URLServiceSubscription)14 SuppressLint (android.annotation.SuppressLint)10 LaunchSession (com.connectsdk.service.sessions.LaunchSession)9 IOException (java.io.IOException)9 JSONArray (org.json.JSONArray)7 AppInfo (com.connectsdk.core.AppInfo)6 ChannelInfo (com.connectsdk.core.ChannelInfo)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)3 HttpConnection (com.connectsdk.etc.helper.HttpConnection)3 InputStream (java.io.InputStream)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3