Search in sources :

Example 56 with ServiceCommandError

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

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

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

the class WebOSTVService method launchYouTube.

@Override
public void launchYouTube(final String contentId, float startTime, final AppLaunchListener listener) {
    JSONObject params = new JSONObject();
    if (contentId != null && contentId.length() > 0) {
        if (startTime < 0.0) {
            Util.postError(listener, new ServiceCommandError(0, "Start time may not be negative", null));
            return;
        }
        try {
            params.put("contentId", String.format("%s&pairingCode=%s&t=%.1f", contentId, UUID.randomUUID().toString(), startTime));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    AppInfo appInfo = new AppInfo() {

        {
            setId("youtube.leanback.v4");
            setName("YouTube");
        }
    };
    launchAppWithInfo(appInfo, params, listener);
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) AppInfo(com.connectsdk.core.AppInfo)

Example 59 with ServiceCommandError

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

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

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