Search in sources :

Example 11 with ServiceCommand

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

the class WebOSTVService method getExternalInputList.

@Override
public void getExternalInputList(final ExternalInputListListener listener) {
    String uri = "ssap://tv/getExternalInputList";
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            try {
                JSONObject jsonObj = (JSONObject) response;
                JSONArray devices = (JSONArray) jsonObj.get("devices");
                Util.postSuccess(listener, externalnputInfoFromJSONArray(devices));
            } 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) JSONArray(org.json.JSONArray) 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 12 with ServiceCommand

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

the class WebOSTVService method closeApp.

@Override
public void closeApp(LaunchSession launchSession, ResponseListener<Object> listener) {
    String uri = "ssap://system.launcher/close";
    String appId = launchSession.getAppId();
    String sessionId = launchSession.getSessionId();
    JSONObject payload = new JSONObject();
    try {
        payload.put("id", appId);
        payload.put("sessionId", sessionId);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(launchSession.getService(), 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 13 with ServiceCommand

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

the class WebOSTVService method closeWebApp.

@Override
public void closeWebApp(LaunchSession launchSession, final ResponseListener<Object> listener) {
    if (launchSession == null || launchSession.getAppId() == null || launchSession.getAppId().length() == 0) {
        Util.postError(listener, new ServiceCommandError(0, "Must provide a valid launch session", null));
        return;
    }
    final WebOSWebAppSession webAppSession = mWebAppSessions.get(launchSession.getAppId());
    if (webAppSession != null) {
        webAppSession.disconnectFromWebApp();
    }
    String uri = "ssap://webapp/closeWebApp";
    JSONObject payload = new JSONObject();
    try {
        if (launchSession.getAppId() != null)
            payload.put("webAppId", launchSession.getAppId());
        if (launchSession.getSessionId() != null)
            payload.put("sessionId", launchSession.getSessionId());
    } 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) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) JSONObject(org.json.JSONObject) WebOSWebAppSession(com.connectsdk.service.sessions.WebOSWebAppSession) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 14 with ServiceCommand

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

the class WebOSTVService method secureAccessTest.

public void secureAccessTest(final SecureAccessTestListener listener) {
    String uri = "ssap://com.webos.service.secondscreen.gateway/test/secure";
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            try {
                JSONObject jsonObj = (JSONObject) response;
                boolean isSecure = (Boolean) jsonObj.get("returnValue");
                Util.postSuccess(listener, isSecure);
            } 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 15 with ServiceCommand

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

the class WebOSTVService method sendToast.

private void sendToast(JSONObject payload, ResponseListener<Object> listener) {
    if (!payload.has("iconData")) {
        Context context = DiscoveryManager.getInstance().getContext();
        try {
            Drawable drawable = context.getPackageManager().getApplicationIcon(context.getPackageName());
            if (drawable != null) {
                BitmapDrawable bitDw = ((BitmapDrawable) drawable);
                Bitmap bitmap = bitDw.getBitmap();
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                byte[] bitmapByte = stream.toByteArray();
                bitmapByte = Base64.encode(bitmapByte, Base64.NO_WRAP);
                String bitmapData = new String(bitmapByte);
                payload.put("iconData", bitmapData);
                payload.put("iconExtension", "png");
            }
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    String uri = "palm://system.notifications/createToast";
    ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, uri, payload, true, listener);
    request.send();
}
Also used : Context(android.content.Context) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) JSONException(org.json.JSONException) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) Bitmap(android.graphics.Bitmap) JSONObject(org.json.JSONObject) 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