📄 gpstrack.java
字号:
// J2ME GPS Track
// Copyright (C) 2006 Dana Peters
// http://www.qcontinuum.org/gpstrack
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
package org.qcontinuum.gpstrack;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;
import henson.midp.Float;
public class GpsTrack extends MIDlet {
private static GpsTrack sGpsTrack;
private static Preferences sPreferences;
private static Display sDisplay;
private static Gps sGps;
private static Track sTrack;
private static BacklightCanvas sBacklightCanvas;
private static AstroInformation sAstroInformation;
private static MainMenu sMainMenu;
private static TrackStatus sTrackStatus;
private static GpsStatus sGpsStatus;
private static GpsSatellites sGpsSatellites;
private static Timer sTimer;
public GpsTrack() {
sGpsTrack = this;
}
public void startApp() {
sDisplay = Display.getDisplay(this);
sPreferences = new Preferences();
sGps = new Gps();
sTrack = new Track();
if (midp2Capable())
sBacklightCanvas = new BacklightCanvas();
sAstroInformation = new AstroInformation();
sMainMenu = new MainMenu();
sTrackStatus = new TrackStatus();
sGpsStatus = new GpsStatus();
sGpsSatellites = new GpsSatellites();
sTimer = new Timer();
sTimer.schedule(new RefreshTimerTask(), 1, 1000);
display(sMainMenu);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
sTrack.close();
sGps.close();
}
public static void exit() {
sGpsTrack.destroyApp(true);
sGpsTrack.notifyDestroyed();
sGpsTrack = null;
}
public class RefreshTimerTask extends TimerTask {
public void run() {
if (sTrackStatus.isShown())
sTrackStatus.timerTick();
else if (sGpsStatus.isShown())
sGpsStatus.timerTick();
else if (sGpsSatellites.isShown())
sGpsSatellites.timerTick();
}
}
public static TrackStatus getTrackStatus() {
return sTrackStatus;
}
public static GpsStatus getGpsStatus() {
return sGpsStatus;
}
public static GpsSatellites getGpsSatellites() {
return sGpsSatellites;
}
public static void stop() {
sTrack.close();
sGps.close();
display(sMainMenu);
}
public static void display(Displayable displayable) {
sDisplay.setCurrent(displayable);
}
public static void display(Alert alert, Displayable displayable) {
sDisplay.setCurrent(alert, displayable);
}
public static void display(Exception e, Displayable displayable) {
Alert alert = new Alert("Error",
"Exception: " + e.getClass().getName() + " " + e.getMessage(), null, AlertType.ERROR);
alert.setTimeout(Alert.FOREVER);
sDisplay.setCurrent(alert, displayable);
}
public static void display(String text, int seconds, Displayable displayable) {
Alert alert = new Alert("GPS Track");
alert.setTimeout(seconds == 0 ? Alert.FOREVER : seconds * 1000);
alert.setType(AlertType.INFO);
alert.setString(text);
display(alert, displayable);
}
public static void display(String text, Displayable displayable) {
display(text, 0, displayable);
}
public static void flashBackLight(int duration) {
sDisplay.flashBacklight(duration);
}
public static Displayable getCurrent() {
return sDisplay.getCurrent();
}
public static GpsTrack getGpsTrack() {
return sGpsTrack;
}
public static Preferences getPreferences() {
return sPreferences;
}
public static Gps getGps() {
return sGps;
}
public static Track getTrack() {
return sTrack;
}
public static AstroInformation getAstroInformation() {
return sAstroInformation;
}
public static boolean fileCapable() {
return System.getProperty("microedition.io.file.FileConnection.version") != null;
}
public static boolean serialCapable() {
return System.getProperty("microedition.commports") != null;
}
public static boolean midp2Capable() {
return System.getProperty("microedition.profiles").equals("MIDP-2.0");
}
public static boolean bluetoothCapable() {
try {
Class.forName("javax.bluetooth.LocalDevice");
return true;
} catch (ClassNotFoundException ex) {
return false;
}
}
public static boolean obexCapable() {
try {
Class.forName("javax.obex.ClientSession");
return true;
} catch (ClassNotFoundException ex) {
return false;
}
}
public static String floatToString(Float f, int decimals) {
StringBuffer sb = new StringBuffer();
sb.append(Float.Int(f).toLong());
if (decimals > 0) {
sb.append('.');
int i;
Float n = Float.abs(f);
for (i = 0; i < decimals; i++) {
n = Float.Frac(n).Mul(10);
sb.append(Float.Int(n).toLong());
}
}
return sb.toString();
}
public static String getDateString(long milliseconds) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getDefault());
calendar.setTime(new Date(milliseconds));
return calendar.get(Calendar.YEAR) + "-" + twoDigits(calendar.get(Calendar.MONTH) + 1) + "-" + twoDigits(calendar.get(Calendar.DAY_OF_MONTH))
+ " " + twoDigits(calendar.get(Calendar.HOUR_OF_DAY)) + ":" + twoDigits(calendar.get(Calendar.MINUTE));
}
private static String twoDigits(int n) {
return (n < 10 ? "0" : "") + n;
}
public static String getDateString() {
return getDateString(System.currentTimeMillis());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -