My first Android Library

Ethics - IT - Family

My first Android Library

November 8, 2017 IT 0


Yay, I just published my first open source Android Library for Android Wear! It’s just 137 lines of code so I’m probably not allowed to call it a real library; but hey! It’s a start.

You’ll find it here on GitHub. I published it to bintray and linked the repository to jcenter (no maven central yet) so its easily downloadable via a single compile / implementation line in your module gradle file.

Here is what it does

When calculating points on a watch face (e.g. position of the digits or the end points of needles) you might think that the formula for a point on a circle is enough. Wrong. Not with all those different formats:

  • Square 
  • Circle 
  • Circle with Chin (commonly used to place sensors)

You’ll want to target all three optimally without adding too much code. Here’s where the library comes in. Using a margin and an angle it will calculate the points for the current watch face. I know it doesn’t sound like much but I realised that my 8 grade trigonometry wasn’t that sharp anymore and maybe that’s also the case for others out there. The chin form especially was a little tricky (thanks David! 🙂 ). After initialisation the library knows the watch format and calls the according formula. So there is only one call required to calculate all three formats. Here is the emulator result of the sample project:

Even the needles can easily adapt their length depending on their angle. For example the needles on the square format get longer in the corners and become shorter again at 12, 3, 6, and 9 o Clock.

I was a little surprised that I didn’t find anything along these lines out there. I guess there just isn’t enough android wear out there yet.



Actually all except one task worked out just peachy. This one issue however got me very cranky! Check out the gradle configs in the GitHub project. It’s really a very minimalistic library so it should be easy to comprehend.

Here is what when wrong: The library was implemented in Kotlin resulting in an error in the javadoc generation (“javadoc: error – Illegal package name”). I’m not the first to come across this. I had to deactivate javadoc generation, then all publishing to bintray and linking to jcenter also went well.

tasks.withType(Javadoc).all {
    enabled = false


Let me know if you have anything to add! It’s my first library so I’m sure there are plenty of things I could have done better. Let me know!


image by chuttersnap

Leave a Reply

Your email address will not be published. Required fields are marked *