Search in sources :

Example 6 with GBDeviceEventFindPhone

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

the class CasioGBX100DeviceSupport method onReverseFindDevice.

private void onReverseFindDevice(boolean start) {
    if (start) {
        SharedPreferences sharedPreferences = GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress());
        String findPhone = sharedPreferences.getString(PREF_FIND_PHONE_ENABLED, getContext().getString(R.string.p_off));
        if (findPhone.equals(getContext().getString(R.string.p_off)))
            return;
        GBDeviceEventFindPhone findPhoneEvent = new GBDeviceEventFindPhone();
        findPhoneEvent.event = GBDeviceEventFindPhone.Event.START;
        evaluateGBDeviceEvent(findPhoneEvent);
        if (!findPhone.equals(getContext().getString(R.string.p_on))) {
            String duration = sharedPreferences.getString(MakibesHR3Constants.PREF_FIND_PHONE_DURATION, "0");
            try {
                int iDuration;
                try {
                    iDuration = Integer.parseInt(duration);
                } catch (Exception ex) {
                    LOG.warn(ex.getMessage());
                    iDuration = 60;
                }
                if (iDuration > 0) {
                    this.mFindPhoneHandler.postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            onReverseFindDevice(false);
                        }
                    }, iDuration * 1000);
                }
            } catch (Exception e) {
                LOG.error("Unexpected exception in MiBand2Coordinator.getTime: " + e.getMessage());
            }
        }
    } else {
        // Always send stop, ignore preferences.
        GBDeviceEventFindPhone findPhoneEvent = new GBDeviceEventFindPhone();
        findPhoneEvent.event = GBDeviceEventFindPhone.Event.STOP;
        evaluateGBDeviceEvent(findPhoneEvent);
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) GBDeviceEventFindPhone(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone) IOException(java.io.IOException)

Example 7 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)

Example 8 with GBDeviceEventFindPhone

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

the class MakibesHR3DeviceSupport method onReverseFindDevice.

private void onReverseFindDevice(boolean start) {
    if (start) {
        SharedPreferences sharedPreferences = GBApplication.getDeviceSpecificSharedPrefs(this.getDevice().getAddress());
        int findPhone = MakibesHR3Coordinator.getFindPhone(sharedPreferences);
        if (findPhone != MakibesHR3Coordinator.FindPhone_OFF) {
            GBDeviceEventFindPhone findPhoneEvent = new GBDeviceEventFindPhone();
            findPhoneEvent.event = GBDeviceEventFindPhone.Event.START;
            evaluateGBDeviceEvent(findPhoneEvent);
            if (findPhone > 0) {
                this.mFindPhoneHandler.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        onReverseFindDevice(false);
                    }
                }, findPhone * 1000);
            }
        }
    } else {
        // Always send stop, ignore preferences.
        GBDeviceEventFindPhone findPhoneEvent = new GBDeviceEventFindPhone();
        findPhoneEvent.event = GBDeviceEventFindPhone.Event.STOP;
        evaluateGBDeviceEvent(findPhoneEvent);
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) GBDeviceEventFindPhone(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone)

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