aboutsummaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2012-02-19 09:41:44 +0000
committerChristopher Baines <cbaines8@gmail.com>2012-02-19 09:41:44 +0000
commitbff738801d5a231806c42bcb06b1e187d120b5a9 (patch)
tree1ed698d5b742226a67fa52844a2fd72dea474ae9 /src/net
parent7bb198687abe16bc457c96b77dc07283b0340832 (diff)
downloadsouthamptonuniversitymap-bff738801d5a231806c42bcb06b1e187d120b5a9.tar
southamptonuniversitymap-bff738801d5a231806c42bcb06b1e187d120b5a9.tar.gz
Fixed a bug with the MapActivity overlay toasts, and improved the BusStopActivity.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/cbaines/suma/BuildingNumOverlay.java25
-rw-r--r--src/net/cbaines/suma/BusActivity.java42
-rw-r--r--src/net/cbaines/suma/BusRoute.java11
-rw-r--r--src/net/cbaines/suma/BusSpecificTimetableAdapter.java2
-rw-r--r--src/net/cbaines/suma/BusStopOverlay.java63
-rw-r--r--src/net/cbaines/suma/MapActivity.java10
-rw-r--r--src/net/cbaines/suma/StopView.java30
7 files changed, 84 insertions, 99 deletions
diff --git a/src/net/cbaines/suma/BuildingNumOverlay.java b/src/net/cbaines/suma/BuildingNumOverlay.java
index 33b5efc..32616a7 100644
--- a/src/net/cbaines/suma/BuildingNumOverlay.java
+++ b/src/net/cbaines/suma/BuildingNumOverlay.java
@@ -182,14 +182,7 @@ public class BuildingNumOverlay extends Overlay {
}
@Override
- public boolean onSingleTapUp(final MotionEvent event, final MapView mapView) {
-
- Log.v(TAG, "Pointer count for onSingleTapUp is " + event.getPointerCount() + " " + event.getAction() + " "
- + event.describeContents());
- if (event.getPointerCount() != 1) {
- Log.v(TAG, "Pointer count for onSingleTapUp not 1, ignoring");
- return false;
- }
+ public boolean onSingleTapConfirmed(final MotionEvent event, final MapView mapView) {
if (!this.isEnabled())
return false;
@@ -197,10 +190,10 @@ public class BuildingNumOverlay extends Overlay {
final Building building = getSelectedItem(event, mapView);
if (building == null) {
- Log.i(TAG, "No building pressed");
+ // Log.v(TAG, "No building pressed");
return false;
} else {
- Log.i(TAG, "building Pressed " + building.id);
+ Log.v(TAG, "building Pressed " + building.id);
if (context.activityToast == null) {
context.activityToast = Toast.makeText(context, building.name + " (" + building.id + ")",
@@ -223,23 +216,16 @@ public class BuildingNumOverlay extends Overlay {
@Override
public boolean onLongPress(final MotionEvent event, final MapView mapView) {
- Log.v(TAG, "Pointer count for onLongPress is " + event.getPointerCount() + " " + event.getAction() + " "
- + event.describeContents());
- if (event.getPointerCount() != 1) {
- Log.v(TAG, "Pointer count for onLongPress not 1, ignoring");
- return false;
- }
-
if (!this.isEnabled())
return false;
final Building building = getSelectedItem(event, mapView);
if (building == null) {
- Log.i(TAG, "No building pressed");
+ // Log.v(TAG, "No building pressed");
return false;
} else {
- Log.i(TAG, "building Pressed " + building.id);
+ Log.v(TAG, "building Pressed " + building.id);
if (building.favourite) {
building.favourite = false;
@@ -269,7 +255,6 @@ public class BuildingNumOverlay extends Overlay {
try {
buildingDao.update(building);
} catch (SQLException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
diff --git a/src/net/cbaines/suma/BusActivity.java b/src/net/cbaines/suma/BusActivity.java
index d632298..b802cfb 100644
--- a/src/net/cbaines/suma/BusActivity.java
+++ b/src/net/cbaines/suma/BusActivity.java
@@ -2,7 +2,6 @@ package net.cbaines.suma;
import java.io.IOException;
import java.sql.SQLException;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -61,7 +60,6 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
// BusStops and if they are being updated by the handler
List<BusStop> busStops;
- ArrayList<Boolean> busStopsActive;
private HashMap<BusStop, GetTimetableStopTask> tasks = new HashMap<BusStop, GetTimetableStopTask>();
@@ -155,10 +153,6 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
busStops = bus.route.getRouteSection(instance, bus.direction);
Log.i(TAG, "Got " + busStops.size() + " bus stops for this bus");
- busStopsActive = new ArrayList<Boolean>(busStops.size());
- for (int i = 0; i < busStops.size(); i++) {
- busStopsActive.add(false);
- }
if (bus.destination != null) {
Log.i(TAG, "Bus destination is " + bus.destination);
@@ -167,7 +161,8 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
}
/*
- * for (int i = 0;; i++) { BusStop nextStop = bus.route.moveInRoute(instance, busStops.get(i), bus.direction, 1);
+ * for (int i = 0;; i++) { BusStop nextStop = bus.route.moveInRoute(instance, busStops.get(i), bus.direction,
+ * 1);
*
* if (nextStop.equals(busStop) || (bus.destination != null && bus.destination.equals(nextStop))) { break; }
*
@@ -179,27 +174,26 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
refreshData = new Runnable() {
@Override
public void run() {
- for (int num = 0; num < timetable.size(); num++) {
- if (busStopsActive.get(num)) {
- Stop stop = timetable.get(num);
+ for (int num = timetableView.getFirstVisiblePosition(); num < timetableView.getLastVisiblePosition(); num++) {
+ Stop stop = timetable.get(num);
- GetTimetableStopTask task = tasks.get(busStops.get(num));
+ 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 (stop.timeOfFetch == null || (stop.timeOfFetch.getTime() - System.currentTimeMillis()) > 20000) {
+ if (task != null) {
+ if (task.getStatus() == AsyncTask.Status.FINISHED) {
+ task = null;
}
+ }
- if (task == null) {
- task = new GetTimetableStopTask();
- BusStop[] str = { stop.busStop };
- task.execute(str);
- tasks.put(stop.busStop, task);
- }
+ if (task == null) {
+ task = new GetTimetableStopTask();
+ BusStop[] str = { stop.busStop };
+ task.execute(str);
+ tasks.put(stop.busStop, task);
}
}
+
}
handler.postDelayed(refreshData, 50000);
}
@@ -336,7 +330,9 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
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));
+ Log.i(TAG,
+ "Moving to position of " + busStop.description + " which is "
+ + busStops.indexOf(busStop));
timetableView.setSelection(busStops.indexOf(busStop));
}
}
diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java
index 97309c4..4152605 100644
--- a/src/net/cbaines/suma/BusRoute.java
+++ b/src/net/cbaines/suma/BusRoute.java
@@ -21,6 +21,7 @@ package net.cbaines.suma;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -445,8 +446,14 @@ public class BusRoute {
Log.e(TAG, "Error, unrecognised direction " + direction);
}
} else if (id == 354) { // U9
- startStopSeq = 1;
- endStopSeq = 74;
+ Calendar rightNow = Calendar.getInstance();
+ if (rightNow.get(Calendar.HOUR_OF_DAY) < 12) {
+ startStopSeq = 1;
+ endStopSeq = 40; // TODO: Guess, and untested
+ } else {
+ startStopSeq = 41; // TODO: Guess, and untested
+ endStopSeq = 74;
+ }
} else {
Log.e(TAG, "Error, unrecognised route " + id);
}
diff --git a/src/net/cbaines/suma/BusSpecificTimetableAdapter.java b/src/net/cbaines/suma/BusSpecificTimetableAdapter.java
index 469fa56..c115fea 100644
--- a/src/net/cbaines/suma/BusSpecificTimetableAdapter.java
+++ b/src/net/cbaines/suma/BusSpecificTimetableAdapter.java
@@ -45,8 +45,6 @@ public class BusSpecificTimetableAdapter extends BaseAdapter {
public View getView(int position, View convertView, ViewGroup parent) {
// Log.i(TAG, "Returning stop " + position + " " + timetable.get(position));
- context.busStopsActive.set(position, true);
-
if (timeOfLastForcedUpdate + 1000 < System.currentTimeMillis()) {
context.handler.post(context.refreshData);
timeOfLastForcedUpdate = System.currentTimeMillis();
diff --git a/src/net/cbaines/suma/BusStopOverlay.java b/src/net/cbaines/suma/BusStopOverlay.java
index 6ef956b..06a1729 100644
--- a/src/net/cbaines/suma/BusStopOverlay.java
+++ b/src/net/cbaines/suma/BusStopOverlay.java
@@ -180,7 +180,8 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
Log.e(TAG, "Unknown route code");
}
- canvas.drawRect(rectLeft, mCurScreenCoords.y + ((yOfsetPerMarker * makersPlaced) - (45 * scale)), rectRight, mCurScreenCoords.y
+ canvas.drawRect(rectLeft, mCurScreenCoords.y
+ + ((yOfsetPerMarker * makersPlaced) - (45 * scale)), rectRight, mCurScreenCoords.y
+ (yOfsetPerMarker * makersPlaced) - ((45 * scale) - markerYSize), paint);
makersPlaced++;
@@ -190,30 +191,20 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
}
}
- public boolean onTouchEvent(final MotionEvent event, final MapView mapView) {
- // Log.i(TAG, "Touch Event " + event.getPointerCount() + " " + event.getAction());
- return false;
- }
-
@Override
- public boolean onSingleTapUp(final MotionEvent event, final MapView mapView) {
-
- Log.v(TAG, "Pointer count for onSingleTapUp is " + event.getPointerCount() + " " + event.getAction());
- if (event.getPointerCount() != 1) {
- Log.v(TAG, "Pointer count for onSingleTapUp not 1, ignoring");
- return false;
- }
+ public boolean onSingleTapConfirmed(final MotionEvent event, final MapView mapView) {
BusStop busStop = getSelectedItem(event, mapView);
if (busStop == null) {
- Log.i(TAG, "No busStop pressed");
+ // Log.v(TAG, "No busStop pressed");
return false;
} else {
Log.i(TAG, "busStop Pressed " + busStop.id);
if (context.activityToast == null) {
- context.activityToast = Toast.makeText(context, busStop.description + " (" + busStop.id + ")", Toast.LENGTH_SHORT);
+ context.activityToast = Toast.makeText(context, busStop.description + " (" + busStop.id + ")",
+ Toast.LENGTH_SHORT);
} else {
context.activityToast.setDuration(Toast.LENGTH_SHORT);
context.activityToast.setText(busStop.description + " (" + busStop.id + ")");
@@ -226,17 +217,10 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
public boolean onDoubleTap(final MotionEvent event, final MapView mapView) {
- Log.v(TAG, "Pointer count for onDoubleTap is " + event.getPointerCount() + " " + event.getAction() + " " + event.describeContents());
- if (event.getPointerCount() != 1) {
- Log.v(TAG, "Pointer count for onDoubleTap not 1, ignoring");
- return false;
- }
-
BusStop busStop = getSelectedItem(event, mapView);
if (busStop == null) {
- Log.i(TAG, "No busStop pressed");
-
+ // Log.v(TAG, "No busStop pressed");
return false;
} else {
Log.i(TAG, "Pressed " + busStop.id);
@@ -254,16 +238,10 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
@Override
public boolean onLongPress(final MotionEvent event, final MapView mapView) {
- Log.v(TAG, "Pointer count for onLongPress is " + event.getPointerCount() + " " + event.getAction() + " " + event.describeContents());
- if (event.getPointerCount() != 1) {
- Log.v(TAG, "Pointer count for onLongPress not 1, ignoring");
- return false;
- }
-
BusStop busStop = getSelectedItem(event, mapView);
if (busStop == null) {
- Log.i(TAG, "No busStop pressed");
+ // Log.v(TAG, "No busStop pressed");
return false;
} else {
Log.i(TAG, "Pressed " + busStop.id);
@@ -272,7 +250,8 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
busStop.favourite = false;
if (context.activityToast == null) {
- context.activityToast = Toast.makeText(context, busStop.id + " removed from favourites", Toast.LENGTH_SHORT);
+ context.activityToast = Toast.makeText(context, busStop.id + " removed from favourites",
+ Toast.LENGTH_SHORT);
} else {
context.activityToast.setDuration(Toast.LENGTH_SHORT);
context.activityToast.setText(busStop.id + " removed from favourites");
@@ -280,7 +259,8 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
context.activityToast.show();
} else {
if (context.activityToast == null) {
- context.activityToast = Toast.makeText(context, busStop.id + " made a favourite", Toast.LENGTH_SHORT);
+ context.activityToast = Toast.makeText(context, busStop.id + " made a favourite",
+ Toast.LENGTH_SHORT);
} else {
context.activityToast.setDuration(Toast.LENGTH_SHORT);
context.activityToast.setText(busStop.id + " made a favourite");
@@ -302,7 +282,6 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
return true;
}
-
}
public void refresh() {
@@ -349,17 +328,19 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
pj.toPixels(busStop.point, mItemPoint);
if (marker.getBounds().contains(mTouchScreenPoint.x - mItemPoint.x, mTouchScreenPoint.y - mItemPoint.y)) {
- boolean drawing = false;
- for (int route = 0; route < 5; route++) {
- if ((busStop.routes & (1 << route)) != 0) {
- if (routes[route]) {
- drawing = true;
- break;
+ if (busStop.uniLink) {
+ boolean drawing = false;
+ for (int route = 0; route < 5; route++) {
+ if ((busStop.routes & (1 << route)) != 0) {
+ if (routes[route]) {
+ drawing = true;
+ break;
+ }
}
}
+ if (!drawing)
+ continue;
}
- if (!drawing)
- continue;
return busStop;
}
diff --git a/src/net/cbaines/suma/MapActivity.java b/src/net/cbaines/suma/MapActivity.java
index 21bcf15..d12057c 100644
--- a/src/net/cbaines/suma/MapActivity.java
+++ b/src/net/cbaines/suma/MapActivity.java
@@ -1050,8 +1050,14 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
Log.v(TAG, "Got a busStop id back from the BusTimeActivity " + busStopID);
BusStop busStop = getHelper().getBusStopDao().queryForId(busStopID);
- uniLinkBusStopOverlay.refresh(busStop); // This does not invalidate the map, but it seems to
- // make the changes appear
+ if (busStop.uniLink) {
+ uniLinkBusStopOverlay.refresh(busStop); // This does not invalidate the map, but it seems to
+ // make the changes appear
+ } else {
+ nonUniLinkBusStopOverlay.refresh(busStop); // This does not invalidate the map, but it seems
+ // to
+ // make the changes appear
+ }
}
} catch (SQLException e) {
e.printStackTrace();
diff --git a/src/net/cbaines/suma/StopView.java b/src/net/cbaines/suma/StopView.java
index 08e5843..32cd3e1 100644
--- a/src/net/cbaines/suma/StopView.java
+++ b/src/net/cbaines/suma/StopView.java
@@ -126,29 +126,41 @@ public class StopView extends LinearLayout implements OnClickListener, OnLongCli
try {
Dao<Bus, Integer> busDao = helper.getBusDao();
+ Dao<BusRoute, Integer> busRouteDao = helper.getBusRouteDao();
busDao.refresh(stop.bus);
+ busRouteDao.refresh(stop.bus.route);
- if (stop.bus.id != null) {
+ if (stop.bus.id != null && stop.bus.route.uniLink) {
Intent i = new Intent(context, BusActivity.class);
i.putExtra("busID", stop.bus.id);
i.putExtra("busStopID", stop.busStop.id);
((Activity) context).startActivityForResult(i, 0);
} else {
- if (context.activityToast == null) {
- context.activityToast = Toast.makeText(context,
- "Arival prediction not avalible for timetabled buses", Toast.LENGTH_SHORT);
+ if (stop.bus.route.uniLink) {
+ if (context.activityToast == null) {
+ context.activityToast = Toast.makeText(context,
+ "Bus schedules only avalible for Uni-Link buses", Toast.LENGTH_SHORT);
+ } else {
+ context.activityToast.setText("Bus schedules only avalible for Uni-Link buses");
+ context.activityToast.setDuration(Toast.LENGTH_SHORT);
+ }
+ context.activityToast.show();
} else {
- context.activityToast.setText("Arival prediction not avalible for timetabled buses");
- context.activityToast.setDuration(Toast.LENGTH_SHORT);
+ if (context.activityToast == null) {
+ context.activityToast = Toast.makeText(context,
+ "Bus schedules not avalible for unidentified buses", Toast.LENGTH_SHORT);
+ } else {
+ context.activityToast.setText("Bus schedules not avalible for unidentified buses");
+ context.activityToast.setDuration(Toast.LENGTH_SHORT);
+ }
+ context.activityToast.show();
}
- context.activityToast.show();
}
} catch (SQLException e) {
e.printStackTrace();
}
- return false;
+ return true;
}
-
}