aboutsummaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
Diffstat (limited to 'src/net')
-rw-r--r--src/net/cbaines/suma/BuildingActivity.java33
-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/DataManager.java21
-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.java6
-rw-r--r--src/net/cbaines/suma/POI.java82
-rw-r--r--src/net/cbaines/suma/POIView.java6
-rw-r--r--src/net/cbaines/suma/StopLoading.java11
14 files changed, 292 insertions, 205 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/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/DataManager.java b/src/net/cbaines/suma/DataManager.java
index ab1f3a7..08425a7 100644
--- a/src/net/cbaines/suma/DataManager.java
+++ b/src/net/cbaines/suma/DataManager.java
@@ -554,7 +554,8 @@ 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);
}
@@ -635,7 +636,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())));
@@ -648,18 +649,18 @@ 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;
}
@@ -734,9 +735,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);
@@ -750,8 +751,8 @@ 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);
@@ -841,7 +842,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 01e8ec6..cc7d7b9 100644
--- a/src/net/cbaines/suma/MapActivity.java
+++ b/src/net/cbaines/suma/MapActivity.java
@@ -173,7 +173,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) {
@@ -476,7 +476,7 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
Log.i(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");
@@ -489,7 +489,7 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
Log.i(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);
}
diff --git a/src/net/cbaines/suma/POI.java b/src/net/cbaines/suma/POI.java
index 485845c..c84f90e 100644
--- a/src/net/cbaines/suma/POI.java
+++ b/src/net/cbaines/suma/POI.java
@@ -25,54 +25,54 @@ import com.j256.ormlite.field.DataType;
import com.j256.ormlite.field.DatabaseField;
public abstract class POI {
- public static final String BUS_STOP = "busstop";
- public static final String BUILDING = "building";
- public static final String WAYPOINT = "waypoint";
- public static final String SITE = "site";
+ public static final String BUS_STOP = "busstop";
+ public static final String BUILDING = "building";
+ public static final String WAYPOINT = "waypoint";
+ public static final String SITE = "site";
- public static final String ID_FIELD_NAME = "id";
- public static final String POINT_FIELD_NAME = "point";
+ public static final String ID_FIELD_NAME = "id";
+ public static final String POINT_FIELD_NAME = "point";
- POI() {
- }
+ POI() {
+ }
- public POI(String id, GeoPoint point) {
- this.id = id;
- this.point = point;
- }
+ public POI(String id, GeoPoint point) {
+ this.id = id;
+ this.point = point;
+ }
- @DatabaseField(dataType = DataType.SERIALIZABLE, canBeNull = false)
- public GeoPoint point;
+ @DatabaseField(dataType = DataType.SERIALIZABLE, canBeNull = false)
+ public GeoPoint point;
- @DatabaseField(id = true)
- public String id;
+ @DatabaseField(id = true)
+ public String id;
- public int distTo = -1; // Used by the comparator to store distances, then later by the gui to display them.
+ public int distTo = -1; // Used by the comparator to store distances, then later by the gui to display them.
- public String type;
+ public String type;
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((id == null) ? 0 : id.hashCode());
- return result;
- }
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ return result;
+ }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- POI other = (POI) obj;
- if (id == null) {
- if (other.id != null)
- return false;
- } else if (!id.equals(other.id))
- return false;
- return true;
- }
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ POI other = (POI) obj;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ return true;
+ }
}
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/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);
+ }
+
+}