use of com.connectsdk.core.TextInputStatusInfo in project butter-android by butterproject.
the class WebOSTVKeyboardInput method connect.
public URLServiceSubscription<TextInputStatusListener> connect(final TextInputStatusListener listener) {
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
JSONObject jsonObj = (JSONObject) response;
TextInputStatusInfo keyboard = parseRawKeyboardData(jsonObj);
Util.postSuccess(listener, keyboard);
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
URLServiceSubscription<TextInputStatusListener> subscription = new URLServiceSubscription<TextInputStatusListener>(service, KEYBOARD_INPUT, null, true, responseListener);
subscription.send();
return subscription;
}
use of com.connectsdk.core.TextInputStatusInfo in project butter-android by butterproject.
the class WebOSTVKeyboardInput method parseRawKeyboardData.
private TextInputStatusInfo parseRawKeyboardData(JSONObject rawData) {
boolean focused = false;
String contentType = null;
boolean predictionEnabled = false;
boolean correctionEnabled = false;
boolean autoCapitalization = false;
boolean hiddenText = false;
boolean focusChanged = false;
TextInputStatusInfo keyboard = new TextInputStatusInfo();
keyboard.setRawData(rawData);
try {
if (rawData.has("currentWidget")) {
JSONObject currentWidget = (JSONObject) rawData.get("currentWidget");
focused = (Boolean) currentWidget.get("focus");
if (currentWidget.has("contentType")) {
contentType = (String) currentWidget.get("contentType");
}
if (currentWidget.has("predictionEnabled")) {
predictionEnabled = (Boolean) currentWidget.get("predictionEnabled");
}
if (currentWidget.has("correctionEnabled")) {
correctionEnabled = (Boolean) currentWidget.get("correctionEnabled");
}
if (currentWidget.has("autoCapitalization")) {
autoCapitalization = (Boolean) currentWidget.get("autoCapitalization");
}
if (currentWidget.has("hiddenText")) {
hiddenText = (Boolean) currentWidget.get("hiddenText");
}
}
if (rawData.has("focusChanged"))
focusChanged = (Boolean) rawData.get("focusChanged");
} catch (JSONException e) {
e.printStackTrace();
}
keyboard.setFocused(focused);
keyboard.setContentType(contentType);
keyboard.setPredictionEnabled(predictionEnabled);
keyboard.setCorrectionEnabled(correctionEnabled);
keyboard.setAutoCapitalization(autoCapitalization);
keyboard.setHiddenText(hiddenText);
keyboard.setFocusChanged(focusChanged);
return keyboard;
}
use of com.connectsdk.core.TextInputStatusInfo 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