diff options
Diffstat (limited to 'src/net/cbaines/suma/MapActivity.java')
-rw-r--r-- | src/net/cbaines/suma/MapActivity.java | 219 |
1 files changed, 64 insertions, 155 deletions
diff --git a/src/net/cbaines/suma/MapActivity.java b/src/net/cbaines/suma/MapActivity.java index e966b57..8ed8e9e 100644 --- a/src/net/cbaines/suma/MapActivity.java +++ b/src/net/cbaines/suma/MapActivity.java @@ -69,7 +69,7 @@ import com.j256.ormlite.dao.Dao; * @author Christopher Baines <cbaines8@gmail.com> * */ -public class MapActivity extends ToastHelperActivity implements MapViewConstants, Runnable, RouteColorConstants, +public class MapActivity extends ToastHelperActivity implements MapViewConstants, RouteColorConstants, OnItemClickListener, OnItemLongClickListener, OnSharedPreferenceChangeListener, Preferences { /** @@ -86,6 +86,8 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants static final int VIEW_DIALOG_ID = 0; static final int FAVOURITE_DIALOG_ID = 1; + static final int WELCOME_DIALOG_ID = 2; + private POIDialog favDialog; private HashMap<String, Overlay> overlays = new HashMap<String, Overlay>(); @@ -174,7 +176,7 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants private MapActivity instance; - private static final String TAG = "SUM"; + private static final String TAG = "MapActivity"; @SuppressWarnings("unchecked") public void onCreate(Bundle savedInstanceState) { @@ -184,8 +186,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); @@ -209,13 +248,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) { @@ -274,12 +308,19 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants mapController.setCenter(userLocation); + final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); + String appVersion = sharedPrefs.getString(APP_VERSION, APP_NOT_INSTALLED); + + if (appVersion.equals(APP_NOT_INSTALLED) || !appVersion.equals(CURRENT_APP_VERSION)) { + 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); @@ -302,7 +343,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() { @@ -323,143 +364,6 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants return overlays; } - @Override - public boolean onSearchRequested() { - Bundle appData = new Bundle(); - appData.putInt(SearchActivity.ORIGIN, SearchActivity.MAP_ACTIVITY); - startSearch(null, false, appData, false); - return true; - } - - 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)); @@ -484,10 +388,11 @@ 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"); + // Log.v(TAG, "Bus route " + busRoute.code + "(" + busRoute.id + + // ") is not unilink"); continue; } Log.v(TAG, "Looking at showing " + busRoute.code + " route overlay"); @@ -495,12 +400,13 @@ 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"); + // Log.v(TAG, "Looking at showing " + site.name + + // " site overlay"); if (activityPrefs.getBoolean(SITE_OVERLAYS + site.name, SITE_OVERLAYS_ENABLED_BY_DEFAULT)) { showSiteOverlay(site); } @@ -508,9 +414,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() { @@ -1108,6 +1014,9 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants favDialog.setOnItemLongClickListener(this); favDialog.setTitle(R.string.favourites_dialog_title); return favDialog; + case WELCOME_DIALOG_ID: + WelcomeDialog welcomeDialog = new WelcomeDialog(instance); + return welcomeDialog; } return null; } |