Package totalcross.ui
Class Switch
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.Switch
-
- All Implemented Interfaces:
ControlAnimation.AnimationFinished,PathAnimation.SetPosition
public class Switch extends Control implements PathAnimation.SetPosition, ControlAnimation.AnimationFinished
This class implements the on/off switch present in many platforms
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description static intANIMATION_TIMEThe animation time.booleancenterTextSet to true to center text instead of moving it to left or rightintcolorBackOffText color to draw when on background or foreground, and when this switch is on or offintcolorBackOnText color to draw when on background or foreground, and when this switch is on or offintcolorBallOffColors used in materialintcolorBallOnColors used in materialintcolorBarOffColors used in materialintcolorBarOnColors used in materialintcolorForeOffText color to draw when on background or foreground, and when this switch is on or offintcolorForeOnText color to draw when on background or foreground, and when this switch is on or offjava.lang.StringtextBackOffText to draw when on background or foreground, and when this switch is on or offjava.lang.StringtextBackOnText to draw when on background or foreground, and when this switch is on or offjava.lang.StringtextForeOffText to draw when on background or foreground, and when this switch is on or offjava.lang.StringtextForeOnText to draw when on background or foreground, and when this switch is on or off-
Fields inherited from class totalcross.ui.Control
AFTER, alphaValue, appId, appObj, asContainer, asWindow, backColor, BEFORE, BOTTOM, BOTTOM_OF, BRIGHTER_BACKGROUND, callListenersOnAllTargets, CENTER, CENTER_OF, clearValueInt, clearValueStr, DARKER_BACKGROUND, DP, effect, enableUpdateScreen, esce, eventsEnabled, FILL, fillColor, FIT, floating, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, FONTSIZE, foreColor, height, ignoreInsets, isHighlighting, isTablet, KEEP, keepDisabled, keepEnabled, LEFT, next, nextTabControl, npParts, offscreen, offscreen0, onEventFirst, parent, PARENTSIZE, PARENTSIZEMAX, PARENTSIZEMIN, PREFERRED, prev, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, SCREENSIZE, SCREENSIZEMAX, SCREENSIZEMIN, setFont, setH, setRel, setW, setX, SETX_NOT_SET, setY, tempW, textShadowColor, TOP, translucentShape, transparentBackground, uiAdjustmentsBasedOnFontHeightIsSupported, uiAndroid, UICONST, uiFlat, uiHolo, uiMaterial, uiVista, visible, width, WILL_RESIZE, x, y
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetPreferredHeight()Returns the preferred height of this control.intgetPreferredWidth()Returns the preferred width of this control.booleanisOn()Returns true if this switch is ON.voidmoveSwitch(boolean toLeft)voidonAnimationFinished(ControlAnimation anim)voidonBoundsChanged(boolean b)Called after a setRect.voidonColorsChanged(boolean b)Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container.voidonEvent(Event event)Called to process key, pen, control and other posted events.voidonPaint(Graphics g)Called to draw the control.voidsetOn(boolean b)Change the on/off state.voidsetPos(int x, int y)Used by animation-
Methods inherited from class totalcross.ui.Control
_onEvent, addEnabledStateListener, addFocusListener, addFontChangeHandler, addGridListener, addHandler, addHighlightListener, addKeyListener, addListContainerListener, addMouseListener, addMultiTouchListener, addPenListener, addPressListener, addPushNotificationListener, addSizeChangeHandler, addTimer, addTimer, addTimerListener, addValueChangeHandler, addWindowListener, bringToFront, changeHighlighted, clear, contains, drawTranslucentBackground, getAbsoluteRect, getBackColor, getDoEffect, getEffectH, getEffectW, getEffectX, getEffectY, getEventListeners, getFont, getForeColor, getGap, getGraphics, getHeight, getNext, getParent, getParentWindow, getPos, getPressedEvent, getPrev, getRect, getSize, getTextShadowColor, getWidth, getX, getX2, getY, getY2, hadParentScrolled, handleGeographicalFocusChangeKeys, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isFloating, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, onFontChanged, onWindowPaintFinished, post, postEvent, postPressedEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHandler, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, reposition, repositionChildren, requestFocus, resetSetPositions, resetStyle, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setDoEffect, setEnabled, setFloating, setFocusLess, setFont, setForeColor, setNinePatch, setNinePatch, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
-
-
-
-
Field Detail
-
ANIMATION_TIME
public static int ANIMATION_TIME
The animation time. Set to 0 to disable animations in all Switches.
-
textBackOn
public java.lang.String textBackOn
Text to draw when on background or foreground, and when this switch is on or off
-
textForeOn
public java.lang.String textForeOn
Text to draw when on background or foreground, and when this switch is on or off
-
textBackOff
public java.lang.String textBackOff
Text to draw when on background or foreground, and when this switch is on or off
-
textForeOff
public java.lang.String textForeOff
Text to draw when on background or foreground, and when this switch is on or off
-
colorBackOn
public int colorBackOn
Text color to draw when on background or foreground, and when this switch is on or off
-
colorForeOn
public int colorForeOn
Text color to draw when on background or foreground, and when this switch is on or off
-
colorBackOff
public int colorBackOff
Text color to draw when on background or foreground, and when this switch is on or off
-
colorForeOff
public int colorForeOff
Text color to draw when on background or foreground, and when this switch is on or off
-
colorBallOn
public int colorBallOn
Colors used in material
-
colorBallOff
public int colorBallOff
Colors used in material
-
colorBarOn
public int colorBarOn
Colors used in material
-
colorBarOff
public int colorBarOff
Colors used in material
-
centerText
public boolean centerText
Set to true to center text instead of moving it to left or right
-
-
Method Detail
-
onBoundsChanged
public void onBoundsChanged(boolean b)
Description copied from class:ControlCalled after a setRect.- Overrides:
onBoundsChangedin classControl- Parameters:
b- If the bounds were changed due to a screen change (rotation, collapse)
-
onColorsChanged
public void onColorsChanged(boolean b)
Description copied from class:ControlCalled after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container. If colorsChanged is true, it was called from setForeColor/setBackColor/Container.add; otherwise, it was called from setEnabled- Overrides:
onColorsChangedin classControl
-
setOn
public void setOn(boolean b)
Change the on/off state.
-
isOn
public boolean isOn()
Returns true if this switch is ON. Note that, if this Switch has animations, you must call this method only after the animation finishes
-
moveSwitch
public void moveSwitch(boolean toLeft)
-
setPos
public void setPos(int x, int y)Used by animation- Specified by:
setPosin interfacePathAnimation.SetPosition
-
onPaint
public void onPaint(Graphics g)
Description copied from class:ControlCalled to draw the control. When this method is called, the graphics object passed has been translated into the coordinate system of the control and the area behind the control has already been painted.
-
onEvent
public void onEvent(Event event)
Description copied from class:ControlCalled to process key, pen, control and other posted events.
-
getPreferredHeight
public int getPreferredHeight()
Description copied from class:ControlReturns the preferred height of this control.- Overrides:
getPreferredHeightin classControl
-
getPreferredWidth
public int getPreferredWidth()
Description copied from class:ControlReturns the preferred width of this control.- Overrides:
getPreferredWidthin classControl
-
onAnimationFinished
public void onAnimationFinished(ControlAnimation anim)
- Specified by:
onAnimationFinishedin interfaceControlAnimation.AnimationFinished
-
-