use of com.connectsdk.service.capability.listeners.ResponseListener 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();
}
use of com.connectsdk.service.capability.listeners.ResponseListener 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();
}
use of com.connectsdk.service.capability.listeners.ResponseListener 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();
}
use of com.connectsdk.service.capability.listeners.ResponseListener 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;
}
use of com.connectsdk.service.capability.listeners.ResponseListener 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();
}
Aggregations