?? mainclass.java
字號:
package org.mcyrrer.ttff;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.CommandListener;import javax.microedition.lcdui.Display;import javax.microedition.lcdui.Displayable;import javax.microedition.location.Location;import javax.microedition.location.LocationException;import javax.microedition.location.LocationListener;import javax.microedition.location.LocationProvider;import javax.microedition.midlet.MIDlet;import java.util.Calendar;import javax.microedition.midlet.MIDletStateChangeException;/** * Main class that sets up an JSR179 locationprovider and use it to calculate Time To First Fix that is presentated in Class MIDPCanvas * @version 1.0 * @author Mattias Gustavsson */public class MainClass extends MIDlet implements CommandListener, LocationListener { private MIDPCanvas appCanvas; private Display display; private boolean ttffDone = false; private long timerStarted; LocationProvider myLocationProvider; Calendar date = Calendar.getInstance(); final Command exitCommand = new Command("Exit", Command.EXIT, 1); protected void startApp() throws MIDletStateChangeException { /* *Set up the Canvas we use and adds softkeys and sets a commandlistener */ try { appCanvas = new MIDPCanvas(); display = Display.getDisplay(this); display.setCurrent(appCanvas); // Set up this canvas to listen to command events this.appCanvas.setCommandListener(this); // Add the Exit command this.appCanvas.addCommand(exitCommand); } catch (Exception e) { e.printStackTrace(); } /* * Set up the location provider and sets a listener to update the signal every 1 second. */ try { myLocationProvider = LocationProvider.getInstance(null); myLocationProvider.setLocationListener(this, 1, 1, 1); //Timer started. This is the base time that we use later on to calculate the TTFF timerStarted = System.currentTimeMillis(); } catch (LocationException ex) { ex.printStackTrace(); } } protected void pauseApp() { throw new UnsupportedOperationException("Not supported yet."); } protected void destroyApp(boolean arg0) throws MIDletStateChangeException { throw new UnsupportedOperationException("Not supported yet."); } public void locationUpdated(LocationProvider arg0, Location locaction) { if (!ttffDone) { /* * myLocationProvider need to up and running (state=AVAILABLE). Otherwise we will not get any signal to work with */ if (myLocationProvider.getState() == LocationProvider.AVAILABLE) { /* * our location need to have all gps data (isValid) to be used for determin TTFF */ if (locaction.isValid()) { long timeresult = (System.currentTimeMillis() - timerStarted) / 1000; appCanvas.setText("TTFF=" + Long.toString(timeresult) + "sec"); ttffDone = true; } else { long timeresult = (System.currentTimeMillis() - timerStarted) / 1000; appCanvas.setText(Long.toString(timeresult) + "sec"); } } if (myLocationProvider.getState() == LocationProvider.TEMPORARILY_UNAVAILABLE) { appCanvas.setText("Location TEMPORARILY_UNAVAILABLE:"); } if (myLocationProvider.getState() == LocationProvider.OUT_OF_SERVICE) { appCanvas.setText("Location OUT_OF_SERVICE:"); } } appCanvas.repaint(); } /** * * @param arg0 * @param arg1 */ public void providerStateChanged(LocationProvider arg0, int arg1) { } /** * * @param c * @param arg1 */ public void commandAction(Command c, Displayable arg1) { if (c == exitCommand) { this.notifyDestroyed(); } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -