📄 track.java
字号:
// catch(Exception e)
// {
// if(description == "")
// description = typeS;
// }
// parser.next();
// } else
// if(parserName.equals("severity"))
// {
// parser.next();
// int severity = Integer.parseInt(parser.getText());
// switch(severity)
// {
// case 5: // '\005'
// color = 0xff0000;
// break;
//
// case 4: // '\004'
// color = 0xff2000;
// break;
//
// case 3: // '\003'
// color = 0xff4000;
// break;
//
// case 2: // '\002'
// color = 0xff6000;
// break;
//
// case 1: // '\001'
// default:
// color = 0xff8080;
// break;
// }
// parser.next();
// } else
// if(parserName.equals("color"))
// {
// parser.next();
// String colS = parser.getText();
// if(inIconStyle)
// {
// int pos = colS.indexOf('x');
// if(pos != -1)
// colS = colS.substring(pos);
// color = (int)Long.parseLong(colS, 16);
// }
// parser.next();
// } else
// if(parserName.equals("tel") || parserName.equals("phonenumber"))
// {
// parser.next();
// tel = parser.getText().trim();
// parser.next();
// } else
// if(parserName.equals("photoURL"))
// {
// parser.next();
// photoName = parser.getText();
// parser.next();
// } else
// if(parserName.equals("description") || parserName.equals("desc"))
// {
// parser.next();
// description = parser.getText();
// }
//// goto _L3
////_L6:
// parserName = parser.getName().toLowerCase();
// if(parserName.equals("item") || parserName.equals("flag") || parserName.equals("poi") || parserName.equals("waypoint") || parserName.equals("result") || parserName.equals("groundoverlay") || parserName.equals("placemark") && lon != null)
// {
// inItem = false;
// try
// {
// if(UtilMidp.DEBUG)
// System.out.println("Location: " + lon + " lat:" + lat + " name:" + name);
// OneLoc p = m_locType.clone(UtilMidp.parseFloat(lon), UtilMidp.parseFloat(lat));
// if(name != null)
// p.name = name;
// if(tel != null)
// p.phoneNum = tel;
// if(iconName != null)
// p.iconName = iconName;
// if(description != null)
// p.description = description;
// if(photoName != null)
// p.imageName = photoName;
// if(adr != null)
// p.address = adr;
// adr = null;
// if(color != -1)
// p.m_col = color;
// color = -1;
// if(type != -1)
// p.m_type = type;
// type = -1;
// String key;
// for(Enumeration e = values.keys(); e.hasMoreElements(); p.setValue(key, values.get(key)))
// key = (String)e.nextElement();
//
// values.clear();
// listPlaces.addElement(p);
// if(m_a != null)
// m_a.setString("Read " + description + "(" + listPlaces.size() + ")");
// }
// catch(Exception e)
// {
// System.out.println(e + "\nWhile trying to create a location");
// }
// iconName = null;
// tel = null;
// photoName = null;
// description = null;
// name = null;
// num++;
// } else
// if(parserName.equals("link") || parserName.equals("networklink"))
// {
// if(parserName.equals("networklink"))
// m_url += (m_url.indexOf('?') != -1 ? 38 : '?') + bbox;
// inLink = false;
// } else
// if(parserName.equals("blocks"))
// inBlock = false;
// else
// if(parserName.equals("wpt"))
// inWpt = false;
// else
// if(!parserName.equals("trkseg"))
// if(parserName.equals("linestring"))
// {
// inLineString = false;
// lon = null;
// } else
// if(parserName.equals("style"))
// {
// if(curStyleName != null)
// styles.put(curStyleName, m_locType);
// } else
// if(parserName.equals("icon"))
// inIcon = false;
// else
// if(parserName.equals("iconstyle"))
// {
// inIconStyle = false;
// m_locType = m_defaultLocType.clone(m_defaultLocType.m_lon, m_defaultLocType.m_lat);
// if(urlIcon != null)
// {
// Image ima = IconPool.getImageFromPool(urlIcon);
// if(iconX == 0 && iconY == 0)
// iconX = ima.getWidth() / 2;
// m_locType.setIconImage(ima, -iconX, -iconY);
// } else
// {
// m_locType.m_col = color;
// }
// }
//// goto _L3
////_L4:
// System.out.println("end doc...");
// for(int i = 0; i < listPlaces.size(); i++)
// {
// Object l = listPlaces.elementAt(i);
// for(int j = 0; j < oldList.size(); j++)
// {
// Object old = (OneLoc)oldList.elementAt(j);
// if(l.equals(old))
// {
// ((OneLoc)old).hash = ((OneLoc)l).hash;
// listPlaces.setElementAt(old, i);
// }
// }
//
// }
//
// if(listPlaces != null)
// nbWaypoints = listPlaces.size();
// if(segments != null)
// {
// coordSeg = new int[nbSegment];
// sizeTrack = nbSegment / 2;
// System.arraycopy(segments, 0, coordSeg, 0, nbSegment);
// }
// if(m_tn_glob != null)
// m_tn_glob.onTrackLoaded(this);
// if(m_tn != null)
// m_tn.onTrackLoaded(this);
// loaded = true;
// if(doReload)
// setUrl(m_url, null);
// return false;
//// Exception e;
//// e;
//// e.printStackTrace();
//// UtilMidp.MsgBox("Importing", e.toString(), AlertType.ERROR, -2);
//// try
//// {
//// Thread.sleep(1000L);
//// }
//// catch(InterruptedException e1)
//// {
//// e1.printStackTrace();
//// }
////_L2:
//// if(m_tn_glob != null)
//// m_tn_glob.onTrackLoaded(this);
//// if(m_tn != null)
//// m_tn.onTrackLoaded(this);
//// loaded = true;
//// if(num != 0);
//// return false;
}
String getNextTextElem(KXmlParser parser)
{
String res = "";
try
{
parser.next();
res = parser.getText();
parser.next();
}
catch(Exception e)
{
e.printStackTrace();
}
return res;
}
public void error(int inErrorCode)
{
String theError = "Error " + inErrorCode + " while accessing the URL " + m_url + "\n check the URL..";
System.out.println(theError);
UtilMidp.MsgBox("Error", theError, AlertType.ERROR, -2);
loaded = true;
if(m_tn_glob != null)
m_tn_glob.onTrackLoaded(this);
if(m_tn != null)
m_tn.onTrackLoaded(this);
}
public void loaded(URLFetcher f)
{
loaded = true;
}
public boolean lineRead(URLFetcher f, String inLine)
{
return false;
}
public static void setGlobalNotifier(TrackNotifier tn)
{
m_tn_glob = tn;
}
public void setNotifier(TrackNotifier tn)
{
m_tn = tn;
if(loaded && m_tn != null)
m_tn.onTrackLoaded(this);
}
public String sendTrack(String theUrl)
{
String res = "Sending ok";
try
{
if(m_rmsId != -1)
loadTrack();
else
saveTrack();
System.out.println("the url:" + theUrl);
HttpConnection cnx = null;
int status = -1;
cnx = URLFetcher.open(theUrl);
cnx.setRequestMethod("POST");
DataOutputStream dos = cnx.openDataOutputStream();
System.out.println("open input stream...");
System.out.println("writing ");
for(int i = 0; i < savedTrack.length; i++)
dos.writeByte(savedTrack[i]);
System.out.println("flush");
dos.flush();
dos.close();
System.out.println(cnx.getResponseMessage());
status = cnx.getResponseCode();
if(status == 200)
{
InputStream is = cnx.openInputStream();
System.out.println("Loaded..");
} else
{
System.out.println("error.." + status);
res = "error..." + status;
}
}
catch(Exception e)
{
e.printStackTrace();
res = e.toString();
}
return res;
}
public void loadTrack()
{
if(!isInit && m_rmsId != -1)
try
{
RecordStore rs = RecordStore.openRecordStore("GPSTrack", true);
savedTrack = rs.getRecord(m_rmsId);
isInit = true;
if(UtilMidp.DEBUG)
System.out.println("Trying to read:" + m_rmsId + " size:" + rs.getRecordSize(m_rmsId));
rs.closeRecordStore();
}
catch(RecordStoreException e)
{
e.printStackTrace();
}
}
public int[] getTrack()
{
int res[] = null;
if(coordSeg == null && m_rmsId != -1)
{
int maxRead = 0;
loadTrack();
try
{
if(savedTrack != null)
{
byte b[] = savedTrack;
int nbElems = sizeTrack;
coordSeg = new int[nbElems * 2];
times = new long[nbElems];
alts = new int[nbElems];
speeds = new int[nbElems];
courses = new int[nbElems];
ByteArrayInputStream bi = new ByteArrayInputStream(b);
DataInputStream dataIn = new DataInputStream(bi);
byte nameb[] = new byte[64];
dataIn.read(nameb);
dataIn.readInt();
dataIn.readInt();
dataIn.readLong();
dataIn.readLong();
for(int i = 0; i < nbElems; i++)
{
Float lon = Float.readFloat(dataIn);
Float lat = Float.readFloat(dataIn);
Float alt = Float.readFloat(dataIn);
Float dir = Float.readFloat(dataIn);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -