use of com.connectsdk.service.capability.listeners.ResponseListener in project butter-android by butterproject.
the class WebOSTVService method get3DEnabled.
private ServiceCommand<State3DModeListener> get3DEnabled(boolean isSubscription, final State3DModeListener listener) {
String uri = "ssap://com.webos.service.tv.display/get3DStatus";
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
JSONObject jsonObj = (JSONObject) response;
JSONObject status;
try {
status = jsonObj.getJSONObject("status3D");
boolean isEnabled = status.getBoolean("status");
Util.postSuccess(listener, isEnabled);
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
ServiceCommand<State3DModeListener> request;
if (isSubscription)
request = new URLServiceSubscription<State3DModeListener>(this, uri, null, true, responseListener);
else
request = new ServiceCommand<State3DModeListener>(this, uri, 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 setChannelById.
public void setChannelById(String channelId, ResponseListener<Object> listener) {
String uri = "ssap://tv/openChannel";
JSONObject payload = new JSONObject();
try {
payload.put("channelId", channelId);
} 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.capability.listeners.ResponseListener in project butter-android by butterproject.
the class WebOSTVService method launchWebApp.
public void launchWebApp(final String webAppId, final JSONObject params, final WebAppSession.LaunchListener listener) {
if (webAppId == null || webAppId.length() == 0) {
Util.postError(listener, new ServiceCommandError(-1, "You need to provide a valid webAppId.", null));
return;
}
final WebOSWebAppSession _webAppSession = mWebAppSessions.get(webAppId);
String uri = "ssap://webapp/launchWebApp";
JSONObject payload = new JSONObject();
try {
payload.put("webAppId", webAppId);
if (params != null)
payload.put("urlParams", params);
} catch (JSONException e) {
e.printStackTrace();
}
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(final Object response) {
JSONObject obj = (JSONObject) response;
LaunchSession launchSession = null;
WebOSWebAppSession webAppSession = _webAppSession;
if (webAppSession != null)
launchSession = webAppSession.launchSession;
else {
launchSession = LaunchSession.launchSessionForAppId(webAppId);
webAppSession = new WebOSWebAppSession(launchSession, WebOSTVService.this);
mWebAppSessions.put(webAppId, webAppSession);
}
launchSession.setService(WebOSTVService.this);
launchSession.setSessionId(obj.optString("sessionId"));
launchSession.setSessionType(LaunchSessionType.WebApp);
launchSession.setRawData(obj);
Util.postSuccess(listener, webAppSession);
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
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 getAppState.
private ServiceCommand<AppStateListener> getAppState(boolean subscription, LaunchSession launchSession, final AppStateListener listener) {
ServiceCommand<AppStateListener> request;
JSONObject params = new JSONObject();
try {
params.put("id", launchSession.getAppId());
params.put("sessionId", launchSession.getSessionId());
} catch (JSONException e) {
e.printStackTrace();
}
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
@Override
public void onSuccess(Object object) {
JSONObject json = (JSONObject) object;
try {
Util.postSuccess(listener, new AppState(json.getBoolean("running"), json.getBoolean("visible")));
} catch (JSONException e) {
Util.postError(listener, new ServiceCommandError(0, "Malformed JSONObject", null));
e.printStackTrace();
}
}
};
if (subscription) {
request = new URLServiceSubscription<Launcher.AppStateListener>(this, APP_STATE, params, true, responseListener);
} else {
request = new ServiceCommand<Launcher.AppStateListener>(this, APP_STATE, params, true, responseListener);
}
request.send();
return request;
}
use of com.connectsdk.service.capability.listeners.ResponseListener in project butter-android by butterproject.
the class WebOSTVService method unPinWebApp.
@Override
public void unPinWebApp(String webAppId, final ResponseListener<Object> listener) {
if (webAppId == null || webAppId.length() == 0) {
if (listener != null) {
listener.onError(new ServiceCommandError(-1, "You must provide a valid web app id", null));
}
return;
}
String uri = "ssap://webapp/removePinnedWebApp";
JSONObject payload = new JSONObject();
try {
payload.put("webAppId", webAppId);
} catch (JSONException e) {
e.printStackTrace();
}
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(final Object response) {
JSONObject obj = (JSONObject) response;
if (obj.has("pairingType")) {
notifyPairingRequired();
} else if (listener != null) {
listener.onSuccess(response);
}
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
ServiceCommand<ResponseListener<Object>> request = new URLServiceSubscription<ResponseListener<Object>>(this, uri, payload, true, responseListener);
request.send();
}
Aggregations