use of com.connectsdk.core.ChannelInfo 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.core.ChannelInfo 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.core.ChannelInfo in project butter-android by butterproject.
the class WebOSTVService method getProgramList.
private ServiceCommand<ResponseListener<Object>> getProgramList(boolean isSubscription, final ProgramListListener listener) {
ServiceCommand<ResponseListener<Object>> request;
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
try {
JSONObject jsonObj = (JSONObject) response;
JSONObject jsonChannel = (JSONObject) jsonObj.get("channel");
ChannelInfo channel = parseRawChannelData(jsonChannel);
JSONArray programList = (JSONArray) jsonObj.get("programList");
Util.postSuccess(listener, new ProgramList(channel, programList));
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
if (isSubscription)
request = new URLServiceSubscription<ResponseListener<Object>>(this, PROGRAM, null, true, responseListener);
else
request = new ServiceCommand<ResponseListener<Object>>(this, PROGRAM, null, true, responseListener);
request.send();
return request;
}
use of com.connectsdk.core.ChannelInfo in project butter-android by butterproject.
the class NetcastChannelParser method parseRawChannelData.
public static ChannelInfo parseRawChannelData(JSONObject channelRawData) {
String channelName = null;
String channelId = null;
String channelNumber = null;
int minorNumber = 0;
int majorNumber = 0;
ChannelInfo channelInfo = new ChannelInfo();
channelInfo.setRawData(channelRawData);
try {
if (!channelRawData.isNull("channelName"))
channelName = (String) channelRawData.get("channelName");
if (!channelRawData.isNull("channelId"))
channelId = (String) channelRawData.get("channelId");
if (!channelRawData.isNull("majorNumber"))
majorNumber = (Integer) channelRawData.get("majorNumber");
if (!channelRawData.isNull("minorNumber"))
minorNumber = (Integer) channelRawData.get("minorNumber");
if (!channelRawData.isNull("channelNumber"))
channelNumber = (String) channelRawData.get("channelNumber");
else {
channelNumber = String.format(String.valueOf(majorNumber) + "-" + String.valueOf(minorNumber));
}
channelInfo.setName(channelName);
channelInfo.setId(channelId);
channelInfo.setNumber(channelNumber);
channelInfo.setMajorNumber(majorNumber);
channelInfo.setMinorNumber(minorNumber);
} catch (JSONException e) {
e.printStackTrace();
}
return channelInfo;
}
use of com.connectsdk.core.ChannelInfo in project butter-android by butterproject.
the class NetcastTVService method getCurrentChannel.
@Override
public void getCurrentChannel(final ChannelListener listener) {
String requestURL = getUDAPRequestURL(UDAP_PATH_DATA, TARGET_CURRENT_CHANNEL);
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();
if (channelArray.length() > 0) {
JSONObject rawData = (JSONObject) channelArray.get(0);
ChannelInfo channel = NetcastChannelParser.parseRawChannelData(rawData);
Util.postSuccess(listener, channel);
}
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException 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.send();
}
Aggregations