aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/net/cbaines/suma/BuildingActivity.java33
-rw-r--r--src/net/cbaines/suma/BuildingNumOverlay.java58
-rw-r--r--src/net/cbaines/suma/BusActivity.java149
-rw-r--r--src/net/cbaines/suma/BusRoute.java9
-rw-r--r--src/net/cbaines/suma/BusSpecificStopView.java93
-rw-r--r--src/net/cbaines/suma/BusSpecificTimetableAdapter.java28
-rw-r--r--src/net/cbaines/suma/BusStop.java3
-rw-r--r--src/net/cbaines/suma/BusStopActivity.java14
-rw-r--r--src/net/cbaines/suma/BusStopOverlay.java33
-rw-r--r--src/net/cbaines/suma/DataManager.java76
-rw-r--r--src/net/cbaines/suma/DatabaseConfigUtil.java5
-rw-r--r--src/net/cbaines/suma/DatabaseHelper.java37
-rw-r--r--src/net/cbaines/suma/MapActivity.java219
-rw-r--r--src/net/cbaines/suma/POIView.java6
-rw-r--r--src/net/cbaines/suma/Preferences.java4
-rw-r--r--src/net/cbaines/suma/StopLoading.java11
-rw-r--r--src/net/cbaines/suma/WelcomeDialog.java64
17 files changed, 480 insertions, 362 deletions
diff --git a/src/net/cbaines/suma/BuildingActivity.java b/src/net/cbaines/suma/BuildingActivity.java
index 509bc41..b4bef1b 100644
--- a/src/net/cbaines/suma/BuildingActivity.java
+++ b/src/net/cbaines/suma/BuildingActivity.java
@@ -62,6 +62,8 @@ public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implem
private CheckBox favouritesCheckBox;
+ private Drawable buildingImage;
+
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.building_activity);
@@ -90,7 +92,12 @@ public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implem
buildingName = (TextView) findViewById(R.id.buildingActivityName);
progressBar = (ProgressBar) findViewById(R.id.buildingActivityLoadBar);
+ progressBar.setVisibility(View.VISIBLE);
message = (TextView) findViewById(R.id.buildingActivityMessage);
+ message.setVisibility(View.GONE);
+
+ imageButton = (ImageButton) findViewById(R.id.buildingActivityImage);
+ imageButton.setVisibility(View.GONE);
Log.i(TAG, "Building id " + ID);
@@ -105,9 +112,24 @@ public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implem
e1.printStackTrace();
}
- GetBuildingImageTask buildingImageTask = new GetBuildingImageTask();
- buildingImageTask.execute(building);
+ }
+
+ protected void onResume() {
+ super.onResume();
+ buildingImage = (Drawable) getLastNonConfigurationInstance();
+ if (buildingImage == null) {
+ GetBuildingImageTask buildingImageTask = new GetBuildingImageTask();
+ buildingImageTask.execute(building);
+ } else {
+ imageButton.setImageDrawable(buildingImage);
+ imageButton.setVisibility(View.VISIBLE);
+ imageButton.setScaleType(ScaleType.CENTER_INSIDE);
+ imageButton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ }
+ });
+ }
}
class GetBuildingImageTask extends AsyncTask<Building, Integer, Drawable> {
@@ -158,7 +180,7 @@ public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implem
errorMessage = "MalformedURLException";
} catch (IOException e) {
e.printStackTrace();
- errorMessage = "IOException";
+ errorMessage = "No Image (Either none avalible, or a connection issue)";
}
return null;
@@ -170,8 +192,11 @@ public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implem
if (image != null) {
Log.i(TAG, "Got a image for " + building + ", now displaying it");
+ buildingImage = image;
+
imageButton = (ImageButton) findViewById(R.id.buildingActivityImage);
imageButton.setImageDrawable(image);
+ imageButton.setVisibility(View.VISIBLE);
imageButton.setScaleType(ScaleType.CENTER_INSIDE);
imageButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
@@ -189,7 +214,7 @@ public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implem
@Override
public Object onRetainNonConfigurationInstance() {
- return null;
+ return buildingImage;
}
public void onCheckedChanged(CompoundButton button, boolean checked) {
diff --git a/src/net/cbaines/suma/BuildingNumOverlay.java b/src/net/cbaines/suma/BuildingNumOverlay.java
index f11a166..b541aa1 100644
--- a/src/net/cbaines/suma/BuildingNumOverlay.java
+++ b/src/net/cbaines/suma/BuildingNumOverlay.java
@@ -94,33 +94,24 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared
}
/**
- * Draw a marker on each of our items. populate() must have been called
- * first.<br/>
+ * Draw a marker on each of our items. populate() must have been called first.<br/>
* <br/>
- * The marker will be drawn twice for each Item in the Overlay--once in the
- * shadow phase, skewed and darkened, then again in the non-shadow phase.
- * The bottom-center of the marker will be aligned with the geographical
- * coordinates of the Item.<br/>
+ * The marker will be drawn twice for each Item in the Overlay--once in the shadow phase, skewed and darkened, then again in
+ * the non-shadow phase. The bottom-center of the marker will be aligned with the geographical coordinates of the Item.<br/>
* <br/>
- * The order of drawing may be changed by overriding the getIndexToDraw(int)
- * method. An item may provide an alternate marker via its
- * OverlayItem.getMarker(int) method. If that method returns null, the
- * default marker is used.<br/>
+ * The order of drawing may be changed by overriding the getIndexToDraw(int) method. An item may provide an alternate marker
+ * via its OverlayItem.getMarker(int) method. If that method returns null, the default marker is used.<br/>
* <br/>
- * The focused item is always drawn last, which puts it visually on top of
- * the other items.<br/>
+ * The focused item is always drawn last, which puts it visually on top of the other items.<br/>
*
* @param canvas
- * the Canvas upon which to draw. Note that this may already have
- * a transformation applied, so be sure to leave it the way you
- * found it
+ * the Canvas upon which to draw. Note that this may already have a transformation applied, so be sure to leave it
+ * the way you found it
* @param mapView
- * the MapView that requested the draw. Use
- * MapView.getProjection() to convert between on-screen pixels
- * and latitude/longitude pairs
+ * the MapView that requested the draw. Use MapView.getProjection() to convert between on-screen pixels and
+ * latitude/longitude pairs
* @param shadow
- * if true, draw the shadow layer. If false, draw the overlay
- * contents.
+ * if true, draw the shadow layer. If false, draw the overlay contents.
*/
@Override
public void draw(final Canvas canvas, final MapView mapView, final boolean shadow) {
@@ -144,8 +135,7 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared
final SharedPreferences favouritesPrefs = context.getSharedPreferences(FAVOURITES_PREFERENCES, 0);
/*
- * Draw in backward cycle, so the items with the least index are on the
- * front.
+ * Draw in backward cycle, so the items with the least index are on the front.
*/
for (Iterator<Building> buildingIter = buildings.iterator(); buildingIter.hasNext();) {
final Building building = buildingIter.next();
@@ -219,8 +209,7 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared
if (showIdentifiers) {
str += " (" + building.id + ")";
}
- context.makeToast(str, context.getResources().getString(R.string.map_activity_toast_help_message),
- Toast.LENGTH_SHORT);
+ context.makeToast(str, context.getResources().getString(R.string.map_activity_toast_help_message), Toast.LENGTH_SHORT);
return true;
}
@@ -230,7 +219,7 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared
public boolean onDoubleTap(final MotionEvent event, final MapView mapView) {
if (!this.isEnabled())
return false;
-
+
Building building = getSelectedItem(event, mapView);
if (building == null) {
@@ -265,19 +254,27 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared
Log.v(TAG, "building Pressed " + building.id);
final SharedPreferences favouritesPrefs = context.getSharedPreferences(FAVOURITES_PREFERENCES, 0);
+ final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
if (favouritesPrefs.getBoolean(building.id, false)) {
favouritesPrefs.edit().remove(building.id).commit();
- context.makeToast(building.id + " removed from favourites", Toast.LENGTH_SHORT);
+ // if (sharedPrefs.getBoolean(SHOW_IDENTIFIERS, SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT)) {
+ context.makeToast(building.name + " removed from favourites", "(" + building.id + ")", Toast.LENGTH_SHORT);
+ // } else {
+ // context.makeToast(building.name + " removed from favourites", Toast.LENGTH_SHORT);
+ // }
} else {
- context.makeToast(building.id + " made a favourite", Toast.LENGTH_SHORT);
+ // if (sharedPrefs.getBoolean(SHOW_IDENTIFIERS, SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT)) {
+ context.makeToast(building.name + " added to favourites", "(" + building.id + ")", Toast.LENGTH_SHORT);
+ // } else {
+ // context.makeToast(building.name + " added to favourites", Toast.LENGTH_SHORT);
+ // }
favouritesPrefs.edit().putBoolean(building.id, true).commit();
}
- Collections.sort(buildings,
- new POIFavouriteComparator(context.getSharedPreferences(FAVOURITES_PREFERENCES, 0)));
+ Collections.sort(buildings, new POIFavouriteComparator(context.getSharedPreferences(FAVOURITES_PREFERENCES, 0)));
mapView.invalidate();
@@ -310,8 +307,7 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Log.i(TAG, "Got a favourites change in the BuildingNumOverlay for key " + key);
- Collections
- .sort(buildings, new POIFavouriteComparator(context.getSharedPreferences(FAVOURITES_PREFERENCES, 0)));
+ Collections.sort(buildings, new POIFavouriteComparator(context.getSharedPreferences(FAVOURITES_PREFERENCES, 0)));
}
}
diff --git a/src/net/cbaines/suma/BusActivity.java b/src/net/cbaines/suma/BusActivity.java
index ae209f4..04fe6cf 100644
--- a/src/net/cbaines/suma/BusActivity.java
+++ b/src/net/cbaines/suma/BusActivity.java
@@ -2,6 +2,7 @@ package net.cbaines.suma;
import java.io.IOException;
import java.sql.SQLException;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -16,6 +17,9 @@ import android.os.Handler;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Gravity;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
@@ -55,6 +59,8 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
Handler handler;
+ long timeOfLastRefresh = 0;
+
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bus_activity);
@@ -107,7 +113,7 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
timetableView = (ListView) findViewById(R.id.busActivityTimes);
if (bus.id != null) {
- Log.i(TAG, "Bus id is not null (" + bus.id + ") setting busIDTextView");
+ // Log.i(TAG, "Bus id is not null (" + bus.id + ") setting busIDTextView");
busIDTextView.setText(bus.id + " " + bus.getName());
} else {
Log.w(TAG, "Bus id is null?");
@@ -116,45 +122,68 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
}
if (bus.destinationString != null) {
- Log.i(TAG, "Bus destination string is " + bus.destinationString);
+ // Log.i(TAG, "Bus destination string is " + bus.destinationString);
busDestTextView
.setText(getResources().getString(R.string.bus_activity_destination_label) + bus.destinationString);
busDestTextView.setVisibility(View.VISIBLE);
} else {
- Log.i(TAG, "Bus destination string is null");
+ // Log.i(TAG, "Bus destination string is null");
busDestTextView.setText(getResources().getString(R.string.bus_activity_no_destination_message));
busDestTextView.setVisibility(View.VISIBLE);
}
busStops = bus.route.getRouteSection(instance, bus.direction);
- Log.i(TAG, "Got " + busStops.size() + " bus stops for this bus");
+ // Log.i(TAG, "Got " + busStops.size() + " bus stops for this bus");
if (bus.destination != null) {
Log.i(TAG, "Bus destination is " + bus.destination);
+
+ int index = busStops.indexOf(bus.destination);
+ if (index != -1) {
+ Log.v(TAG, "Found destination stop in busStops");
+ for (int i = index + 1; i < busStops.size(); i++) {
+ Log.v(TAG, "Removing " + busStops.get(i));
+ busStops.remove(i);
+ }
+ }
} else {
Log.i(TAG, "Bus destination is null");
}
refreshData = new Runnable() {
public void run() {
- for (int num = timetableView.getFirstVisiblePosition(); num < timetableView.getLastVisiblePosition(); num++) {
- Stop stop = timetable.get(num);
+ Log.v(TAG, "Refreshing data " + (System.currentTimeMillis() - timeOfLastRefresh));
+ timeOfLastRefresh = System.currentTimeMillis();
+ for (int num = timetableView.getFirstVisiblePosition(); num <= timetableView.getLastVisiblePosition(); num++) {
+ final Stop stop = timetable.get(num);
- GetTimetableStopTask task = tasks.get(busStops.get(num));
+ if (System.currentTimeMillis() - stop.timeOfFetch.getTime() > 20000) {
+ GetTimetableStopTask task = tasks.get(busStops.get(num));
- if (stop.timeOfFetch == null || (stop.timeOfFetch.getTime() - System.currentTimeMillis()) > 20000) {
- if (task != null) {
- if (task.getStatus() == AsyncTask.Status.FINISHED) {
- task = null;
+ if (task != null) { // If there is a taks
+ if (task.getStatus() == AsyncTask.Status.FINISHED) { // If its finished
+ task = null; // Delete it
}
}
- if (task == null) {
+ if (task == null) { // If there is now no task
+ // Log.v(TAG, "Updating " + busStops.get(num));
+
+ // Remove the old time from the timetable
+ synchronized (timetable) {
+ timetable.set(num,
+ new StopLoading(bus, busStops.get(num), null, new Date(
+ System.currentTimeMillis() - 21000), false));
+ displayTimetable(timetable);
+ }
+
task = new GetTimetableStopTask();
BusStop[] str = { stop.busStop };
task.execute(str);
tasks.put(stop.busStop, task);
}
+ } else {
+ // Log.v(TAG, "Not updating " + busStops.get(num));
}
}
@@ -166,13 +195,20 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
}
}
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.bus_menu, menu);
+ return true;
+ }
+
public void onResume() {
super.onResume();
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
if (sharedPrefs.getBoolean(UNI_LINK_BUS_TIMES, UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT)
|| sharedPrefs.getBoolean(NON_UNI_LINK_BUS_TIMES, NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT)) {
- Log.i(TAG, "Live Times enabled");
+ // Log.i(TAG, "Live Times enabled");
timetable = (Timetable) getLastNonConfigurationInstance();
handler = new Handler();
@@ -181,14 +217,19 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
Log.i(TAG, "No Previous timetable");
timetable = new Timetable();
for (int i = 0; i < busStops.size(); i++) {
- timetable.add(new Stop(bus, busStops.get(i), null, null, false));
+ // Add a loading stop, with a fetch time such that it will be fetched
+ timetable
+ .add(new StopLoading(bus, busStops.get(i), null, new Date(System.currentTimeMillis() - 21000), false));
}
- Log.v(TAG, "Finished adding placeholder stops");
+ // Log.v(TAG, "Finished adding placeholder stops");
} else {
Log.i(TAG, "Displaying previous timetable");
-
}
displayTimetable(timetable);
+ if (busStop != null) {
+ Log.i(TAG, "Moving to position of " + busStop.description + " which is " + busStops.indexOf(busStop));
+ timetableView.setSelection(busStops.indexOf(busStop));
+ }
handler.postDelayed(refreshData, 500);
} else {
@@ -214,8 +255,47 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
super.onPause();
}
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+
+ if (item.getItemId() == R.id.menu_refresh_bus) {
+ if (handler != null) { // BusTimes are enabled
+ handler.removeCallbacks(refreshData);
+ for (GetTimetableStopTask task : tasks.values()) {
+ task.cancel(true);
+ }
+
+ for (int num = timetableView.getFirstVisiblePosition(); num <= timetableView.getLastVisiblePosition(); num++) {
+ final Stop stop = timetable.get(num);
+
+ // Log.v(TAG, "Updating " + busStops.get(num));
+
+ // Remove the old time from the timetable
+ synchronized (timetable) {
+ timetable.set(num, new StopLoading(bus, busStops.get(num), null, new Date(
+ System.currentTimeMillis() - 21000), false));
+ displayTimetable(timetable);
+ }
+
+ GetTimetableStopTask task = new GetTimetableStopTask();
+ BusStop[] str = { stop.busStop };
+ task.execute(str);
+ tasks.put(stop.busStop, task);
+ }
+
+ handler.postDelayed(refreshData, 50000);
+ } else {
+ // TODO: Toast here...
+ }
+ } else {
+ Log.e(TAG, "No known menu option selected");
+ return super.onOptionsItemSelected(item);
+ }
+ return true;
+ }
+
private class GetTimetableStopTask extends AsyncTask<BusStop, Integer, Stop> {
- private String errorMessage;
+ // private String errorMessage;
private BusStop busStop;
@@ -231,23 +311,23 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
Stop stop = null;
try {
- Log.i(TAG, "Fetching stop for busStop " + position);
+ // Log.i(TAG, "Fetching stop for busStop " + position);
stop = DataManager.getStop(instance, bus, busStop);
if (stop == null) {
- stop = new Stop(bus, busStop, null, null, false);
+ stop = new Stop(bus, busStop, null, new Date(System.currentTimeMillis()), false);
}
- Log.i(TAG, "Finished fetching stop for busStop " + position);
+ // Log.i(TAG, "Finished fetching stop for busStop " + position);
} catch (SQLException e) {
- errorMessage = "Error message regarding SQL?";
+ // errorMessage = "Error message regarding SQL?";
e.printStackTrace();
} catch (ClientProtocolException e) {
- errorMessage = "ClientProtocolException!?!";
+ // errorMessage = "ClientProtocolException!?!";
e.printStackTrace();
} catch (IOException e) {
- errorMessage = "Error fetching bus times from server, are you connected to the internet?";
+ // errorMessage = "Error fetching bus times from server, are you connected to the internet?";
e.printStackTrace();
} catch (JSONException e) {
- errorMessage = "Error parsing bus times";
+ // errorMessage = "Error parsing bus times";
e.printStackTrace();
}
return stop;
@@ -255,21 +335,20 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
protected void onPostExecute(Stop stop) {
// Log.i(TAG, "Got timetable");
- if (stop == null) {
- Log.i(TAG, "Its null");
- busContentMessage.setText(errorMessage);
- busContentMessage.setVisibility(View.VISIBLE);
- } else {
- synchronized (timetable) {
- timetable.set(position, stop);
- displayTimetable(timetable);
- }
+ synchronized (timetable) {
+ timetable.set(position, stop);
+ displayTimetable(timetable);
}
}
}
+ @Override
+ public Object onRetainNonConfigurationInstance() {
+ return timetable;
+ }
+
private void displayTimetable(Timetable timetable) {
visibleTimetable = (Timetable) timetable.clone();
@@ -292,10 +371,6 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
} else {
adapter = new BusSpecificTimetableAdapter(this, visibleTimetable);
timetableView.setAdapter(adapter);
- if (busStop != null) {
- Log.i(TAG, "Moving to position of " + busStop.description + " which is " + busStops.indexOf(busStop));
- timetableView.setSelection(busStops.indexOf(busStop));
- }
}
busActivityContentLayout.setGravity(Gravity.TOP);
}
diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java
index 793cc24..e38d06a 100644
--- a/src/net/cbaines/suma/BusRoute.java
+++ b/src/net/cbaines/suma/BusRoute.java
@@ -433,8 +433,6 @@ public class BusRoute {
if (direction != null) {
- if (direction.equals("E"))
- direction = "A"; // Quick hack for U1E
} else {
throw new NullPointerException("direction is null");
}
@@ -458,11 +456,14 @@ public class BusRoute {
int endStopSeq = -1;
if (id == 326) { // U1
- if (direction.equals(forwardDirection)) {
+ if (direction.equals("E")) {
startStopSeq = 1;
endStopSeq = 43;
+ } else if (direction.equals(forwardDirection)) {
+ startStopSeq = 1;
+ endStopSeq = 36;
} else if (direction.equals(reverseDirection)) {
- startStopSeq = 44;
+ startStopSeq = 51;
endStopSeq = 88;
} else {
Log.e(TAG, "Error, unrecognised direction " + direction);
diff --git a/src/net/cbaines/suma/BusSpecificStopView.java b/src/net/cbaines/suma/BusSpecificStopView.java
index f0fc273..777d031 100644
--- a/src/net/cbaines/suma/BusSpecificStopView.java
+++ b/src/net/cbaines/suma/BusSpecificStopView.java
@@ -32,6 +32,7 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.LinearLayout;
+import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
@@ -46,6 +47,8 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener
private final TextView location;
private final TextView time;
+ private final ProgressBar timeProgress;
+
private String onClickMessage = "";
private final BusActivity context;
@@ -59,14 +62,19 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener
this.context = context;
- this.setOrientation(HORIZONTAL);
+ View.inflate(context, R.layout.bus_specific_stop_view, this);
- location = new TextView(context);
+ // location = new TextView(context);
+ location = (TextView) findViewById(R.id.busSpecificStopViewName);
location.setTextSize(22f);
+ location.setGravity(Gravity.LEFT);
- time = new TextView(context);
+ // time = new TextView(context);
+ time = (TextView) findViewById(R.id.busSpecificStopViewTime);
time.setTextSize(22f);
- time.setGravity(Gravity.RIGHT);
+
+ // timeProgress = new ProgressBar(context, null, android.R.attr.progressBarStyleSmall);
+ timeProgress = (ProgressBar) findViewById(R.id.busSpecificStopViewProgressBar);
Resources resources = context.getResources();
onClickHelpMessage = resources.getString(R.string.bus_stop_view_on_click_toast_help_message);
@@ -74,9 +82,22 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener
setStop(stop);
- addView(location, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
- addView(time, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
-
+ // RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
+ // LayoutParams.WRAP_CONTENT);
+ // relativeParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
+ //
+ // RelativeLayout.LayoutParams relativeParams2 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
+ // LayoutParams.FILL_PARENT);
+ // relativeParams2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
+ //
+ // addView(location, relativeParams);
+ // addView(time, relativeParams2);
+ //
+ // // LinearLayout progressLayout = new LinearLayout(context);
+ // // progressLayout.setOrientation(LinearLayout.VERTICAL);
+ // // progressLayout.addView(timeProgress, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
+ //
+ // addView(timeProgress, relativeParams2);
}
public void setStop(Stop stop) {
@@ -85,15 +106,24 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener
this.stop = stop;
- if (stop.busStop.description.length() > 20) {
- location.setText(stop.busStop.description.substring(0, 20)); // TODO
- } else {
- location.setText(stop.busStop.description); // TODO
- }
- if (stop.arivalTime != null) {
+ // if (stop.busStop.description.length() > 20) {
+ // location.setText(stop.busStop.description.substring(0, 20)); // TODO
+ // } else {
+ location.setText(stop.busStop.description); // TODO
+ // }
+
+ if (stop.arivalTime != null) { // Time available
time.setText(stop.getShortTimeToArival());
- } else {
+ time.setVisibility(View.VISIBLE);
+ timeProgress.setVisibility(View.GONE);
+ } else if (stop instanceof StopLoading) {
+ time.setText("");
+ time.setVisibility(View.GONE);
+ timeProgress.setVisibility(View.VISIBLE);
+ } else { // No time available (yet) and not currently loading
+ time.setVisibility(View.GONE);
time.setText("");
+ timeProgress.setVisibility(View.GONE);
}
DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
@@ -104,38 +134,15 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener
busDao.refresh(stop.bus);
if (stop.arivalTime != null) {
-
- if (stop.bus.id != null) {
- if (stop.live) {
- onClickMessage = "Bus " + stop.bus.toString() + " at "
- + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime);
- } else {
- onClickMessage = "Timetabled bus " + stop.bus.toString() + " at "
- + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime);
- }
+ if (stop.live) {
+ onClickMessage = stop.busStop.description + " at "
+ + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime);
} else {
- if (stop.live) {
- onClickMessage = "Unidentified bus (" + stop.bus.getName() + ") at "
- + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime);
- } else {
- onClickMessage = "Timetabled bus (" + stop.bus.getName() + ") at "
- + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime);
- }
+ onClickMessage = stop.busStop.description + " at "
+ + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime) + " (timetabled)";
}
} else {
- if (stop.bus.id != null) {
- if (stop.live) {
- onClickMessage = "Bus " + stop.bus.toString();
- } else {
- onClickMessage = "Timetabled bus " + stop.bus.toString();
- }
- } else {
- if (stop.live) {
- onClickMessage = "Unidentified bus (" + stop.bus.getName() + ")";
- } else {
- onClickMessage = "Timetabled bus (" + stop.bus.getName() + ")";
- }
- }
+ onClickMessage = stop.busStop.description + " on route, but arival time is not avalible";
}
} catch (SQLException e) {
e.printStackTrace();
diff --git a/src/net/cbaines/suma/BusSpecificTimetableAdapter.java b/src/net/cbaines/suma/BusSpecificTimetableAdapter.java
index 7bcb560..954217c 100644
--- a/src/net/cbaines/suma/BusSpecificTimetableAdapter.java
+++ b/src/net/cbaines/suma/BusSpecificTimetableAdapter.java
@@ -21,16 +21,14 @@ package net.cbaines.suma;
import android.view.View;
import android.view.ViewGroup;
-import android.view.animation.Animation;
-import android.view.animation.AnimationUtils;
import android.widget.BaseAdapter;
public class BusSpecificTimetableAdapter extends BaseAdapter {
private final BusActivity context;
private Timetable timetable;
- private final Animation a;
- private boolean[] changed;
+ // private final Animation a;
+ // private boolean[] changed;
private long timeOfLastForcedUpdate = System.currentTimeMillis();
@@ -39,7 +37,7 @@ public class BusSpecificTimetableAdapter extends BaseAdapter {
public BusSpecificTimetableAdapter(BusActivity context, Timetable timetable) {
this.context = context;
this.timetable = timetable;
- this.a = AnimationUtils.loadAnimation(context, R.anim.updated_stop_view);
+ // this.a = AnimationUtils.loadAnimation(context, R.anim.updated_stop_view);
}
public View getView(int position, View convertView, ViewGroup parent) {
@@ -47,6 +45,7 @@ public class BusSpecificTimetableAdapter extends BaseAdapter {
// timetable.get(position));
if (timeOfLastForcedUpdate + 1000 < System.currentTimeMillis()) {
+ context.handler.removeCallbacks(context.refreshData);
context.handler.post(context.refreshData);
timeOfLastForcedUpdate = System.currentTimeMillis();
}
@@ -59,12 +58,6 @@ public class BusSpecificTimetableAdapter extends BaseAdapter {
stopView.setStop(timetable.get(position));
}
- if (changed == null || changed[position]) {
- a.reset();
- stopView.startAnimation(a);
- // Log.i(TAG, "Animating it");
- }
-
return stopView;
}
@@ -81,19 +74,6 @@ public class BusSpecificTimetableAdapter extends BaseAdapter {
}
public void updateTimetable(Timetable newTimetable) {
- // Log.v(TAG, "Old timetable " + timetable);
- // Log.v(TAG, "Adaptor loading new timetable");
- changed = new boolean[newTimetable.size()];
- for (int i = 0; i < newTimetable.size(); i++) {
- if (newTimetable.get(i).arivalTime != null && !timetable.contains(newTimetable.get(i), true)) {
- changed[i] = true;
- // Log.i(TAG, "Old timetable does not contain: " +
- // newTimetable.get(i));
- } else {
- // Log.i(TAG, "Old timetable contains: " + newTimetable.get(i));
- changed[i] = false;
- }
- }
timetable = newTimetable;
this.notifyDataSetChanged();
}
diff --git a/src/net/cbaines/suma/BusStop.java b/src/net/cbaines/suma/BusStop.java
index 750f2d1..85f6d01 100644
--- a/src/net/cbaines/suma/BusStop.java
+++ b/src/net/cbaines/suma/BusStop.java
@@ -50,8 +50,7 @@ public class BusStop extends POI {
String bay;
/**
- * Used to speed up accessing the relevent uni link routes for a bus stop,
- * this is not a uni link stop
+ * Used to speed up accessing the relevent uni link routes for a bus stop, this is not a uni link stop
*/
@DatabaseField(canBeNull = false)
byte routes;
diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java
index f432803..b80d5b4 100644
--- a/src/net/cbaines/suma/BusStopActivity.java
+++ b/src/net/cbaines/suma/BusStopActivity.java
@@ -59,8 +59,8 @@ import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.PreparedQuery;
import com.j256.ormlite.stmt.QueryBuilder;
-public class BusStopActivity extends ToastHelperActivity implements OnCheckedChangeListener, Preferences, OnItemClickListener,
- OnLongClickListener {
+public class BusStopActivity extends ToastHelperActivity implements OnCheckedChangeListener, Preferences,
+ OnItemClickListener, OnLongClickListener {
final static String TAG = "BusTimeActivity";
@@ -320,10 +320,10 @@ public class BusStopActivity extends ToastHelperActivity implements OnCheckedCha
try {
final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(instance);
- newTimetable = DataManager
- .getTimetable(instance, busStop.id, sharedPrefs.getBoolean(MapActivity.UNI_LINK_BUS_TIMES,
- MapActivity.UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT), sharedPrefs.getBoolean(
- MapActivity.NON_UNI_LINK_BUS_TIMES, MapActivity.NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT));
+ newTimetable = DataManager.getTimetable(instance, busStop.id, sharedPrefs.getBoolean(
+ MapActivity.UNI_LINK_BUS_TIMES, MapActivity.UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT), sharedPrefs
+ .getBoolean(MapActivity.NON_UNI_LINK_BUS_TIMES,
+ MapActivity.NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT));
} catch (SQLException e) {
errorMessage = "Error message regarding SQL?";
e.printStackTrace();
@@ -363,7 +363,7 @@ public class BusStopActivity extends ToastHelperActivity implements OnCheckedCha
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.stop_menu, menu);
+ inflater.inflate(R.menu.bus_stop_menu, menu);
return true;
}
diff --git a/src/net/cbaines/suma/BusStopOverlay.java b/src/net/cbaines/suma/BusStopOverlay.java
index 778b306..b8377cf 100644
--- a/src/net/cbaines/suma/BusStopOverlay.java
+++ b/src/net/cbaines/suma/BusStopOverlay.java
@@ -110,8 +110,7 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref
final SharedPreferences favouritesPreferences = context.getSharedPreferences(FAVOURITES_PREFERENCES, 0);
/*
- * Draw in backward cycle, so the items with the least index are on the
- * front.
+ * Draw in backward cycle, so the items with the least index are on the front.
*/
for (int stopNum = 0; stopNum < busStops.size(); stopNum++) {
@@ -184,9 +183,9 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref
Log.e(TAG, "Unknown route code");
}
- canvas.drawRect(rectLeft, mCurScreenCoords.y
- + ((yOfsetPerMarker * makersPlaced) - (45 * scale)), rectRight, mCurScreenCoords.y
- + (yOfsetPerMarker * makersPlaced) - ((45 * scale) - markerYSize), paint);
+ canvas.drawRect(rectLeft, mCurScreenCoords.y + ((yOfsetPerMarker * makersPlaced) - (45 * scale)),
+ rectRight, mCurScreenCoords.y + (yOfsetPerMarker * makersPlaced) - ((45 * scale) - markerYSize),
+ paint);
makersPlaced++;
}
@@ -210,8 +209,7 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref
if (showIdentifiers) {
str += " (" + busStop.id + ")";
}
- context.makeToast(str, context.getResources().getString(R.string.map_activity_toast_help_message),
- Toast.LENGTH_SHORT);
+ context.makeToast(str, context.getResources().getString(R.string.map_activity_toast_help_message), Toast.LENGTH_SHORT);
return true;
}
@@ -250,21 +248,28 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref
} else {
Log.i(TAG, "Pressed " + busStop.id);
- SharedPreferences favouritesPreferences = context.getSharedPreferences(FAVOURITES_PREFERENCES, 0);
+ final SharedPreferences favouritesPreferences = context.getSharedPreferences(FAVOURITES_PREFERENCES, 0);
+ final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
if (favouritesPreferences.getBoolean(busStop.id, false)) {
favouritesPreferences.edit().remove(busStop.id).commit();
- context.makeToast(busStop.id + " removed from favourites", Toast.LENGTH_SHORT);
-
+ if (sharedPrefs.getBoolean(SHOW_IDENTIFIERS, SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT)) {
+ context.makeToast(busStop.description + " removed from favourites", "(" + busStop.id + ")",
+ Toast.LENGTH_SHORT);
+ } else {
+ context.makeToast(busStop.description + " removed from favourites", Toast.LENGTH_SHORT);
+ }
} else {
- context.makeToast(busStop.id + " made a favourite", Toast.LENGTH_SHORT);
-
+ if (sharedPrefs.getBoolean(SHOW_IDENTIFIERS, SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT)) {
+ context.makeToast(busStop.description + " added to favourites", "(" + busStop.id + ")", Toast.LENGTH_SHORT);
+ } else {
+ context.makeToast(busStop.description + " added to favourites", Toast.LENGTH_SHORT);
+ }
favouritesPreferences.edit().putBoolean(busStop.id, true).commit();
}
- Collections.sort(busStops,
- new POIFavouriteComparator(context.getSharedPreferences(FAVOURITES_PREFERENCES, 0)));
+ Collections.sort(busStops, new POIFavouriteComparator(context.getSharedPreferences(FAVOURITES_PREFERENCES, 0)));
mapView.invalidate();
diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java
index fd47360..082631c 100644
--- a/src/net/cbaines/suma/DataManager.java
+++ b/src/net/cbaines/suma/DataManager.java
@@ -75,6 +75,56 @@ 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");
+
+ DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
+
+ 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();
@@ -574,8 +624,9 @@ public class DataManager {
List<RouteStop> routeStops = routeStopsDao.query(routeStopsPreparedQuery);
if (routeStops.size() > 0) {
- Log.i(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route "
- + route.code);
+ // Log.i(TAG, "Found " + routeStops.size() +
+ // " stops matching the destStop " + destStop + " on route " +
+ // route.code);
} else {
Log.w(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route "
+ route.code);
@@ -657,7 +708,7 @@ public class DataManager {
Iterator<String> keyIter = routesObject.keys(); keyIter.hasNext();) {
String key = keyIter.next();
- Log.v(TAG, "Route Key: " + key);
+ // Log.v(TAG, "Route Key: " + key);
BusRoute route = busRouteDao.queryForId(Integer.parseInt(key.substring(key.length() - 3, key.length())));
@@ -671,18 +722,20 @@ public class DataManager {
int age = Integer.parseInt(data.getString("age"));
- Log.v(TAG, "Stops: " + data.getJSONArray("stops"));
+ // Log.v(TAG, "Stops: " + data.getJSONArray("stops"));
for (int stopNum = 0; stopNum < stopsArray.length(); stopNum++) {
JSONObject stopObj = stopsArray.getJSONObject(stopNum);
if (!keepNonUniLink && !stopObj.getString("name").startsWith("U")) {
- Log.v(TAG, "Skipping non uni-link stop " + stopObj.getString("name"));
+ // Log.v(TAG, "Skipping non uni-link stop " +
+ // stopObj.getString("name"));
continue;
}
if (!keepUniLink && stopObj.getString("name").startsWith("U")) {
- Log.v(TAG, "Skipping uni-link stop " + stopObj.getString("name"));
+ // Log.v(TAG, "Skipping uni-link stop " +
+ // stopObj.getString("name"));
continue;
}
@@ -757,9 +810,9 @@ public class DataManager {
HashSet<BusRoute> busRoutes = new HashSet<BusRoute>();
busRoutes.add(bus.route);
- Log.v(TAG, "Number of entries " + data.length());
+ // Log.v(TAG, "Number of entries " + data.length());
- Log.v(TAG, "Stops: " + data.getJSONArray("stops"));
+ // Log.v(TAG, "Stops: " + data.getJSONArray("stops"));
for (int stopNum = 0; stopNum < stopsArray.length(); stopNum++) {
JSONObject stopObj = stopsArray.getJSONObject(stopNum);
@@ -773,8 +826,9 @@ public class DataManager {
continue;
}
- Log.v(TAG, "Found stop for a unidentified " + stop.bus.toString() + " at " + stop.busStop.id
- + " at " + stop.arivalTime);
+ // Log.v(TAG, "Found stop for a unidentified " +
+ // stop.bus.toString() + " at " + stop.busStop.id + " at "
+ // + stop.arivalTime);
timetable.add(stop);
@@ -864,7 +918,7 @@ public class DataManager {
StringBuilder builder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(request);
- Log.v("Util.getFileFromServer", "Request used: " + request);
+ // Log.v("Util.getFileFromServer", "Request used: " + request);
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
diff --git a/src/net/cbaines/suma/DatabaseConfigUtil.java b/src/net/cbaines/suma/DatabaseConfigUtil.java
index 08a54b0..31cc934 100644
--- a/src/net/cbaines/suma/DatabaseConfigUtil.java
+++ b/src/net/cbaines/suma/DatabaseConfigUtil.java
@@ -22,7 +22,10 @@ package net.cbaines.suma;
import com.j256.ormlite.android.apptools.OrmLiteConfigUtil;
public class DatabaseConfigUtil extends OrmLiteConfigUtil {
+ private static final Class<?>[] classes = new Class[] { Building.class, BusStop.class, BusRoute.class, RouteStop.class,
+ Site.class, Bus.class, POI.class };
+
public static void main(String[] args) throws Exception {
- writeConfigFile("ormlite_config.txt");
+ writeConfigFile("ormlite_config.txt", classes);
}
}
diff --git a/src/net/cbaines/suma/DatabaseHelper.java b/src/net/cbaines/suma/DatabaseHelper.java
index 73f4c79..17ef720 100644
--- a/src/net/cbaines/suma/DatabaseHelper.java
+++ b/src/net/cbaines/suma/DatabaseHelper.java
@@ -55,7 +55,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
private Context context;
public DatabaseHelper(Context context) {
- super(context, DATABASE_NAME, null, DATABASE_VERSION);
+ super(context, DATABASE_NAME, null, DATABASE_VERSION, R.raw.ormlite_config);
Log.i(TAG, "Database Helper created");
this.context = context;
}
@@ -89,8 +89,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
/**
- * Returns the Database Access Object (DAO) for our SimpleData class. It
- * will create it or just give the cached value.
+ * Returns the Database Access Object (DAO) for our SimpleData class. It will create it or just give the cached value.
*/
public Dao<Building, String> getBuildingDao() throws SQLException {
if (buildingDao == null) {
@@ -100,8 +99,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
/**
- * Returns the Database Access Object (DAO) for our SimpleData class. It
- * will create it or just give the cached value.
+ * Returns the Database Access Object (DAO) for our SimpleData class. It will create it or just give the cached value.
*/
public Dao<BusStop, String> getBusStopDao() throws SQLException {
if (busStopDao == null) {
@@ -111,8 +109,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
/**
- * Returns the Database Access Object (DAO) for our SimpleData class. It
- * will create it or just give the cached value.
+ * Returns the Database Access Object (DAO) for our SimpleData class. It will create it or just give the cached value.
*/
public Dao<BusRoute, Integer> getBusRouteDao() throws SQLException {
if (busRouteDao == null) {
@@ -122,8 +119,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
/**
- * Returns the Database Access Object (DAO) for our SimpleData class. It
- * will create it or just give the cached value.
+ * Returns the Database Access Object (DAO) for our SimpleData class. It will create it or just give the cached value.
*/
public Dao<RouteStop, Integer> getRouteStopsDao() throws SQLException {
if (routeStopsDao == null) {
@@ -133,8 +129,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
/**
- * Returns the Database Access Object (DAO) for our SimpleData class. It
- * will create it or just give the cached value.
+ * Returns the Database Access Object (DAO) for our SimpleData class. It will create it or just give the cached value.
*/
public Dao<Site, String> getSiteDao() throws SQLException {
if (siteDao == null) {
@@ -144,8 +139,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
/**
- * Returns the Database Access Object (DAO) for our SimpleData class. It
- * will create it or just give the cached value.
+ * Returns the Database Access Object (DAO) for our SimpleData class. It will create it or just give the cached value.
*/
public Dao<Bus, Integer> getBusDao() throws SQLException {
if (busDao == null) {
@@ -155,8 +149,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
/**
- * Check if the database already exist to avoid re-copying the file each
- * time you open the application.
+ * Check if the database already exist to avoid re-copying the file each time you open the application.
*
* @return true if it exists, false if it doesn't
*/
@@ -166,8 +159,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
/*
* SQLiteDatabase checkDB = null;
*
- * try { String myPath = DATABASE_PATH + DATABASE_NAME; checkDB =
- * SQLiteDatabase.openDatabase(myPath, null,
+ * try { String myPath = DATABASE_PATH + DATABASE_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null,
* SQLiteDatabase.OPEN_READONLY); } catch (SQLiteException e) {
*
* // database does't exist yet.
@@ -180,8 +172,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
*
* }
*
- * Log.i(TAG, "Finished checking database"); return checkDB != null ?
- * true : false;
+ * Log.i(TAG, "Finished checking database"); return checkDB != null ? true : false;
*/
File dbFile = new File(DATABASE_PATH + DATABASE_NAME);
@@ -189,9 +180,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
/**
- * Copies your database from your local assets-folder to the just created
- * empty database in the system folder, from where it can be accessed and
- * handled. This is done by transfering bytestream.
+ * Copies your database from your local assets-folder to the just created empty database in the system folder, from where it
+ * can be accessed and handled. This is done by transfering bytestream.
* */
public void copyDataBase() throws IOException {
Log.i(TAG, "Begining copy database");
@@ -228,8 +218,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
/**
- * Creates a empty database on the system and rewrites it with your own
- * database.
+ * Creates a empty database on the system and rewrites it with your own database.
* */
public void createDataBase() throws IOException {
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;
}
diff --git a/src/net/cbaines/suma/POIView.java b/src/net/cbaines/suma/POIView.java
index 95c571c..6324aeb 100644
--- a/src/net/cbaines/suma/POIView.java
+++ b/src/net/cbaines/suma/POIView.java
@@ -91,11 +91,7 @@ public class POIView extends LinearLayout implements Preferences {
Building building = (Building) poi;
// Log.i(TAG, "Its a building of name " + building.name);
- if (identifiersEnabled) {
- name.setText(building.name + " (" + building.id + ")");
- } else {
- name.setText(building.name);
- }
+ name.setText(building.name + " (" + building.id + ")");
} else if (poi.type == POI.BUS_STOP) {
BusStop busStop = (BusStop) poi;
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/StopLoading.java b/src/net/cbaines/suma/StopLoading.java
new file mode 100644
index 0000000..e8ca8e5
--- /dev/null
+++ b/src/net/cbaines/suma/StopLoading.java
@@ -0,0 +1,11 @@
+package net.cbaines.suma;
+
+import java.util.Date;
+
+public class StopLoading extends Stop {
+
+ public StopLoading(Bus bus, BusStop busStop, Date arivalTime, Date timeOfFetch, boolean live) {
+ super(bus, busStop, arivalTime, timeOfFetch, live);
+ }
+
+}
diff --git a/src/net/cbaines/suma/WelcomeDialog.java b/src/net/cbaines/suma/WelcomeDialog.java
new file mode 100644
index 0000000..7262f48
--- /dev/null
+++ b/src/net/cbaines/suma/WelcomeDialog.java
@@ -0,0 +1,64 @@
+/*
+ * Southampton University Map App
+ * Copyright (C) 2011 Christopher Baines
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+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;
+import android.widget.TextView;
+
+public class WelcomeDialog extends Dialog implements OnClickListener, Preferences {
+
+ // private static final String TAG = "WelcomeDialog";
+
+ final SharedPreferences sharedPrefs;
+
+ private Button continueButton;
+
+ public WelcomeDialog(Context context) {
+ super(context);
+
+ this.setTitle(R.string.welcome_dialog_title);
+
+ setContentView(R.layout.welcome_dialog);
+
+ sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
+ String appVersion = sharedPrefs.getString(APP_VERSION, APP_NOT_INSTALLED);
+
+ if (!appVersion.equals(CURRENT_APP_VERSION)) {
+ TextView welcomeDialogMessage = (TextView) findViewById(R.id.welcomeDialogMessage);
+ welcomeDialogMessage.setText(R.string.welcome_dialog_upgrade_message);
+ }
+
+ 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();
+ }
+}