1

I have a watch face built upon latest API (extending CanvasWatchFaceService.Engine). Now I'd like to get touch event to have kind of active area in watch face that can be touched to open settings, etc. A CanvasWatchFaceService.Engine inherits from WallpaperService.Engine, which declares two important methods: setTouchEventsEnabled(boolean) and onTouchEvent(MotionEvent).

But even when I call setTouchEventsEnabled(true) in onCreate() method of the Engine I never receive a call to onTouchEvent(MotionEvent) in my engine implementation.

Am I doing something wrong or is it simply not possible? I'm aware of some watch faces that offer active areas, but I'm not sure if these are built upon latest API or if they are build upon deprecated API (using layouts and GUI elements).

d.aemon
  • 761
  • 1
  • 7
  • 20

2 Answers2

6

Use the Interactive Watch Face API in new Android Wear 1.3:

UPDATE:

Add just one line to the init function in the onCreate function in your CanvasWatchFaceService.Engine based class:

setWatchFaceStyle(new WatchFaceStyle.Builder(mService)
    .setAcceptsTapEvents(true)
    // other style customizations
    .build());

And manage the tap events under

@Override
public void onTapCommand(int tapType, int x, int y, long eventTime) { }

Notes:

  • you'll have to add your own code to find which touch targets (if any) were tapped (tapType==TAP_TYPE_TAP)
  • you can only detect single, short taps, no swipes or long presses.
  • by detecting TAP_TYPE_TOUCH and TAP_TYPE_TOUCH_CANCEL you can kind of guess swipe gestures, though TAP_TYPE_TOUCH_CANCEL doesn't provide the exit coordinates.

For more control your only bet is to add a SYSTEM_ALERT layer and toggle it on/off based on information you can gather from onVisibilityChanged and onAmbientModeChanged...

vgergo
  • 71
  • 2
  • 7
  • Link only answers are discouraged. Please quote the essential parts of the answer from the reference link(s), as the answer can become invalid if the linked page(s) change. – Stuart Siegler Sep 20 '15 at 16:41
  • yep, this is correct. refer to official doc pls http://developer.android.com/training/wearables/watch-faces/interacting.html – Demo_S Mar 18 '16 at 16:51
-3

It is not possible. I guess I read it in a thread on Google Plus on the Android developers group.

The watch face is meant to be a "static" thing, just there, just showing the time. Touch events are never dispatched to it.

The suggested pattern for Settings is to implement it on a companion app on the phone app.

Budius
  • 39,391
  • 16
  • 102
  • 144