Google Wear 2.0 : How to handle touch events in watchfaces ?

Google Wear 2.0 : How to handle touch events in watchfaces ?

                                      With the advancement in technology, We can see smartwatch users are increasing day by day, many companies manufacturing the smartwatches like Asus, Motorola, Armani, Misfit, Samsung, Fossil, Sony and so on.Google introduced its smartwatch OS  “Google Wear” version 2.0 in 2017. Since then, its adoption is on the rise.Before we start, let us understand what watch faces are. Watch faces are virtual dials which can be customized and changed by a user to suit their style and mood.


The smartwatch user can select a watch face from watch service OR a companion app on the paired phone.
Watchfaces also have categories.

  • Simple watch faces.
  • Complications Data Providers.





To handle touch event on watch faces, there is an override method called “onTapCommand” with following parameters :

  1. “Taptype”  – Types of Touch Events likes “Tap_Type_Tap”,”Tap_Type_Touch” and “Type_Tap_Cancel”.
  2. “TouchX” – The X-Axis value
  3. “TouchY” – The Y-Axis value
  4. “EventTime”

Important : We first have to set setAcceptsTapEvents(true) when watch face is initialized.


Steps : 

1. Set parameter true for setAcceptsTapEvents(true) function to accept touch event.

  	override fun onApplyWindowInsets(insets: WindowInsets) {

            val gravity = if (!insets.isRound) Gravity.START or Gravity.TOP else Gravity.CENTER

2. Handling Touch Events.

        override fun onTapCommand(@TapType tapType: Int, x: Int, y: Int, eventTime:Long) { 
             when(tapType) { 
                 WatchFaceService.TAP_TYPE_TAP-> {
                 WatchFaceService.TAP_TYPE_TOUCH-> { 
                     if(x >= ivImageView.x && 
                     y >= ivImageView.y && 
                     x <= (ivImageView .x + ivImageView.width) &&
                     y <= (ivImageView .y + ivImageView.height)) { 
                              //do your stuff 
                 WatchFaceService.TAP_TYPE_TOUCH_CANCEL -> { 
                else-> super.onTapCommand(tapType, x, y, eventTime) 

Download Sample Code :


Download App :

No Comments

Sorry, the comment form is closed at this time.