3

I've been researching how to make an android wear watchface with little luck. Youtube does not appear to have very much information on actually designing a watchface.

Is there a way to use an XML layout for the watchface rather than, for example, manually drawing each block through on draw?

Chris Martin
  • 30,334
  • 10
  • 78
  • 137
XvKnightvX
  • 579
  • 7
  • 23

1 Answers1

3

It's possible, though there are some extra hoops you need to jump through. I've written up instructions at https://sterlingudell.wordpress.com/2015/05/10/layout-based-watch-faces-for-android-wear/

Sterling
  • 6,365
  • 2
  • 32
  • 40
  • Thanks for the reply i checked out the link and setup my watchface service but unfortunately whenever i try launching it on my lg urbane the watchface becomes unresponsive and crashes. – XvKnightvX Jan 31 '16 at 16:57
  • i found this in my log cat hopefully it helps 01-31 09:49:48.088 2442-2442/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.watchface.knight.watchfacetesting, PID: 2442 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference at com.watchface.knight.watchfacetesting.DefaultTestFace$Engine.onDraw(DefaultTestFace.java:316) – XvKnightvX Jan 31 '16 at 17:23
  • As you know, it's very difficult to tell from one line out of logcat, but I'd guess that your layout isn't inflated. But this crash is just a regular NPE, and your existing Android debugging skills should be applicable. – Sterling Jan 31 '16 at 19:00
  • This approach works fine, but apparently for text-based views only, `ImageView` and empty layouts aren't working. Any particular reason behind that? – Devesh Khandelwal Feb 02 '17 at 15:27
  • Not sure about empty layouts, but I definitely have this working with `ImageView`s in other watch faces. Are you doing the `measure` and `layout` calls after all your views are set up? – Sterling Feb 02 '17 at 16:18
  • I tried your instructions with a custom view and it works really good ... but i don't get touch events on that view ... is it somehow possible to enable touch events on a custom view on a watch face? – PrfctByDsgn Oct 30 '18 at 07:08
  • No, you can't get ordinary touch events on a watch face, regardless of whether you use a layout. You need to work within the scope of the `onTapCommand` event: https://developer.android.com/training/wearables/watch-faces/interacting – Sterling Oct 30 '18 at 14:16