Package totalcross.io.device.gps
Class GPSView
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.Container
-
- totalcross.io.device.gps.GPSView
-
- All Implemented Interfaces:
EventHandler,TimerListener
public class GPSView extends Container implements TimerListener
Control that display GPS coordinates read from the COM (or Bluetooth, or IR) port. In Windows Mobile and Android, it uses the native API instead of reading from the COM port. For example:add(gps = new GPSView(1000),LEFT,TOP);
See the tc.samples.io.device.GPSTest. On Android, don't forget to turn on the GPS, going to Settings / Security & Location / Enable GPS satellites. The other platforms may require that as well. If the GPS fails connecting to the satellites, and the phone has signal, you can use the cell tower location as a rough location. The precision is vary between 50m to 3km, depending where the phone is. You can get the latitude and longitude using CellInfo.toCoordinates. This class uses the GPS class to show the values on Labels. You can use the GPS class standalone if you wish. See the tc.samples.maps.GoogleMaps sample.- Since:
- TotalCross 1.38
- See Also:
GPS,CellInfo.toCoordinates()
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description GPSgpsClass used to retrieve the GPS coordinates.static java.lang.StringLAT_LOW_SIGNALString that will be printed with there longitude can't be acquired.static java.lang.StringLON_LOW_SIGNALString that will be printed with there longitude can't be acquired.-
Fields inherited from class totalcross.ui.Container
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, children, controlFound, finishedStart, ignoreOnAddAgain, ignoreOnRemove, insets, lastH, lastScreenWidth, lastW, lastX, lastY, npback, numChildren, started, tabOrder, tail, TRANSITION_CLOSE, TRANSITION_FADE, TRANSITION_NONE, TRANSITION_OPEN, TRANSITION_TIME, transitionEffect
-
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
-
-
Constructor Summary
Constructors Constructor Description GPSView()Constructs a GPS using a read interval of 2 seconds.GPSView(int readInterval)Constructs a GPSView using the given read interval.GPSView(GPS gps, int readInterval)Constructs a GPSView using the given GPS as input.GPSView(PortConnector sp, int readInterval)Constructs a GPSView using the given PortConnector and read interval.
-
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.voidinitUI()Called to initialize the User Interface of this container.protected voidonColorsChanged(boolean colorsChanged)Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container.protected voidonFontChanged()Called after a setFontvoidretrieveGPSData()Retrieves the GPS data and updates the fields with it.voidstop()Removes the timer and stops the GPS.voidtimerTriggered(TimerEvent e)A TRIGGERED event was dispatched.-
Methods inherited from class totalcross.ui.Container
add, add, add, add, add, applyTransitionEffect, broadcastEvent, clear, fillBackground, findChild, findNearestChild, findNextFocusControl, getBorderStyle, getChildren, getChildrenCount, getClientRect, getClientRect, getFirstChild, getFocusableControls, getInsets, incLastX, incLastY, isPressed, moveFocusToNextControl, moveFocusToNextEditable, onAddAgain, onPaint, onRemove, onSwapFinished, paintChildren, remove, removeAll, resize, resizeHeight, resizeWidth, setBorderStyle, setEnabled, setFocusTraversable, setHighlighting, setInsets, setNextTransitionEffect, setPressColor, setPressed, swapToTopmostWindow
-
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, 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, 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
-
-
-
-
Field Detail
-
LON_LOW_SIGNAL
public static java.lang.String LON_LOW_SIGNAL
String that will be printed with there longitude can't be acquired. You can localize this string.
-
LAT_LOW_SIGNAL
public static java.lang.String LAT_LOW_SIGNAL
String that will be printed with there longitude can't be acquired. You can localize this string.
-
gps
public GPS gps
Class used to retrieve the GPS coordinates.
-
-
Constructor Detail
-
GPSView
public GPSView() throws IOExceptionConstructs a GPS using a read interval of 2 seconds.- Throws:
IOException
-
GPSView
public GPSView(int readInterval) throws IOExceptionConstructs a GPSView using the given read interval.- Parameters:
readInterval- The interval used to fetch data, in milliseconds. A ControlEvent.PRESSED is posted each time the TRIGGERED event occurs.- Throws:
IOException
-
GPSView
public GPSView(PortConnector sp, int readInterval) throws IOException
Constructs a GPSView using the given PortConnector and read interval. In Android and Windows Mobile, you should use the other constructor. #GPSView(int)- Throws:
IOException
-
GPSView
public GPSView(GPS gps, int readInterval) throws IOException
Constructs a GPSView using the given GPS as input.- Throws:
IOException- Since:
- TotalCross 1.5
-
-
Method Detail
-
initUI
public void initUI()
Description copied from class:ContainerCalled to initialize the User Interface of this container. This differs from the onAddAgain method by that this method is called only once, at the first time the control is added to the parent. When the container is being setup, the initUI method is called; then, the onAddAgain is called every time the container is added again.
-
timerTriggered
public void timerTriggered(TimerEvent e)
Description copied from interface:TimerListenerA TRIGGERED event was dispatched.- Specified by:
timerTriggeredin interfaceTimerListener- See Also:
TimerEvent
-
stop
public void stop() throws IOExceptionRemoves the timer and stops the GPS.- Throws:
IOException
-
retrieveGPSData
public void retrieveGPSData()
Retrieves the GPS data and updates the fields with it.
-
getPreferredWidth
public int getPreferredWidth()
Description copied from class:ControlReturns the preferred width of this control.- Overrides:
getPreferredWidthin classControl
-
getPreferredHeight
public int getPreferredHeight()
Description copied from class:ControlReturns the preferred height of this control.- Overrides:
getPreferredHeightin classControl
-
onColorsChanged
protected void onColorsChanged(boolean colorsChanged)
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 classContainer
-
onFontChanged
protected void onFontChanged()
Description copied from class:ControlCalled after a setFont- Overrides:
onFontChangedin classControl
-
-