[go: up one dir, main page]

Menu

[r5]: / ociScreen.java  Maximize  Restore  History

Download this file

175 lines (163 with data), 5.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
* ociScreen.java
*
* Copyright (C) 2008 by delta_foxtrot@users.sourceforge.net
* http://gpsavenger.sf.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;
import net.rim.blackberry.api.browser.*;
public class ociScreen extends MainScreen
{
private RadioStatusListener radioStatusListener = null;
private GPS doGPS = null;
private LabelField lf = new LabelField("Click on the Start GPS menu item to start logging locations");
private LabelField lf2 = new LabelField("");
public ociScreen()
{
super();
LabelField title = new LabelField("OpenCellID 4 BlackBerry", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
doGPS = new GPS();
radioStatusListener = new RadioStatusListener()
{
public void signalLevel(int level)
{
onRadioStatusChanged();
}
public void networkStarted(int networkId, int service)
{
onRadioStatusChanged();
}
public void baseStationChange()
{
onRadioStatusChanged();
}
public void radioTurnedOff()
{
onRadioStatusChanged();
}
public void pdpStateChange(int apn, int state, int cause)
{
onRadioStatusChanged();
}
public void networkStateChange(int state)
{
onRadioStatusChanged();
}
public void networkScanComplete(boolean success)
{
onRadioStatusChanged();
}
/*
public void mobilityManagementEvent(int eventCode, int cause)
{
onRadioStatusChanged();
}
*/
public void networkServiceChange(int networkId, int service)
{
onRadioStatusChanged();
}
};
Application.getApplication().addRadioListener(radioStatusListener);
add(lf);
add(lf2);
}
public boolean onClose()
{
System.exit(0);
return(true);
}
MenuItem gpsRunMenu = new MenuItem("Start GPS", 30, 30)
{
public void run()
{
if(gpsRunMenu.toString().equals("Start GPS"))
{
doGPS.startLocationUpdate();
gpsRunMenu.setText("Stop GPS");
lf.setText("Starting GPS, please wait while a lock is achieved.");
} else {
doGPS.stopLocationUpdate();
gpsRunMenu.setText("Start GPS");
doGPS.latitude = -999.0;
doGPS.longitude = -999.0;
lf.setText("Click on the Start GPS menu item to start logging locations");
}
}
};
MenuItem websiteMenu = new MenuItem("OCI4BB Homepage", 40, 40)
{
public void run()
{
Browser.getDefaultSession().displayPage("http://oci4bb.sourceforge.net");
}
};
MenuItem aboutMenu = new MenuItem("About", 50, 50)
{
public void run()
{
Browser.getDefaultSession().displayPage("http://www.opencellid.org");
}
};
MenuItem quitMenu = new MenuItem("Quit", 60, 60)
{
public void run()
{
onClose();
}
};
protected void makeMenu(Menu menu, int instance)
{
menu.add(gpsRunMenu);
menu.add(websiteMenu);
menu.add(aboutMenu);
menu.add(quitMenu);
}
protected void onRadioStatusChanged()
{
System.out.println("lat: "+doGPS.latitude);
System.out.println("lon: "+doGPS.longitude);
System.out.println("last: "+doGPS.lastupdate);
System.out.println("time: "+(System.currentTimeMillis() / 1000));
if(doGPS.latitude < -90 || doGPS.latitude > 90 ||
doGPS.longitude < -180 || doGPS.longitude > 180 ||
doGPS.lastupdate < ((System.currentTimeMillis() / 1000) - 120) ||
!ServerCommunication.getGPRSConnectionAvailable())
{
lf2.setText("Still waiting for lock...");
return;
}
String string = "http://www.opencellid.org/measure/add";
string += "?key=9c46be0fe0d6b163f75b22a4acbc6a50";
string += "&userkey="+ociApp.getkey();
string += "&mnc="+RadioInfo.getMNC(RadioInfo.getCurrentNetworkIndex());
string += "&mcc="+Integer.toHexString(GPRSInfo.getCellInfo().getMCC());
string += "&lac="+GPRSInfo.getCellInfo().getLAC();
string += "&cellid="+GPRSInfo.getCellInfo().getCellId();
string += "&lat="+doGPS.latitude;
string += "&lon="+doGPS.longitude;
string += "&signal="+RadioInfo.getSignalLevel();
lf.setText(string);
System.out.println("url: "+string);
String reply = ServerCommunication.http_get(string);
lf2.setText(reply);
}
}