diff options
Diffstat (limited to 'src/net/cbaines/suma/MapActivity.java')
-rw-r--r-- | src/net/cbaines/suma/MapActivity.java | 202 |
1 files changed, 55 insertions, 147 deletions
diff --git a/src/net/cbaines/suma/MapActivity.java b/src/net/cbaines/suma/MapActivity.java index 413ec48..9e6ccf1 100644 --- a/src/net/cbaines/suma/MapActivity.java +++ b/src/net/cbaines/suma/MapActivity.java @@ -69,8 +69,8 @@ import com.j256.ormlite.dao.Dao; * @author Christopher Baines <cbaines8@gmail.com> * */ -public class MapActivity extends ToastHelperActivity implements MapViewConstants, Runnable, RouteColorConstants, - OnItemClickListener, OnItemLongClickListener, OnSharedPreferenceChangeListener, Preferences { +public class MapActivity extends ToastHelperActivity implements MapViewConstants, RouteColorConstants, OnItemClickListener, + OnItemLongClickListener, OnSharedPreferenceChangeListener, Preferences { /** * Enable to use the database in the assets folder, if its not enabled, the database is built from the csv files in the assets @@ -185,8 +185,45 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants instance = this; - Thread databaseThread = new Thread(this); // Start the database thread - databaseThread.start(); + Log.i(TAG, "Begining loading database " + (System.currentTimeMillis() - startTime)); + + DatabaseHelper helper = getHelper(); + Log.i(TAG, "Got the helper at " + (System.currentTimeMillis() - startTime)); + + boolean dbExist = helper.checkDataBase(); + Log.i(TAG, "Finished checking the database at " + (System.currentTimeMillis() - startTime)); + + if (dbExist) { + // do nothing - database already exist + } else { + + if (useBundledDatabase) { + try { + // By calling this method and empty database will be created + // into the default system path + // of your application so we are gonna be able to overwrite + // that database with our database. + Log.i(TAG, "GetReadableDatabase"); + helper.getWritableDatabase().close(); + + helper.copyDataBase(); + Log.i(TAG, "Out of copy database"); + } catch (IOException ioe) { + throw new Error("Unable to create database"); + } + } else { + try { + DataManager.createDatabase(instance); + } catch (SQLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + } + + Log.i(TAG, "Finished the database " + (System.currentTimeMillis() - startTime)); setContentView(R.layout.map_activity); @@ -208,13 +245,8 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants myLocationOverlay.setEnabled(true); Log.i(TAG, "Finished creating myLocationOverlay"); - while (databaseThread.isAlive()) { - Thread.yield(); - } - new Thread(new Runnable() { public void run() { - Thread.currentThread().setPriority(Thread.MAX_PRIORITY); try { showOverlays(); } catch (SQLException e) { @@ -272,15 +304,20 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants } mapController.setCenter(userLocation); - - showDialog(WELCOME_DIALOG_ID); + + final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); + String appVersion = sharedPrefs.getString(APP_VERSION, APP_NOT_INSTALLED); + + if (appVersion.equals(APP_NOT_INSTALLED)) { + showDialog(WELCOME_DIALOG_ID); + } Log.i(TAG, "Finished onCreate " + (System.currentTimeMillis() - startTime)); } public void onResume() { super.onResume(); - Log.i(TAG, "OnResume"); + Log.i(TAG, "OnResume " + (System.currentTimeMillis() - startTime)); if (myLocationOverlay != null) { final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); final SharedPreferences activityPrefs = getPreferences(0); @@ -303,7 +340,7 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants sharedPrefs.registerOnSharedPreferenceChangeListener(this); activityPrefs.registerOnSharedPreferenceChangeListener(this); } - Log.i(TAG, "Finished OnResume"); + Log.i(TAG, "Finished OnResume " + (System.currentTimeMillis() - startTime)); } public void onPause() { @@ -324,135 +361,6 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants return overlays; } - public void run() { - Log.i(TAG, "Begining loading database " + (System.currentTimeMillis() - startTime)); - - DatabaseHelper helper = getHelper(); - Log.i(TAG, "Got the helper at " + (System.currentTimeMillis() - startTime)); - - boolean dbExist = helper.checkDataBase(); - Log.i(TAG, "Finished checking the database at " + (System.currentTimeMillis() - startTime)); - - if (dbExist) { - // do nothing - database already exist - } else { - - if (useBundledDatabase) { - try { - // By calling this method and empty database will be created - // into the default system path - // of your application so we are gonna be able to overwrite - // that database with our database. - Log.i(TAG, "GetReadableDatabase"); - helper.getWritableDatabase().close(); - - helper.copyDataBase(); - Log.i(TAG, "Out of copy database"); - } catch (IOException ioe) { - throw new Error("Unable to create database"); - } - } else { - Thread buildingThread = null; - Thread busStopThread = null; - Thread siteThread = null; - - Log.i(TAG, "Begining loading databases " + (System.currentTimeMillis() - startTime)); - try { - Dao<Building, String> buildingDao; - - buildingDao = helper.getBuildingDao(); - - long buildingCount = buildingDao.countOf(); - Log.i(TAG, "Building count " + buildingCount); - if (buildingCount < 260) { - buildingThread = new Thread(new Runnable() { - public void run() { - try { - DataManager.loadBuildings(instance); - Log.i(TAG, "Loaded building database " + (System.currentTimeMillis() - startTime)); - } catch (SQLException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } - }); - - buildingThread.start(); - } - - Dao<BusStop, String> busStopDao = helper.getBusStopDao(); - Dao<BusRoute, Integer> busRouteDao = helper.getBusRouteDao(); - Dao<RouteStop, Integer> routeStopsDao = helper.getRouteStopsDao(); - - long busStopCount = busStopDao.countOf(); - long busRouteCount = busRouteDao.countOf(); - long routeStopsCount = routeStopsDao.countOf(); - - Log.i(TAG, "BusStop count " + busStopCount); - Log.i(TAG, "BusRoute count " + busRouteCount); - Log.i(TAG, "RouteStops count " + routeStopsCount); - if (busStopCount < 217 || busRouteCount < 5 || routeStopsCount < 327) { - busStopThread = new Thread(new Runnable() { - public void run() { - try { - DataManager.loadBusData(instance, true); - Log.i(TAG, "Loaded bus stop database " + (System.currentTimeMillis() - startTime)); - } catch (SQLException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } - }); - - busStopThread.start(); - } - - Dao<Site, String> siteDao = helper.getSiteDao(); - - long siteCount = siteDao.countOf(); - Log.i(TAG, "Sites count " + siteCount); - if (siteCount < 21) { - siteThread = new Thread(new Runnable() { - public void run() { - try { - DataManager.loadSiteData(instance); - Log.i(TAG, "Loaded site database " + (System.currentTimeMillis() - startTime)); - } catch (SQLException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } - }); - - siteThread.start(); - } - - while (true) { - if ((buildingThread == null || !buildingThread.isAlive()) - && (busStopThread == null || !busStopThread.isAlive()) - && (siteThread == null || !siteThread.isAlive())) - break; - - Thread.yield(); - } - - Log.i(TAG, "Finished loading databases " + (System.currentTimeMillis() - startTime)); - - } catch (SQLException e1) { - e1.printStackTrace(); - } - } - - } - - Log.i(TAG, "Begining setting up the static values " + (System.currentTimeMillis() - startTime)); - - Log.i(TAG, "Finished the database thread " + (System.currentTimeMillis() - startTime)); - } - private void showOverlays() throws SQLException { Log.i(TAG, "Began showing overlays at " + (System.currentTimeMillis() - startTime)); @@ -477,7 +385,7 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants showBuildingOverlays(); } - Log.i(TAG, "Begining to show the route overlays at " + (System.currentTimeMillis() - startTime)); + Log.v(TAG, "Begining to show the route overlays at " + (System.currentTimeMillis() - startTime)); for (BusRoute busRoute : getHelper().getBusRouteDao()) { if (!busRoute.uniLink) { // Log.v(TAG, "Bus route " + busRoute.code + "(" + busRoute.id + ") is not unilink"); @@ -488,9 +396,9 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants showRouteOverlay(busRoute); } } - Log.i(TAG, "Finished loading routes " + (System.currentTimeMillis() - startTime)); + Log.v(TAG, "Finished loading routes " + (System.currentTimeMillis() - startTime)); - Log.i(TAG, "Begining to show the site overlays at " + (System.currentTimeMillis() - startTime)); + Log.v(TAG, "Begining to show the site overlays at " + (System.currentTimeMillis() - startTime)); try { for (Site site : getHelper().getSiteDao()) { // Log.v(TAG, "Looking at showing " + site.name + " site overlay"); @@ -501,9 +409,9 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants } catch (SQLException e) { e.printStackTrace(); } - Log.i(TAG, "Finished showing the site overlays " + (System.currentTimeMillis() - startTime)); + Log.v(TAG, "Finished showing the site overlays " + (System.currentTimeMillis() - startTime)); - Log.i(TAG, "Finished showing all the overlays " + (System.currentTimeMillis() - startTime)); + Log.v(TAG, "Finished showing all the overlays " + (System.currentTimeMillis() - startTime)); } private void showUtilityOverlays() { |