Search in sources :

Example 21 with ServiceCommand

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

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

the class WebOSTVService method launchBrowser.

@Override
public void launchBrowser(String url, final Launcher.AppLaunchListener listener) {
    String uri = "ssap://system.launcher/open";
    JSONObject payload = new JSONObject();
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            JSONObject obj = (JSONObject) response;
            LaunchSession launchSession = new LaunchSession();
            launchSession.setService(WebOSTVService.this);
            // note that response uses id to mean appId
            launchSession.setAppId(obj.optString("id"));
            launchSession.setSessionId(obj.optString("sessionId"));
            launchSession.setSessionType(LaunchSessionType.App);
            launchSession.setRawData(obj);
            Util.postSuccess(listener, launchSession);
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    try {
        payload.put("target", url);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, uri, payload, true, responseListener);
    request.send();
}
Also used : JSONObject(org.json.JSONObject) LaunchSession(com.connectsdk.service.sessions.LaunchSession) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 23 with ServiceCommand

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

the class WebOSTVService method getACRAuthToken.

public void getACRAuthToken(final ACRAuthTokenListener listener) {
    String uri = "ssap://tv/getACRAuthToken";
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            try {
                JSONObject jsonObj = (JSONObject) response;
                String authToken = (String) jsonObj.get("token");
                Util.postSuccess(listener, authToken);
            } 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 : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 24 with ServiceCommand

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

the class WebOSTVService method getVolume.

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

        @Override
        public void onSuccess(Object response) {
            try {
                JSONObject jsonObj = (JSONObject) response;
                int iVolume = (Integer) jsonObj.get("volume");
                float fVolume = (float) (iVolume / 100.0);
                Util.postSuccess(listener, fVolume);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    if (isSubscription)
        request = new URLServiceSubscription<VolumeListener>(this, VOLUME, null, true, responseListener);
    else
        request = new ServiceCommand<VolumeListener>(this, VOLUME, 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)

Example 25 with ServiceCommand

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

the class WebOSTVService method setExternalInput.

@Override
public void setExternalInput(ExternalInputInfo externalInputInfo, final ResponseListener<Object> listener) {
    String uri = "ssap://tv/switchInput";
    JSONObject payload = new JSONObject();
    try {
        if (externalInputInfo != null && externalInputInfo.getId() != null) {
            payload.put("inputId", externalInputInfo.getId());
        } else {
            Log.w(Util.T, "ExternalInputInfo has no id");
        }
    } 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)

Aggregations

ResponseListener (com.connectsdk.service.capability.listeners.ResponseListener)64 ServiceCommand (com.connectsdk.service.command.ServiceCommand)64 JSONObject (org.json.JSONObject)64 ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)55 JSONException (org.json.JSONException)47 SuppressLint (android.annotation.SuppressLint)9 URLServiceSubscription (com.connectsdk.service.command.URLServiceSubscription)9 LaunchSession (com.connectsdk.service.sessions.LaunchSession)9 JSONArray (org.json.JSONArray)8 IOException (java.io.IOException)7 AppInfo (com.connectsdk.core.AppInfo)6 ChannelInfo (com.connectsdk.core.ChannelInfo)5 HashMap (java.util.HashMap)5 ArrayList (java.util.ArrayList)4 HttpConnection (com.connectsdk.etc.helper.HttpConnection)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Context (android.content.Context)2 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)2