public class

TimePicker

extends View
java.lang.Object
   ↳ com.neomades.ui.View
     ↳ com.neomades.ui.TimePicker

Class Overview

This view lets the user pick a Time. Only hours and minutes are available.

Default properties

By default, the following properties are applied to a new TimePicker:

  • focusable (limited to some devices)
  • clickable
  • enabled
  • current time
  • 24H mode
  • width content stretch : MATCH_CONTENT.
  • height content stretch : MATCH_CONTENT.
  • content alignment : HCENTER|VCENTER.

Handling Time Changes

 TimeChangedListener timeListener = new TimeChangedListener() {
 	public void onTimeChanged(View source, int hours, int minutes, int seconds) {
 		// do some stuff
 	}
 };
 TimePicker myTimePicker = new TimePicker();
 myTimePicker.setDateChangedListener(dateListener);
 

Time Picker modes

The TimePicker has two modes : MODE_INLINE, MODE_DIALOG_PICKER. The MODE_INLINE enables wrapping TimePicker control inside a Layout. The MODE_DIALOG_PICKER mode shows a button with the selected time, when the end-user click him, a dialog is displayed : TimePickerDialog.

Default properties

By default, the following properties are applied to a new TimePicker:

  • focusable (limited to some devices)
  • clickable
  • enabled
  • Selected date (today)
  • no icon
  • width content stretch : MATCH_CONTENT.
  • height content stretch : MATCH_CONTENT.
  • content alignment : HCENTER|VCENTER.
  • mode : MODE_DIALOG_PICKER

Summary

XML Attributes
Attribute Name Related Method Description
contentAlignment setContentAlignment(int) A combination of alignment values (eg: TOP|LEFT)  
font setFont(Font) Font resource id: Res.font.FONT_XXXX  
hours setHours(int) If the view could be clicked  
minutes setMinutes(int)  
textColor setTextColor(Color) #AARRGGBB or a color  
textSize setTextSize(int) a size in dp  
[Expand]
Inherited XML Attributes
From class com.neomades.ui.View
Constants
int MODE_DIALOG_PICKER A button is displayed with the value of Time.
int MODE_INLINE The TimePicker inputs will be displayed directly in the layout.
[Expand]
Inherited Constants
From interface com.neomades.ui.Alignment
From interface com.neomades.ui.StretchMode
Public Constructors
TimePicker()
Constructs a new time picker with the time set to the current time, and 24 hours mode activated by default.
TimePicker(int mode)
Constructs a new time picker with the time set to the current time, and 24 hours mode activated by default.
TimePicker(int hours, int minutes, boolean mode)
Constructs a new time picker with the time set to the given parameters.
Public Methods
int getHours()
Returns the hours of this time picker (always between 0 and 23)
int getMinutes()
Returns the minutes of this time picker (always between 0 and 59)
boolean is24HoursMode()
Returns if the time picker is configured in the 24 hours mode.
static void openChooser(View origin, Calendar selectedTime, boolean is24hoursMode, TimeChangedListener listener)
Opens a dialog to choose a Time.
void set24HoursMode(boolean mode)
Sets the time picker mode to 24 hours.
void setContentAlignment(int alignment)
Sets the alignment of the text or icon in the button.
void setFont(Font font)
Sets the timepicker's button text font.
void setHours(int hours)
Sets the hours of this time picker (always between 0 and 23)
void setMinutes(int minutes)
Sets the minutes of this time picker (always between 0 and 59)
void setTextColor(Color textColor)
Sets the TimePicker text color.
void setTextSize(int sizeInDp)
Sets the text size to a given value (in dp).
void setTimeChangedListener(TimeChangedListener listener)
Sets the listener for this TimePicker, that will be notified if the time changes.
[Expand]
Inherited Methods
From class com.neomades.ui.View
From class java.lang.Object

XML Attributes

contentAlignment

A combination of alignment values (eg: TOP|LEFT)

Related Methods

font

Font resource id: Res.font.FONT_XXXX

Related Methods

hours

If the view could be clicked

Related Methods

minutes

Related Methods

textColor

#AARRGGBB or a color

Related Methods

textSize

a size in dp

Related Methods

Constants

public static final int MODE_DIALOG_PICKER

A button is displayed with the value of Time. When the user clicks on the button, a Dialog is displayed in order to pick a Time.

Default mode for all platforms.

Constant Value: 0 (0x00000000)

public static final int MODE_INLINE

The TimePicker inputs will be displayed directly in the layout.

In this mode, text customization methods and background customization methods do nothing (text color, text font, text size, text alignment, background color...).

Constant Value: 1 (0x00000001)

Public Constructors

public TimePicker ()

Constructs a new time picker with the time set to the current time, and 24 hours mode activated by default.

The mode used here is MODE_DIALOG_PICKER.

public TimePicker (int mode)

Constructs a new time picker with the time set to the current time, and 24 hours mode activated by default.

This constructor enables to choose between MODE_DIALOG_PICKER and MODE_INLINE. The default mode is MODE_DIALOG_PICKER.

public TimePicker (int hours, int minutes, boolean mode)

Constructs a new time picker with the time set to the given parameters.

Parameters
hours the hour to set to this time picker. This value must be between 0 and 23.
minutes the minute to set to this time picker. This value must be between 0 and 59.
mode the 24 hours mode to set (true to enable the 24Hours mode, false to enable the AM/PM mode)

Public Methods

public int getHours ()

Returns the hours of this time picker (always between 0 and 23)

Related XML Attributes
Returns
  • the hours of this time picker (always between 0 and 23)

public int getMinutes ()

Returns the minutes of this time picker (always between 0 and 59)

Related XML Attributes
Returns
  • the minutes of this time picker (always between 0 and 59)

public boolean is24HoursMode ()

Returns if the time picker is configured in the 24 hours mode.

Returns
  • true if the mode is 24 hours, else false (AM/PM mode)

public static void openChooser (View origin, Calendar selectedTime, boolean is24hoursMode, TimeChangedListener listener)

Opens a dialog to choose a Time.

Parameters
origin the view from here the dialog should be opened in iOS.
selectedTime the selected time when the chooser will be shown at the user
is24hoursMode true for 24H mode, false for AM/PM
listener the callback used to get the selected date or null
Throws
NullPointerException for iOS if the origin parameter is null.

public void set24HoursMode (boolean mode)

Sets the time picker mode to 24 hours. The time will be displayed differently, according to the mode.

Parameters
mode true to set the mode to 24 hours, else false (mode AM/PM)
Throws
CrossThreadException if the method is called from outside the UI-Thread

public void setContentAlignment (int alignment)

Sets the alignment of the text or icon in the button. The parameter is a combination of values from Alignment

Only available in MODE_DIALOG_PICKER.

Related XML Attributes
Parameters
alignment The new alignment of the timepicker's text
Throws
CrossThreadException if the method is called from outside the UI-Thread

public void setFont (Font font)

Sets the timepicker's button text font.

Related XML Attributes
Parameters
font new font for the text
Throws
CrossThreadException if the method is called from outside the UI-Thread
NullPointerException if the font parameter is null

public void setHours (int hours)

Sets the hours of this time picker (always between 0 and 23)

Related XML Attributes
Parameters
hours the hours to set (always between 0 and 23)
Throws
CrossThreadException if the method is called from outside the UI-Thread

public void setMinutes (int minutes)

Sets the minutes of this time picker (always between 0 and 59)

Related XML Attributes
Parameters
minutes the minutes to set (always between 0 and 59)
Throws
CrossThreadException if the method is called from outside the UI-Thread

public void setTextColor (Color textColor)

Sets the TimePicker text color.

Related XML Attributes
Parameters
textColor new color for the text
Throws
CrossThreadException if the method is called from outside the UI-Thread
NullPointerException if the parameter is null

public void setTextSize (int sizeInDp)

Sets the text size to a given value (in dp).

Related XML Attributes
Parameters
sizeInDp size to set to the text

public void setTimeChangedListener (TimeChangedListener listener)

Sets the listener for this TimePicker, that will be notified if the time changes.

Parameters
listener the listener