btgpsreader.java

来自「一个可以连接gps的程序」· Java 代码 · 共 104 行

JAVA
104
字号
package GPSreader;

import javax.bluetooth.ServiceRecord;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class btGPSreader extends MIDlet implements CommandListener
{
    public static Display display = null;
    public MessageUI msgUI = null;
    public RemoteDeviceUI remotedeviceUI = null;
    private BtConnect btConn = null;
    private int selectedDevice;
    private GpsStream reader = null;
    
    public btGPSreader()
    {
        msgUI = new MessageUI(this);
        remotedeviceUI = new RemoteDeviceUI(this);
        btConn = new BtConnect(this, this);
    }
    
    public void startApp() throws javax.microedition.midlet.MIDletStateChangeException
    {
        display = Display.getDisplay(this);
        display.setCurrent(msgUI);
        remotedeviceUI.showui();
    }
    
    public void pauseApp() 
    {}
    
    public void destroyApp(boolean unconditional)
    {}
    
    public void commandAction(Command c, Displayable d)
    {
        if(d == msgUI && c.getLabel().equals("Search"))
        {
            remotedeviceUI.setMsg("[Please Wait....]");
            display.setCurrent(remotedeviceUI);
            btConn.startInquiry(remotedeviceUI);
        }
        else if (d == msgUI && c.getLabel().equals("Stop"))
        {
            if(reader != null && !reader.isStop())
                reader.stop();
        }
        else if(c.getLabel().equals("Exit"))
        {
            if(reader != null && !reader.isStop())
                reader.stop();
            notifyDestroyed();
            destroyApp(false);
        }
        else if(d == remotedeviceUI && c.getLabel().equals("Search"))
        {
            if(reader != null && !reader.isStop())
                reader.stop();
            remotedeviceUI.setMsg("[Please Wait....]");
            btConn.startInquiry(remotedeviceUI);
        }
        else if(d == remotedeviceUI && c.getLabel().equals("Select"))
        {
            selectedDevice = remotedeviceUI.getSelectedIndex();
            btConn.ServiceSearch(selectedDevice);
        }
        else if(d == remotedeviceUI && c.getLabel().equals("Back"))
        {
            display.setCurrent(msgUI);
        }
        else if(c.equals(BtConnect.COMPLETED))
        {
            display.setCurrent(msgUI);
            startGPSread();
        }
    }
    
    private void startGPSread()
    {
        ServiceRecord sr = btConn.getFirstDiscoveredService();
        String url = sr.getConnectionURL(sr.NOAUTHENTICATE_NOENCRYPT, false);
        
        reader = new GpsStream(this, url);
        reader.start();
    }
    
    public void log(String m)
    {
        this.msgUI.add(m);
        this.msgUI.repaint();
    }
    
    public void log(String parsedData[])
    {
        this.msgUI.clear();
        for(int i=0; i<parsedData.length; i++)
        {
            this.msgUI.add(parsedData[i]);
            this.msgUI.repaint();
        }
    }
}

⌨️ 快捷键说明

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