AI2 Component  (Version nb184)
com.google.appinventor.components.runtime.Clock Class Reference
Inheritance diagram for com.google.appinventor.components.runtime.Clock:
com.google.appinventor.components.runtime.AndroidNonvisibleComponent com.google.appinventor.components.runtime.Component com.google.appinventor.components.runtime.AlarmHandler com.google.appinventor.components.runtime.OnStopListener com.google.appinventor.components.runtime.OnResumeListener com.google.appinventor.components.runtime.OnDestroyListener com.google.appinventor.components.runtime.Deleteable com.google.appinventor.components.runtime.Component

Public Member Functions

 Clock (ComponentContainer container)
 
 Clock ()
 
void Timer ()
 
int TimerInterval ()
 
void TimerInterval (int interval)
 
boolean TimerEnabled ()
 
void TimerEnabled (boolean enabled)
 
boolean TimerAlwaysFires ()
 
void TimerAlwaysFires (boolean always)
 
void alarm ()
 
Calendar MakeDate (int year, int month, int day)
 
Calendar MakeTime (int hour, int minute, int second)
 
Calendar MakeInstantFromParts (int year, int month, int day, int hour, int minute, int second)
 
void onStop ()
 
void onResume ()
 
void onDestroy ()
 
void onDelete ()
 
- Public Member Functions inherited from com.google.appinventor.components.runtime.AndroidNonvisibleComponent
HandlesEventDispatching getDispatchDelegate ()
 

Static Public Member Functions

static long SystemTime ()
 
static Calendar Now ()
 
static Calendar MakeInstant (String from)
 
static Calendar MakeInstantFromMillis (long millis)
 
static long GetMillis (Calendar instant)
 
static Calendar AddDuration (Calendar instant, long quantity)
 
static Calendar AddSeconds (Calendar instant, int quantity)
 
static Calendar AddMinutes (Calendar instant, int quantity)
 
static Calendar AddHours (Calendar instant, int quantity)
 
static Calendar AddDays (Calendar instant, int quantity)
 
static Calendar AddWeeks (Calendar instant, int quantity)
 
static Calendar AddMonths (Calendar instant, int quantity)
 
static Calendar AddYears (Calendar instant, int quantity)
 
static long Duration (Calendar start, Calendar end)
 
static long DurationToSeconds (long duration)
 
static long DurationToMinutes (long duration)
 
static long DurationToHours (long duration)
 
static long DurationToDays (long duration)
 
static long DurationToWeeks (long duration)
 
static int Second (Calendar instant)
 
static int Minute (Calendar instant)
 
static int Hour (Calendar instant)
 
static int DayOfMonth (Calendar instant)
 
static int Weekday (Calendar instant)
 
static String WeekdayName (Calendar instant)
 
static int Month (Calendar instant)
 
static String MonthName (Calendar instant)
 
static int Year (Calendar instant)
 
static String FormatDateTime (Calendar instant, String pattern)
 
static String FormatDate (Calendar instant, String pattern)
 
static String FormatTime (Calendar instant)
 

Additional Inherited Members

- Static Public Attributes inherited from com.google.appinventor.components.runtime.Component
static final String ASSET_DIRECTORY = "component"
 
static final int ALIGNMENT_NORMAL = 0
 
static final int ALIGNMENT_CENTER = 1
 
static final int ALIGNMENT_OPPOSITE = 2
 
static final int ACCELEROMETER_SENSITIVITY_WEAK = 1
 
static final int ACCELEROMETER_SENSITIVITY_MODERATE = 2
 
static final int ACCELEROMETER_SENSITIVITY_STRONG = 3
 
static final int BUTTON_SHAPE_DEFAULT = 0
 
static final int BUTTON_SHAPE_ROUNDED = 1
 
static final int BUTTON_SHAPE_RECT = 2
 
static final int BUTTON_SHAPE_OVAL = 3
 
static final int COLOR_NONE = 0x00FFFFFF
 
static final int COLOR_BLACK = 0xFF000000
 
static final int COLOR_BLUE = 0xFF0000FF
 
static final int COLOR_CYAN = 0xFF00FFFF
 
static final int COLOR_DKGRAY = 0xFF444444
 
static final int COLOR_GRAY = 0xFF888888
 
static final int COLOR_GREEN = 0xFF00FF00
 
static final int COLOR_LTGRAY = 0xFFCCCCCC
 
static final int COLOR_MAGENTA = 0xFFFF00FF
 
static final int COLOR_ORANGE = 0xFFFFC800
 
static final int COLOR_PINK = 0xFFFFAFAF
 
static final int COLOR_RED = 0xFFFF0000
 
static final int COLOR_WHITE = 0xFFFFFFFF
 
static final int COLOR_YELLOW = 0xFFFFFF00
 
static final int COLOR_DEFAULT = 0x00000000
 
static final String DEFAULT_VALUE_COLOR_NONE = "&H00FFFFFF"
 
static final String DEFAULT_VALUE_COLOR_BLACK = "&HFF000000"
 
static final String DEFAULT_VALUE_COLOR_BLUE = "&HFF0000FF"
 
static final String DEFAULT_VALUE_COLOR_CYAN = "&HFF00FFFF"
 
static final String DEFAULT_VALUE_COLOR_DKGRAY = "&HFF444444"
 
static final String DEFAULT_VALUE_COLOR_GRAY = "&HFF888888"
 
static final String DEFAULT_VALUE_COLOR_GREEN = "&HFF00FF00"
 
static final String DEFAULT_VALUE_COLOR_LTGRAY = "&HFFCCCCCC"
 
static final String DEFAULT_VALUE_COLOR_MAGENTA = "&HFFFF00FF"
 
static final String DEFAULT_VALUE_COLOR_ORANGE = "&HFFFFC800"
 
static final String DEFAULT_VALUE_COLOR_PINK = "&HFFFFAFAF"
 
static final String DEFAULT_VALUE_COLOR_RED = "&HFFFF0000"
 
static final String DEFAULT_VALUE_COLOR_WHITE = "&HFFFFFFFF"
 
static final String DEFAULT_VALUE_COLOR_YELLOW = "&HFFFFFF00"
 
static final String DEFAULT_VALUE_COLOR_DEFAULT = "&H00000000"
 
static final float FONT_DEFAULT_SIZE = 14
 
static final int LAYOUT_ORIENTATION_HORIZONTAL = ComponentConstants.LAYOUT_ORIENTATION_HORIZONTAL
 
static final int LAYOUT_ORIENTATION_VERTICAL = ComponentConstants.LAYOUT_ORIENTATION_VERTICAL
 
static final int SCALING_SCALE_PROPORTIONALLY = 0
 
static final int SCALING_SCALE_TO_FIT = 1
 
static final int TYPEFACE_DEFAULT = 0
 
static final int TYPEFACE_SANSSERIF = 1
 
static final int TYPEFACE_SERIF = 2
 
static final int TYPEFACE_MONOSPACE = 3
 
static final int LENGTH_PREFERRED = -1
 
static final int LENGTH_FILL_PARENT = -2
 
static final int LENGTH_UNKNOWN = -3
 
static final int LENGTH_PERCENT_TAG = -1000
 
static final int TOAST_LENGTH_SHORT = 0
 
static final int TOAST_LENGTH_LONG = 1
 
static final int DIRECTION_NORTH = 1
 
static final int DIRECTION_NORTHEAST = 2
 
static final int DIRECTION_EAST = 3
 
static final int DIRECTION_SOUTHEAST = 4
 
static final int DIRECTION_SOUTH = -1
 
static final int DIRECTION_SOUTHWEST = -2
 
static final int DIRECTION_WEST = -3
 
static final int DIRECTION_NORTHWEST = -4
 
static final int DIRECTION_NONE = 0
 
static final int DIRECTION_MIN = -4
 
static final int DIRECTION_MAX = 4
 
static float SLIDER_MIN_VALUE = 10
 
static float SLIDER_MAX_VALUE = 50
 
static float SLIDER_THUMB_VALUE = (SLIDER_MIN_VALUE + SLIDER_MAX_VALUE) / 2.0f
 
static final String DEFAULT_VALUE_TEXT_TO_SPEECH_COUNTRY = ""
 
static final String DEFAULT_VALUE_TEXT_TO_SPEECH_LANGUAGE = ""
 
- Protected Member Functions inherited from com.google.appinventor.components.runtime.AndroidNonvisibleComponent
 AndroidNonvisibleComponent (Form form)
 
- Protected Attributes inherited from com.google.appinventor.components.runtime.AndroidNonvisibleComponent
final Form form
 

Detailed Description

Image of the Clock component

Non-visible component that provides the instant in time using the internal clock on the phone. It can fire a timer at regularly set intervals and perform time calculations, manipulations, and conversions.

Operations on dates and times, such as from DatePicker and TimePicker, are accomplished through methods in Clock. Date and Time are represented as InstantInTime and Duration.

Instants are assumed to be in the device's local time zone. When they are converted to or from milliseconds, the milliseconds for a given Instance are calculated from January 1, 1970 in UTC (Greenwich Mean Time).

Methods to convert an Instant to text are also available. Acceptable patterns are empty string, MM/dd/YYYY HH:mm:ss a, or MMM d, yyyy HH:mm. The empty string will provide the default format, which is "MMM d, yyyy HH:mm:ss a" for FormatDateTime(Calendar, String), "MMM d, yyyy" for FormatDate(Calendar, String). To see all possible formats, please see here.

A note on combining date and time: In order to combine the date from one Instant and the time from another, for example from a DatePicker and TimePicker, extract the parts as text and use the text to create a new Instant. For example:

Example code blocks to combine date and time picker data

Definition at line 73 of file Clock.java.

Constructor & Destructor Documentation

◆ Clock() [1/2]

com.google.appinventor.components.runtime.Clock.Clock ( ComponentContainer  container)

Creates a new Clock component.

Parameters
containerignored (because this is a non-visible component)

Definition at line 88 of file Clock.java.

◆ Clock() [2/2]

com.google.appinventor.components.runtime.Clock.Clock ( )

Definition at line 105 of file Clock.java.

Member Function Documentation

◆ AddDays()

static Calendar com.google.appinventor.components.runtime.Clock.AddDays ( Calendar  instant,
int  quantity 
)
static

Definition at line 401 of file Clock.java.

◆ AddDuration()

static Calendar com.google.appinventor.components.runtime.Clock.AddDuration ( Calendar  instant,
long  quantity 
)
static

Definition at line 373 of file Clock.java.

◆ AddHours()

static Calendar com.google.appinventor.components.runtime.Clock.AddHours ( Calendar  instant,
int  quantity 
)
static

Definition at line 394 of file Clock.java.

◆ AddMinutes()

static Calendar com.google.appinventor.components.runtime.Clock.AddMinutes ( Calendar  instant,
int  quantity 
)
static

Definition at line 387 of file Clock.java.

◆ AddMonths()

static Calendar com.google.appinventor.components.runtime.Clock.AddMonths ( Calendar  instant,
int  quantity 
)
static

Definition at line 415 of file Clock.java.

◆ AddSeconds()

static Calendar com.google.appinventor.components.runtime.Clock.AddSeconds ( Calendar  instant,
int  quantity 
)
static

Definition at line 380 of file Clock.java.

◆ AddWeeks()

static Calendar com.google.appinventor.components.runtime.Clock.AddWeeks ( Calendar  instant,
int  quantity 
)
static

Definition at line 408 of file Clock.java.

◆ AddYears()

static Calendar com.google.appinventor.components.runtime.Clock.AddYears ( Calendar  instant,
int  quantity 
)
static

Definition at line 422 of file Clock.java.

◆ alarm()

void com.google.appinventor.components.runtime.Clock.alarm ( )

◆ DayOfMonth()

static int com.google.appinventor.components.runtime.Clock.DayOfMonth ( Calendar  instant)
static

Returns the day of the month.

Parameters
instantinstant to use day of the month of
Returns
day: [1...31]

Definition at line 536 of file Clock.java.

◆ Duration()

static long com.google.appinventor.components.runtime.Clock.Duration ( Calendar  start,
Calendar  end 
)
static

Returns the milliseconds by which end follows start (+ or -)

Parameters
startbeginning instant
endending instant
Returns
milliseconds

Definition at line 437 of file Clock.java.

◆ DurationToDays()

static long com.google.appinventor.components.runtime.Clock.DurationToDays ( long  duration)
static

Returns the duration converted from milliseconds to days.

Parameters
durationtime interval to convert
Returns
duration in days

Definition at line 481 of file Clock.java.

◆ DurationToHours()

static long com.google.appinventor.components.runtime.Clock.DurationToHours ( long  duration)
static

Returns the duration converted from milliseconds to hours.

Parameters
durationtime interval to convert
Returns
duration in hours

Definition at line 470 of file Clock.java.

◆ DurationToMinutes()

static long com.google.appinventor.components.runtime.Clock.DurationToMinutes ( long  duration)
static

Returns the duration converted from milliseconds to minutes.

Parameters
durationtime interval to convert
Returns
duration in minutes

Definition at line 459 of file Clock.java.

◆ DurationToSeconds()

static long com.google.appinventor.components.runtime.Clock.DurationToSeconds ( long  duration)
static

Returns the duration converted from milliseconds to seconds.

Parameters
durationtime interval to convert
Returns
duration in seconds

Definition at line 448 of file Clock.java.

◆ DurationToWeeks()

static long com.google.appinventor.components.runtime.Clock.DurationToWeeks ( long  duration)
static

Returns the duration converted from milliseconds to weeks.

Parameters
durationtime interval to convert
Returns
duration in weeks

Definition at line 492 of file Clock.java.

◆ FormatDate()

static String com.google.appinventor.components.runtime.Clock.FormatDate ( Calendar  instant,
String  pattern 
)
static

Converts and formats an instant into a string of date with the specified pattern. To learn more about valid patterns, please see SimpleDateFormat.

Parameters
instantinstant to format
patternformat of the date e.g. MM/DD/YYYY or MMM d, yyyy
Returns
formatted instant

Definition at line 630 of file Clock.java.

◆ FormatDateTime()

static String com.google.appinventor.components.runtime.Clock.FormatDateTime ( Calendar  instant,
String  pattern 
)
static

Converts and formats an instant into a string of date and time with the specified pattern. To learn more about valid patterns, please see SimpleDateFormat.

Parameters
instantinstant to format
patternformat of the date and time e.g. MM/dd/YYYY hh:mm:ss a, MMM d, yyyy HH:mm
Returns
formatted instant

Definition at line 609 of file Clock.java.

◆ FormatTime()

static String com.google.appinventor.components.runtime.Clock.FormatTime ( Calendar  instant)
static

Converts and formats the given instant into a string with the specified pattern. To learn more about valid patterns, please see SimpleDateFormat.

Parameters
instantinstant to format
Returns
formatted instant

Definition at line 650 of file Clock.java.

◆ GetMillis()

static long com.google.appinventor.components.runtime.Clock.GetMillis ( Calendar  instant)
static

Calendar property getter method: gets the raw millisecond representation of a Calendar.

Parameters
instantCalendar
Returns
milliseconds since 1/1/1970. @suppressdoc

Definition at line 368 of file Clock.java.

◆ Hour()

static int com.google.appinventor.components.runtime.Clock.Hour ( Calendar  instant)
static

Returns the hours for the given date.

Parameters
instantCalendar to use hours of
Returns
hours (range 0 - 23)

Definition at line 525 of file Clock.java.

◆ MakeDate()

Calendar com.google.appinventor.components.runtime.Clock.MakeDate ( int  year,
int  month,
int  day 
)

An instant in time specified by number year, number month, number day

Parameters
yearyear integer
monthmonth integer
dayday integer
Returns
Calendar instant @suppressdoc

Definition at line 262 of file Clock.java.

◆ MakeInstant()

static Calendar com.google.appinventor.components.runtime.Clock.MakeInstant ( String  from)
static

An instant in time specified by MM/DD/YYYY hh:mm:ss or MM/DD/YYYY or hh:mm where MM is the month (01-12), DD the day (01-31), YYYY the year (0000-9999), hh the hours (00-23), mm the minutes (00-59) and ss the seconds (00-59).

Parameters
fromstring to convert
Returns
date @suppressdoc

Definition at line 242 of file Clock.java.

◆ MakeInstantFromMillis()

static Calendar com.google.appinventor.components.runtime.Clock.MakeInstantFromMillis ( long  millis)
static

Create an Calendar from ms since 1/1/1970 00:00:00.0000 Probably should go in Calendar.

Parameters
millisraw millisecond number. @suppressdoc

Definition at line 354 of file Clock.java.

◆ MakeInstantFromParts()

Calendar com.google.appinventor.components.runtime.Clock.MakeInstantFromParts ( int  year,
int  month,
int  day,
int  hour,
int  minute,
int  second 
)

An instant in time specified by number year, number month, number day, number hour, number minute, number second

Parameters
yearyear integer
monthmonth integer
dayday integer
hourhour integer
minuteminute integer
secondminute integer
Returns
Calendar instant @suppressdoc

Definition at line 316 of file Clock.java.

◆ MakeTime()

Calendar com.google.appinventor.components.runtime.Clock.MakeTime ( int  hour,
int  minute,
int  second 
)

An instant in time specified by integer hour, integer minute, and integer second

Parameters
hourhour integer
minuteminute integer
secondsecond integer
Returns
Calendar instant since 1/1/1970 @suppressdoc

Definition at line 289 of file Clock.java.

◆ Minute()

static int com.google.appinventor.components.runtime.Clock.Minute ( Calendar  instant)
static

Returns the minutes for the given date.

Parameters
instantinstant to use minutes of
Returns
minutes (range 0 - 59)

Definition at line 514 of file Clock.java.

◆ Month()

static int com.google.appinventor.components.runtime.Clock.Month ( Calendar  instant)
static

Returns the number of the month for the given instant.

Parameters
instantinstant to use month of
Returns
number of month

Definition at line 571 of file Clock.java.

◆ MonthName()

static String com.google.appinventor.components.runtime.Clock.MonthName ( Calendar  instant)
static

Returns the name of the month for the given instant.

Parameters
instantinstant to use month of
Returns
name of month

Definition at line 583 of file Clock.java.

◆ Now()

static Calendar com.google.appinventor.components.runtime.Clock.Now ( )
static

Definition at line 225 of file Clock.java.

◆ onDelete()

void com.google.appinventor.components.runtime.Clock.onDelete ( )

Implements com.google.appinventor.components.runtime.Deleteable.

Definition at line 670 of file Clock.java.

◆ onDestroy()

void com.google.appinventor.components.runtime.Clock.onDestroy ( )

◆ onResume()

void com.google.appinventor.components.runtime.Clock.onResume ( )

◆ onStop()

void com.google.appinventor.components.runtime.Clock.onStop ( )

◆ Second()

static int com.google.appinventor.components.runtime.Clock.Second ( Calendar  instant)
static

Returns the seconds for the given instant.

Parameters
instantinstant to use seconds of
Returns
seconds (range 0 - 59)

Definition at line 503 of file Clock.java.

◆ SystemTime()

static long com.google.appinventor.components.runtime.Clock.SystemTime ( )
static

Returns the current system time in milliseconds.

Returns
current system time in milliseconds @suppressdoc

Definition at line 219 of file Clock.java.

◆ Timer()

void com.google.appinventor.components.runtime.Clock.Timer ( )

Default Timer event handler.

@suppressdoc

Definition at line 117 of file Clock.java.

◆ TimerAlwaysFires() [1/2]

boolean com.google.appinventor.components.runtime.Clock.TimerAlwaysFires ( )

TimerAlwaysFires property getter method.

@suppressdoc

Returns
true
if the timer event will fire even if the application is not on the screen

Definition at line 188 of file Clock.java.

◆ TimerAlwaysFires() [2/2]

void com.google.appinventor.components.runtime.Clock.TimerAlwaysFires ( boolean  always)

TimerAlwaysFires property setter method: instructs when to disable

@suppressdoc

Parameters
always

Definition at line 201 of file Clock.java.

◆ TimerEnabled() [1/2]

boolean com.google.appinventor.components.runtime.Clock.TimerEnabled ( )

Enabled property getter method.

Returns
true
indicates a running timer,
false
a stopped timer

Definition at line 160 of file Clock.java.

◆ TimerEnabled() [2/2]

void com.google.appinventor.components.runtime.Clock.TimerEnabled ( boolean  enabled)

Specifies whether the Timer() event should run.

Parameters
enabled

Definition at line 173 of file Clock.java.

◆ TimerInterval() [1/2]

int com.google.appinventor.components.runtime.Clock.TimerInterval ( )

Interval property getter method.

Returns
timer interval in ms

Definition at line 131 of file Clock.java.

◆ TimerInterval() [2/2]

void com.google.appinventor.components.runtime.Clock.TimerInterval ( int  interval)

Specifies the interval between subsequent Timer() events.

Note: Drift may occur over time and that the system may not honor the timing specified here if the app or another process on the phone is busy.

Parameters
intervaltimer interval in ms

Definition at line 147 of file Clock.java.

◆ Weekday()

static int com.google.appinventor.components.runtime.Clock.Weekday ( Calendar  instant)
static

Returns the weekday for the given instant.

Parameters
instantinstant to use day of week of
Returns
day of week: [1...7] starting with Sunday

Definition at line 548 of file Clock.java.

◆ WeekdayName()

static String com.google.appinventor.components.runtime.Clock.WeekdayName ( Calendar  instant)
static

Returns the name of the weekday for the given instant.

Parameters
instantinstant to use weekday of
Returns
weekday, as a string.

Definition at line 559 of file Clock.java.

◆ Year()

static int com.google.appinventor.components.runtime.Clock.Year ( Calendar  instant)
static

Returns the year of the given instant.

Parameters
instantinstant to use year of
Returns
year

Definition at line 594 of file Clock.java.


The documentation for this class was generated from the following file: