public class ToggleHelper extends java.lang.Object implements OnStateChangeListener
Constructor and Description |
---|
ToggleHelper(GenericListener helperListener)
Creates a toggle helper.
|
ToggleHelper(GenericListener helperListener,
ToggleModel toggle)
Creates a toggle helper with a referent toggle model.
|
ToggleHelper(GenericListener helperListener,
ToggleModel toggle,
java.lang.String group)
Creates a toggle helper with a referent toggle model and a group.
|
Modifier and Type | Method and Description |
---|---|
void |
addOnStateChangeListener(OnStateChangeListener listener)
Adds a listener on the state change event of the toggle.
|
ToggleModel |
getToggle()
Gets the toggle.
|
boolean |
handleEvent(int event) |
boolean |
isChecked()
Gets whether or not the toggle button is checked.
|
boolean |
isPressed()
Gets the pressed.
|
void |
onStateChange(boolean newState)
Invoked when the target of the listener has changed its state.
|
void |
removeOnStateChangeListener(OnStateChangeListener listener)
Removes a listener on the state change event of the toggle.
|
void |
setChecked(boolean checked)
Sets the state of the toggle.
|
void |
setGroup(java.lang.String groupName)
Sets the group of this toggle.
|
void |
setPressed(boolean pressed)
Sets the pressed state of the toggle.
|
void |
toggle()
Changes the state of the toggle to the inverse of the current state.
|
public ToggleHelper(GenericListener helperListener)
helperListener
- the listener to notify when the state changed.public ToggleHelper(GenericListener helperListener, ToggleModel toggle)
Events received by the toggle button are forwarded to the referent toggle.
helperListener
- the listener to notify when the state changed.toggle
- the referent toggle.java.lang.NullPointerException
- if the given toggle is null
.public ToggleHelper(GenericListener helperListener, ToggleModel toggle, @Nullable java.lang.String group)
Events received by the toggle button are forwarded to the referent toggle.
The toggle is registered in the group with the given name.
helperListener
- the listener to notify when the state changed.toggle
- the referent toggle.group
- the name of the toggle group.java.lang.NullPointerException
- if the given toggle is null
.public ToggleModel getToggle()
public void setGroup(@Nullable java.lang.String groupName)
For each name, a toggle group is created to group the toggles (only one toggle selected at a time).
groupName
- the name of the toggle group.ToggleGroup
public void addOnStateChangeListener(OnStateChangeListener listener)
listener
- the listener to add.java.lang.NullPointerException
- if the given listener is null
.public void removeOnStateChangeListener(OnStateChangeListener listener)
listener
- the listener to add.public void setChecked(boolean checked)
If the toggle is not enabled or is already in the given state, nothing change.
checked
- the new state of the toggle.public void toggle()
If the toggle is not enabled, nothing change.
public boolean isChecked()
true
if the toggle button is checked otherwise false
.public boolean isPressed()
public void setPressed(boolean pressed)
pressed
- the new pressed state of the toggle.public void onStateChange(boolean newState)
OnStateChangeListener
onStateChange
in interface OnStateChangeListener
newState
- the new state of the listened object.public boolean handleEvent(int event)