Search in sources :

Example 1 with TextInputStatusInfo

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;
}
Also used : JSONObject(org.json.JSONObject) URLServiceSubscription(com.connectsdk.service.command.URLServiceSubscription) TextInputStatusListener(com.connectsdk.service.capability.TextInputControl.TextInputStatusListener) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) TextInputStatusInfo(com.connectsdk.core.TextInputStatusInfo)

Example 2 with TextInputStatusInfo

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;
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) TextInputStatusInfo(com.connectsdk.core.TextInputStatusInfo)

Example 3 with TextInputStatusInfo

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();
            }
        }
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) ChannelInfo(com.connectsdk.core.ChannelInfo) SAXException(org.xml.sax.SAXException) URLServiceSubscription(com.connectsdk.service.command.URLServiceSubscription) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TextInputStatusInfo(com.connectsdk.core.TextInputStatusInfo) PrintWriter(java.io.PrintWriter) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Calendar(java.util.Calendar) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JSONException(org.json.JSONException) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) JSONObject(org.json.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedReader(java.io.BufferedReader) JSONObject(org.json.JSONObject) SimpleDateFormat(java.text.SimpleDateFormat) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

TextInputStatusInfo (com.connectsdk.core.TextInputStatusInfo)3 JSONObject (org.json.JSONObject)3 ResponseListener (com.connectsdk.service.capability.listeners.ResponseListener)2 URLServiceSubscription (com.connectsdk.service.command.URLServiceSubscription)2 JSONException (org.json.JSONException)2 ChannelInfo (com.connectsdk.core.ChannelInfo)1 TextInputStatusListener (com.connectsdk.service.capability.TextInputControl.TextInputStatusListener)1 ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1