startprogress.java

来自「GPS Track connects to a GPS and records 」· Java 代码 · 共 55 行

JAVA
55
字号
// J2ME GPS Track
// Copyright (C) 2006 Dana Peters
// http://www.qcontinuum.org/gpstrack

package org.qcontinuum.gpstrack;

import javax.microedition.lcdui.*;
import java.util.*;

public class StartProgress extends Form implements CommandListener {

    private Displayable mParent;
    private Command mCancelCommand;
    private Gps mGps;
    private Timer mTimer;

    public StartProgress(Displayable parent) {
        super("Start");
        mParent = parent;
        Preferences preferences = GpsTrack.getPreferences();
        mGps = GpsTrack.getGps();
        append(new StringItem(null, "Connecting to GPS...\n"));
        if (GpsTrack.midp2Capable())
            append(new Gauge(null, false, Gauge.INDEFINITE, Gauge.CONTINUOUS_RUNNING));
        mGps.open();
        addCommand(mCancelCommand = new Command("Cancel", Command.CANCEL, 0));
        setCommandListener(this);
        mTimer = new Timer();
        mTimer.schedule(new StartProgressTimerTask(), 1, 1000);
    }

    public class StartProgressTimerTask extends TimerTask {
        public void run() {
            if (mGps.getNmeaCount() > 0) {
                mTimer.cancel();
                try {
                    GpsTrack.getTrack().open();
                } catch (Exception ex) {
                    GpsTrack.display(ex, GpsTrack.getTrackStatus());
                }
                GpsTrack.display(GpsTrack.getTrackStatus());
            }
        }
    }

    public void commandAction(Command c, Displayable d)  {
        if (c == mCancelCommand) {
            mTimer.cancel();
            mGps.close();
            GpsTrack.display(mParent);
        }
    }

}

⌨️ 快捷键说明

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