use of com.connectsdk.service.command.ServiceCommand in project butter-android by butterproject.
the class WebOSWebAppSession method handleMediaCommandResponse.
@SuppressWarnings("unchecked")
public void handleMediaCommandResponse(final JSONObject payload) {
String requestID = payload.optString("requestId");
if (requestID.length() == 0)
return;
final ServiceCommand<ResponseListener<Object>> command = (ServiceCommand<ResponseListener<Object>>) mActiveCommands.get(requestID);
if (command == null)
return;
String mError = payload.optString("error");
if (mError.length() != 0) {
Util.postError(command.getResponseListener(), new ServiceCommandError(0, mError, null));
} else {
Util.postSuccess(command.getResponseListener(), payload);
}
mActiveCommands.remove(requestID);
}
use of com.connectsdk.service.command.ServiceCommand in project butter-android by butterproject.
the class WebOSWebAppSession method getDuration.
@Override
public void getDuration(final DurationListener listener) {
int requestIdNumber = getNextId();
final String requestId = String.format(Locale.US, "req%d", requestIdNumber);
JSONObject message = null;
try {
message = new JSONObject() {
{
put("contentType", namespaceKey + "mediaCommand");
put("mediaCommand", new JSONObject() {
{
put("type", "getDuration");
put("requestId", requestId);
}
});
}
};
} catch (JSONException e) {
Util.postError(listener, new ServiceCommandError(0, "JSON Parse error", null));
}
ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(null, null, null, new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
try {
long position = ((JSONObject) response).getLong("duration");
Util.postSuccess(listener, position * 1000);
} catch (JSONException e) {
Util.postError(listener, new ServiceCommandError(0, "JSON Parse error", null));
}
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
});
mActiveCommands.put(requestId, command);
sendMessage(message, new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
});
}
use of com.connectsdk.service.command.ServiceCommand in project butter-android by butterproject.
the class WebOSWebAppSession method getPlayState.
@Override
public void getPlayState(final PlayStateListener listener) {
int requestIdNumber = getNextId();
final String requestId = String.format(Locale.US, "req%d", requestIdNumber);
JSONObject message = null;
try {
message = new JSONObject() {
{
put("contentType", namespaceKey + "mediaCommand");
put("mediaCommand", new JSONObject() {
{
put("type", "getPlayState");
put("requestId", requestId);
}
});
}
};
} catch (JSONException e) {
Util.postError(listener, new ServiceCommandError(0, "JSON Parse error", null));
}
ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(null, null, null, new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
try {
String playStateString = ((JSONObject) response).getString("playState");
PlayStateStatus playState = parsePlayState(playStateString);
Util.postSuccess(listener, playState);
} catch (JSONException e) {
this.onError(new ServiceCommandError(0, "JSON Parse error", null));
}
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
});
mActiveCommands.put(requestId, command);
sendMessage(message, new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
});
}
use of com.connectsdk.service.command.ServiceCommand in project butter-android by butterproject.
the class RokuService method getAppList.
@Override
public void getAppList(final AppListListener listener) {
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
String msg = (String) response;
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
InputStream stream;
try {
stream = new ByteArrayInputStream(msg.getBytes("UTF-8"));
SAXParser saxParser = saxParserFactory.newSAXParser();
RokuApplicationListParser parser = new RokuApplicationListParser();
saxParser.parse(stream, parser);
List<AppInfo> appList = parser.getApplicationList();
Util.postSuccess(listener, appList);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
String action = "query";
String param = "apps";
String uri = requestURL(action, param);
ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, uri, null, responseListener);
request.setHttpMethod(ServiceCommand.TYPE_GET);
request.send();
}
Aggregations