Search in sources :

Example 6 with AppInfo

use of com.connectsdk.core.AppInfo in project butter-android by butterproject.

the class WebOSTVService method getAppList.

@Override
public void getAppList(final AppListListener listener) {
    String uri = "ssap://com.webos.applicationManager/listApps";
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            try {
                JSONObject jsonObj = (JSONObject) response;
                JSONArray apps = (JSONArray) jsonObj.get("apps");
                List<AppInfo> appList = new ArrayList<AppInfo>();
                for (int i = 0; i < apps.length(); i++) {
                    final JSONObject appObj = apps.getJSONObject(i);
                    AppInfo appInfo = new AppInfo() {

                        {
                            setId(appObj.getString("id"));
                            setName(appObj.getString("title"));
                            setRawData(appObj);
                        }
                    };
                    appList.add(appInfo);
                }
                Util.postSuccess(listener, appList);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, uri, null, true, responseListener);
    request.send();
}
Also used : JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) SuppressLint(android.annotation.SuppressLint) AppInfo(com.connectsdk.core.AppInfo) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 7 with AppInfo

use of com.connectsdk.core.AppInfo in project butter-android by butterproject.

the class RokuService method launchApp.

@Override
public void launchApp(String appId, AppLaunchListener listener) {
    if (appId == null) {
        Util.postError(listener, new ServiceCommandError(0, "Must supply a valid app id", null));
        return;
    }
    AppInfo appInfo = new AppInfo();
    appInfo.setId(appId);
    launchAppWithInfo(appInfo, listener);
}
Also used : ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) AppInfo(com.connectsdk.core.AppInfo)

Example 8 with AppInfo

use of com.connectsdk.core.AppInfo in project butter-android by butterproject.

the class NetcastTVService method getApplication.

public void getApplication(final String appName, final AppInfoListener listener) {
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            final String strObj = (String) response;
            AppInfo appId = new AppInfo() {

                {
                    setId(decToHex(strObj));
                }
            };
            Util.postSuccess(listener, appId);
        }

        @Override
        public void onError(ServiceCommandError error) {
            if (listener != null)
                Util.postError(listener, error);
        }
    };
    String uri = UDAP_PATH_APPTOAPP_DATA + appName;
    String requestURL = getUDAPRequestURL(uri);
    ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(this, requestURL, null, responseListener);
    command.setHttpMethod(ServiceCommand.TYPE_GET);
    command.send();
}
Also used : 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 9 with AppInfo

use of com.connectsdk.core.AppInfo in project butter-android by butterproject.

the class NetcastTVService method launchNetflix.

@Override
public void launchNetflix(final String contentId, final Launcher.AppLaunchListener listener) {
    if (!serviceDescription.getModelNumber().equals("4.0")) {
        launchApp("Netflix", listener);
        return;
    }
    final String appName = "Netflix";
    getApplication(appName, new AppInfoListener() {

        @Override
        public void onSuccess(final AppInfo appInfo) {
            JSONObject jsonObj = new JSONObject();
            try {
                jsonObj.put("id", appInfo.getId());
                jsonObj.put("name", appName);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            ResponseListener<Object> responseListener = new ResponseListener<Object>() {

                @Override
                public void onSuccess(Object response) {
                    LaunchSession launchSession = LaunchSession.launchSessionForAppId(appInfo.getId());
                    launchSession.setAppName(appName);
                    launchSession.setService(NetcastTVService.this);
                    launchSession.setSessionType(LaunchSessionType.App);
                    Util.postSuccess(listener, launchSession);
                }

                @Override
                public void onError(ServiceCommandError error) {
                    Util.postError(listener, error);
                }
            };
            String requestURL = getUDAPRequestURL(UDAP_PATH_APPTOAPP_COMMAND);
            Map<String, String> params = new HashMap<String, String>();
            params.put("name", "SearchCMDPlaySDPContent");
            params.put("content_type", "1");
            params.put("conts_exec_type", "20");
            params.put("conts_plex_type_flag", "N");
            params.put("conts_search_id", "2023237");
            params.put("conts_age", "18");
            params.put("exec_id", "netflix");
            params.put("item_id", "-Q m=http%3A%2F%2Fapi.netflix.com%2Fcatalog%2Ftitles%2Fmovies%2F" + contentId + "&amp;source_type=4&amp;trackId=6054700&amp;trackUrl=https%3A%2F%2Fapi.netflix.com%2FAPI_APP_ID_6261%3F%23Search%3F");
            params.put("app_type", "");
            String httpMessage = getUDAPMessageBody(UDAP_API_COMMAND, params);
            ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(NetcastTVService.this, requestURL, httpMessage, responseListener);
            request.send();
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    });
}
Also used : LaunchSession(com.connectsdk.service.sessions.LaunchSession) JSONException(org.json.JSONException) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) AppInfo(com.connectsdk.core.AppInfo) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) Map(java.util.Map) HashMap(java.util.HashMap) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 10 with AppInfo

use of com.connectsdk.core.AppInfo 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)

Aggregations

AppInfo (com.connectsdk.core.AppInfo)17 JSONObject (org.json.JSONObject)12 ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)11 JSONException (org.json.JSONException)9 ResponseListener (com.connectsdk.service.capability.listeners.ResponseListener)6 ServiceCommand (com.connectsdk.service.command.ServiceCommand)6 LaunchSession (com.connectsdk.service.sessions.LaunchSession)2 ArrayList (java.util.ArrayList)2 JSONArray (org.json.JSONArray)2 SuppressLint (android.annotation.SuppressLint)1 URLServiceSubscription (com.connectsdk.service.command.URLServiceSubscription)1 RokuApplicationListParser (com.connectsdk.service.roku.RokuApplicationListParser)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXParser (javax.xml.parsers.SAXParser)1