diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/deviceevents/GBDeviceEventFindPhone.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/deviceevents/GBDeviceEventFindPhone.java new file mode 100644 index 000000000..a708ec05b --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/deviceevents/GBDeviceEventFindPhone.java @@ -0,0 +1,28 @@ +/* Copyright (C) 2015-2017 Andreas Shimokawa + + This file is part of Gadgetbridge. + + Gadgetbridge is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Gadgetbridge is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . */ + +package nodomain.freeyourgadget.gadgetbridge.deviceevents; + +public class GBDeviceEventFindPhone extends GBDeviceEvent { + public Event event = Event.UNKNOWN; + + public enum Event { + UNKNOWN, + START, + STOP + } +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java index 24e014b9e..a17d8fc25 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java @@ -44,6 +44,7 @@ import java.util.Objects; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.activities.FindPhoneActivity; import nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AbstractAppManagerFragment; import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsHost; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent; @@ -51,6 +52,7 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppInfo; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventDisplayMessage; +import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventNotificationControl; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventScreenshot; @@ -153,6 +155,25 @@ public abstract class AbstractDeviceSupport implements DeviceSupport { handleGBDeviceEvent((GBDeviceEventNotificationControl) deviceEvent); } else if (deviceEvent instanceof GBDeviceEventBatteryInfo) { handleGBDeviceEvent((GBDeviceEventBatteryInfo) deviceEvent); + } else if (deviceEvent instanceof GBDeviceEventFindPhone) { + handleGBDeviceEvent((GBDeviceEventFindPhone) deviceEvent); + } + } + + private void handleGBDeviceEvent(GBDeviceEventFindPhone deviceEvent) { + Context context = getContext(); + LOG.info("Got GBDeviceEventFindPhone"); + switch (deviceEvent.event) { + case START: + Intent startIntent = new Intent(getContext(), FindPhoneActivity.class); + context.startActivity(startIntent); + break; + case STOP: + Intent intent = new Intent(FindPhoneActivity.ACTION_FOUND); + LocalBroadcastManager.getInstance(context).sendBroadcast(intent); + break; + default: + LOG.warn("unknown GBDeviceEventFindPhone"); } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java index 464ed50c2..85972ce69 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java @@ -48,12 +48,12 @@ import java.util.concurrent.TimeUnit; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.Logging; import nodomain.freeyourgadget.gadgetbridge.R; -import nodomain.freeyourgadget.gadgetbridge.activities.FindPhoneActivity; import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity; import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; import nodomain.freeyourgadget.gadgetbridge.database.DBHelper; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl; +import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo; import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; @@ -159,6 +159,8 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport { private final GBDeviceEventVersionInfo versionCmd = new GBDeviceEventVersionInfo(); private final GBDeviceEventBatteryInfo batteryCmd = new GBDeviceEventBatteryInfo(); + private final GBDeviceEventFindPhone findPhoneEvent = new GBDeviceEventFindPhone(); + private RealtimeSamplesSupport realtimeSamplesSupport; private boolean alarmClockRinging; @@ -957,15 +959,14 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport { break; case HuamiDeviceEvent.FIND_PHONE_START: LOG.info("find phone started"); - // FIXME: premature - acknowledgeFindPhone(); - Intent startIntent = new Intent(getContext(), FindPhoneActivity.class); - getContext().startActivity(startIntent); + acknowledgeFindPhone(); // FIXME: premature + findPhoneEvent.event = GBDeviceEventFindPhone.Event.START; + evaluateGBDeviceEvent(findPhoneEvent); break; case HuamiDeviceEvent.FIND_PHONE_STOP: LOG.info("find phone stopped"); - Intent intent = new Intent(FindPhoneActivity.ACTION_FOUND); - LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent); + findPhoneEvent.event = GBDeviceEventFindPhone.Event.STOP; + evaluateGBDeviceEvent(findPhoneEvent); break; default: LOG.warn("unhandled event " + value[0]); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerGBPebble.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerGBPebble.java new file mode 100644 index 000000000..74d751158 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerGBPebble.java @@ -0,0 +1,72 @@ +/* Copyright (C) 2015-2017 Andreas Shimokawa + + This file is part of Gadgetbridge. + + Gadgetbridge is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Gadgetbridge is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . */ + +package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble; + +import android.util.Pair; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.UUID; + +import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent; +import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone; +import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes; + +public class AppMessageHandlerGBPebble extends AppMessageHandler { + + private static final Logger LOG = LoggerFactory.getLogger(AppMessageHandlerMisfit.class); + + private static final int KEY_FIND_PHONE_START = 1; + private static final int KEY_FIND_PHONE_STOP = 2; + + + AppMessageHandlerGBPebble(UUID uuid, PebbleProtocol pebbleProtocol) { + super(uuid, pebbleProtocol); + } + + @Override + public GBDeviceEvent[] handleMessage(ArrayList> pairs) { + GBDeviceEventFindPhone gbDeviceEventFindPhone = null; + + for (Pair 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}; + } +} \ No newline at end of file diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java index 41eb585e3..79a494b47 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java @@ -418,6 +418,7 @@ public class PebbleProtocol extends GBDeviceProtocol { mAppMessageHandlers.put(UUID_ZALEWSZCZAK_FANCY, new AppMessageHandlerZalewszczak(UUID_ZALEWSZCZAK_FANCY, PebbleProtocol.this)); mAppMessageHandlers.put(UUID_ZALEWSZCZAK_TALLY, new AppMessageHandlerZalewszczak(UUID_ZALEWSZCZAK_TALLY, PebbleProtocol.this)); mAppMessageHandlers.put(UUID_OBSIDIAN, new AppMessageHandlerObsidian(UUID_OBSIDIAN, PebbleProtocol.this)); + mAppMessageHandlers.put(UUID_GBPEBBLE, new AppMessageHandlerGBPebble(UUID_GBPEBBLE, PebbleProtocol.this)); } }