public class Bar extends Container
Bar
without title and buttons.
You can add or remove buttons, and change the title text; the title text can have an icon at left.
Here's an example of how to use it, taken from the old UIGadgets sample:
final Bar h1,h2; Font f = Font.getFont(true,Font.NORMAL_SIZE+2); h1 = new Bar("fakeboot"); h1.canSelectTitle = true; h1.setFont(f); h1.setBackForeColors(0x0A246A,Color.WHITE); h1.addButton(new Image("ic_dialog_alert.png")); h1.addButton(new Image("ic_dialog_info.png")); add(h1, LEFT,0,FILL,PREFERRED); // use 0 instead of TOP to overwrite the default menu areaA
ControlEvent.PRESSED
is sent to the caller, and the button index can be retrieved using the getSelectedIndex()
method.
By default, the background is shaded. You can change it to plain using h1.backgroundStyle = BACKGROUND_SOLID;
.Modifier and Type | Class and Description |
---|---|
class |
Bar.BarButton
A Bar's button.
|
Control.TranslucentShape
Modifier and Type | Field and Description |
---|---|
boolean |
canSelectTitle
Set to
true to allow the title to be selected and send events. |
boolean |
drawBorders
Set to
false to remove the borders |
int |
landscapePrefH
The preferred height on portrait or landscape, in pixels.
|
int |
portraitPrefH
The preferred height on portrait or landscape, in pixels.
|
int |
titleAlign
The title horizontal alignment (
LEFT , CENTER , or RIGHT ). |
alwaysEraseBackground, BACKGROUND_CYLINDRIC_SHADED, BACKGROUND_SHADED, BACKGROUND_SHADED_INV, BACKGROUND_SOLID, backgroundStyle, BORDER_LOWERED, BORDER_NONE, BORDER_RAISED, BORDER_ROUNDED, BORDER_SIMPLE, BORDER_TOP, borderColor, borderRadius, children, controlFound, finishedStart, ignoreOnAddAgain, ignoreOnRemove, insets, lastH, lastScreenWidth, lastW, lastX, lastY, numChildren, started, tabOrder, tail, TRANSITION_TIME
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
Constructor and Description |
---|
Bar()
Constructs a
Bar object without a title. |
Bar(java.lang.String title)
Constructs a
Bar object with the given title. |
Modifier and Type | Method and Description |
---|---|
int |
addButton(Icon icon,
boolean atRight) |
int |
addButton(Image icon)
Adds an image button at right.
|
int |
addButton(Image icon,
boolean atRight)
Adds an image button at the given position.
|
int |
addControl(Control c)
Adds a control to the bar at right.
|
int |
addControl(Control c,
boolean atRight)
Adds a control to the bar.
|
void |
assignBackKeyToButton(int idx)
Assigns the BACK key on Android (mapped to
SpecialKeys.ESCAPE ) to the given button. |
void |
createSpinner(int color)
Creates a spinner with the following color.
|
protected int |
getButtonWidth(int idx)
Override this method to return a customized button's width
|
Image |
getIcon()
Returns the icon set (and possibly resized) with setIcon, or null if none was set
|
int |
getPreferredHeight()
Returns the preferred height of this control.
|
int |
getPreferredWidth()
Returns the preferred width of this control.
|
int |
getSelectedIndex()
Returns the selected button, or -1 if none was selected.
|
java.lang.String |
getTitle()
Retrieves the current title.
|
int |
getTitleWidth() |
void |
initUI()
Called to initialize the user interface of this container.
|
void |
onColorsChanged(boolean colorsChanged)
Called after a
setEnabled() , setForeColor() , or setBackColor() ; or when a control has been added to a
container. |
void |
onFontChanged()
Called after a setFont
|
void |
removeButton(int index)
Removes a button at the given index, starting at 1.
|
void |
reposition()
Repositions this control, calling again
setRect() with the original parameters. |
void |
setButtonRepeatRate(int idx,
int ms)
Sets the given button with an auto-repeat interval in the given milliseconds.
|
void |
setButtonsVisible(boolean visible,
int... indexes)
Shows or hide a set of buttons.
|
void |
setIcon(Image icon)
An image icon that can be placed at the left of the title.
|
void |
setSpinner(Spinner s)
Sets the spinner to the given one.
|
void |
setTitle(java.lang.String newTitle)
Changes the title to the given one.
|
void |
startSpinner()
Shows and starts the spinner (if one has been assigned to the
spinner field). |
void |
stopSpinner()
Stops and hides the spinner (if createSpinner or setSpinner was called before)
|
void |
updateSinner()
Updates the spinner; sets it visible if not yet.
|
add, add, add, add, add, broadcastEvent, clear, fillBackground, findChild, findNearestChild, findNextFocusControl, getBorderRadius, getBorderStyle, getChildren, getChildrenCount, getClientRect, getClientRect, getFirstChild, getFocusableControls, getInsets, incLastX, incLastY, isPressed, moveFocusToNextControl, moveFocusToNextEditable, onAddAgain, onPaint, onRemove, onSwapFinished, paintChildren, remove, removeAll, resize, resizeHeight, resizeWidth, setBorderRadius, setBorderStyle, setEnabled, setFocusTraversable, setHighlighting, setInsets, setPressColor, setPressed, swapToTopmostWindow
_onEvent, addEnabledStateListener, addFocusListener, addFontChangeHandler, addGridListener, addHandler, addHighlightListener, addKeyListener, addListContainerListener, addMouseListener, addMultiTouchListener, addPenListener, addPressListener, addPushNotificationListener, addSizeChangeHandler, addTimer, addTimer, addTimerListener, addValueChangeHandler, addWindowListener, bringToFront, changeHighlighted, 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, onBoundsChanged, onEvent, onWindowPaintFinished, post, postEvent, postPressedEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHandler, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, repositionChildren, requestFocus, resetSetPositions, resetStyle, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setDoEffect, setFloating, setFocusLess, setFont, setForeColor, setNinePatch, setNinePatch, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
public boolean drawBorders
false
to remove the borderspublic boolean canSelectTitle
true
to allow the title to be selected and send events.public int titleAlign
LEFT
, CENTER
, or RIGHT
). Defaults to LEFT
.public int portraitPrefH
public int landscapePrefH
public Bar()
Bar
object without a title. Note that if you call the setTitle()
method, a RuntimeException
will be thrown.
If you want to change the title later, use the other constructor and pass an empty string (""
).public Bar(java.lang.String title)
Bar
object with the given title.title
- The bar title.public void setIcon(Image icon)
null
to remove the icon if
it was previously set.icon
- The image icon.public Image getIcon()
public void setTitle(java.lang.String newTitle)
newTitle
- The bar new title.public java.lang.String getTitle()
public int addButton(Image icon)
icon
- The image to the add to a button in the bar.public int addButton(Icon icon, boolean atRight)
public int addButton(Image icon, boolean atRight)
icon
- The image to the add to a button in the bar.atRight
- if true, button is added at right; if false, button is added at left.public void setButtonRepeatRate(int idx, int ms)
idx
- The index of the button in the bar.ms
- The auto-repeat interval in milliseconds.public int addControl(Control c)
c
- The control to be added.public int addControl(Control c, boolean atRight)
atRight
- if true, button is added at right; if false, button is added at left.c
- The control to be added.public void removeButton(int index)
index
- The index of the button to be removed.public void setButtonsVisible(boolean visible, int... indexes)
public int getSelectedIndex()
public void initUI()
protected int getButtonWidth(int idx)
public void onColorsChanged(boolean colorsChanged)
setEnabled()
, setForeColor()
, or setBackColor()
; or 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()
.onColorsChanged
in class Container
colorsChanged
- Indicates if the control colors have changed, which happens after a setForeColor()
,
setBackColor()
, or Container.add()
.public int getPreferredWidth()
getPreferredWidth
in class Control
public int getPreferredHeight()
getPreferredHeight
in class Control
public void startSpinner()
spinner
field).spinner
public void updateSinner()
public void stopSpinner()
spinner
public void reposition()
setRect()
with the original parameters.reposition
in class Control
public void onFontChanged()
Control
onFontChanged
in class Control
public void assignBackKeyToButton(int idx)
SpecialKeys.ESCAPE
) to the given button. This can only be called after the bar has been
added to a container.
For example, if button 1 is assigned with totalcross.res.Resources.back
, call assignBackKeyToButton(1);
.idx
- The index of the bar button, starting at 1.public void createSpinner(int color)
color
- The spinner color.public void setSpinner(Spinner s)
public int getTitleWidth()