fbpx

Our Story

Enterprise solutions to empower people.
Company was established in the year 2012. Provide high quality cost effective services to the community and businesses. Goldenmace is a company with young, energetic, curious and committed minds who are excited about solving complex business problems, ethically. We build long term relationships and provide quality products and services that will exceed the expectations of all our customers. We deliver secure, reliable and scalable applications that help businesses excel in today’s rapidly evolving economy.

Working Hours

Monday to Saturday ................. 09:00 - 18:00

Sunday ......................... CLOSED

 

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.

 

 

HOW TO HANDLE TOUCH EVENTS? 

 

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) {
            super.onApplyWindowInsets(insets)

            val gravity = if (!insets.isRound) Gravity.START or Gravity.TOP else Gravity.CENTER
            setWatchFaceStyle(WatchFaceStyle
                    .Builder(this@WatchfaceCalculator)
                    .setStatusBarGravity(gravity)
                    .setAcceptsTapEvents(true)
                    .setAccentColor(-0xad9302)
                    .build())
          
        }

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 :
https://github.com/Goldenmace/Watchface-Touch-Sample

 

Download App :
https://play.google.com/store/apps/details?id=com.gmits.watchfacetools

No Comments

Sorry, the comment form is closed at this time.