use of com.connectsdk.service.capability.listeners.ResponseListener in project butter-android by butterproject.
the class NetcastTVService method connectMouse.
@Override
public void connectMouse() {
ResponseListener<Object> listener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
Log.d(Util.T, "Netcast TV's mouse has been connected");
mMouseDistance = new PointF(0, 0);
mMouseIsMoving = false;
}
@Override
public void onError(ServiceCommandError error) {
Log.w(Util.T, "Netcast TV's mouse connection has been failed");
}
};
setMouseCursorVisible(true, listener);
}
use of com.connectsdk.service.capability.listeners.ResponseListener in project butter-android by butterproject.
the class NetcastTVService method getApplications.
private void getApplications(int type, int number, final AppListListener listener) {
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
String strObj = (String) response;
JSONArray applicationArray = parseApplicationsXmlToJSON(strObj);
List<AppInfo> appList = new ArrayList<AppInfo>();
for (int i = 0; i < applicationArray.length(); i++) {
try {
final JSONObject appJSON = applicationArray.getJSONObject(i);
AppInfo appInfo = new AppInfo() {
{
setId(appJSON.getString("id"));
setName(appJSON.getString("title"));
}
};
appList.add(appInfo);
} catch (JSONException e) {
e.printStackTrace();
}
}
Util.postSuccess(listener, appList);
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
String requestURL = getUDAPRequestURL(UDAP_PATH_DATA, TARGET_APPLIST_GET, String.valueOf(type), "0", String.valueOf(number));
ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(this, requestURL, null, responseListener);
command.setHttpMethod(ServiceCommand.TYPE_GET);
command.send();
}
use of com.connectsdk.service.capability.listeners.ResponseListener in project butter-android by butterproject.
the class NetcastTVService method getChannelList.
@Override
public void getChannelList(final ChannelListListener listener) {
String requestURL = getUDAPRequestURL(UDAP_PATH_DATA, TARGET_CHANNEL_LIST);
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
String strObj = (String) response;
try {
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
InputStream stream = new ByteArrayInputStream(strObj.getBytes("UTF-8"));
SAXParser saxParser = saxParserFactory.newSAXParser();
NetcastChannelParser parser = new NetcastChannelParser();
saxParser.parse(stream, parser);
JSONArray channelArray = parser.getJSONChannelArray();
ArrayList<ChannelInfo> channelList = new ArrayList<ChannelInfo>();
for (int i = 0; i < channelArray.length(); i++) {
JSONObject rawData;
try {
rawData = (JSONObject) channelArray.get(i);
ChannelInfo channel = NetcastChannelParser.parseRawChannelData(rawData);
channelList.add(channel);
} catch (JSONException e) {
e.printStackTrace();
}
}
Util.postSuccess(listener, channelList);
} 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);
}
};
ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, requestURL, null, responseListener);
request.setHttpMethod(ServiceCommand.TYPE_GET);
request.send();
}
use of com.connectsdk.service.capability.listeners.ResponseListener 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.capability.listeners.ResponseListener 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();
}
Aggregations