Search in sources :

Example 1 with StringCallback

use of com.gwtmobile.phonegap.client.plugins.Bluetooth.StringCallback in project GwtMobile by dennisjzh.

the class BluetoothUi method listDevices.

public void listDevices() {
    Bluetooth.listDevices(new StringCallback() {

        @Override
        public void onSuccess(String result) {
            try {
                String textHTML = "";
                JSONValue value = JSONParser.parseLenient(result);
                JSONArray devicesArray = value.isArray();
                if (devicesArray != null) {
                    textHTML = "Result:";
                    for (int i = 0; i < devicesArray.size(); i++) {
                        JSONObject deviceObj = devicesArray.get(i).isObject();
                        textHTML = textHTML + "<br/>" + deviceObj.get("name");
                    }
                    text.setHTML(textHTML);
                }
            } catch (Exception e) {
                e.printStackTrace();
                text.setHTML("Error: " + e.getMessage());
            }
        }

        @Override
        public void onError(String message) {
            text.setHTML("Error: " + message);
        }
    });
}
Also used : JSONValue(com.google.gwt.json.client.JSONValue) JSONObject(com.google.gwt.json.client.JSONObject) StringCallback(com.gwtmobile.phonegap.client.plugins.Bluetooth.StringCallback) JSONArray(com.google.gwt.json.client.JSONArray)

Example 2 with StringCallback

use of com.gwtmobile.phonegap.client.plugins.Bluetooth.StringCallback in project GwtMobile by dennisjzh.

the class BluetoothUi method listBoundDevices.

public void listBoundDevices() {
    Bluetooth.listBoundDevices(new StringCallback() {

        @Override
        public void onSuccess(String result) {
            try {
                String textHTML = "";
                JSONValue value = JSONParser.parseLenient(result);
                JSONArray devicesArray = value.isArray();
                if (devicesArray != null) {
                    textHTML = "Result:";
                    for (int i = 0; i < devicesArray.size(); i++) {
                        JSONObject deviceObj = devicesArray.get(i).isObject();
                        textHTML = textHTML + "<br/>" + deviceObj.get("name");
                    }
                    text.setHTML(textHTML);
                }
            } catch (Exception e) {
                e.printStackTrace();
                text.setHTML("Error: " + e.getMessage());
            }
        }

        @Override
        public void onError(String message) {
            text.setHTML("Error: " + message);
        }
    });
}
Also used : JSONValue(com.google.gwt.json.client.JSONValue) JSONObject(com.google.gwt.json.client.JSONObject) StringCallback(com.gwtmobile.phonegap.client.plugins.Bluetooth.StringCallback) JSONArray(com.google.gwt.json.client.JSONArray)

Aggregations

JSONArray (com.google.gwt.json.client.JSONArray)2 JSONObject (com.google.gwt.json.client.JSONObject)2 JSONValue (com.google.gwt.json.client.JSONValue)2 StringCallback (com.gwtmobile.phonegap.client.plugins.Bluetooth.StringCallback)2