@@ -139,6 +139,7 @@ public void onDestroy() {
139
139
private class CanvasEngine extends CanvasWatchFaceService .Engine implements ServiceEngine {
140
140
private PApplet sketch ;
141
141
private Method compUpdatedMethod ;
142
+ private Method tapCommandMethod ;
142
143
private boolean isRound = false ;
143
144
private Rect insets = new Rect ();
144
145
private boolean lowBitAmbient = false ;
@@ -153,15 +154,26 @@ public void onCreate(SurfaceHolder surfaceHolder) {
153
154
sketch = createSketch ();
154
155
PGraphicsAndroid2D .useBitmap = false ;
155
156
sketch .initSurface (PWatchFaceCanvas .this , null );
157
+ initTapEvents ();
156
158
initComplications ();
157
159
requestPermissions ();
158
160
}
159
161
160
162
163
+ private void initTapEvents () {
164
+ try {
165
+ tapCommandMethod = sketch .getClass ().getMethod ("onTapCommand" ,
166
+ new Class [] {int .class , int .class , int .class , long .class });
167
+ } catch (Exception e ) {
168
+ tapCommandMethod = null ;
169
+ }
170
+ }
171
+
172
+
161
173
private void initComplications () {
162
174
try {
163
175
compUpdatedMethod = sketch .getClass ().getMethod ("complicationsUpdated" ,
164
- new Class [] {int .class , ComplicationData .class });
176
+ new Class [] {int .class , ComplicationData .class });
165
177
} catch (Exception e ) {
166
178
compUpdatedMethod = null ;
167
179
}
@@ -228,9 +240,7 @@ public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int he
228
240
229
241
230
242
@ Override
231
- public void onPeekCardPositionUpdate (Rect rect ) {
232
-
233
- }
243
+ public void onPeekCardPositionUpdate (Rect rect ) { }
234
244
235
245
236
246
@ Override
@@ -251,65 +261,21 @@ public void onDraw(Canvas canvas, Rect bounds) {
251
261
252
262
253
263
@ Override
254
- public void onTapCommand (
255
- @ TapType int tapType , int x , int y , long eventTime ) {
256
- switch (tapType ) {
257
- case WatchFaceService .TAP_TYPE_TOUCH :
258
- // The system sends the first command, TAP_TYPE_TOUCH, when the user initially touches the screen
259
- // if (withinTapRegion(x, y)) {
260
- // // Provide visual feedback of touch event
261
- // startTapHighlight(x, y, eventTime);
262
- // }
263
- sketch .postEvent (new MouseEvent (null , eventTime ,
264
- MouseEvent .PRESS , 0 ,
265
- x , y , LEFT , 1 ));
266
- invalidate ();
267
- break ;
268
-
269
-
270
- case WatchFaceService .TAP_TYPE_TAP :
271
- // Before sending the next command, the system judges whether the contact is a single tap,
272
- // which is the only gesture allowed. If the user immediately lifts their finger,
273
- // the system determines that a single tap took place, and forwards a TAP_TYPE_TAP event
274
- sketch .postEvent (new MouseEvent (null , eventTime ,
275
- MouseEvent .RELEASE , 0 ,
276
- x , y , LEFT , 1 ));
277
-
278
- // hideTapHighlight();
279
- // if (withinTapRegion(x, y)) {
280
- // // Implement the tap action
281
- // // (e.g. show detailed step count)
282
- // onWatchFaceTap();
283
- // }
284
-
285
-
286
- invalidate ();
287
- break ;
288
-
289
- case WatchFaceService .TAP_TYPE_TOUCH_CANCEL :
290
- // If the user does not immediately lift their finger, the system forwards a
291
- // TAP_TYPE_TOUCH_CANCEL event. Once the user has triggered a TAP_TYPE_TOUCH_CANCEL event,
292
- // they cannot trigger a TAP_TYPE_TAP event until they make a new contact with the screen.
293
- //hideTapHighlight();
294
-
295
- // New type of event...
296
- sketch .postEvent (new MouseEvent (null , eventTime ,
297
- MouseEvent .RELEASE , 0 ,
298
- x , y , LEFT , 1 ));
299
- invalidate ();
300
- break ;
301
-
302
- default :
303
- super .onTapCommand (tapType , x , y , eventTime );
304
- break ;
305
- }
264
+ public void onTouchEvent (MotionEvent event ) {
265
+ super .onTouchEvent (event );
266
+ if (sketch != null ) sketch .surfaceTouchEvent (event );
306
267
}
307
268
308
269
309
270
@ Override
310
- public void onTouchEvent (MotionEvent event ) {
311
- super .onTouchEvent (event );
312
- if (sketch != null ) sketch .surfaceTouchEvent (event );
271
+ public void onTapCommand (
272
+ @ TapType int tapType , int x , int y , long eventTime ) {
273
+ if (tapCommandMethod != null ) {
274
+ try {
275
+ tapCommandMethod .invoke (tapType , x , y , eventTime );
276
+ } catch (Exception e ) { }
277
+ invalidate ();
278
+ }
313
279
}
314
280
315
281
@@ -319,8 +285,7 @@ public void onComplicationDataUpdate(
319
285
if (compUpdatedMethod != null ) {
320
286
try {
321
287
compUpdatedMethod .invoke (complicationId , complicationData );
322
- } catch (Exception e ) {
323
- }
288
+ } catch (Exception e ) { }
324
289
invalidate ();
325
290
}
326
291
}
0 commit comments