Search code examples
androidwear-osandroid-wear-2.0watch-face-api

Handling change of a timezone in a watch face


If you take a look at Google's example of an analog watch face you can see that they are handling timezone change using BroadcastReceiver.

In documentation, it says that onTimeTick will be triggered by timezone change. Would it be enough to just update timezone data every time when onTimeTick is called?

The only problem that I see is that mCalendar.setTimeZone(TimeZone.getDefault()); will be called on every onTimeTick call, but it's not heavy operation, so I don't really see any problem.


Solution

  • I think the example is just outdated. When I started building watch faces the onTimeTick() method would not be called if you e.g. changed the date or time zone from Settings on your paired device. You had to register a BroadcastReceiver to catch those events.

    I'm not sure when this stopped being the case, but currently onTimeTick() seems to be called for all events related to updating time, date, and time zone.

    We use an android.text.format.Time object and update its timezone field whenever onTimeTick() is called.

    I guess you could optimize this slightly by only setting it if it has changed. However, like you mentioned in your question, this isn't an expensive operation. I doubt that this change would make a noticeable improvement.

    Much more important is to make sure that you don't run the watch face code that handles time zone changes unless it has actually changed. That would trigger unnecessary (and expensive) redraw operations.