Search in sources :

Example 1 with GBDeviceEventFindPhone

use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone in project Gadgetbridge by Freeyourgadget.

the class LefunDeviceSupport method handleAntiLoss.

/**
 * Handles find phone request
 *
 * @param data the response
 * @return whether the response has been handled
 */
private boolean handleAntiLoss(byte[] data) {
    try {
        FindPhoneCommand cmd = new FindPhoneCommand();
        cmd.deserialize(data);
        GBDeviceEventFindPhone event = new GBDeviceEventFindPhone();
        event.event = GBDeviceEventFindPhone.Event.START;
        evaluateGBDeviceEvent(event);
        return true;
    } catch (IllegalArgumentException e) {
        LOG.error("Failed to handle anti-loss", e);
        return false;
    }
}
Also used : GBDeviceEventFindPhone(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone) FindPhoneCommand(nodomain.freeyourgadget.gadgetbridge.devices.lefun.commands.FindPhoneCommand)

Example 2 with GBDeviceEventFindPhone

use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone in project Gadgetbridge by Freeyourgadget.

the class FitProDeviceSupport method handleFindPhone.

public void handleFindPhone() {
    LOG.info("FitPro find phone");
    GBDeviceEventFindPhone deviceEventFindPhone = new GBDeviceEventFindPhone();
    deviceEventFindPhone.event = GBDeviceEventFindPhone.Event.START;
    evaluateGBDeviceEvent(deviceEventFindPhone);
}
Also used : GBDeviceEventFindPhone(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone)

Example 3 with GBDeviceEventFindPhone

use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone in project Gadgetbridge by Freeyourgadget.

the class CasioGB6900DeviceSupport method onCharacteristicChanged.

@Override
public boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    boolean handled = false;
    UUID characteristicUUID = characteristic.getUuid();
    byte[] data = characteristic.getValue();
    if (data.length == 0)
        return true;
    if (characteristicUUID.equals(CasioConstants.CASIO_A_NOT_W_REQ_NOT)) {
        handled = handleCasioCom(data, true);
    }
    if (characteristicUUID.equals(CasioConstants.CASIO_A_NOT_COM_SET_NOT)) {
        handled = handleCasioCom(data, false);
    }
    if (characteristicUUID.equals(CasioConstants.ALERT_LEVEL_CHARACTERISTIC_UUID)) {
        GBDeviceEventFindPhone findPhoneEvent = new GBDeviceEventFindPhone();
        if (data[0] == 0x02) {
            findPhoneEvent.event = GBDeviceEventFindPhone.Event.START;
        } else {
            findPhoneEvent.event = GBDeviceEventFindPhone.Event.STOP;
        }
        evaluateGBDeviceEvent(findPhoneEvent);
        handled = true;
    }
    if (characteristicUUID.equals(CasioConstants.RINGER_CONTROL_POINT)) {
        if (data[0] == 0x02) {
            GBDeviceEventCallControl callControlEvent = new GBDeviceEventCallControl();
            callControlEvent.event = GBDeviceEventCallControl.Event.IGNORE;
            evaluateGBDeviceEvent(callControlEvent);
        }
        handled = true;
    }
    if (!handled) {
        LOG.info("Unhandled characteristic change: " + characteristicUUID + " code: " + String.format("0x%1x ...", data[0]));
        return super.onCharacteristicChanged(gatt, characteristic);
    }
    return true;
}
Also used : GBDeviceEventFindPhone(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone) GBDeviceEventCallControl(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl) UUID(java.util.UUID)

Example 4 with GBDeviceEventFindPhone

use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone in project Gadgetbridge by Freeyourgadget.

the class FossilHRWatchAdapter method handleBackgroundCharacteristic.

@Override
protected void handleBackgroundCharacteristic(BluetoothGattCharacteristic characteristic) {
    super.handleBackgroundCharacteristic(characteristic);
    byte[] value = characteristic.getValue();
    byte requestType = value[1];
    if (requestType == (byte) 0x04) {
        if (value[7] == 0x00 || value[7] == 0x01) {
            handleCallRequest(value);
        } else if (value[7] == 0x02) {
            handleDeleteNotification(value);
        } else if (value[7] == 0x03) {
            handleQuickReplyRequest(value);
        }
    } else if (requestType == (byte) 0x05) {
        handleMusicRequest(value);
    } else if (requestType == (byte) 0x01) {
        int eventId = value[2];
        LOG.info("got event id " + eventId);
        try {
            String jsonString = new String(value, 3, value.length - 3);
            // logger.info(jsonString);
            JSONObject requestJson = new JSONObject(jsonString);
            JSONObject request = requestJson.getJSONObject("req");
            int requestId = request.getInt("id");
            if (request.has("ringMyPhone")) {
                String action = request.getJSONObject("ringMyPhone").getString("action");
                LOG.info("got ringMyPhone request; " + action);
                GBDeviceEventFindPhone findPhoneEvent = new GBDeviceEventFindPhone();
                JSONObject responseObject = new JSONObject().put("res", new JSONObject().put("id", requestId).put("set", new JSONObject().put("ringMyPhone", new JSONObject())));
                if ("on".equals(action)) {
                    findPhoneEvent.event = GBDeviceEventFindPhone.Event.START;
                    getDeviceSupport().evaluateGBDeviceEvent(findPhoneEvent);
                    responseObject.getJSONObject("res").getJSONObject("set").getJSONObject("ringMyPhone").put("result", "on");
                    queueWrite(new JsonPutRequest(responseObject, this));
                } else if ("off".equals(action)) {
                    findPhoneEvent.event = GBDeviceEventFindPhone.Event.STOP;
                    getDeviceSupport().evaluateGBDeviceEvent(findPhoneEvent);
                    responseObject.getJSONObject("res").getJSONObject("set").getJSONObject("ringMyPhone").put("result", "off");
                    queueWrite(new JsonPutRequest(responseObject, this));
                }
            } else if (request.has("weatherInfo") || request.has("weatherApp._.config.locations")) {
                LOG.info("Got weatherInfo request");
                WeatherSpec weatherSpec = Weather.getInstance().getWeatherSpec();
                if (weatherSpec != null) {
                    onSendWeather(weatherSpec);
                } else {
                    LOG.info("no weather data available  - ignoring request");
                }
            } else if (request.has("commuteApp._.config.commute_info")) {
                String action = request.getJSONObject("commuteApp._.config.commute_info").getString("dest");
                String startStop = request.getJSONObject("commuteApp._.config.commute_info").getString("action");
                if (startStop.equals("stop")) {
                    // overwriteButtons(null);
                    return;
                }
                queueWrite(new SetCommuteMenuMessage(getContext().getString(R.string.fossil_hr_commute_processing), false, this));
                Intent menuIntent = new Intent(QHybridSupport.QHYBRID_EVENT_COMMUTE_MENU);
                menuIntent.putExtra("EXTRA_ACTION", action);
                getContext().sendBroadcast(menuIntent);
            } else if (request.has("master._.config.app_status")) {
                queueWrite(new ConfirmAppStatusRequest(requestId, this));
            } else {
                LOG.warn("Unhandled request from watch: " + requestJson.toString());
            }
        } catch (JSONException e) {
            LOG.error("Error while handling received characteristic", e);
        }
    }
}
Also used : JSONObject(org.json.JSONObject) JsonPutRequest(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.json.JsonPutRequest) GBDeviceEventFindPhone(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone) WeatherSpec(nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec) JSONException(org.json.JSONException) Intent(android.content.Intent) ConfirmAppStatusRequest(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.async.ConfirmAppStatusRequest) SetCommuteMenuMessage(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.menu.SetCommuteMenuMessage) Paint(android.graphics.Paint)

Example 5 with GBDeviceEventFindPhone

use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone in project Gadgetbridge by Freeyourgadget.

the class AppMessageHandlerGBPebble method handleMessage.

@Override
public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
    GBDeviceEventFindPhone gbDeviceEventFindPhone = null;
    for (Pair<Integer, Object> pair : pairs) {
        switch(pair.first) {
            case KEY_FIND_PHONE_START:
                LOG.info("find phone start");
                gbDeviceEventFindPhone = new GBDeviceEventFindPhone();
                gbDeviceEventFindPhone.event = GBDeviceEventFindPhone.Event.START;
                break;
            case KEY_FIND_PHONE_STOP:
                LOG.info("find phone stop");
                gbDeviceEventFindPhone = new GBDeviceEventFindPhone();
                gbDeviceEventFindPhone.event = GBDeviceEventFindPhone.Event.STOP;
                break;
            default:
                LOG.info("unhandled key: " + pair.first);
                break;
        }
    }
    // always ack
    GBDeviceEventSendBytes sendBytesAck = new GBDeviceEventSendBytes();
    sendBytesAck.encodedBytes = mPebbleProtocol.encodeApplicationMessageAck(mUUID, mPebbleProtocol.last_id);
    return new GBDeviceEvent[] { sendBytesAck, gbDeviceEventFindPhone };
}
Also used : GBDeviceEvent(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent) GBDeviceEventFindPhone(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone) GBDeviceEventSendBytes(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes)

Aggregations

GBDeviceEventFindPhone (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone)8 SharedPreferences (android.content.SharedPreferences)3 Intent (android.content.Intent)1 Paint (android.graphics.Paint)1 IOException (java.io.IOException)1 UUID (java.util.UUID)1 GBDeviceEvent (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent)1 GBDeviceEventCallControl (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl)1 GBDeviceEventSendBytes (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes)1 FindPhoneCommand (nodomain.freeyourgadget.gadgetbridge.devices.lefun.commands.FindPhoneCommand)1 WeatherSpec (nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec)1 ConfirmAppStatusRequest (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.async.ConfirmAppStatusRequest)1 JsonPutRequest (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.json.JsonPutRequest)1 SetCommuteMenuMessage (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.menu.SetCommuteMenuMessage)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1