AnalogClock


public class AnalogClock
extends View

java.lang.Object
   ↳ android.view.View
     ↳ android.widget.AnalogClock


This class was deprecated in API level 23.
This widget is no longer supported; except for RemoteViews use cases like app widgets.

This widget displays an analogic clock with two hands for hours and minutes.

Summary

XML attributes

android:dial  
android:dialTint Tint to apply to the dial graphic. 
android:dialTintMode Blending mode used to apply the dial graphic tint. 
android:hand_hour  
android:hand_hourTint Tint to apply to the hour hand graphic. 
android:hand_hourTintMode Blending mode used to apply the hour hand graphic tint. 
android:hand_minute  
android:hand_minuteTint Tint to apply to the minute hand graphic. 
android:hand_minuteTintMode Blending mode used to apply the minute hand graphic tint. 
android:hand_second  
android:hand_secondTint Tint to apply to the second hand graphic. 
android:hand_secondTintMode Blending mode used to apply the second hand graphic tint. 
android:timeZone Specifies the time zone to use. 

Inherited XML attributes

Inherited constants

Inherited fields

Public constructors

AnalogClock(Context context)
AnalogClock(Context context, AttributeSet attrs)
AnalogClock(Context context, AttributeSet attrs, int defStyleAttr)
AnalogClock(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Public methods

BlendMode getDialTintBlendMode()
ColorStateList getDialTintList()
BlendMode getHourHandTintBlendMode()
ColorStateList getHourHandTintList()
BlendMode getMinuteHandTintBlendMode()
ColorStateList getMinuteHandTintList()
BlendMode getSecondHandTintBlendMode()
ColorStateList getSecondHandTintList()
String getTimeZone()

Indicates which time zone is currently used by this view.

void onVisibilityAggregated(boolean isVisible)

Called when the user-visibility of this View is potentially affected by a change to this view itself, an ancestor view or the window this view is attached to.

void setDial(Icon icon)

Sets the dial of the clock to the specified Icon.

void setDialTintBlendMode(BlendMode blendMode)

Specifies the blending mode used to apply the tint specified by setDialTintList(android.content.res.ColorStateList)} to the dial drawable.

void setDialTintList(ColorStateList tint)

Applies a tint to the dial drawable.

void setHourHand(Icon icon)

Sets the hour hand of the clock to the specified Icon.

void setHourHandTintBlendMode(BlendMode blendMode)

Specifies the blending mode used to apply the tint specified by setHourHandTintList(android.content.res.ColorStateList)} to the hour hand drawable.

void setHourHandTintList(ColorStateList tint)

Applies a tint to the hour hand drawable.

void setMinuteHand(Icon icon)

Sets the minute hand of the clock to the specified Icon.

void setMinuteHandTintBlendMode(BlendMode blendMode)

Specifies the blending mode used to apply the tint specified by setMinuteHandTintList(android.content.res.ColorStateList)} to the minute hand drawable.

void setMinuteHandTintList(ColorStateList tint)

Applies a tint to the minute hand drawable.

void setSecondHand(Icon icon)

Sets the second hand of the clock to the specified Icon, or hides the second hand if it is null.

void setSecondHandTintBlendMode(BlendMode blendMode)

Specifies the blending mode used to apply the tint specified by setSecondHandTintList(android.content.res.ColorStateList)} to the second hand drawable.

void setSecondHandTintList(ColorStateList tint)

Applies a tint to the second hand drawable.

void setTimeZone(String timeZone)

Sets the specified time zone to use in this clock.

Protected methods

void onAttachedToWindow()

This is called when the view is attached to a window.

void onDetachedFromWindow()

This is called when the view is detached from a window.

void onDraw(Canvas canvas)

Implement this to do your drawing.

void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height.

void onSizeChanged(int w, int h, int oldw, int oldh)

This is called during layout when the size of this view has changed.

Inherited methods

XML attributes

android:dial

android:dialTint

Tint to apply to the dial graphic.

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

Related methods:

android:dialTintMode

Blending mode used to apply the dial graphic tint.

Must be one of the following constant values.

ConstantValueDescription
add10Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D)
multiplyeMultiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc]
screenf[Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
src_atop9The tint is drawn above the drawable, but with the drawable\u2019s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc]
src_in5The tint is masked by the alpha channel of the drawable. The drawable\u2019s color channels are thrown out. [Sa * Da, Sc * Da]
src_over3The tint is drawn on top of the drawable. [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc]

Related methods:

android:hand_hour

android:hand_hourTint

Tint to apply to the hour hand graphic.

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

Related methods:

android:hand_hourTintMode

Blending mode used to apply the hour hand graphic tint.

Must be one of the following constant values.

ConstantValueDescription
add10Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D)
multiplyeMultiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc]
screenf[Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
src_atop9The tint is drawn above the drawable, but with the drawable\u2019s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc]
src_in5The tint is masked by the alpha channel of the drawable. The drawable\u2019s color channels are thrown out. [Sa * Da, Sc * Da]
src_over3The tint is drawn on top of the drawable. [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc]

Related methods:

android:hand_minute

android:hand_minuteTint

Tint to apply to the minute hand graphic.

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

Related methods:

android:hand_minuteTintMode

Blending mode used to apply the minute hand graphic tint.

Must be one of the following constant values.

ConstantValueDescription
add10Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D)
multiplyeMultiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc]
screenf[Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
src_atop9The tint is drawn above the drawable, but with the drawable\u2019s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc]
src_in5The tint is masked by the alpha channel of the drawable. The drawable\u2019s color channels are thrown out. [Sa * Da, Sc * Da]
src_over3The tint is drawn on top of the drawable. [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc]

Related methods:

android:hand_second

android:hand_secondTint

Tint to apply to the second hand graphic.

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

Related methods:

android:hand_secondTintMode

Blending mode used to apply the second hand graphic tint.

Must be one of the following constant values.

ConstantValueDescription
add10Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D)
multiplyeMultiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc]
screenf[Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
src_atop9The tint is drawn above the drawable, but with the drawable\u2019s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc]
src_in5The tint is masked by the alpha channel of the drawable. The drawable\u2019s color channels are thrown out. [Sa * Da, Sc * Da]
src_over3The tint is drawn on top of the drawable. [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc]

Related methods:

android:timeZone

Specifies the time zone to use. When this attribute is specified, the TextClock will ignore the time zone of the system. To use the user's time zone, do not specify this attribute. The default value is the user's time zone. Please refer to TimeZone for more information about time zone ids.

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

Related methods:

Public constructors

AnalogClock

Added in API level 1
public AnalogClock (Context context)

Parameters
context Context

AnalogClock

Added in API level 1
public AnalogClock (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

AnalogClock

Added in API level 1
public AnalogClock (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

AnalogClock

Added in API level 21
public AnalogClock (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

defStyleRes int

Public methods

getDialTintBlendMode

Added in API level 31
Deprecated in API level 23
public BlendMode getDialTintBlendMode ()

Related XML Attributes:

Returns
BlendMode the blending mode used to apply the tint to the dial drawable This value may be null.

getDialTintList

Added in API level 31
Deprecated in API level 23
public ColorStateList getDialTintList ()

Related XML Attributes:

Returns
ColorStateList the tint applied to the dial drawable This value may be null.

getHourHandTintBlendMode

Added in API level 31
Deprecated in API level 23
public BlendMode getHourHandTintBlendMode ()

Related XML Attributes:

Returns
BlendMode the blending mode used to apply the tint to the hour hand drawable This value may be null.

getHourHandTintList

Added in API level 31
Deprecated in API level 23
public ColorStateList getHourHandTintList ()

Related XML Attributes:

Returns
ColorStateList the tint applied to the hour hand drawable This value may be null.

getMinuteHandTintBlendMode

Added in API level 31
Deprecated in API level 23
public BlendMode getMinuteHandTintBlendMode ()

Related XML Attributes:

Returns
BlendMode the blending mode used to apply the tint to the minute hand drawable This value may be null.

getMinuteHandTintList

Added in API level 31
Deprecated in API level 23
public ColorStateList getMinuteHandTintList ()

Related XML Attributes:

Returns
ColorStateList the tint applied to the minute hand drawable This value may be null.

getSecondHandTintBlendMode

Added in API level 31
Deprecated in API level 23
public BlendMode getSecondHandTintBlendMode ()

Related XML Attributes:

Returns
BlendMode the blending mode used to apply the tint to the second hand drawable This value may be null.

getSecondHandTintList

Added in API level 31
Deprecated in API level 23
public ColorStateList getSecondHandTintList ()

Related XML Attributes:

Returns
ColorStateList the tint applied to the second hand drawable This value may be null.

getTimeZone

Added in API level 31
Deprecated in API level 23
public String getTimeZone ()

Indicates which time zone is currently used by this view.

Returns
String The ID of the current time zone or null if the default time zone, as set by the user, must be used

onVisibilityAggregated

Added in API level 24
Deprecated in API level 23
public void onVisibilityAggregated (boolean isVisible)

Called when the user-visibility of this View is potentially affected by a change to this view itself, an ancestor view or the window this view is attached to.
If you override this method you must call through to the superclass implementation.

Parameters
isVisible boolean: true if this view and all of its ancestors are View.VISIBLE and this view's window is also visible

setDial

Added in API level 31
Deprecated in API level 23
public void setDial (Icon icon)

Sets the dial of the clock to the specified Icon.

Parameters
icon Icon: This value cannot be null.

setDialTintBlendMode

Added in API level 31
Deprecated in API level 23
public void setDialTintBlendMode (BlendMode blendMode)

Specifies the blending mode used to apply the tint specified by setDialTintList(android.content.res.ColorStateList)} to the dial drawable. The default mode is BlendMode#SRC_IN.

Related XML Attributes:

Parameters
blendMode BlendMode: the blending mode used to apply the tint, may be null to clear tint

setDialTintList

Added in API level 31
Deprecated in API level 23
public void setDialTintList (ColorStateList tint)

Applies a tint to the dial drawable.

Subsequent calls to setDial(android.graphics.drawable.Icon) will automatically mutate the drawable and apply the specified tint and tint mode using Drawable#setTintList(ColorStateList).

Related XML Attributes:

Parameters
tint ColorStateList: the tint to apply, may be null to clear tint

setHourHand

Added in API level 31
Deprecated in API level 23
public void setHourHand (Icon icon)

Sets the hour hand of the clock to the specified Icon.

Parameters
icon Icon: This value cannot be null.

setHourHandTintBlendMode

Added in API level 31
Deprecated in API level 23
public void setHourHandTintBlendMode (BlendMode blendMode)

Specifies the blending mode used to apply the tint specified by setHourHandTintList(android.content.res.ColorStateList)} to the hour hand drawable. The default mode is BlendMode#SRC_IN.

Related XML Attributes:

Parameters
blendMode BlendMode: the blending mode used to apply the tint, may be null to clear tint

setHourHandTintList

Added in API level 31
Deprecated in API level 23
public void setHourHandTintList (ColorStateList tint)

Applies a tint to the hour hand drawable.

Subsequent calls to setHourHand(android.graphics.drawable.Icon) will automatically mutate the drawable and apply the specified tint and tint mode using Drawable#setTintList(ColorStateList).

Related XML Attributes:

Parameters
tint ColorStateList: the tint to apply, may be null to clear tint

setMinuteHand

Added in API level 31
Deprecated in API level 23
public void setMinuteHand (Icon icon)

Sets the minute hand of the clock to the specified Icon.

Parameters
icon Icon: This value cannot be null.

setMinuteHandTintBlendMode

Added in API level 31
Deprecated in API level 23
public void setMinuteHandTintBlendMode (BlendMode blendMode)

Specifies the blending mode used to apply the tint specified by setMinuteHandTintList(android.content.res.ColorStateList)} to the minute hand drawable. The default mode is BlendMode#SRC_IN.

Related XML Attributes:

Parameters
blendMode BlendMode: the blending mode used to apply the tint, may be null to clear tint

setMinuteHandTintList

Added in API level 31
Deprecated in API level 23
public void setMinuteHandTintList (ColorStateList tint)

Applies a tint to the minute hand drawable.

Subsequent calls to setMinuteHand(android.graphics.drawable.Icon) will automatically mutate the drawable and apply the specified tint and tint mode using Drawable#setTintList(ColorStateList).

Related XML Attributes:

Parameters
tint ColorStateList: the tint to apply, may be null to clear tint

setSecondHand

Added in API level 31
Deprecated in API level 23
public void setSecondHand (Icon icon)

Sets the second hand of the clock to the specified Icon, or hides the second hand if it is null.

Parameters
icon Icon: This value may be null.

setSecondHandTintBlendMode

Added in API level 31
Deprecated in API level 23
public void setSecondHandTintBlendMode (BlendMode blendMode)

Specifies the blending mode used to apply the tint specified by setSecondHandTintList(android.content.res.ColorStateList)} to the second hand drawable. The default mode is BlendMode#SRC_IN.

Related XML Attributes:

Parameters
blendMode BlendMode: the blending mode used to apply the tint, may be null to clear tint

setSecondHandTintList

Added in API level 31
Deprecated in API level 23
public void setSecondHandTintList (ColorStateList tint)

Applies a tint to the second hand drawable.

Subsequent calls to setSecondHand(android.graphics.drawable.Icon) will automatically mutate the drawable and apply the specified tint and tint mode using Drawable#setTintList(ColorStateList).

Related XML Attributes:

Parameters
tint ColorStateList: the tint to apply, may be null to clear tint

setTimeZone

Added in API level 31
Deprecated in API level 23
public void setTimeZone (String timeZone)

Sets the specified time zone to use in this clock. When the time zone is set through this method, system time zone changes (when the user sets the time zone in settings for instance) will be ignored.

Related XML Attributes:

Parameters
timeZone String: The desired time zone's ID as specified in TimeZone or null to user the time zone specified by the user (system time zone)

Protected methods

onAttachedToWindow

Added in API level 1
protected void onAttachedToWindow ()

This is called when the view is attached to a window. At this point it has a Surface and will start drawing. Note that this function is guaranteed to be called before onDraw(android.graphics.Canvas), however it may be called any time before the first onDraw -- including before or after onMeasure(int, int).
If you override this method you must call through to the superclass implementation.

onDetachedFromWindow

Added in API level 1
protected void onDetachedFromWindow ()

This is called when the view is detached from a window. At this point it no longer has a surface for drawing.
If you override this method you must call through to the superclass implementation.

onDraw

Added in API level 1
protected void onDraw (Canvas canvas)

Implement this to do your drawing.

Parameters
canvas Canvas: the canvas on which the background will be drawn This value cannot be null.

onMeasure

Added in API level 1
protected void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overridden by subclasses to provide accurate and efficient measurement of their contents.

CONTRACT: When overriding this method, you must call setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by measure(int, int). Calling the superclass' onMeasure(int, int) is a valid use.

The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override onMeasure(int, int) to provide better measurements of their content.

If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (getSuggestedMinimumHeight() and getSuggestedMinimumWidth()).

Parameters
widthMeasureSpec int: horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.

heightMeasureSpec int: vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.

onSizeChanged

Added in API level 1
protected void onSizeChanged (int w, 
                int h, 
                int oldw, 
                int oldh)

This is called during layout when the size of this view has changed. If you were just added to the view hierarchy, you're called with the old values of 0.

Parameters
w int: Current width of this view.

h int: Current height of this view.

oldw int: Old width of this view.

oldh int: Old height of this view.