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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations