Simple Analog Clock

Simple clock view for displaying uh...time?
Alternatives To Simple Analog Clock
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Googleclock780
7 years ago1Java
The core of it is SVG .
Loaderspack Android90
4 years agoapache-2.0Kotlin
Android LoadersPack - a replacement of default android material progressbar with different loaders
Simple Analog Clock20
4 years agoapache-2.0Java
Simple clock view for displaying uh...time?
Compassview11
5 years ago1Java
Android Compass Widget
Timing Driven Variation Aware Clock Mesh Synthesis4
7 years agootherVerilog
Timing-Driven Variation-Aware Clock Mesh Synthesis Environment; programmed in Perl and TCL scripts
Alternatives To Simple Analog Clock
Select To Compare


Alternative Project Comparisons
Readme

simple-analog-clock

Release API Android Arsenal

A simple clock view. The clock drawables can be changed with your own custom assets.

Preview

Prerequisites

Your project must be using AndroidX artifacts instead of Support Libraries. Otherwise your project build will fail due to Manifest merger failed error.

Installation

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}
dependencies {
  implementation 'com.github.leondzn:simple-analog-clock:${version}'
}

Usage

XML

<com.leondzn.simpleanalogclock.SimpleAnalogClock
    android:id="@+id/clock"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="16dp"
    app:hourTint="@color/colorPrimary"                                        
    app:secondTint="@color/colorAccent" />

The following XML attributes are supported:

app:faceTint, app:hourTint, app:minuteTint, app:secondTint

to colorize the clock's face and hands.

You can manually set the individual hands' rotation value given a specific angle using

app:hourRotation, app:minuteRotation, app:secondRotation

You can also provide custom drawables for the clock using

app:faceDrawable, app:hourDrawable, app:minuteDrawable, app:secondDrawable

More info on providing custom drawables are detailed below.

Java

SimpleAnalogClock clock = findViewById(...);

clock.setSecondTint(...)
  .setTime(hour, minute, second);

You can rotate the clock hands individually using the following methods:

rotateHourHand(angle), rotateMinuteHand(angle), rotateSecondHand(angle)

Using the methods above requires you to calculate the corresponding angles for each time value.

To use exact time values, use the following methods:

setTime(int hour, int minute, int second) or setTime(int hour, int munute, int second, int millis)

Using the millisecond parameter allows for the second hand to turn more smoothly as opposed to traditional analog clock "ticking" behavior.

Similar to the XML attributes, you can also provide custom drawables to use with the analog clock:

setFaceDrawable(Drawable), setHourDrawable(Drawable), setMinuteDrawable(Drawable), setSecondDrawable(Drawable)

Using Custom Drawables

Simple default clock face and hands are provided but you are free to use custom drawables provided that they follow these guidelines:

  • All 4 layers (face, hour hand, minute hand, second hand) should all be the same image size
  • The images should be square
  • Clock hands should be pointing at the 12 o' clock position
  • SVG or PNG can be used

Example:

Face Drawable

Face

Hour Drawable

Short hand

Minute Drawable

Long hand

Second Drawable

Second hand

Popular Clock Projects
Popular Xml Projects
Popular User Interface Components Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Java
Xml
Time
Face
Clock