use of com.connectsdk.core.ChannelInfo in project butter-android by butterproject.
the class WebOSTVService method getCurrentChannel.
private ServiceCommand<ResponseListener<Object>> getCurrentChannel(boolean isSubscription, final ChannelListener listener) {
ServiceCommand<ResponseListener<Object>> request;
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
JSONObject jsonObj = (JSONObject) response;
ChannelInfo channel = parseRawChannelData(jsonObj);
Util.postSuccess(listener, channel);
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
if (isSubscription) {
request = new URLServiceSubscription<ResponseListener<Object>>(this, CHANNEL, null, true, responseListener);
} else
request = new ServiceCommand<ResponseListener<Object>>(this, CHANNEL, null, true, responseListener);
request.send();
return request;
}
use of com.connectsdk.core.ChannelInfo in project butter-android by butterproject.
the class WebOSTVService method parseRawProgramInfo.
private ProgramInfo parseRawProgramInfo(JSONObject programRawData) {
String programId;
String programName;
ProgramInfo programInfo = new ProgramInfo();
programInfo.setRawData(programRawData);
programId = programRawData.optString("programId");
programName = programRawData.optString("programName");
ChannelInfo channelInfo = parseRawChannelData(programRawData);
programInfo.setId(programId);
programInfo.setName(programName);
programInfo.setChannelInfo(channelInfo);
return programInfo;
}
use of com.connectsdk.core.ChannelInfo in project butter-android by butterproject.
the class WebOSTVService method parseRawChannelData.
private ChannelInfo parseRawChannelData(JSONObject channelRawData) {
String channelName = null;
String channelId = null;
String channelNumber = null;
int minorNumber;
int majorNumber;
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");
channelNumber = channelRawData.optString("channelNumber");
if (!channelRawData.isNull("majorNumber"))
majorNumber = (Integer) channelRawData.get("majorNumber");
else
majorNumber = parseMajorNumber(channelNumber);
if (!channelRawData.isNull("minorNumber"))
minorNumber = (Integer) channelRawData.get("minorNumber");
else
minorNumber = parseMinorNumber(channelNumber);
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 NetcastHttpServer method start.
public void start() {
// TODO: this method is too complex and should be refactored
if (running)
return;
running = true;
try {
welcomeSocket = new ServerSocket(this.port);
} catch (IOException ex) {
ex.printStackTrace();
}
while (running) {
if (welcomeSocket == null || welcomeSocket.isClosed()) {
stop();
break;
}
Socket connectionSocket = null;
BufferedReader inFromClient = null;
DataOutputStream outToClient = null;
try {
connectionSocket = welcomeSocket.accept();
} catch (IOException ex) {
ex.printStackTrace();
// this socket may have been closed, so we'll stop
stop();
return;
}
String str = null;
int c;
StringBuilder sb = new StringBuilder();
try {
inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
while ((str = inFromClient.readLine()) != null) {
if (str.equals("")) {
break;
}
}
while ((c = inFromClient.read()) != -1) {
sb.append((char) c);
String temp = sb.toString();
if (temp.endsWith("</envelope>"))
break;
}
} catch (IOException ex) {
ex.printStackTrace();
}
String body = sb.toString();
Log.d(Util.T, "got message body: " + body);
Calendar calendar = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
String date = dateFormat.format(calendar.getTime());
String androidOSVersion = android.os.Build.VERSION.RELEASE;
PrintWriter out = null;
try {
outToClient = new DataOutputStream(connectionSocket.getOutputStream());
out = new PrintWriter(outToClient);
out.println("HTTP/1.1 200 OK");
out.println("Server: Android/" + androidOSVersion + " UDAP/2.0 ConnectSDK/1.2.1");
out.println("Cache-Control: no-store, no-cache, must-revalidate");
out.println("Date: " + date);
out.println("Connection: Close");
out.println("Content-Length: 0");
out.println();
out.flush();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
inFromClient.close();
out.close();
outToClient.close();
connectionSocket.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
InputStream stream = null;
try {
stream = new ByteArrayInputStream(body.getBytes("UTF-8"));
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
}
NetcastPOSTRequestParser handler = new NetcastPOSTRequestParser();
SAXParser saxParser;
try {
saxParser = saxParserFactory.newSAXParser();
saxParser.parse(stream, handler);
} catch (IOException ex) {
ex.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
}
if (body.contains("ChannelChanged")) {
ChannelInfo channel = NetcastChannelParser.parseRawChannelData(handler.getJSONObject());
Log.d(Util.T, "Channel Changed: " + channel.getNumber());
for (URLServiceSubscription<?> sub : subscriptions) {
if (sub.getTarget().equalsIgnoreCase("ChannelChanged")) {
for (int i = 0; i < sub.getListeners().size(); i++) {
@SuppressWarnings("unchecked") ResponseListener<Object> listener = (ResponseListener<Object>) sub.getListeners().get(i);
Util.postSuccess(listener, channel);
}
}
}
} else if (body.contains("KeyboardVisible")) {
boolean focused = false;
TextInputStatusInfo keyboard = new TextInputStatusInfo();
keyboard.setRawData(handler.getJSONObject());
try {
JSONObject currentWidget = (JSONObject) handler.getJSONObject().get("currentWidget");
focused = (Boolean) currentWidget.get("focus");
keyboard.setFocused(focused);
} catch (JSONException e) {
e.printStackTrace();
}
Log.d(Util.T, "KeyboardFocused?: " + focused);
for (URLServiceSubscription<?> sub : subscriptions) {
if (sub.getTarget().equalsIgnoreCase("KeyboardVisible")) {
for (int i = 0; i < sub.getListeners().size(); i++) {
@SuppressWarnings("unchecked") ResponseListener<Object> listener = (ResponseListener<Object>) sub.getListeners().get(i);
Util.postSuccess(listener, keyboard);
}
}
}
} else if (body.contains("TextEdited")) {
System.out.println("TextEdited");
String newValue = "";
try {
newValue = handler.getJSONObject().getString("value");
} catch (JSONException ex) {
ex.printStackTrace();
}
Util.postSuccess(textChangedListener, newValue);
} else if (body.contains("3DMode")) {
try {
String enabled = (String) handler.getJSONObject().get("value");
boolean bEnabled;
bEnabled = enabled.equalsIgnoreCase("true");
for (URLServiceSubscription<?> sub : subscriptions) {
if (sub.getTarget().equalsIgnoreCase("3DMode")) {
for (int i = 0; i < sub.getListeners().size(); i++) {
@SuppressWarnings("unchecked") ResponseListener<Object> listener = (ResponseListener<Object>) sub.getListeners().get(i);
Util.postSuccess(listener, bEnabled);
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
Aggregations