diff options
author | Christopher Baines <cbaines8@gmail.com> | 2012-03-08 23:41:16 +0000 |
---|---|---|
committer | Christopher Baines <cbaines8@gmail.com> | 2012-03-08 23:41:16 +0000 |
commit | 86d0e42fa3300f5c765982a9e75ee37b42cb1edf (patch) | |
tree | 7e621d8d7ebd3639523a8d217e0c393a5118e226 /src/net | |
parent | ac9a84e8bb5dc43a5d72840eaa325c5e99ac610a (diff) | |
download | southamptonuniversitymap-86d0e42fa3300f5c765982a9e75ee37b42cb1edf.tar southamptonuniversitymap-86d0e42fa3300f5c765982a9e75ee37b42cb1edf.tar.gz |
More improvements.
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/cbaines/suma/DataManager.java | 47 | ||||
-rw-r--r-- | src/net/cbaines/suma/MapActivity.java | 202 | ||||
-rw-r--r-- | src/net/cbaines/suma/Preferences.java | 4 | ||||
-rw-r--r-- | src/net/cbaines/suma/WelcomeDialog.java | 15 |
4 files changed, 118 insertions, 150 deletions
diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java index 08425a7..2dcba40 100644 --- a/src/net/cbaines/suma/DataManager.java +++ b/src/net/cbaines/suma/DataManager.java @@ -75,6 +75,53 @@ public class DataManager { private static Dao<Bus, Integer> busDao; private static Dao<BusStop, String> busStopDao; + static void createDatabase(final Context context) throws SQLException, IOException { + Log.i(TAG, "Begining loading databases"); + Dao<Building, String> buildingDao; + + buildingDao = helper.getBuildingDao(); + + long buildingCount = buildingDao.countOf(); + Log.i(TAG, "Building count " + buildingCount); + if (buildingCount < 260) { + + loadBuildings(context); + Log.i(TAG, "Loaded building database"); + + } + + 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) { + + loadBusData(context, true); + Log.i(TAG, "Loaded bus stop database"); + + } + + Dao<Site, String> siteDao = helper.getSiteDao(); + + long siteCount = siteDao.countOf(); + Log.i(TAG, "Sites count " + siteCount); + if (siteCount < 21) { + + loadSiteData(context); + + } + + Log.i(TAG, "Finished loading databases"); + + } + public static void loadBuildings(Context context) throws SQLException, IOException { DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); Dao<Building, String> buildingDao = helper.getBuildingDao(); 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() { diff --git a/src/net/cbaines/suma/Preferences.java b/src/net/cbaines/suma/Preferences.java index 0508251..fde8b70 100644 --- a/src/net/cbaines/suma/Preferences.java +++ b/src/net/cbaines/suma/Preferences.java @@ -14,5 +14,9 @@ public interface Preferences { static final String SHOW_IDENTIFIERS = "showIdentifiers"; static final boolean SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT = false; + static final String APP_VERSION = "appVersion"; + static final String APP_NOT_INSTALLED = ""; + static final String CURRENT_APP_VERSION = "0.8"; + static final String FAVOURITES_PREFERENCES = "favourites"; } diff --git a/src/net/cbaines/suma/WelcomeDialog.java b/src/net/cbaines/suma/WelcomeDialog.java index d0d6fd0..d89abf0 100644 --- a/src/net/cbaines/suma/WelcomeDialog.java +++ b/src/net/cbaines/suma/WelcomeDialog.java @@ -21,13 +21,18 @@ package net.cbaines.suma; import android.app.Dialog; import android.content.Context; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; import android.view.View; +import android.view.View.OnClickListener; import android.widget.Button; -public class WelcomeDialog extends Dialog implements android.view.View.OnClickListener { +public class WelcomeDialog extends Dialog implements OnClickListener, Preferences { // private static final String TAG = "WelcomeDialog"; + final SharedPreferences sharedPrefs; + private Button continueButton; public WelcomeDialog(Context context) { @@ -36,13 +41,17 @@ public class WelcomeDialog extends Dialog implements android.view.View.OnClickLi this.setTitle(R.string.welcome_dialog_title); setContentView(R.layout.welcome_dialog); - + + sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + continueButton = (Button) findViewById(R.id.welcomeDialogButton); continueButton.setOnClickListener(this); } public void onClick(View arg0) { + + sharedPrefs.edit().putString(APP_VERSION, CURRENT_APP_VERSION).commit(); + this.dismiss(); } - } |