Quantcast
Channel: Envato Tuts+ Code - Mobile Development
Viewing all articles
Browse latest Browse all 1836

Build a Custom Clock Widget: Clock Design

$
0
0

Developing widgets for the Android platform involves a slightly different set of tasks than standard app development. In this series of tutorials, we will work through the process of developing a customizable analog clock widget. The clock will be based on the Android AnalogClock class and customized with your own graphics.


Tutorial Teaser

Step 1: Create Images for the Clock Dial

We are going to create three clock designs, each with a dial, minute hand, and hour hand. You can of course use your own designs instead, but feel free to use the image files we are using here to get started. The image files for each design at each density are included in the download link for this tutorial and will also be included in the download for Part 4.

First up is the clock dial. Remember that we specified the widget as being two cells wide and two cells high, resulting in a maximum size of 146dp (density-independent pixels). For this tutorial series we will create four versions of each image to suit the four density categories.

Instead of creating images for each density, you can alternatively use NinePatch graphics, which are bitmaps that can be scaled up and down to suit device densities, allowing you to create a single image for each design. The feasibility of using NinePatch depends partly on the content of the designs you are using but there are tools to help you create them if you wish.

It’s easiest if you start with the medium density, which should be a maximum of 146px on both axes. Here is the default clock dial we are using at medium density, which you can use either as a reference for your own designs or if you don’t want to create your own until later:

Clock Dial

In this case, the image is 146px on both axes, but you can make it smaller if you wish. We will specify a margin for devices running Android APIs less than 14 but will not supply a margin for devices on 14-plus, because at the more recent API levels an automatic margin is placed between widgets. You can use pretty much any design you like – your clock doesn’t even have to be circular. Including either marks or numbers indicating the hours on the dial is advisable from a usability perspective although it is not essential.

Here are the two alternative clock dial designs we will be using, one stone style and the other metallic, displayed here at medium density:

Clock Dial
Clock Dial

Once you have your clock dials designed, you can create alternative versions of each image for the different densities. Depending on your designs this may not be necessary, but we will be including tailored versions of each image for the designs in this tutorial. The following indicates the maximum size we are using for our widget on both the X and Y axes at each density:

  • Low density: 110px
  • Medium density: 146px
  • High density: 220px
  • Extra high density: 292px

Get the Full Series!

This tutorial series is available to Tuts+ Premium members only. Read a preview of this tutorial series on the Tuts+ Premium web site or login to Tuts+ Premium to access the full content.


Joining Tuts+ Premium. . .

For those unfamiliar, the family of Tuts+ sites runs a premium membership service called Tuts+ Premium. For $19 per month, you gain access to exclusive premium tutorials, screencasts, and freebies from Mobiletuts+, Nettuts+, Aetuts+, Audiotuts+, Vectortuts+, and CgTuts+. You’ll learn from some of the best minds in the business. Become a premium member to access this tutorial, as well as hundreds of other advanced tutorials and screencasts.



Viewing all articles
Browse latest Browse all 1836

Trending Articles