NightscoutFoundation / xDrip

Nightscout version of xDrip+
https://jamorham.github.io/#xdrip-plus
GNU General Public License v3.0
1.4k stars 1.14k forks source link

Support for Android Wear 2.0 Complications #101

Closed pimeys closed 7 years ago

pimeys commented 7 years ago

Hi,

Android Wear 2.0 is coming very soon for many smart watch owners and it has one pretty cool API to use with xDrip+: the Watch Face Complications[0]. I already branched and started working on it, thinking that it would be quite easy: the class just needs to extend the ComplicationProviderService and implement an asynchronious method onComplicationUpdate, allowing the user to display xDrip data on any Android watchface, basically removing the need for separate watchfaces only for xDrip.

I realized the current watchfaces take the value updates as callbacks from the xDrip running on the mobile phone, but here the watchface itself should trigger the updates and the new provider should reply with the values the watchface wants to display. This made me think for a while... I either need:

Both of the options mean the values are a bit older than the ones on the phone or the watch is using more battery if it asks for new data too often.

I'd like to hear some ideas how to move forward and if any of these two options is the way to go, some hints how on earth the value update works between the watch and the phone. The prize is basically to create infinite amount of different possibilities how the watch looks like while still having the most important information visible.

Regards, Julius

[0] https://developer.android.com/wear/preview/features/complications.html

jamorham commented 7 years ago

Any thoughts about this @kskandispersonal ?

kskandispersonal commented 7 years ago

The main code you'd want to look at is in ListenerService.java if you are interested in data being exchanged between phone and watch. The ListenerService sends a LocalBroadcast of the BG data received from the phone to the Watchface in the onDataChanged method. The xdrip Watchface, for eg., BaseWatchFace.jave, onReceive method processes this data for display on the watch. The data received from the phone is triggered in a number of ways, including by the phone itself when it receives a bg reading from the transmitter, via request from the phone menu "Resend glucose to watch" request, a request from the watch, etc. This "request" is similar to what you describe in your 2nd bullet. So XDrip+ already supports such a request to integrate in a complication. Again, see the methods I mentioned above.
Also, if the collector runs on the watch, there is no need to request the data from the phone. The watch maintains its own database on the watch when running the collector (i.e., when Force Wear is enabled).
I haven't looked into supporting Complications yet. Unfortunately, my watch, the Sony Smartwatch 3, does not support Android 2.0. Hwr, I think it is just a matter of "Exposing Data to Complications"), as described in your link. In our case, the BG data, perhaps other data such as BG delta, time delta, and other optional status fields should be exposed. Then it is up to the Watchface user to add whatever fields they want to display. Do you have a watch which supports Android 2.0? If so, we could try exposing such data and you could test it out.

pimeys commented 7 years ago

I'm having a Sony Smartwatch 3 wrapped over the Freestyle Libre and then Huawei Watch on my wrist to show the glucose values. The Huawei will get the 2.0 update and right now I'm able to install a developer preview to test things out.

Thanks for the tips. I think I'll try to write the code myself, with the info you provided and what I already thought of writing I think it's doable in a couple of nights for code review. I have a working development environment for xDrip and I already did the InfluxDB support before, so I know a bit how to navigate in this codebase.

I'm a Rust/Clojure developer during my work hours, so please bear with me if my Java is not always following the best practices :)

chrisprad commented 7 years ago

Was there anything in particular that you had to do to get the watch face to load on AW 2.0? I cannot seem to install the watch face now that my LG Urbane 1st edition has upgraded to it.

EDIT: I was able to get this working by following various stackoverflow guides and upgrading the min/compileSdkVersion and tweaking a few other settings. If anyone is interested I can submit a pull request, but I'm guessing that pimeys work would be a better place to source it from at this point.

pimeys commented 7 years ago

I haven't tried the new API yet, had a super busy week at work and completely tired now... My Huawei Watch didn't get the update yet, so I either need to install the preview edition or wait. Of course I can start the development with the API, but it would be very nice to see it working and see is this new API useful at all.

@chrisprad I guess it would be good to provide a patch now so people's systems will not get broken when they get the AW 2.0 update.

pimeys commented 7 years ago

I started writing the code today and it should be pretty straightforward. So I have my listener service providing only the BG values for testing (extending it with subclasses for other information when I get this working). The complication data is going to be the BG value as SHORT_TEXT with an optional title, which would be the unit (mmo/l or mg/dl).

Some questions. because I can't really test this with real device yet:

And if the unit is not included, it would be nice to get it somehow. The SHORT_TEXT accepts maximum of seven characters as a value, so adding the unit directly in there is not possible, but doabie in the optional title field.

The other option would be to use the RANGED_VALUE, where again we need to check the configured unit from xDrip, set the minimum (in my case 2.2 mmol/l) and maximum (22.2 mmol/l). With this type of field it is also possible to set a title, which would be the unit, but the watchface don't have to show it.

Now what I'm looking for is that exact current BG value what I see in xDrip right now. In that format and an indication of the value unit, so I can build this service for both units.

pimeys commented 7 years ago

Another update: you can actually set the complications to work in push style, so when the BroadcastReceiver onReceive() is called, you can call requestUpdate which will trigger updates to defined complication providers.

Basically what I want to do for the first test branch is a provider for blood glucose values, where we have three different types for data:

If I don't get the AW 2.0 update next week, it would be nice if somebody like @chrisprad would test the change with a proper device. I could install the preview, but I seriously want to wait the OTA.

pimeys commented 7 years ago

Here's the first draft:

https://github.com/pimeys/xDrip-plus/tree/watch_complications

I have no clue if it works yet, but when I get the AW2 update I'm very eager to test this. Meanwhile if somebody wants to test this and maybe even finish/extend it before I get my hands to the new OS, I would be very happy. :)

chrisprad commented 7 years ago

pimeys,

When I get a chance I'll try to demo your changes.

One thing to consider: I think you have to use "flavors" to create both wear 1.x compatible xDrip release apks as well as standalone 2.0 wear projects. At least that's what developers on stack overflow seem to think. It's also kind of a pain to install, since the watch only accepts apps from the play store or side loaded through adb.

Hopefully this weekend I'll be able to load your changes up and give them a spin.

pimeys commented 7 years ago

@chrisprad Is there a good documentation somewhere how much work this would be? I'll try to get some time on next week again for writing this.

chrisprad commented 7 years ago

@pimeys

Yep, this is a relatively short document and mirrors my experience locally:

https://developer.android.com/training/wearables/apps/packaging.html

For a quick explanation just scroll down to the gradle section to see how it's setup. For xDrip I did the following (probably badly named):

android {
 ...
    compileSdkVersion 25
    buildToolsVersion '25.0.2'
...
    defaultConfig {
        applicationId "com.eveningoutpost.dexdrip"
        minSdkVersion 20
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
...
    }
...
    productFlavors {
        wear2x {
            minSdkVersion 24
            versionCode 2
        }
        wear1x {
        }

    }
}
jamorham commented 7 years ago

Is there really no way to install the existing wear 1.x micro apk on wear 2.0 using the menus?

I heard that play store on the watch did allow it but through some obscure slightly hidden option? I also heard that when upgrading a watch to wear 2.0, if the xdrip watchface was already on there then it remained. If it is compatible then it seems odd if there isn't a menu driven way to allow the installation.

I don't have any devices which work with wear 2.0 and its going to be very awkward if debug based side loading is the only way to do it.

chrisprad commented 7 years ago

@jamorham There may be some way I'm not aware of, but I was unable to find it.

I have been unable to open the play store on my watch since I don't connect using wifi and bluetooth doesn't seem to work. I just get a "Retry connection" over and over. Wear 2.0 seems completely focused on the standalone watch experience, which my watch is only sorta-kinda capable of (LG Urbane 1x).

It IS true that your 1.x watch face remains. I made the mistake of uninstalling it when trying to get newer versions installed, and after that I was unable to install the old version. The system did seem to run it, so you may be right that it's simply a software barrier in the way.

They seem to be attempting to make a hard line in the sand between wear 1.x and 2.x, so I do think it will be difficult/annoying to debug without a wear 2.x device. I'm willing to do some debugging over the weekend since it seems like I'm the only person with a wear 2.x device currently.

Mondelman commented 7 years ago

I've used for a couple of days a Huawei Smartwatch 2, using Wear 2.0 and it works, but not as collector. It means you can see std xDrip screen, any of the 4 options, but it can't work as Sony SW3, that is the one I use today. You install the app via PlayStore in the watch, but it seems to be working as a watchface only. Apologies for not being able to bring more to this topic, I sent the watch back to Amazon.

pimeys commented 7 years ago

Sorry for being quiet for a while, but I got a new Dexcom system that I run now with xDrip and finally the AW2 update to my Huawei, so I guess I'll be testing this through the weekend.

ChrisWoodward89 commented 7 years ago

I would be really interested to see how you get on with this, given that Android Wear 2.0 can display data from apps on any watch face it would be nice not to be limited to the Xdrip pre-defined watch faces which whilst very informative are pretty ugly.

billymild commented 7 years ago

I see a few mentions of Android Wear 2 and the Huawei Watch. What makes the Sony SW3 work as a standalone collector but not the Huawei? Is there anyway for me to help with testing/debugging of this for the developers?

kskandispersonal commented 7 years ago

I only have the SW3 watch so development is geared toward it. It uses standard BLE so other watches which support standard BLE also work as the collector. I believe the LG Urbane with Wear 2.0 also works as the collector. If you'd like to help and you have the Huawei watch, you could test it with Force Wear enabled and also enable Sync Wear Logs. See the watchguide for instructions on enabling these preferences. It is located under the Documentation directory.

billymild commented 7 years ago

@kskandispersonal I did that and I was posting screenshots to xDrip G5 Facebook group with no comments being made. Should I post screenshots here?

kskandispersonal commented 7 years ago

Oh, sorry, I try to respond to xDrip G5 FB but apparently missed your postings. The gitter channel, https://gitter.im/jamorham/xDrip-plus, is more timely for direct conversation re: issues and testing. You could open a new issue here on xDrip GitHub specifically for the Huawei Wear 2.0 (since it is not directly related to this issue, Wear 2.0 Complications).

tswire commented 7 years ago

Any further update as to complications working in AW2 with xdrip?

pimeys commented 7 years ago

Ok, now, let me open this up a bit as the original developer who wanted to investigate how to add a complication for xDrip:

The biggest problem is the complication system itself: basically the watchface decides when it wants to update the values. xDrip watchfaces update the values when the transmitter has new data. My idea was to cache the value to the complication class and call an update function which SHOULD update a new value, but it never did. So at least for my case, using complications as they are currently is definitely worse than having an automatically updating graph in my watch. If the glucose value is 30 minutes late, I don't really care if it looks pretty.

There's a link to the pull request in this post. If somebody wants to continue the work and try to find a way to always display the latest value through complications, I'm definitely happy to test and give help in this proces...

But right now I get the most out of the big graph watchface.

badgerisop commented 7 years ago

As a parent of a T1D I'm interested to hear if anyone has managed to get this working as a Dexcom follower. Have the Huawei 2 Classic with 2.0

heygar commented 7 years ago

Think this article: https://www.smashingmagazine.com/2017/01/bringing-app-data-every-user-wrist-android-wear/ explains exactly what you want to do. I just got the AW2 update this morning on my ZenWatch. I've done a couple of simple forays into Android development, but I'm mostly a novice (prefer Unix Server Development in C++ -- Java kind of makes me ill).

Anyway, if I get the time (and that's a big if), I may try and git your branch to see if I can make it work. Assuming this branch is still the way to go?

pimeys commented 7 years ago

@heygar Google's own documentation is better though. https://developer.android.com/training/wearables/watch-faces/complications.html

But the biggest problem here is, that whatever your transmitter is, it's been read approximately every five minutes by xDrip and the value immediately shown in the device you're wearing. The complication's main purpose is, that the watchface should ask the value to be displayed from the complications provider. It looks like, that you can define to look frequently, but it's just an suggestion that actually can be overriden.

Here's my code so far https://github.com/pimeys/xDrip-plus/tree/watch_complications

As you can see I added a listener for BG data updates, and try to enforce a complication update. I also got a problem instantizing the classes correctly, if you look into the debug log. I'm also a backend developer focusing on Rust and Clojure, so I'm not so happy with Java and Anrdoid API's :)

badgerisop commented 7 years ago

How hard would it be to modify the Nightwatch app functionality that allows access to Dexcom share server data to work on a stand alone 2.0 watch face? Particularly with AW 2.0 on iOS.

tswire commented 7 years ago

THANK YOU. That is exactly what I am looking for. I have iPhone but love AW2.0 but cannot find a combination for any way to get blood sugar on watch with this combo. Any insight would be awesome.

kevinfmanning commented 7 years ago

I am a Android developer in my free time. I haven't done anything with wear though. I'm willing to learn. Anyone in particular I should get in contact with?

tswire commented 7 years ago

Any further development with this? Xdrip+ is way more advanced than the Dexcom G5 app and all that it's missing is a complication for AW2. That would make this even better!!!!

jamorham commented 7 years ago

So I have blindly implemented a complication data provider in xDrip+ I have no idea if I have done this correctly as I only have android wear 1.x

If you would like to try this, please download the Sept 13th nightly and let me know what happens? If this works then we can look at refining the support.

tswire commented 7 years ago

Ok. Is it the one linked that you have updated??

On Sep 13, 2017 6:15 PM, "Jamorham" notifications@github.com wrote:

So I have blindly implemented a complication data provider in xDrip+ I have no idea if I have done this correctly as I only have android wear 1.x

If you would like to try this, please download the Sept 13th nightly and let me know what happens? If this works then we can look at refining the support.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/NightscoutFoundation/xDrip/issues/101#issuecomment-329312498, or mute the thread https://github.com/notifications/unsubscribe-auth/ActA9vvriDdZF6uIsgm9yG1TCcIQcJ1Mks5siFPvgaJpZM4M4KE6 .

recursive-descent commented 7 years ago

Works on my lg sport. Would be great if a direction arrow could be added as well.

On Sep 13, 2017 5:15 PM, "Jamorham" notifications@github.com wrote:

So I have blindly implemented a complication data provider in xDrip+ I have no idea if I have done this correctly as I only have android wear 1.x

If you would like to try this, please download the Sept 13th nightly and let me know what happens? If this works then we can look at refining the support.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/NightscoutFoundation/xDrip/issues/101#issuecomment-329312498, or mute the thread https://github.com/notifications/unsubscribe-auth/AZ_4SIYkdabV2VjR1h-ghAN29hFW-Hrbks5siFPvgaJpZM4M4KE6 .

jamorham commented 7 years ago

@tswire you can download it from here: https://github.com/NightscoutFoundation/xDrip/releases or select the Nightly update channel in the App, if you don't see nightly then select alpha first and then go out and in to settings and nightly option should become visible.

@recursive-descent can you confirm that the complication updates as it should? Are you using mg/dl or mmol/l ?

@pimeys how much space do we have to display the data? what happens if it is oversized? I assume it will be able to handle unicode so we can use slope arrows. I think we should now look at improving the support probably using the work you have done previously for this. I haven't studied it in detail.

pimeys commented 7 years ago

@jamorham You could try to add more complication data types, such as LONG_TEXT or that RANGE value. The watch face will then decide how much space there is and which version to fit.

Damn, I just uninstalled my custom xDrip to try this version and now the watch app doesn't install anymore to my AW 2.0 device. Hopefully I can force install it without getting the cable from home.

jamorham commented 7 years ago

@pimeys Is it done like this ?

On Android Wear 2.0 watches you need to install (activate) the wear component separately from the Play-Store on the watch (under the section "Apps on your phone") after installing xDrip+ on the phone.

jamorham commented 7 years ago

@pimeys do we know ahead of time how much space there is a in a short type?

pimeys commented 7 years ago

@jamorham

TYPE_SHORT_TEXT

Type used for complications where the primary piece of data is a short piece of text (expected to be no more than seven characters in length).

https://developer.android.com/reference/android/support/wearable/complications/ComplicationData.html

So 22.2 is the longest possible value shown here? Then you have three extra characters for the short text, so you can fit in an arrow.

Another option is to use the short title, which is shown in many watchfaces under the actual value, like so:

new ComplicationData.Builder(ComplicationData.TYPE_SHORT_TEXT)
    .setShortText(ComplicationText.plainText(numberText))
    .setShortTitle(ComplicationText.plainText(deltaValue OR "mmol/l" OR "mg/dl"))
    .setTapAction(complicationPendingIntent)
    .build();

And of course I'd recommend adding support for the long text type too, which could hold all the important data, such as the glucose value, delta value and minutes from the last measurement. I'm trying to test these currently, but my android studio is still giving hiccups.

jamorham commented 7 years ago

@pimeys this is very helpful thank you

pimeys commented 7 years ago

@jamorham No, thank you for actually getting a working complication out! This works on my watch, I just want all the possible data visible, so I feel safer when biking home today.

jamorham commented 7 years ago

I plan to update the short text very soon

recursive-descent commented 7 years ago

After further review the complication does not update after the first one after watch power-up.

pimeys commented 7 years ago

@recursive-descent Which watchface you're using? For me it works with the default Google watchface, but what you have found here might be the same I noticed some months ago, that some watchfaces don't get the updates that often.

jamorham commented 7 years ago

@recursive-descent out of interest, if you tap the complication does it update?

jamorham commented 7 years ago

I updated the support for this in today's nightly. It should include trend arrow and delta. Does it work??

tswire commented 7 years ago

I have the 09 15 version installed and no arrows that i can see. I am using it on Tag android wear with default "Interactive" theme with complications and I seem to be getting updates regularly. Fyi.

On Sep 15, 2017 8:54 AM, "Jamorham" notifications@github.com wrote:

I updated the support for this in today's nightly. It should include trend arrow and delta. Does it work??

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NightscoutFoundation/xDrip/issues/101#issuecomment-329774483, or mute the thread https://github.com/notifications/unsubscribe-auth/ActA9tSS1_uxuByI1h1CJawW9gvIz38yks5sinN2gaJpZM4M4KE6 .

recursive-descent commented 7 years ago

Arrows and delta are displaying now. Still having the issue of only updating once, at the initialization of the watch from power up. Deleting a watch face and adding it doesn't change anything. The complication doesn't update.

On Fri, Sep 15, 2017 at 8:19 AM, tswire notifications@github.com wrote:

I have the 09 15 version installed and no arrows that i can see. I am using it on Tag android wear with default "Interactive" theme with complications and I seem to be getting updates regularly. Fyi.

On Sep 15, 2017 8:54 AM, "Jamorham" notifications@github.com wrote:

I updated the support for this in today's nightly. It should include trend arrow and delta. Does it work??

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NightscoutFoundation/xDrip/issues/101#issuecomment- 329774483, or mute the thread https://github.com/notifications/unsubscribe-auth/ActA9tSS1_ uxuByI1h1CJawW9gvIz38yks5sinN2gaJpZM4M4KE6 .

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NightscoutFoundation/xDrip/issues/101#issuecomment-329780338, or mute the thread https://github.com/notifications/unsubscribe-auth/AZ_4SPk1v0lE7PDGr5ZdG5xqSE8CZaO_ks5sinlhgaJpZM4M4KE6 .

recursive-descent commented 7 years ago

@jamorham https://github.com/jamorham In answer to your previous question. I've tried the complication on multiple watch faces. All are standard issue from the mfg.

On Fri, Sep 15, 2017 at 8:25 AM, E.J. McKernan ejm@recursive-descent.com wrote:

Arrows and delta are displaying now. Still having the issue of only updating once, at the initialization of the watch from power up. Deleting a watch face and adding it doesn't change anything. The complication doesn't update.

On Fri, Sep 15, 2017 at 8:19 AM, tswire notifications@github.com wrote:

I have the 09 15 version installed and no arrows that i can see. I am using it on Tag android wear with default "Interactive" theme with complications and I seem to be getting updates regularly. Fyi.

On Sep 15, 2017 8:54 AM, "Jamorham" notifications@github.com wrote:

I updated the support for this in today's nightly. It should include trend arrow and delta. Does it work??

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NightscoutFoundation/xDrip/issues/101# issuecomment-329774483, or mute the thread https://github.com/notifications/unsubscribe-auth/ ActA9tSS1_uxuByI1h1CJawW9gvIz38yks5sinN2gaJpZM4M4KE6 .

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NightscoutFoundation/xDrip/issues/101#issuecomment-329780338, or mute the thread https://github.com/notifications/unsubscribe-auth/AZ_4SPk1v0lE7PDGr5ZdG5xqSE8CZaO_ks5sinlhgaJpZM4M4KE6 .

jamorham commented 7 years ago

Does either of you see the delta value, like +0.1 displayed anywhere?

recursive-descent commented 7 years ago

Yes. The items displayed: actual reading, arrow and delta.

On Sep 15, 2017 8:57 AM, "Jamorham" notifications@github.com wrote:

Does either of you see the delta value, like +0.1 displayed anywhere?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NightscoutFoundation/xDrip/issues/101#issuecomment-329790347, or mute the thread https://github.com/notifications/unsubscribe-auth/AZ_4SGuYpA4rpIK7SbYgOLmUi6jDbrsxks5sioJHgaJpZM4M4KE6 .

jamorham commented 7 years ago

@recursive-descent I wonder if it can be related to your collector, what data source is the phone that the watch is connected to using to get glucose data?