Based on xxv/24AnalogWidget
This is a super easy to implement and highly customizable analog clock library
Add this to your app build.gradle file
dependencies {
compile 'com.tomerrosenfeld.customanalogclockview:custom-analog-clock-view:1.1'
}
In your layout:
<com.tomerrosenfeld.customanalogclockview.CustomAnalogClock
android:id="@+id/analog_clock"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:default_watchface="true" />
In your activity:
CustomAnalogClock customAnalogClock = (CustomAnalogClock) findViewById(R.id.analog_clock);
customAnalogClock.setAutoUpdate(true);
To adjust the size of the clock
setScale(float scale)
So for example
setScale(0.5f) //to make the clock smaller
setScale(2f) //to make the clock larger
You can completely change the look of the widget by using the init function:
init(Context context, @DrawableRes int watchFace, @DrawableRes int hourHand, @DrawableRes int minuteHand, int alpha, boolean is24, boolean hourOnTop)
So for example:
customAnalogClock.init(MainActivity.this, R.drawable.default_face, R.drawable.default_hour_hand, R.drawable.default_minute_hand, 0, false, false);
In this example, we are creating an analog clock with custom drawables, the background is R.drawable.default_face
, the hour hand is R.drawable.default_hour_hand
and the minute hand is R.drawable.default_minute_hand
.
In addition to that, we chose to keep the clock 12H, like a standard clock, if you want to make it 24H, pass true
for is24.
The alpha parameter sets the opacity of the hour hand, set it to 0 to make it completely visible (alpha can vary between 1-254).
The hourOnTop parameter determines the hour hand placement. If set to true, the hour hand will appear on top of the minutes hand, otherwise, the minute hand will show up on top.
I suggest that you base your clock drawables on my default ones:
Using this library I was easily able to create these analog clock widgets:
Pebble Theme | S7 Theme | Default |
---|---|---|
Custom Analog Clock View is licensed under the GNU v3 Public License.