public class MainWindow extends Window implements MainClass
All TotalCross programs with an user-interface must have one and only one main window.
Here is an example showing a basic application:
public class MyProgram extends MainWindow { Edit edName; public void initUI() { ... initialization code ... add(new Label("Name:"), LEFT,TOP+2); add(edName = new Edit(""), AFTER,SAME-2); } }
Control.TranslucentShape
Modifier and Type | Field and Description |
---|---|
protected TimerEvent |
firstTimer |
_controlEvent, _dragEvent, _focus, _keyEvent, _mouseEvent, _multiEvent, _penEvent, androidBorderThickness, beepIfOut, blocking, borderStyle, cancelPenUp, canDrag, dragThreshold, fadeOtherWindows, fadeValue, firstFocus, flickEnabled, focusOnPenUp, footerColor, footerH, gradientTitleEndColor, gradientTitleStartColor, headerColor, highlighted, highResPrepared, HORIZONTAL_GRADIENT, ignoreEventOfType, keyHook, lastShiftY, lastSwappedContainer, mainSwapContainer, menubar, multiTouching, needsPaint, NO_BORDER, ORIENTATION_INVERTED, ORIENTATION_LANDSCAPE, ORIENTATION_PORTRAIT, popped, RECT_BORDER, repaintOnSwap, robot, ROUND_BORDER, rTitle, sameBackgroundColor, shiftH, shiftY, SIP_BOTTOM, SIP_HIDE, SIP_SHOW, SIP_TOP, TAB_BORDER, TAB_ONLY_BORDER, tempTitle, title, titleAlign, titleColor, titleFont, titleGap, topMost, VERTICAL_GRADIENT, zStack
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, 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 |
---|
MainWindow()
Constructs a main window with no title and no border.
|
MainWindow(java.lang.String title,
byte style)
Constructs a main window with the given title and border style.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_onMinimize() |
protected void |
_onRestore() |
void |
_onTimerTick(boolean canUpdate)
Called by the VM to process timer interrupts.
|
protected TimerEvent |
addTimer(Control target,
int millis)
Adds a timer to a control.
|
protected void |
addTimer(TimerEvent t,
Control target,
int millis)
Adds the timer t to the target control.
|
protected void |
addTimer(TimerEvent te,
Control target,
int millis,
boolean append)
Adds the timer t to the target control.
|
void |
addUpdateListener(UpdateListener listener)
Adds a listener for Update events.
|
void |
appEnding()
Called by the system so we can finish things correctly.
|
void |
appStarting(int timeAvail)
Called by the VM when the application is starting.
|
static void |
exit(int exitCode)
Notifies the application that it should stop executing and exit.
|
static java.lang.String |
getCommandLine()
Returns the command line passed by the application that called this application in the Vm.exec method.
|
static Font |
getDefaultFont()
Returns the default font.
|
static MainWindow |
getMainWindow()
Returns the instance of the current main window.
|
static Image |
getScreenShot()
Takes a screen shot of the current screen.
|
protected FirebaseInstanceIdService |
initFirebaseInstanceIdService()
Register your own FirebaseInstanceIdService when initializing the app
|
protected FirebaseMessagingService |
initFirebaseMessagingService()
Register a FireBaseMessagingService when initializing the app
|
static boolean |
isMainThread()
Returns true if this is the main thread.
|
static void |
minimize()
Notifies the application that it should be minimized, that is, transfered
to the background.
|
void |
onExit()
Called just before an application exits.
|
void |
onMinimize()
Called just after the application is minimized.
|
void |
onRestore()
Called just after the application is restored.
|
boolean |
removeTimer(TimerEvent timer)
Removes the given timer from the timers queue.
|
void |
removeUpdateListener(UpdateListener listener)
Removes a listener for Update events
|
static void |
restore()
Notifies the application that it should be restored, that is, transfered
to the foreground.
|
void |
runOnMainThread(java.lang.Runnable r)
The same of
runOnMainThread(r, true) . |
void |
runOnMainThread(java.lang.Runnable r,
boolean singleInstance)
Runs the given code in the main thread.
|
static void |
setDefaultFont(Font newFont)
Sets the default font used in all controls created.
|
void |
setRect(int x,
int y,
int width,
int height,
Control relative,
boolean screenChanged)
This method can't be called for a MainWindow
|
void |
setUIStyle(byte style)
Changes the user interface style to the given one.
|
_doPaint, _postEvent, destroyZStack, drawHighlight, getBorderStyle, getClientRect, getClientRect, getDefaultDragThreshold, getFocus, getHighlighted, getPopupCount, getPreferredHeight, getPreferredWidth, getTitleFont, getTopMost, handleFocusChangeKeys, isScreenShifted, isSipShown, isSipShown4D, isTopMost, isVisible, loadBehind, makeUnmovable, onClickedOutside, onPopup, onRobotKey, onUnpop, paintTitle, paintWindowBackground, popup, popupMenuBar, popupNonBlocking, postPopup, postPressedEvent, postUnpop, pumpEvents, removeFocus, repaintActiveWindows, resize, resizeHeight, resizeWidth, screenResized, setBorderStyle, setDeviceTitle, setFocus, setGrabPenEvents, setHighlighted, setMenuBar, setOrientation, setSIP, setTitle, setTitleFont, shiftScreen, swap, swapFocus, unpop, validate
add, add, add, add, add, broadcastEvent, clear, fillBackground, findChild, findNearestChild, findNextFocusControl, getBorderRadius, getChildren, getChildrenCount, getFirstChild, getFocusableControls, getInsets, incLastX, incLastY, initUI, isPressed, moveFocusToNextControl, moveFocusToNextEditable, onAddAgain, onColorsChanged, onPaint, onRemove, onSwapFinished, paintChildren, remove, removeAll, setBorderRadius, 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, isVisibleAndInside, onBoundsChanged, onEvent, onFontChanged, onWindowPaintFinished, post, postEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHandler, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, reposition, repositionChildren, requestFocus, resetSetPositions, resetStyle, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setDoEffect, setFloating, setFocusLess, setFont, setForeColor, setNinePatch, setNinePatch, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
_postEvent
protected TimerEvent firstTimer
public MainWindow()
public MainWindow(java.lang.String title, byte style)
Window.NO_BORDER
,
Window.RECT_BORDER
,
Window.ROUND_BORDER
,
Window.TAB_BORDER
,
Window.TAB_ONLY_BORDER
protected FirebaseInstanceIdService initFirebaseInstanceIdService()
protected FirebaseMessagingService initFirebaseMessagingService()
public static boolean isMainThread()
public static void setDefaultFont(Font newFont)
public MyApp() { MainWindow.setDefaultFont(Font.getFont(false, Font.NORMAL_SIZE+2)); setBorderStyle(TAB_ONLY_BORDER); setTitle("My application"); }
public static Font getDefaultFont()
public void setUIStyle(byte style)
public class Foo extends MainWindow { public Foo() { super("Hi bar",TAB_ONLY_BORDER); setUIStyle(totalcross.sys.Settings.Flat);Changing to Android style will also set Settings.fingerTouch to true. If you don't like such behaviour in non finger devices, set this property to false after calling setUIStyle.
Settings.Flat
,
Settings.Vista
,
Settings.Android
,
Settings.Holo
,
Settings.Material
public static final void exit(int exitCode)
If you want your code to be called when the VM exits, extend the onExit method.
onExit()
public static void minimize()
onMinimize()
. Note: On Android, calling minimize()
will
pause the application execution and it can only be restored manually by the user. This method is
also supported on Windows 32.onMinimize()
,
onRestore()
public static void restore()
onRestore()
. Note: This method is supported on Android but the user must restore
the application manually. This method is also supported on Windows 32.public static MainWindow getMainWindow()
MainWindow
class from outside the class.
It is also possible to cast the returned class to the class that is extending MainWindow
(this is a normal Java behavior).
So, if UiGadgets is running, it is correct to do:
UIGadgets instance = (UIGadgets)MainWindow.getMainWindow();
protected TimerEvent addTimer(Control target, int millis)
protected void addTimer(TimerEvent t, Control target, int millis)
protected void addTimer(TimerEvent te, Control target, int millis, boolean append)
public boolean removeTimer(TimerEvent timer)
target
member is set to null.removeTimer
in class Control
public final void appStarting(int timeAvail)
appStarting
in interface MainClass
public final void appEnding()
protected final void _onMinimize()
protected final void _onRestore()
public void onExit()
public void onMinimize()
minimize()
public void onRestore()
onRestore()
public final void _onTimerTick(boolean canUpdate)
_onTimerTick
in interface MainClass
public static final java.lang.String getCommandLine()
adb shell am start -a android.intent.action.MAIN -n totalcross.app.uigadgets/.UIGadgets -e cmdline "Hello world"In the sample above, we're starting UIGadgets. Your app should be: totalcross.app.yourMainWindowClass/.yourMainWindowClass Note: When you click on the application's icon, there's no command line.
public void setRect(int x, int y, int width, int height, Control relative, boolean screenChanged)
setRect
in class Control
x
- One of the relative positioning constants: LEFT, RIGHT, SAME, BEFORE, AFTER, CENTER, with a small adjustment. You can also use an absolute value, but this is strongly discouraged.y
- One of the relative positioning constants: TOP, BOTTOM, SAME, BEFORE, AFTER, CENTER, with a small adjustment. You can also use an absolute value, but this is strongly discouraged.width
- One of the relative positioning constants: PREFERRED, FILL, FIT, SAME. You can also use an absolute value, but this is strongly discouraged.height
- One of the relative positioning constants: PREFERRED, FILL, FIT, SAME. You can also use an absolute value, but this is strongly discouraged.relative
- To whom the position should be relative to; or null to be relative to the last control.screenChanged
- Indicates that a screen change (resize, collapse) occured and the reposition
method is calling this method. Set by the system. If you call this method directly, always pass false to it.Control.LEFT
,
Control.TOP
,
Control.RIGHT
,
Control.BOTTOM
,
Control.BEFORE
,
Control.AFTER
,
Control.CENTER
,
Control.SAME
,
Control.FILL
,
Control.PREFERRED
,
Control.FIT
,
Control.CENTER_OF
,
Control.RIGHT_OF
,
Control.BOTTOM_OF
,
Control.SCREENSIZE
,
Control.SCREENSIZEMIN
,
Control.SCREENSIZEMAX
,
Control.PARENTSIZE
,
Control.PARENTSIZEMIN
,
Control.PARENTSIZEMAX
,
Control.FONTSIZE
,
Container.add(Control, int, int)
,
Container.add(Control, int, int, Control)
public static Image getScreenShot()
Image img = MainWindow.getScreenShot(); File f = new File(Settings.appPath + "/screen.png", File.CREATE_EMPTY); img.createPng(f); f.close();Note that the font varies from device to device and even to desktop. So, if you want to compare a device's screen shot with one taken at desktop, be sure to set the default font in both to the same, like using
setDefaultFont(Font.getFont(false,20))
.public void addUpdateListener(UpdateListener listener)
UpdateListener
public void removeUpdateListener(UpdateListener listener)
totalcross.ui.event.UpdateEventListener
public void runOnMainThread(java.lang.Runnable r)
runOnMainThread(r, true)
.Note that this
public void runOnMainThread(java.lang.Runnable r, boolean singleInstance)
new Thread() { public void run() { while (true) { Vm.sleep(1000); MainWindow.getMainWindow().runOnMainThread(new Runnable() { public void run() { log("babi "+ ++contador); } }); } } }.start();