Loading...
Home
  • News
    • Android News
    • Droidcon News
  • Conferences
    • Conference Videos
    • Upcoming Conferences
    • Become a Partner
    • Past Events
  • Community
    • droidcon Team
    • Forums
    • Keep Me Informed
    • How to Hold a Droidcon
  • Jobs
    • jobs.droidcon.com
Sign In

Global CSS

 

Build watch faces for Wear OS

 

 
Nikit Bhandari
Android developer -> Find more about me here https://nikit19.github.io/
Tweet
Share
 

 

Wear OS, previously called Android Wear, is a version of Google’s Android operating system designed for smartwatches. There are millions of devices currently using Wear OS and I believe this is only going to increase. In this blog post you will understand everything that you need to know to publish a watch face in Wear OS.

When you create a new Android project and select the Wear option, Android Studio will provide you with all the code that you need to create a watch face, you just need to understand it. So let’s get started!

The AndroidManifest.xml file is almost the same as you will see in any other app. At the top you will notice two permissions.

 

The first permission is required by all watch faces and the second permission is required only if you are displaying some data in the watch face through a complication.

 

This is another important tag that needs to be declared in the manifest. This is the only way to identify a Wear OS app from an Android app.

Watch faces in Wear OS are implemented as services. So we need to register our watch face service in the manifest.

 

Let’s dive into the code and start exploring the MyWatchFace.kt file.

 

We are initialising all our variables in the onCreate. We are initialising our variables only once when our WatchFace service is created and then we are re using them, this helps us to improve battery life. Battery life of smartwatches is usually only 1/10th of a smart phone, so it is important that we take necessary steps to improve the battery life.

The Wear OS devices will switch between two modes, ie Ambient mode and the Interactive mode. In the Ambient mode, the device will be running on low power mode whereas in the Interactive, the user can actively use the device.

 

You can access the onAmbientModeChanged method to adjust the style of the watch face according to the mode.

 

onSurfaceChanged is where all the graphical computations should happen. This is the first time we have access to the device’s height and width. It is a good practice to use these measurements for our calculations instead of using hardcoded values. We can use it to calculate the centre of the watch face, height of hour and minute hands etc. We should also create our Bitmap here.

Now we will understand how to implement the onDraw method. This method provides us with a canvas which we can use to draw our background bitmap and the watch hands. We will also calculate when the hands of the clock should be rotated here.

 

The users of your watch face can be travelling from one timezone to another. We need to handle this case too. We need to create a BroadcastReceiver to check if the timezone of the user has changed. We can check the timezone in the onVisibilityChanged method. This method tells whether our watch face is visible or not. We can check if the timezone has changed while our watch face wasn’t visible.

 

This is pretty much all that you need to know about the Wear OS ecosystem to build your own watch face. The project from where all the above code snippets are, is linked below. Feel free to fork and create your own watch faces with it.

nikit19/WatchFace

Contribute to nikit19/WatchFace development by creating an account on GitHub.

github.com

 

There are few things that I would like to highlight about Wear OS:

  • You have the option creating a watch face with Kotlin or Java and I know we all love Kotlin but the size of the apk will increase if you chose Kotlin. In my experience the size of the apk was around 600 KB more when I made a project in Kotlin. Smart watches have limited storage so we should try our best to keep the project size as small as possible.
  • All Wear OS apps are reviewed after you publish them. So even after publishing the app in the PlayStore, it won’t be available unless it gets approved. So it usually takes a few days before the watch face is approved and becomes available to all the users.

Screenshot of the Play Console :(
  • If you set the minSdkVersion to 25, your watch face will only be available to devices running Wear OS 2.0 or higher. If you want your watch face to be available to all the Wear OS devices set the minSdkVersion to 23.
  • In Wear 1.x, watch apps were distributed by embedding it inside a phone app but now Wear OS allows us to distribute standalone Wear apps in the same way for both Wear 1.0 and 2.0.
  • Wear OS devices will not always have a circular screen. It may be square shaped also. So… you have to handle that case also. It’s a good practice to create 2 dimensions, one for circular devices and the other for square devices.
  • The process of publishing a watch face in PlayStore is exactly the same as publishing an app, you just have to specify that it is an app for the Wear OS platform.

I have linked below a few watch faces made by me feel free to check them out!

 

Digital Watch Face - Apps on Google Play

Features: Support both round and square watch Support ambient mode More customisation options will be added in future…

play.google.com

 

Analog Watch Face - Apps on Google Play

Features: Support both round and square watch Support ambient mode More customisation options will be added in future…

play.google.com

 

Tags: Android, Wear OS, Watchface, Android App Development, AndroidDev

 

View original article at: 


Published July 13, 2019

 

Android News
Creating an Expandable Floating Action Button in Android — Part 2
Creating an Expandable Floating Action Button in Android — Part 2

By TJ

It’s been a little over a year since the post above, and a lot of things can change in a year. Specifically, I’ve since moved to Kotlin as my primary language for Android development, and I’ve found a cleaner and more aesthetically pleasing way to create an expandable floating action button in Android; let’s talk more about the latter.

 

By ProAndroidDev -
Android News
Phantom Types in Kotlin
Phantom Types in Kotlin

By Danny Preussler

While working on my KotlinConf presentation about types I stumbled upon this post by Maximiliano Felice about Phantom types with Scala. The idea: prevent objects from having an illegal state or forbid illegal operation at compile time. The example given was a class Door. A door is either open or closed. In Kotlin this would look like:

By ProAndroidDev -
Android News
Exploring the new CameraX library in Android
Exploring the new CameraX library in Android

By Siva Ganesh Kantamani

CameraX is a Jetpack support library which is in Alpha at present. CameraX library is build to simplify the usage of camera features in app development. CameraX provides an in-depth analysis of what camera is pointed at through Image Analysis and also provides a way to use built-in device camera features like HDR, portrait mode and so on through extensions.

By ProAndroidDev -
Android News
A fusion between WorkManager and AlarmManager
A fusion between WorkManager and AlarmManager

By Stavro Xhardha

Android’s WorkManager has been around for a while. However my own expectations about it were a little higher. I wished that the WorkManager could fire events at exact timing. But since it was made to respect doze mode, I should respect that too. That means that if the phone is idle, the WorkManager  won’t run.

By ProAndroidDev -

Follow us

Team droidcon

Get in touch with us

Write us an Email

 

 

Quicklinks

> Code of Conduct

> Terms and Conditions

> How to hold a conference

> FAQs

> Imprint

Droidcon is a registered trademark of Mobile Seasons GmbH Copyright © 2019. All rights reserved.

powered by Breakpoint One