use of net.wigle.wigleandroid.DBException in project wigle-wifi-wardriving by wiglenet.
the class KmlWriter method subRun.
@SuppressLint("SimpleDateFormat")
@Override
protected void subRun() throws IOException {
final Bundle bundle = new Bundle();
final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
final SimpleDateFormat fileDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
final String filename = "WigleWifi_" + fileDateFormat.format(new Date()) + ".kml";
final FileOutputStream fos = MainActivity.createFile(context, filename, false);
// header
ObservationUploader.writeFos(fos, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<kml xmlns=\"http://www.opengis.net/kml/2.2\"><Document>" + "<Style id=\"red\"><IconStyle><Icon><href>http://maps.google.com/mapfiles/ms/icons/red-dot.png</href></Icon></IconStyle></Style>" + "<Style id=\"yellow\"><IconStyle><Icon><href>http://maps.google.com/mapfiles/ms/icons/yellow-dot.png</href></Icon></IconStyle></Style>" + "<Style id=\"green\"><IconStyle><Icon><href>http://maps.google.com/mapfiles/ms/icons/green-dot.png</href></Icon></IconStyle></Style>" + "<Folder><name>Wifi Networks</name>\n");
// body
Cursor cursor = null;
Status status = null;
try {
if (this.networks == null) {
cursor = dbHelper.networkIterator();
writeKmlFromCursor(fos, cursor, dateFormat, 0, dbHelper.getNetworkCount(), bundle);
} else {
int count = 0;
for (String network : networks) {
// MainActivity.info( "network: " + network );
cursor = dbHelper.getSingleNetwork(network);
writeKmlFromCursor(fos, cursor, dateFormat, count, networks.size(), bundle);
cursor.close();
cursor = null;
count++;
}
}
status = Status.WRITE_SUCCESS;
} catch (final InterruptedException ex) {
MainActivity.info("Writing Kml Interrupted: " + ex);
} catch (DBException ex) {
dbHelper.deathDialog("Writing Kml", ex);
status = Status.EXCEPTION;
} catch (final Exception ex) {
ex.printStackTrace();
MainActivity.error("ex problem: " + ex, ex);
MainActivity.writeError(this, ex, context);
status = Status.EXCEPTION;
bundle.putString(BackgroundGuiHandler.ERROR, "ex problem: " + ex);
} finally {
if (cursor != null) {
cursor.close();
}
}
// footer
ObservationUploader.writeFos(fos, "</Folder>\n</Document></kml>");
fos.close();
bundle.putString(BackgroundGuiHandler.FILEPATH, MainActivity.getSDPath() + filename);
bundle.putString(BackgroundGuiHandler.FILENAME, filename);
MainActivity.info("done with kml export");
// status is null on interrupted
if (status != null) {
// tell gui
sendBundledMessage(status.ordinal(), bundle);
}
}
use of net.wigle.wigleandroid.DBException in project wigle-wifi-wardriving by wiglenet.
the class QueryThread method run.
@Override
public void run() {
while (!done.get()) {
try {
final Request request = queue.take();
// if(true) throw new DBException("meh", new SQLiteException("meat puppets"));
if (request != null) {
final SQLiteDatabase db = dbHelper.getDB();
if (db != null) {
final Cursor cursor = db.rawQuery(request.sql, null);
while (cursor.moveToNext()) {
if (!request.handler.handleRow(cursor)) {
break;
}
}
request.handler.complete();
cursor.close();
}
}
} catch (InterruptedException ex) {
MainActivity.info(getName() + " interrupted: " + ex);
} catch (IllegalStateException ex) {
MainActivity.info(getName() + " illegal state ex: " + ex);
} catch (DBException ex) {
dbHelper.deathDialog("query thread", ex);
}
}
}
Aggregations