bc... [google]
Home » Source Code » » GPSTracker.java

GPSTracker.java ( File view )

From:
  • By 2010-08-17
  • View(s):3
  • Download(s):0
  • Point(s): 1
			// Please leave the link below with the source code, thank you.
// http://www.websmithing.com/portal/Programming/tabid/55/articleType/ArticleView/articleId/6/Google-Map-GPS-Cell-Phone-Tracker-Version-2.aspx

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.location.*;
import java.util.Calendar;

public class GPSTracker extends MIDlet implements CommandListener, ItemStateListener {

    private Display display;
    private Form form;
    private Form zoomScreen;
    private Form settingsScreen;
    private Command exitCmd;
    private Command saveCmd;
    private Command zoomCmd;
    private Command settingsCmd;
    private Command backCmd;
    private TextField phoneNumberTextField;
    private TextField uploadWebsiteTextField;
    private Gauge zoomGauge;
    private StringItem zoomStringItem;
    private ChoiceGroup updateIntervalCG;
    private String updateInterval;
    private int[] iTimes = {
60, 120, 180, 300, 600
};
    
    private RMS rms;
    private GPS gps;
    
    private String uploadWebsite;    
    private String defaultUploadWebsite = "http://www.websmithing.com/gpstracker/GetGoogleMap2.aspx";

    protected String phoneNumber;
    protected String zoomLevel;
    protected int height, width;   
    protected Calendar currentTime;    
    protected long sessionID;
    protected Image im = null;
    
    public GPSTracker(){

        form = new Form("GPSTracker2.0");
        display = Display.getDisplay(this);
        exitCmd = new Command("Exit", Command.EXIT, 1); 
        zoomCmd = new Command("Zoom", Command.SCREEN, 2);
        settingsCmd = new Command("Settings", Command.SCREEN, 3);
        
        form.addCommand(exitCmd);
        form.addCommand(zoomCmd);
        form.addCommand(settingsCmd);
        form.setCommandListener(this);        
        
        display.setCurrent(form);
        currentTime = Calendar.getInstance();
        sessionID = System.currentTimeMillis();
        height = form.getHeight();
        width = form.getWidth();
        
        // RMS is the phone's built in storage, kind of like a database, but
        // it only stores name-value pairs (like an associative array or hashtable). 
        // eveything is stored as a string.
        getSettingsFromRMS();
        
        // the phone number field is the only empty field when the application is 
        // first loaded. it does not have to be a phone number, it can be any string,
        // but for uniqueness, it's best to use a phone number. this only has to be 
        // done once.
        if (hasPhoneNumber()) {

            startGPS();
            displayInterval();
        
}
    
} 
   
    public void startApp() {

        if ( form != null ) {
 
            display.setCurrent(form); 
        
} 
    
}
 
    // let the user know how often map will be updated
    private void displayInterval() {

        int tempTime = iTimes[Integer.parseInt(updateInterval)]/60;
    
        display.setCurrent(form);
        form.deleteAll();
         
        if (tempTime == 1) {

            log("Getting map once a minute...");
        
}
        else {

           log("Getting map every " + String.valueOf(tempTime) + " minutes..."); 
        
}       
    
}    
    
    private void loadZoomScreen() {

        zoomScreen = new Form("Zoom");
        zoomGauge = new Gauge("Google Map Zoom", true, 17, Integer.parseInt(zoomLevel));
        zoomStringItem = new StringItem(null, "");
        zoomStringItem.setText("Zoom level: " + zoomGauge.getValue());
        backCmd = new Command("Back", Command.SCREEN, 1);

        zoomScreen.append(zoomGauge);
        zoomScreen.append(zoomStringItem);
        zoomScreen.addCommand(backCmd);
        zoomScreen.setItemStateListener(this);
        zoomScreen.setCommandListener(this);

        display.setCurrent(zoomScreen);
    
}
 
    // this method is called every time the zoom guage changes value. the zoom level is 
    // reset and saved
    public void itemStateChanged(Item item) {

        if (item == zoomGauge) {

            zoomStringItem.setText("Zoom level: " + zoomGauge.getValue());
            zoomLevel = String.valueOf(zoomGauge.getValue());

            try {
 
                rms.put("zoomLevel", zoomLevel);
                rms.save(); 
            
}
            catch (Exception e) {

                log("GPSTracker.itemStateChanged: " + e);
            
} 
        
}
    
}    

    private void loadSettingsScreen() {

        settingsScreen = new Form("Settings");

        phoneNumberTextField = new TextField("Phone number or user name", phoneNumber, 20, TextField.ANY);
        uploadWebsiteTextField = new TextField("Upload website", uploadWebsite, 100, TextField.ANY);
        settingsScreen.append(phoneNumberTextField);
        settingsScreen.append(uploadWebsiteTextField);

        String[] times = {
 "1 minute", "2 minutes", "3 minutes", "5 minutes", "10 minutes"
};
        updateIntervalCG = new ChoiceGroup("Update map how often?", ChoiceGroup.EXCLUSIVE, times, null);
        updateIntervalCG.setSelectedIndex(Integer.parseInt(updateInterval), true);
        settingsScreen.append(updateIntervalCG);        

        saveCmd = new Command("Save", Command.SCREEN, 1);
        settingsScreen.addCommand(saveCmd);

        settingsScreen.setCommandListener(this);
        display.setCurrent(settingsScreen);
    
}    
    
    // get the settings from the phone's storage and load 4 global variables
    public void getSettingsFromRMS() {

        try {

            rms = new RMS(this, "GPSTracker");

            phoneNumber = rms.get("phoneNumber");
            uploadWebsite = rms.get("uploadWebsite");
            zoomLevel = rms.get("zoomLevel");
            updateInterval = rms.get("updateInterval");
        
}
        catch (Exception e) {

            log("GPSTracker.getSettingsFromRMS: " + e);
        
}
        
        if ((uploadWebsite == null) || (uploadWebsite.trim().length() == 0)) {

            uploadWebsite = defaultUploadWebsite;
        
}        

        if ((zoomLevel == null) || (zoomLevel.trim().length() == 0)) {

            zoomLevel = "12";
        
}
        if ((updateInterval == null) || (updateInterval.trim().length() == 0)) {

            updateInterval = "1";
        
}        
    
}    

    private boolean hasPhoneNumber() {

        if ((phoneNumber == null) || (phoneNumber.trim().length() == 0)) {

           log("Phone number required. Please go to settings.");
           return false;
        
}
        else {

           return true;
      
}
    
}
  
    // gps is started with the update interval. the interval is the time in between
    // map updates
    private void startGPS() {

        if (gps == null) {

            gps = new GPS(this, iTimes[Integer.parseInt(updateInterval)], uploadWebsite);
            gps.startGPS();
        
}
    
}
    
    // this is called when the user changes the interval in the settings screen
    private void changeInterval() {

        if (gps == null) {

            startGPS(); 
        
}
        else {

            gps.changeInterval(iTimes[Integer.parseInt(updateInterval)]);
        
}
    
}
    
    // save settings back to phone memory
    private void saveSettingsToRMS() {

        try {
 
            phoneNumber = phoneNumberTextField.getString();
            uploadWebsite = uploadWebsiteTextField.getString();
            updateInterval = String.valueOf(updateIntervalCG.getSelectedIndex());
            
            rms.put("phoneNumber", phoneNumber);
            rms.put("uploadWebsite", uploadWebsite);
            rms.put("updateInterval", updateInterval);

            rms.save(); 
        
}
        catch (Exception e) {

            log("GPSTracker.saveSettings: " + e);
        
} 
        display.setCurrent(form);
    
}

    // this method displays the map image, it is called from the networker object
    public void showMap(boolean flag)
    {

        if (flag == false) {

            log("Map could not be downloaded.");
        
}
        else {

            ImageItem imageitem = new ImageItem(null, im, ImageItem.LAYOUT_DEFAULT, null);

            if(form.size()!= 0) {

                form.set(0, imageitem);
            
}
            else {

                form.append(imageitem);
            
}
        
}
    
}   
        
    public void log(String text) {

        StringItem si = new StringItem(null, text);
        si.setLayout(Item.LAYOUT_NEWLINE_AFTER);
        form.append(si);
    
}

    public void commandAction(Command cmd, Displayable screen) {
		
        if (cmd == exitCmd) {

            shutDownApp();
        
}
        else if (cmd == saveCmd) {

            saveSettingsToRMS();

            if (hasPhoneNumber()) {

                changeInterval();
                displayInterval();
            
}
        
}
        else if (cmd == settingsCmd) {

            loadSettingsScreen(); 
        
}
        else if (cmd == zoomCmd) {

            loadZoomScreen(); 
        
}        
        else if (cmd == backCmd) {

            displayInterval();
        
}
    
}
     
    public void pauseApp() {

}

    public void destroyApp(boolean unconditional) {

}

    protected void shutDownApp() {

        destroyApp(true);
        notifyDestroyed();   
    
}

}



			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
源码文件 004.00 B
code file data.txtdata.txt11.07 kB04-19-08 09:53
源码文件 GPSTracker.bakGPSTracker.bak1.46 MB04-19-08 09:56
code file GPSTracker.sqlGPSTracker.sql4.46 kB04-19-08 09:54
code file License.txtLicense.txt34.98 kB07-16-07 01:45
源码文件 004.00 B
源码文件 004.00 B
源码文件 004.00 B
源码文件 .timestamp.timestamp9.00 B04-20-08 18:21
源码文件 before-obfuscation.jarbefore-obfuscation.jar11.52 kB04-20-08 18:19
源码文件 004.00 B
源码文件 GPS$1.classGPS$1.class447.00 B04-20-08 18:19
源码文件 GPS$2.classGPS$2.class574.00 B04-20-08 18:19
源码文件 GPS.classGPS.class5.50 kB04-20-08 18:19
源码文件 gps32.pnggps32.png310.00 B04-20-08 18:19
源码文件 GPSTracker.classGPSTracker.class7.88 kB04-20-08 18:19
源码文件 NetWorker.classNetWorker.class3.20 kB04-20-08 18:19
源码文件 RMS.classRMS.class2.94 kB04-20-08 18:19
源码文件 manifest.mfmanifest.mf349.00 B04-20-08 18:21
源码文件 004.00 B
源码文件 a.classa.class348.00 B04-20-08 18:19
源码文件 b.classb.class2.05 kB04-20-08 18:19
源码文件 c.classc.class246.00 B04-20-08 18:19
源码文件 d.classd.class2.09 kB04-20-08 18:19
源码文件 e.classe.class3.92 kB04-20-08 18:19
源码文件 gps32.pnggps32.png310.00 B04-20-08 18:19
源码文件 GPSTracker.classGPSTracker.class5.93 kB04-20-08 18:19
源码文件 004.00 B
源码文件 MANIFEST.MFMANIFEST.MF106.00 B04-20-08 18:19
源码文件 obfuscated.jarobfuscated.jar8.27 kB04-20-08 18:19
源码文件 004.00 B
code file GPS.javaGPS.java5.92 kB04-20-08 18:19
code file GPSTracker.javaGPSTracker.java9.02 kB04-20-08 18:19
code file NetWorker.javaNetWorker.java3.51 kB04-20-08 18:19
code file RMS.javaRMS.java2.49 kB04-20-08 18:19
源码文件 004.00 B
源码文件 a.classa.class348.00 B04-20-08 18:19
源码文件 b.classb.class2.41 kB04-20-08 18:19
源码文件 c.classc.class246.00 B04-20-08 18:19
源码文件 d.classd.class3.04 kB04-20-08 18:19
源码文件 e.classe.class4.14 kB04-20-08 18:19
源码文件 gps32.pnggps32.png310.00 B04-20-08 18:19
源码文件 GPSTracker.classGPSTracker.class6.38 kB04-20-08 18:19
源码文件 004.00 B
源码文件 MANIFEST.MFMANIFEST.MF106.00 B04-20-08 18:19
源码文件 004.00 B
源码文件 a.classa.class348.00 B04-20-08 18:19
源码文件 b.classb.class2.05 kB04-20-08 18:19
源码文件 c.classc.class246.00 B04-20-08 18:19
源码文件 d.classd.class2.09 kB04-20-08 18:19
源码文件 e.classe.class3.92 kB04-20-08 18:19
源码文件 GPSTracker.classGPSTracker.class5.93 kB04-20-08 18:19
code file build.xmlbuild.xml4.03 kB04-03-08 21:19
源码文件 004.00 B
源码文件 GPST2.0.jadGPST2.0.jad410.00 B04-20-08 18:21
源码文件 GPST2.0.jarGPST2.0.jar8.96 kB04-20-08 18:21
源码文件 004.00 B
源码文件 004.00 B
code file build-impl.xmlbuild-impl.xml66.72 kB04-03-08 21:19
源码文件 genfiles.propertiesgenfiles.properties455.00 B04-03-08 21:19
源码文件 004.00 B
源码文件 private.propertiesprivate.properties335.00 B04-20-08 18:21
code file private.xmlprivate.xml211.00 B04-20-08 18:09
源码文件 project.propertiesproject.properties4.92 kB04-20-08 18:10
code file project.xmlproject.xml389.00 B04-03-08 21:19
源码文件 004.00 B
源码文件 gps32.pnggps32.png310.00 B04-09-08 03:49
源码文件 004.00 B
code file GPS.javaGPS.java5.92 kB04-20-08 11:08
code file GPSTracker.javaGPSTracker.java9.02 kB04-20-08 02:43
code file NetWorker.javaNetWorker.java3.51 kB04-20-08 14:53
code file RMS.javaRMS.java2.49 kB04-03-08 21:22
code file ReadMe.txtReadMe.txt5.28 kB04-19-08 13:40
源码文件 004.00 B
源码文件 004.00 B
源码文件 004.00 B
code file DbWriter.csDbWriter.cs1.87 kB04-18-08 14:29
code file DbXmlReader.csDbXmlReader.cs1.84 kB04-18-08 14:29
源码文件 004.00 B
code file DeleteRoute.aspxDeleteRoute.aspx106.00 B03-29-08 03:57
code file DeleteRoute.aspx.csDeleteRoute.aspx.cs970.00 B04-19-08 09:18
code file DisplayMap2.aspxDisplayMap2.aspx4.13 kB04-18-08 20:41
code file DisplayMap2.aspx.csDisplayMap2.aspx.cs1.34 kB04-19-08 09:18
code file GetGoogleMap2.aspxGetGoogleMap2.aspx110.00 B04-06-08 15:49
code file GetGoogleMap2.aspx.csGetGoogleMap2.aspx.cs5.35 kB04-18-08 06:38
code file GetRouteForMap.aspxGetRouteForMap.aspx112.00 B03-22-08 05:31
code file GetRouteForMap.aspx.csGetRouteForMap.aspx.cs1.11 kB04-19-08 09:18
code file GetRoutes.aspxGetRoutes.aspx102.00 B03-21-08 23:33
code file GetRoutes.aspx.csGetRoutes.aspx.cs575.00 B04-19-08 09:18
源码文件 GPSTracker.slnGPSTracker.sln1.57 kB06-20-07 09:38
源码文件 GPSTracker.suoGPSTracker.suo15.00 kB04-20-08 18:30
源码文件 004.00 B
源码文件 ajax-loader.gifajax-loader.gif3.13 kB04-02-08 11:37
源码文件 compassE.jpgcompassE.jpg1.21 kB05-21-07 13:23
源码文件 compassN.jpgcompassN.jpg1.24 kB05-21-07 13:20
源码文件 compassNE.jpgcompassNE.jpg1.23 kB05-21-07 13:26
源码文件 compassNW.jpgcompassNW.jpg1.22 kB05-21-07 13:26
源码文件 compassS.jpgcompassS.jpg1.23 kB05-21-07 13:23
源码文件 compassSE.jpgcompassSE.jpg1.22 kB05-21-07 13:26
源码文件 compassSW.jpgcompassSW.jpg1.22 kB05-21-07 13:25
源码文件 compassW.jpgcompassW.jpg1.21 kB05-21-07 13:25
源码文件 coolblue_small.pngcoolblue_small.png478.00 B05-02-06 13:46
源码文件 coolred_small.pngcoolred_small.png466.00 B05-02-06 13:45
源码文件 coolshadow_small.pngcoolshadow_small.png436.00 B05-02-06 13:36
源码文件 cooltransparent_small.pngcooltransparent_small.png3.08 kB05-02-06 13:37
源码文件 004.00 B
code file maps2.jsmaps2.js11.22 kB04-18-08 21:09
源码文件 004.00 B
code file Download.aspxDownload.aspx547.00 B04-18-08 06:35
code file Download.aspx.csDownload.aspx.cs412.00 B06-19-07 12:53
源码文件 GPST2.0.jadGPST2.0.jad410.00 B04-20-08 18:19
源码文件 GPST2.0.jarGPST2.0.jar8.96 kB04-20-08 18:19
源码文件 004.00 B
code file styles.cssstyles.css1.04 kB04-18-08 19:59
源码文件 Web.configWeb.config533.00 B04-18-08 06:16
源码文件 004.00 B
...
×

GPSTracker.java (369.70 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

×

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com
×

切换到中文版?

CodeForge Chinese Version
CodeForge English Version
×

Where are you going?

×

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK
×

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D