Search in sources :

Example 11 with AppInfo

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

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

the class WebOSTVService method launchApp.

@Override
public void launchApp(String appId, AppLaunchListener listener) {
    AppInfo appInfo = new AppInfo();
    appInfo.setId(appId);
    launchAppWithInfo(appInfo, listener);
}
Also used : AppInfo(com.connectsdk.core.AppInfo)

Example 13 with AppInfo

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

the class RokuService method getAppList.

@Override
public void getAppList(final AppListListener listener) {
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            String msg = (String) response;
            SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
            InputStream stream;
            try {
                stream = new ByteArrayInputStream(msg.getBytes("UTF-8"));
                SAXParser saxParser = saxParserFactory.newSAXParser();
                RokuApplicationListParser parser = new RokuApplicationListParser();
                saxParser.parse(stream, parser);
                List<AppInfo> appList = parser.getApplicationList();
                Util.postSuccess(listener, appList);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (ParserConfigurationException e) {
                e.printStackTrace();
            } catch (SAXException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    String action = "query";
    String param = "apps";
    String uri = requestURL(action, param);
    ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, uri, null, responseListener);
    request.setHttpMethod(ServiceCommand.TYPE_GET);
    request.send();
}
Also used : RokuApplicationListParser(com.connectsdk.service.roku.RokuApplicationListParser) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) IOException(java.io.IOException) AppInfo(com.connectsdk.core.AppInfo) SAXException(org.xml.sax.SAXException) ByteArrayInputStream(java.io.ByteArrayInputStream) SAXParser(javax.xml.parsers.SAXParser) JSONObject(org.json.JSONObject) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ServiceCommand(com.connectsdk.service.command.ServiceCommand) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 14 with AppInfo

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

the class RokuService method launchAppStore.

@Override
public void launchAppStore(final String appId, AppLaunchListener listener) {
    AppInfo appInfo = new AppInfo("11");
    appInfo.setName("Channel Store");
    JSONObject params = null;
    try {
        params = new JSONObject() {

            {
                put("contentId", appId);
            }
        };
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    launchAppWithInfo(appInfo, params, listener);
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) AppInfo(com.connectsdk.core.AppInfo)

Example 15 with AppInfo

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

the class DIALService method launchYouTube.

@Override
public void launchYouTube(String contentId, float startTime, AppLaunchListener listener) {
    String params = null;
    AppInfo appInfo = new AppInfo("YouTube");
    appInfo.setName(appInfo.getId());
    if (contentId != null && contentId.length() > 0) {
        if (startTime < 0.0) {
            if (listener != null) {
                listener.onError(new ServiceCommandError(0, "Start time may not be negative", null));
            }
            return;
        }
        String pairingCode = java.util.UUID.randomUUID().toString();
        params = String.format(Locale.US, "pairingCode=%s&v=%s&t=%.1f", pairingCode, contentId, startTime);
    }
    launchAppWithInfo(appInfo, params, listener);
}
Also used : 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