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
04.00 B
data.txt11.07 kB04-19-08 09:53
GPSTracker.bak1.46 MB04-19-08 09:56
GPSTracker.sql4.46 kB04-19-08 09:54
License.txt34.98 kB07-16-07 01:45
04.00 B
04.00 B
04.00 B
.timestamp9.00 B04-20-08 18:21
before-obfuscation.jar11.52 kB04-20-08 18:19
04.00 B
GPS$1.class447.00 B04-20-08 18:19
GPS$2.class574.00 B04-20-08 18:19
GPS.class5.50 kB04-20-08 18:19
gps32.png310.00 B04-20-08 18:19
GPSTracker.class7.88 kB04-20-08 18:19
NetWorker.class3.20 kB04-20-08 18:19
RMS.class2.94 kB04-20-08 18:19
manifest.mf349.00 B04-20-08 18:21
04.00 B
a.class348.00 B04-20-08 18:19
b.class2.05 kB04-20-08 18:19
c.class246.00 B04-20-08 18:19
d.class2.09 kB04-20-08 18:19
e.class3.92 kB04-20-08 18:19
gps32.png310.00 B04-20-08 18:19
GPSTracker.class5.93 kB04-20-08 18:19
04.00 B
MANIFEST.MF106.00 B04-20-08 18:19
obfuscated.jar8.27 kB04-20-08 18:19
04.00 B
GPS.java5.92 kB04-20-08 18:19
GPSTracker.java9.02 kB04-20-08 18:19
NetWorker.java3.51 kB04-20-08 18:19
RMS.java2.49 kB04-20-08 18:19
04.00 B
a.class348.00 B04-20-08 18:19
b.class2.41 kB04-20-08 18:19
c.class246.00 B04-20-08 18:19
d.class3.04 kB04-20-08 18:19
e.class4.14 kB04-20-08 18:19
gps32.png310.00 B04-20-08 18:19
GPSTracker.class6.38 kB04-20-08 18:19
04.00 B
MANIFEST.MF106.00 B04-20-08 18:19
04.00 B
a.class348.00 B04-20-08 18:19
b.class2.05 kB04-20-08 18:19
c.class246.00 B04-20-08 18:19
d.class2.09 kB04-20-08 18:19
e.class3.92 kB04-20-08 18:19
GPSTracker.class5.93 kB04-20-08 18:19
build.xml4.03 kB04-03-08 21:19
04.00 B
GPST2.0.jad410.00 B04-20-08 18:21
GPST2.0.jar8.96 kB04-20-08 18:21
04.00 B
04.00 B
build-impl.xml66.72 kB04-03-08 21:19
genfiles.properties455.00 B04-03-08 21:19
04.00 B
private.properties335.00 B04-20-08 18:21
private.xml211.00 B04-20-08 18:09
project.properties4.92 kB04-20-08 18:10
project.xml389.00 B04-03-08 21:19
04.00 B
gps32.png310.00 B04-09-08 03:49
04.00 B
GPS.java5.92 kB04-20-08 11:08
GPSTracker.java9.02 kB04-20-08 02:43
NetWorker.java3.51 kB04-20-08 14:53
RMS.java2.49 kB04-03-08 21:22
ReadMe.txt5.28 kB04-19-08 13:40
04.00 B
04.00 B
04.00 B
DbWriter.cs1.87 kB04-18-08 14:29
DbXmlReader.cs1.84 kB04-18-08 14:29
04.00 B
DeleteRoute.aspx106.00 B03-29-08 03:57
DeleteRoute.aspx.cs970.00 B04-19-08 09:18
DisplayMap2.aspx4.13 kB04-18-08 20:41
DisplayMap2.aspx.cs1.34 kB04-19-08 09:18
GetGoogleMap2.aspx110.00 B04-06-08 15:49
GetGoogleMap2.aspx.cs5.35 kB04-18-08 06:38
GetRouteForMap.aspx112.00 B03-22-08 05:31
GetRouteForMap.aspx.cs1.11 kB04-19-08 09:18
GetRoutes.aspx102.00 B03-21-08 23:33
GetRoutes.aspx.cs575.00 B04-19-08 09:18
GPSTracker.sln1.57 kB06-20-07 09:38
GPSTracker.suo15.00 kB04-20-08 18:30
04.00 B
ajax-loader.gif3.13 kB04-02-08 11:37
compassE.jpg1.21 kB05-21-07 13:23
compassN.jpg1.24 kB05-21-07 13:20
compassNE.jpg1.23 kB05-21-07 13:26
compassNW.jpg1.22 kB05-21-07 13:26
compassS.jpg1.23 kB05-21-07 13:23
compassSE.jpg1.22 kB05-21-07 13:26
compassSW.jpg1.22 kB05-21-07 13:25
compassW.jpg1.21 kB05-21-07 13:25
coolblue_small.png478.00 B05-02-06 13:46
coolred_small.png466.00 B05-02-06 13:45
coolshadow_small.png436.00 B05-02-06 13:36
cooltransparent_small.png3.08 kB05-02-06 13:37
04.00 B
maps2.js11.22 kB04-18-08 21:09
04.00 B
Download.aspx547.00 B04-18-08 06:35
Download.aspx.cs412.00 B06-19-07 12:53
GPST2.0.jad410.00 B04-20-08 18:19
GPST2.0.jar8.96 kB04-20-08 18:19
04.00 B
styles.css1.04 kB04-18-08 19:59
Web.config533.00 B04-18-08 06:16
04.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