⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trackstatus.java

📁 GPS Track connects to a GPS and records the path that you travel. Tracks can be uploaded to a web s
💻 JAVA
字号:
// J2ME GPS Track
// Copyright (C) 2006 Dana Peters
// http://www.qcontinuum.org/gpstrack

package org.qcontinuum.gpstrack;

import javax.microedition.lcdui.*;
import henson.midp.Float;
import java.util.*;

public class TrackStatus extends Form implements CommandListener {
    
    private Command mNextCommand, mStopCommand;
    private StringItem mNameStringItem;
    private StringItem mRecordsStringItem, mSpeedStringItem, mDistanceStringItem;
    private StringItem mNoFixTimeStringItem, mStopTimeStringItem, mRunTimeStringItem;
    private Preferences mPreferences;
    private Gps mGps;
    private Track mTrack;
    
    private static final Float mMetresToFeet = new Float(3281, -3);
    private static final Float mKmToMph = new Float(6214, -4);
    
    public TrackStatus() {
        super("Track Status");
        mPreferences = GpsTrack.getPreferences();
        mGps = GpsTrack.getGps();
        mTrack = GpsTrack.getTrack();
        append(mNameStringItem = new StringItem("Name:", " \n"));
        append(mRecordsStringItem = new StringItem("Records:", " \n"));
        append(mSpeedStringItem = new StringItem("Speed:", " \n"));
        append(mDistanceStringItem = new StringItem("Distance:", " \n"));
        append(mNoFixTimeStringItem = new StringItem("No Fix:", " \n"));
        append(mStopTimeStringItem = new StringItem("Stationary:", " \n"));
        append(mRunTimeStringItem = new StringItem("Moving:", " \n"));
        addCommand(mStopCommand = new Command("Stop", Command.STOP, 0));
        addCommand(mNextCommand = new Command("Next", Command.SCREEN, 0));
        setCommandListener(this);
    }

    public void timerTick() {
        int unitType = mPreferences.getUnitType();
        Float speed = mGps.getSpeed();
        Float distance = mTrack.getDistance();
        mNameStringItem.setText(mTrack.getName() + "\n");
        mRecordsStringItem.setText(mTrack.getNumRecords() + "\n");
        switch (unitType) {
            case Preferences.UNITTYPE_METRIC:
                if (speed != null)
                    mSpeedStringItem.setText(GpsTrack.floatToString(speed, 1) + " km/h\n");
                if (distance != null) {
                    if (distance.Less(1000))
                        mDistanceStringItem.setText(GpsTrack.floatToString(distance, 0) + " m\n");
                    else
                        mDistanceStringItem.setText(GpsTrack.floatToString(distance.Div(1000), 2) + " km\n");
                }
                break;
            case Preferences.UNITTYPE_US:
                if (speed != null)
                    mSpeedStringItem.setText(GpsTrack.floatToString(speed.Mul(mKmToMph), 1) + " mph\n");
                if (distance != null) {
                    Float feet = distance.Mul(mMetresToFeet);
                    if (feet.Less(5280))
                        mDistanceStringItem.setText(GpsTrack.floatToString(feet, 0) + " ft\n");
                    else
                        mDistanceStringItem.setText(GpsTrack.floatToString(feet.Div(5280), 2) + " mi\n");
                }
                break;
        }
        mNoFixTimeStringItem.setText(msecToString(mTrack.getNoFixTime()));
        mStopTimeStringItem.setText(msecToString(mTrack.getStopTime()));
        mRunTimeStringItem.setText(msecToString(mTrack.getRunTime()));
    }

    public void commandAction(Command c, Displayable d)  {
        if (c == mNextCommand) {
            GpsTrack.display(GpsTrack.getGpsStatus());
        } else if (c == mStopCommand) {
            GpsTrack.stop();
        }
    }

    private String msecToString(long msec) {
        StringBuffer sb = new StringBuffer();
        long hours = msec / 3600000;
        msec -= hours * 3600000;
        long minutes = msec / 60000;
        msec -= minutes * 60000;
        long seconds = msec / 1000;
        if (hours < 10)
            sb.append('0');
        sb.append(hours);
        sb.append(':');
        if (minutes < 10)
            sb.append('0');
        sb.append(minutes);
        sb.append(':');
        if (seconds < 10)
            sb.append('0');
        sb.append(seconds);
        return sb.toString();        
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -