use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.
the class NetcastTVService method sendCommand.
@Override
public void sendCommand(final ServiceCommand<?> mCommand) {
Util.runInBackground(new Runnable() {
@SuppressWarnings("unchecked")
@Override
public void run() {
final ServiceCommand<ResponseListener<Object>> command = (ServiceCommand<ResponseListener<Object>>) mCommand;
Object payload = command.getPayload();
try {
HttpConnection connection = HttpConnection.newInstance(URI.create(command.getTarget()));
connection.setHeader(HttpMessage.USER_AGENT, HttpMessage.UDAP_USER_AGENT);
connection.setHeader(HttpMessage.CONTENT_TYPE_HEADER, HttpMessage.CONTENT_TYPE_TEXT_XML);
if (payload != null && command.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_POST)) {
connection.setMethod(HttpConnection.Method.POST);
connection.setPayload(payload.toString());
}
connection.execute();
int code = connection.getResponseCode();
Log.d("", "RESP " + code);
if (code == 200) {
Util.postSuccess(command.getResponseListener(), connection.getResponseString());
} else {
Util.postError(command.getResponseListener(), ServiceCommandError.getError(code));
}
} catch (IOException e) {
e.printStackTrace();
Util.postError(command.getResponseListener(), new ServiceCommandError(0, e.getMessage(), null));
}
}
});
}
use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.
the class NetcastTVService method getVolumeStatus.
private void getVolumeStatus(final VolumeStatusListener listener) {
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
String strObj = (String) response;
JSONObject volumeStatus = parseVolumeXmlToJSON(strObj);
try {
boolean isMute = (Boolean) volumeStatus.get("mute");
int volume = (Integer) volumeStatus.get("level");
Util.postSuccess(listener, new VolumeStatus(isMute, volume));
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
String requestURL = getUDAPRequestURL(UDAP_PATH_DATA, TARGET_VOLUME_INFO);
ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, requestURL, null, responseListener);
request.setHttpMethod(ServiceCommand.TYPE_GET);
request.send();
}
use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.
the class WebOSTVService method launchInputPicker.
@Override
public void launchInputPicker(final AppLaunchListener listener) {
final AppInfo appInfo = new AppInfo() {
{
setId("com.webos.app.inputpicker");
setName("InputPicker");
}
};
launchAppWithInfo(appInfo, null, new AppLaunchListener() {
@Override
public void onSuccess(LaunchSession object) {
listener.onSuccess(object);
}
@Override
public void onError(ServiceCommandError error) {
appInfo.setId("com.webos.app.inputmgr");
launchAppWithInfo(appInfo, null, listener);
}
});
}
use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.
the class WebOSTVService method getChannelList.
private ServiceCommand<ResponseListener<Object>> getChannelList(boolean isSubscription, final ChannelListListener listener) {
ServiceCommand<ResponseListener<Object>> request;
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
try {
JSONObject jsonObj = (JSONObject) response;
ArrayList<ChannelInfo> list = new ArrayList<ChannelInfo>();
JSONArray array = (JSONArray) jsonObj.get("channelList");
for (int i = 0; i < array.length(); i++) {
JSONObject object = (JSONObject) array.get(i);
ChannelInfo channel = parseRawChannelData(object);
list.add(channel);
}
Util.postSuccess(listener, list);
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
if (isSubscription)
request = new URLServiceSubscription<ResponseListener<Object>>(this, CHANNEL_LIST, null, true, responseListener);
else
request = new ServiceCommand<ResponseListener<Object>>(this, CHANNEL_LIST, null, true, responseListener);
request.send();
return request;
}
use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.
the class WebOSTVService method pinWebApp.
@Override
public void pinWebApp(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/pinWebApp";
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