Search in sources :

Example 16 with ResponseListener

use of com.connectsdk.service.capability.listeners.ResponseListener 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 17 with ResponseListener

use of com.connectsdk.service.capability.listeners.ResponseListener 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 18 with ResponseListener

use of com.connectsdk.service.capability.listeners.ResponseListener 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 19 with ResponseListener

use of com.connectsdk.service.capability.listeners.ResponseListener 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 20 with ResponseListener

use of com.connectsdk.service.capability.listeners.ResponseListener 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)76 JSONObject (org.json.JSONObject)75 ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)65 ServiceCommand (com.connectsdk.service.command.ServiceCommand)64 JSONException (org.json.JSONException)54 URLServiceSubscription (com.connectsdk.service.command.URLServiceSubscription)14 SuppressLint (android.annotation.SuppressLint)10 LaunchSession (com.connectsdk.service.sessions.LaunchSession)9 IOException (java.io.IOException)9 JSONArray (org.json.JSONArray)7 AppInfo (com.connectsdk.core.AppInfo)6 ChannelInfo (com.connectsdk.core.ChannelInfo)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)3 HttpConnection (com.connectsdk.etc.helper.HttpConnection)3 InputStream (java.io.InputStream)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3