From ff96598874103eb2141f01b8b9ace300dfd3ab45 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Wed, 29 Feb 2012 19:37:44 +0000 Subject: New Toast stuff, needs some work. --- src/net/cbaines/suma/BuildingNumOverlay.java | 28 ++-------------- src/net/cbaines/suma/BusStopOverlay.java | 47 ++++++++++++--------------- src/net/cbaines/suma/MapActivity.java | 13 ++------ src/net/cbaines/suma/ToastHelperActivity.java | 26 +++++++++++++++ 4 files changed, 52 insertions(+), 62 deletions(-) create mode 100644 src/net/cbaines/suma/ToastHelperActivity.java (limited to 'src') diff --git a/src/net/cbaines/suma/BuildingNumOverlay.java b/src/net/cbaines/suma/BuildingNumOverlay.java index a4cf556..3e2a731 100644 --- a/src/net/cbaines/suma/BuildingNumOverlay.java +++ b/src/net/cbaines/suma/BuildingNumOverlay.java @@ -209,14 +209,7 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared } else { Log.v(TAG, "building Pressed " + building.id); - if (context.activityToast == null) { - context.activityToast = Toast.makeText(context, building.name + " (" + building.id + ")", - Toast.LENGTH_SHORT); - } else { - context.activityToast.setDuration(Toast.LENGTH_SHORT); - context.activityToast.setText(building.name + " (" + building.id + ")"); - } - context.activityToast.show(); + context.makeToast(building.name + " (" + building.id + ")", Toast.LENGTH_SHORT); return true; } @@ -262,24 +255,9 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared if (favouritesPrefs.getBoolean(building.id, false)) { favouritesPrefs.edit().remove(building.id).commit(); - if (context.activityToast == null) { - context.activityToast = Toast.makeText(context, building.id + " removed from favourites", - Toast.LENGTH_SHORT); - } else { - context.activityToast.setDuration(Toast.LENGTH_SHORT); - context.activityToast.setText(building.id + " removed from favourites"); - } - context.activityToast.show(); - + context.makeToast(building.id + " removed from favourites", Toast.LENGTH_SHORT); } else { - if (context.activityToast == null) { - context.activityToast = Toast.makeText(context, building.id + " made a favourite", - Toast.LENGTH_SHORT); - } else { - context.activityToast.setDuration(Toast.LENGTH_SHORT); - context.activityToast.setText(building.id + " made a favourite"); - } - context.activityToast.show(); + context.makeToast(building.id + " made a favourite", Toast.LENGTH_SHORT); favouritesPrefs.edit().putBoolean(building.id, true).commit(); } diff --git a/src/net/cbaines/suma/BusStopOverlay.java b/src/net/cbaines/suma/BusStopOverlay.java index b8f1077..254e03a 100644 --- a/src/net/cbaines/suma/BusStopOverlay.java +++ b/src/net/cbaines/suma/BusStopOverlay.java @@ -36,6 +36,7 @@ import android.graphics.Point; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.net.Uri; +import android.preference.PreferenceManager; import android.util.Log; import android.view.MotionEvent; import android.widget.Toast; @@ -63,6 +64,8 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref private boolean[] routes = new boolean[5]; + private boolean showIdentifiers; + public BusStopOverlay(MapActivity context, List busStops) throws SQLException { super(context); @@ -71,6 +74,9 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref marker = context.getResources().getDrawable(R.drawable.busstop); favMarker = context.getResources().getDrawable(R.drawable.busstop_fav); + showIdentifiers = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SHOW_IDENTIFIERS, + SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT); + paint = new Paint(); paint.setStyle(Style.FILL); paint.setStrokeWidth(6); @@ -104,7 +110,8 @@ 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++) { @@ -177,9 +184,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++; } @@ -199,14 +206,12 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref } else { Log.i(TAG, "busStop Pressed " + busStop.id); - if (context.activityToast == null) { - 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 + ")"); + String str = busStop.description; + if (showIdentifiers) { + str += " (" + busStop.id + ")"; } - context.activityToast.show(); + str += "\n" + context.getResources().getString(R.string.map_activity_toast_help_message); + context.makeToast(str, Toast.LENGTH_SHORT); return true; } @@ -250,26 +255,16 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref if (favouritesPreferences.getBoolean(busStop.id, false)) { favouritesPreferences.edit().remove(busStop.id).commit(); - if (context.activityToast == null) { - 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"); - } - context.activityToast.show(); + context.makeToast(busStop.id + " removed from favourites", Toast.LENGTH_SHORT); + } else { - if (context.activityToast == null) { - 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"); - } - context.activityToast.show(); + context.makeToast(busStop.id + " made a favourite", 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/MapActivity.java b/src/net/cbaines/suma/MapActivity.java index 8a7a39a..728591d 100644 --- a/src/net/cbaines/suma/MapActivity.java +++ b/src/net/cbaines/suma/MapActivity.java @@ -61,9 +61,7 @@ import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemLongClickListener; -import android.widget.Toast; -import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; import com.j256.ormlite.dao.Dao; /** @@ -71,9 +69,8 @@ import com.j256.ormlite.dao.Dao; * @author Christopher Baines * */ -public class MapActivity extends OrmLiteBaseActivity implements MapViewConstants, Runnable, - RouteColorConstants, OnItemClickListener, OnItemLongClickListener, OnSharedPreferenceChangeListener, - Preferences { +public class MapActivity extends ToastHelperActivity implements MapViewConstants, Runnable, RouteColorConstants, + OnItemClickListener, OnItemLongClickListener, OnSharedPreferenceChangeListener, Preferences { /** * Enable to use the database in the assets folder, if its not enabled, the @@ -175,12 +172,6 @@ public class MapActivity extends OrmLiteBaseActivity implements static final String[][] PREFERENCES_CHILDREN = { UNI_LINK_ROUTES, UNI_LINK_ROUTES, BUILDING_TYPES, SITE_NAMES, OTHER_OVERLAY_NAMES }; - /** - * The toast for this activity, storing the toast centrally allows it to be - * changed quickly, instead of a queue building up - */ - Toast activityToast; - private MapActivity instance; private static final String TAG = "SUM"; diff --git a/src/net/cbaines/suma/ToastHelperActivity.java b/src/net/cbaines/suma/ToastHelperActivity.java new file mode 100644 index 0000000..6c5974c --- /dev/null +++ b/src/net/cbaines/suma/ToastHelperActivity.java @@ -0,0 +1,26 @@ +package net.cbaines.suma; + +import android.widget.TextView; +import android.widget.Toast; + +import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; + +public class ToastHelperActivity extends OrmLiteBaseActivity { + + protected Toast toast; + protected TextView toastView; + + void makeToast(String message, int length) { + if (toastView == null) { + toastView = (TextView) getLayoutInflater().inflate(R.layout.toast_view, null); + } + toastView.setText(message); + if (toast == null) { + toast = new Toast(this); + } + toast.setDuration(length); + toast.setView(toastView); + toast.show(); + } + +} -- cgit v1.2.3 From fc2b0ff3aefea51227894804cbcde97d55b79f30 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Thu, 1 Mar 2012 10:34:16 +0000 Subject: Better toasts implemented. --- src/net/cbaines/suma/BuildingNumOverlay.java | 13 ++++++++++++- src/net/cbaines/suma/BusStopOverlay.java | 4 ++-- src/net/cbaines/suma/ToastHelperActivity.java | 27 +++++++++++++++++++++++---- 3 files changed, 37 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/net/cbaines/suma/BuildingNumOverlay.java b/src/net/cbaines/suma/BuildingNumOverlay.java index 3e2a731..c2a9d7c 100644 --- a/src/net/cbaines/suma/BuildingNumOverlay.java +++ b/src/net/cbaines/suma/BuildingNumOverlay.java @@ -40,6 +40,7 @@ import android.graphics.Point; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.net.Uri; +import android.preference.PreferenceManager; import android.util.Log; import android.view.MotionEvent; import android.widget.Toast; @@ -65,6 +66,8 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared private float userScale = 1f; + private boolean showIdentifiers; + public BuildingNumOverlay(MapActivity context, List buildings) throws SQLException { super(context); @@ -76,6 +79,9 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared final SharedPreferences favouritesPrefs = context.getSharedPreferences(FAVOURITES_PREFERENCES, 0); favouritesPrefs.registerOnSharedPreferenceChangeListener(this); + showIdentifiers = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SHOW_IDENTIFIERS, + SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT); + paint = new Paint(); paint.setColor(Color.BLACK); paint.setAntiAlias(true); @@ -209,7 +215,12 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared } else { Log.v(TAG, "building Pressed " + building.id); - context.makeToast(building.name + " (" + building.id + ")", Toast.LENGTH_SHORT); + String str = building.name; + if (showIdentifiers) { + str += " (" + building.id + ")"; + } + context.makeToast(str, context.getResources().getString(R.string.map_activity_toast_help_message), + Toast.LENGTH_SHORT); return true; } diff --git a/src/net/cbaines/suma/BusStopOverlay.java b/src/net/cbaines/suma/BusStopOverlay.java index 254e03a..778b306 100644 --- a/src/net/cbaines/suma/BusStopOverlay.java +++ b/src/net/cbaines/suma/BusStopOverlay.java @@ -210,8 +210,8 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref if (showIdentifiers) { str += " (" + busStop.id + ")"; } - str += "\n" + context.getResources().getString(R.string.map_activity_toast_help_message); - context.makeToast(str, Toast.LENGTH_SHORT); + context.makeToast(str, context.getResources().getString(R.string.map_activity_toast_help_message), + Toast.LENGTH_SHORT); return true; } diff --git a/src/net/cbaines/suma/ToastHelperActivity.java b/src/net/cbaines/suma/ToastHelperActivity.java index 6c5974c..a7997e9 100644 --- a/src/net/cbaines/suma/ToastHelperActivity.java +++ b/src/net/cbaines/suma/ToastHelperActivity.java @@ -1,5 +1,6 @@ package net.cbaines.suma; +import android.view.View; import android.widget.TextView; import android.widget.Toast; @@ -7,17 +8,35 @@ import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; public class ToastHelperActivity extends OrmLiteBaseActivity { - protected Toast toast; - protected TextView toastView; + private Toast toast; + private View toastView; + private TextView toastMessageTextView; + private TextView toastSubMessageTextView; void makeToast(String message, int length) { + makeToast(message, null, length); + } + + void makeToast(String message, String subMessage, int length) { if (toastView == null) { - toastView = (TextView) getLayoutInflater().inflate(R.layout.toast_view, null); + toastView = (View) getLayoutInflater().inflate(R.layout.toast_view, null); } - toastView.setText(message); if (toast == null) { toast = new Toast(this); } + + toastMessageTextView = (TextView) toastView.findViewById(R.id.toastViewText); + toastMessageTextView.setText(message); + + toastSubMessageTextView = (TextView) toastView.findViewById(R.id.toastViewSubMessage); + if (subMessage != null) { + toastSubMessageTextView.setText(subMessage); + toastSubMessageTextView.setVisibility(View.VISIBLE); + } else { + toastSubMessageTextView.setText(""); + toastSubMessageTextView.setVisibility(View.GONE); + } + toast.setDuration(length); toast.setView(toastView); toast.show(); -- cgit v1.2.3 From 4619835948a40c3ecffe3c7001cab295e58e5bdd Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Thu, 1 Mar 2012 12:29:50 +0000 Subject: Added the libs I forgot to add properly last commit, also changed versions stuff. --- src/net/cbaines/suma/MapActivity.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/net/cbaines/suma/MapActivity.java b/src/net/cbaines/suma/MapActivity.java index 728591d..9dd927a 100644 --- a/src/net/cbaines/suma/MapActivity.java +++ b/src/net/cbaines/suma/MapActivity.java @@ -293,6 +293,7 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants if (activityPrefs.getBoolean(OTHER_OVERLAYS + MY_LOCATION_OVERLAY, MY_LOCATION_OVERLAY_ENABLED_BY_DEFAULT) && sharedPrefs.getBoolean(GPS_ENABLED, GPS_ENABLED_BY_DEFAULT)) { + // The following can cause problems in some emulators, myLocationOverlay.enableMyLocation(); } else { myLocationOverlay.disableMyLocation(); @@ -301,6 +302,7 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants sharedPrefs.registerOnSharedPreferenceChangeListener(this); activityPrefs.registerOnSharedPreferenceChangeListener(this); } + Log.i(TAG, "Finished OnResume"); } public void onPause() { -- cgit v1.2.3 From 7125dc4757c29dfe9f451e51078ff59ce1521a6c Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Thu, 1 Mar 2012 13:42:29 +0000 Subject: Fix the bus stop movement, havent fully tested this yet as the live bus data is not working... Conflicts: gen/net/cbaines/suma/R.java --- src/net/cbaines/suma/BusRoute.java | 42 +++++++++++++++++-------------- src/net/cbaines/suma/BusStopActivity.java | 33 ++++++++++-------------- 2 files changed, 36 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java index ff80c66..e57e49c 100644 --- a/src/net/cbaines/suma/BusRoute.java +++ b/src/net/cbaines/suma/BusRoute.java @@ -65,7 +65,8 @@ public class BusRoute { String label; /** - * The direction the bus is travelling if it is moving through the route and sequence is increasing. + * The direction the bus is travelling if it is moving through the route and + * sequence is increasing. *
    *
  • U1 = A
  • *
  • U2 = B
  • @@ -76,7 +77,8 @@ public class BusRoute { String forwardDirection; /** - * The direction the bus is travelling if it is moving through the route and sequence is decreasing. + * The direction the bus is travelling if it is moving through the route and + * sequence is decreasing. *
      *
    • U1 = C
    • *
    • U2 = C
    • @@ -92,7 +94,8 @@ public class BusRoute { BusRoute() { } - public BusRoute(Integer id, String code, String label, String forwardDirection, String reverseDirection, boolean uniLink) { + public BusRoute(Integer id, String code, String label, String forwardDirection, String reverseDirection, + boolean uniLink) { this.id = id.intValue(); this.code = code; this.label = label; @@ -132,7 +135,8 @@ public class BusRoute { } /** - * Untested? + * Return the set of bus stops that can be thought of moveAmount away from + * the busStop. The method returns a set as * * @param context * @param busStop @@ -165,7 +169,7 @@ public class BusRoute { for (RouteStop routeStop : routeStopsFound) { if (routeStop.busStop.id.equals(busStop.id)) { - stopIndexs.add(routeStop.sequence - 1); + stopIndexs.add(routeStop.sequence); } } @@ -174,24 +178,24 @@ public class BusRoute { if (moveAmount > 0) { Log.v(TAG, "Moving forward " + moveAmount + " stops from " + busStop + " (" + stopIndex + "/" + routeStopsFound.size() + ")"); - int stopWanted = stopIndex + moveAmount; - if ((stopWanted + 1) > routeStopsFound.size()) { + int stopWantedSeq = stopIndex + moveAmount; + if (stopWantedSeq > routeStopsFound.size()) { Log.v(TAG, "Off the end of the route"); - stopWanted = stopWanted % (routeStopsFound.size() - 1); + stopWantedSeq = ((stopWantedSeq - 1) % (routeStopsFound.size())) + 1; } - Log.v(TAG, " Stop wanted " + stopWanted); - BusStop busStopWanted = routeStopsFound.get(stopWanted).busStop; + Log.v(TAG, " Stop wanted " + stopWantedSeq); + BusStop busStopWanted = routeStopsFound.get(stopWantedSeq - 1).busStop; busStopDao.refresh(busStopWanted); - Log.v(TAG, " Moving to " + busStopWanted + " (" + stopWanted + ") in route " + this); + Log.v(TAG, " Moving to " + busStopWanted + " (" + stopWantedSeq + ") in route " + this); busStops.add(busStopWanted); } else { Log.v(TAG, "stopIndex " + stopIndex); int stopWanted = stopIndex + moveAmount; - if (stopWanted < 0) { - stopWanted = routeStopsFound.size() - (Math.abs(stopWanted) % routeStopsFound.size()); + if (stopWanted < 1) { + stopWanted = routeStopsFound.size() - (Math.abs(stopWanted - 1) % routeStopsFound.size()); } Log.v(TAG, "stopWanted " + stopWanted); busStopDao.refresh(routeStopsFound.get(stopWanted).busStop); @@ -377,11 +381,10 @@ public class BusRoute { } if (moveAmount > 0) { - Log.v(TAG, - "Moving forward " + moveAmount + " stops from " + busStop + " (" + stopIndex + "/" - + routeStopsFound.size() + ")"); + Log.v(TAG, "Moving forward " + moveAmount + " stops from " + busStop + " (" + stopIndex + "/" + + routeStopsFound.size() + ")"); int stopWanted = stopIndex + moveAmount; - if ((stopWanted + 1) > routeStopsFound.size()) { + if (stopWanted > routeStopsFound.size()) { Log.v(TAG, "Off the end of the route"); stopWanted = stopWanted % (routeStopsFound.size() - 1); } @@ -402,8 +405,9 @@ public class BusRoute { Log.v(TAG, "stopWanted " + stopWanted); busStopDao.refresh(routeStopsFound.get(stopWanted).busStop); - Log.v(TAG, "Moving backwards " + moveAmount + " stops from " + busStop + " to " - + routeStopsFound.get(stopWanted).busStop + " in route " + this); + Log.v(TAG, + "Moving backwards " + moveAmount + " stops from " + busStop + " to " + + routeStopsFound.get(stopWanted).busStop + " in route " + this); return routeStopsFound.get(stopWanted).busStop; } diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java index cab81b1..81dbcc1 100644 --- a/src/net/cbaines/suma/BusStopActivity.java +++ b/src/net/cbaines/suma/BusStopActivity.java @@ -93,7 +93,7 @@ public class BusStopActivity extends OrmLiteBaseActivity impleme private CheckBox U9RouteRadioButton; private static final int POI_DIALOG_ID = 0; - private POIDialog busDialog; + private POIDialog busStopDialog; private HashSet routes = new HashSet(); @@ -398,15 +398,9 @@ public class BusStopActivity extends OrmLiteBaseActivity impleme if (busStops.size() == 1) { - BusStop stop = (BusStop) busStops.iterator().next(); - if (stop == null) { - Log.e(TAG, "stop == null"); - } - if (stop.id == null) { - Log.e(TAG, "stop.id == null"); - } + BusStop nextBusStop = (BusStop) busStops.iterator().next(); - Uri uri = Uri.parse("http://id.southampton.ac.uk/bus-stop/" + busStop.id); + Uri uri = Uri.parse("http://id.southampton.ac.uk/bus-stop/" + nextBusStop.id); Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath()); @@ -415,14 +409,14 @@ public class BusStopActivity extends OrmLiteBaseActivity impleme } else { showDialog(POI_DIALOG_ID); - if (busDialog == null) { + if (busStopDialog == null) { Log.e(TAG, "Very wierd, just tried to launch the favourite's dialog, but its null?"); return false; } - busDialog.setMessage(""); - busDialog.setItems(busStops); - busDialog.setTitle("Choose Bus Stop"); + busStopDialog.setMessage(""); + busStopDialog.setItems(busStops); + busStopDialog.setTitle("Choose Bus Stop"); Log.i(TAG, "Showing dialog"); } @@ -505,9 +499,9 @@ public class BusStopActivity extends OrmLiteBaseActivity impleme protected Dialog onCreateDialog(int id) { switch (id) { case POI_DIALOG_ID: - busDialog = new POIDialog(instance); - busDialog.setOnItemClickListener(this); - return busDialog; + busStopDialog = new POIDialog(instance); + busStopDialog.setOnItemClickListener(this); + return busStopDialog; } return null; } @@ -515,16 +509,15 @@ public class BusStopActivity extends OrmLiteBaseActivity impleme public void onItemClick(AdapterView parent, View view, int position, long id) { Log.i(TAG, "OnItemClick pos " + position + " id " + id); - String busId = busDialog.adapter.getItemStringId(position); + String busStopID = busStopDialog.adapter.getItemStringId(position); - Log.i(TAG, "Bus " + busId + " selected"); + Log.i(TAG, "Bus " + busStopID + " selected"); - Uri uri = Uri.parse("http://id.southampton.ac.uk/bus/" + busId); + Uri uri = Uri.parse("http://id.southampton.ac.uk/bus-stop/" + busStopID); Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath()); Intent busStopIntent = new Intent(Intent.ACTION_VIEW, uri); - busStopIntent.putExtra("busStopID", busStop.id); startActivity(busStopIntent); } -- cgit v1.2.3 From 8e2005fa2650b142b89799249b07ea72bdbcc906 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Thu, 1 Mar 2012 18:12:21 +0000 Subject: Fixed route movement, now tested. --- src/net/cbaines/suma/BusRoute.java | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java index e57e49c..793cc24 100644 --- a/src/net/cbaines/suma/BusRoute.java +++ b/src/net/cbaines/suma/BusRoute.java @@ -65,8 +65,7 @@ public class BusRoute { String label; /** - * The direction the bus is travelling if it is moving through the route and - * sequence is increasing. + * The direction the bus is travelling if it is moving through the route and sequence is increasing. *
        *
      • U1 = A
      • *
      • U2 = B
      • @@ -77,8 +76,7 @@ public class BusRoute { String forwardDirection; /** - * The direction the bus is travelling if it is moving through the route and - * sequence is decreasing. + * The direction the bus is travelling if it is moving through the route and sequence is decreasing. *
          *
        • U1 = C
        • *
        • U2 = C
        • @@ -94,8 +92,7 @@ public class BusRoute { BusRoute() { } - public BusRoute(Integer id, String code, String label, String forwardDirection, String reverseDirection, - boolean uniLink) { + public BusRoute(Integer id, String code, String label, String forwardDirection, String reverseDirection, boolean uniLink) { this.id = id.intValue(); this.code = code; this.label = label; @@ -135,8 +132,8 @@ public class BusRoute { } /** - * Return the set of bus stops that can be thought of moveAmount away from - * the busStop. The method returns a set as + * Return the set of bus stops that can be thought of moveAmount away from the busStop. The method returns a set as for some + * movements, the destination stop is ambiguous. * * @param context * @param busStop @@ -165,6 +162,7 @@ public class BusRoute { List routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); Collections.sort(routeStopsFound); + // Starting from 1, as the data does :( Set stopIndexs = new HashSet(); for (RouteStop routeStop : routeStopsFound) { @@ -193,18 +191,18 @@ public class BusRoute { busStops.add(busStopWanted); } else { Log.v(TAG, "stopIndex " + stopIndex); - int stopWanted = stopIndex + moveAmount; + int stopWanted = stopIndex + moveAmount; // This will end up as the sequence number of the wanted stop if (stopWanted < 1) { - stopWanted = routeStopsFound.size() - (Math.abs(stopWanted - 1) % routeStopsFound.size()); + stopWanted = routeStopsFound.size() - (Math.abs(stopWanted) % routeStopsFound.size()); } Log.v(TAG, "stopWanted " + stopWanted); - busStopDao.refresh(routeStopsFound.get(stopWanted).busStop); + BusStop wantedBusStop = routeStopsFound.get(stopWanted - 1).busStop; // Need the -1 as sequence starts at 1 + busStopDao.refresh(wantedBusStop); - Log.v(TAG, - "Moving backwards " + moveAmount + " stops from " + busStop + " to " - + routeStopsFound.get(stopWanted).busStop + " in route " + this); + Log.v(TAG, "Moving backwards " + (-1 * moveAmount) + " stops from " + busStop + " to " + wantedBusStop + + " in route " + this); - busStops.add(routeStopsFound.get(stopWanted).busStop); + busStops.add(wantedBusStop); } } @@ -381,8 +379,9 @@ public class BusRoute { } if (moveAmount > 0) { - Log.v(TAG, "Moving forward " + moveAmount + " stops from " + busStop + " (" + stopIndex + "/" - + routeStopsFound.size() + ")"); + Log.v(TAG, + "Moving forward " + moveAmount + " stops from " + busStop + " (" + stopIndex + "/" + + routeStopsFound.size() + ")"); int stopWanted = stopIndex + moveAmount; if (stopWanted > routeStopsFound.size()) { Log.v(TAG, "Off the end of the route"); @@ -405,9 +404,8 @@ public class BusRoute { Log.v(TAG, "stopWanted " + stopWanted); busStopDao.refresh(routeStopsFound.get(stopWanted).busStop); - Log.v(TAG, - "Moving backwards " + moveAmount + " stops from " + busStop + " to " - + routeStopsFound.get(stopWanted).busStop + " in route " + this); + Log.v(TAG, "Moving backwards " + moveAmount + " stops from " + busStop + " to " + + routeStopsFound.get(stopWanted).busStop + " in route " + this); return routeStopsFound.get(stopWanted).busStop; } -- cgit v1.2.3 From 75dc55b83cf983872f3f84b8950da27738f46b3e Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Thu, 1 Mar 2012 20:36:22 +0000 Subject: Better toasts in the BusStopActivity, many other improvements. --- src/net/cbaines/suma/Bus.java | 194 +++++++++++++------------- src/net/cbaines/suma/BusActivity.java | 95 ++++++------- src/net/cbaines/suma/BusSpecificStopView.java | 11 -- src/net/cbaines/suma/BusStopActivity.java | 15 +- src/net/cbaines/suma/DataManager.java | 148 ++++++++++---------- src/net/cbaines/suma/DatabaseHelper.java | 2 +- src/net/cbaines/suma/MapActivity.java | 2 +- src/net/cbaines/suma/StopView.java | 41 ++---- 8 files changed, 242 insertions(+), 266 deletions(-) (limited to 'src') diff --git a/src/net/cbaines/suma/Bus.java b/src/net/cbaines/suma/Bus.java index b36dd89..865384f 100644 --- a/src/net/cbaines/suma/Bus.java +++ b/src/net/cbaines/suma/Bus.java @@ -31,100 +31,106 @@ import com.j256.ormlite.table.DatabaseTable; @DatabaseTable(tableName = "buses") public class Bus { - final static String ID_FIELD_NAME = "id"; - final static String ROUTE_FIELD_NAME = "route"; - final static String DIRECTION_FIELD_NAME = "direction"; - - @DatabaseField(generatedId = true) - int gid; - - /** - * The identification number of the bus. - */ - @DatabaseField(canBeNull = true) - String id; - - /** - * The route the bus is travelling. - */ - @DatabaseField(canBeNull = false, foreign = true) - BusRoute route; - - /** - * The direction which the bus is travelling. - */ - @DatabaseField(canBeNull = true) - String direction; - - /** - * The destination the bus is travelling towards. - */ - @DatabaseField(canBeNull = true, foreign = true) - BusStop destination; - - Bus() { - } - - /** - * Create a bus. - * - * @param id - * The identification number of the bus. - * @param route - * The route the bus is travelling. - * @param dir - * The direction which the bus is travelling. - */ - Bus(String id, BusRoute route, String direction) { - this.id = id; - this.route = route; - this.direction = direction; - } - - /** - * Create a bus. - * - * @param id - * The identification number of the bus. - * @param route - * The route the bus is travelling. - */ - Bus(String id, BusRoute route) { - this(id, route, null); - } - - public String toString() { - return String.valueOf(id + " (" + route.code + direction + ")"); - } - - String getName() { - if (direction != null) { - return route.code + direction; - } else { - return route.code; + final static String ID_FIELD_NAME = "id"; + final static String ROUTE_FIELD_NAME = "route"; + final static String DIRECTION_FIELD_NAME = "direction"; + + @DatabaseField(generatedId = true) + int gid; + + /** + * The identification number of the bus. + */ + @DatabaseField(canBeNull = true) + String id; + + /** + * The route the bus is travelling. + */ + @DatabaseField(canBeNull = false, foreign = true) + BusRoute route; + + /** + * The direction which the bus is travelling. + */ + @DatabaseField(canBeNull = true) + String direction; + + /** + * The destination the bus is travelling towards. + */ + @DatabaseField(canBeNull = true, foreign = true) + BusStop destination; + + /** + * The destination the bus is travelling towards. + */ + @DatabaseField(canBeNull = true) + String destinationString; + + Bus() { + } + + /** + * Create a bus. + * + * @param id + * The identification number of the bus. + * @param route + * The route the bus is travelling. + * @param dir + * The direction which the bus is travelling. + */ + Bus(String id, BusRoute route, String direction) { + this.id = id; + this.route = route; + this.direction = direction; + } + + /** + * Create a bus. + * + * @param id + * The identification number of the bus. + * @param route + * The route the bus is travelling. + */ + Bus(String id, BusRoute route) { + this(id, route, null); + } + + public String toString() { + return String.valueOf(id + " (" + route.code + direction + ")"); + } + + String getName() { + if (direction != null) { + return route.code + direction; + } else { + return route.code; + } + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + gid; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Bus other = (Bus) obj; + if (id != other.id) + return false; + return true; } - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + gid; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Bus other = (Bus) obj; - if (id != other.id) - return false; - return true; - } } diff --git a/src/net/cbaines/suma/BusActivity.java b/src/net/cbaines/suma/BusActivity.java index 1a8baf9..c1519ec 100644 --- a/src/net/cbaines/suma/BusActivity.java +++ b/src/net/cbaines/suma/BusActivity.java @@ -28,6 +28,7 @@ public class BusActivity extends OrmLiteBaseActivity implements final static String TAG = "BusActivity"; private TextView busIDTextView; + private TextView busDestTextView; private TextView busContentMessage; private LinearLayout busActivityContentLayout; @@ -64,28 +65,22 @@ public class BusActivity extends OrmLiteBaseActivity implements setContentView(R.layout.bus_activity); instance = this; - Log.i(TAG, "getIntent().getDataString() " + getIntent().getDataString()); - String busID; if (getIntent().getDataString().startsWith("http://data")) { - String[] uriParts = getIntent().getDataString().split("/"); - busID = uriParts[uriParts.length - 1].replace(".html", ""); - } else { - String[] uriParts = getIntent().getDataString().split("/"); - busID = uriParts[uriParts.length - 1]; } String busStopID = getIntent().getExtras().getString("busStopID"); - final DatabaseHelper helper = getHelper(); try { + final DatabaseHelper helper = getHelper(); List buses = helper.getBusDao().queryForEq(Bus.ID_FIELD_NAME, busID); + bus = null; if (buses.size() == 0) { Log.e(TAG, "Bus " + busID + " not found!"); @@ -110,6 +105,7 @@ public class BusActivity extends OrmLiteBaseActivity implements } busIDTextView = (TextView) findViewById(R.id.busActivityBusID); + busDestTextView = (TextView) findViewById(R.id.busActivityBusDestination); busContentMessage = (TextView) findViewById(R.id.busActivityMessage); busActivityContentLayout = (LinearLayout) findViewById(R.id.busActivityContentLayout); @@ -124,58 +120,53 @@ public class BusActivity extends OrmLiteBaseActivity implements busIDTextView.setText("Unidentified"); } - } catch (NumberFormatException e) { - e.printStackTrace(); - } catch (SQLException e) { - e.printStackTrace(); - } + if (bus.destinationString != null) { + Log.i(TAG, "Bus destination string is " + bus.destinationString); + busDestTextView.setText(bus.destinationString); + busDestTextView.setVisibility(View.VISIBLE); + } else { + Log.i(TAG, "Bus destination string is null"); + busDestTextView.setVisibility(View.GONE); + } - busStops = bus.route.getRouteSection(instance, bus.direction); - Log.i(TAG, "Got " + busStops.size() + " bus stops for this bus"); + busStops = bus.route.getRouteSection(instance, bus.direction); + Log.i(TAG, "Got " + busStops.size() + " bus stops for this bus"); - if (bus.destination != null) { - Log.i(TAG, "Bus destination is " + bus.destination); - } else { - Log.i(TAG, "Bus destination is null"); - } + if (bus.destination != null) { + Log.i(TAG, "Bus destination is " + bus.destination); + } 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); - /* - * 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; } - * - * busStops.add(nextStop); busStopsActive.add(false); - * - * if (busStops.size() > 50) { Log.e(TAG, "Got more than 50 bus stops"); break; } } - */ - - refreshData = new Runnable() { - public void run() { - for (int num = timetableView.getFirstVisiblePosition(); num < timetableView.getLastVisiblePosition(); num++) { - Stop stop = timetable.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; + 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) { - 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); } - handler.postDelayed(refreshData, 50000); - } - }; - + }; + } catch (SQLException e) { + e.printStackTrace(); + } } public void onResume() { diff --git a/src/net/cbaines/suma/BusSpecificStopView.java b/src/net/cbaines/suma/BusSpecificStopView.java index 610ee76..deaf932 100644 --- a/src/net/cbaines/suma/BusSpecificStopView.java +++ b/src/net/cbaines/suma/BusSpecificStopView.java @@ -24,7 +24,6 @@ import java.text.DateFormat; import android.app.Activity; import android.content.Intent; -import android.util.Log; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; @@ -76,16 +75,6 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener this.stop = stop; - if (stop == null) { - Log.e(TAG, "stop == null"); - } - if (stop.busStop == null) { - Log.e(TAG, "stop.busStop == null"); - } - if (stop.busStop.description == null) { - Log.e(TAG, "stop.busStop.description == null"); - } - if (stop.busStop.description.length() > 20) { location.setText(stop.busStop.description.substring(0, 20)); // TODO } else { diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java index 81dbcc1..9f422af 100644 --- a/src/net/cbaines/suma/BusStopActivity.java +++ b/src/net/cbaines/suma/BusStopActivity.java @@ -54,15 +54,13 @@ import android.widget.LinearLayout; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; -import android.widget.Toast; -import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; import com.j256.ormlite.dao.Dao; import com.j256.ormlite.stmt.PreparedQuery; import com.j256.ormlite.stmt.QueryBuilder; -public class BusStopActivity extends OrmLiteBaseActivity implements OnCheckedChangeListener, Preferences, - OnItemClickListener, OnLongClickListener { +public class BusStopActivity extends ToastHelperActivity implements OnCheckedChangeListener, Preferences, OnItemClickListener, + OnLongClickListener { final static String TAG = "BusTimeActivity"; @@ -97,8 +95,6 @@ public class BusStopActivity extends OrmLiteBaseActivity impleme private HashSet routes = new HashSet(); - Toast activityToast; - public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.bus_stop_activity); @@ -214,14 +210,18 @@ public class BusStopActivity extends OrmLiteBaseActivity impleme busName = (TextView) findViewById(R.id.busStopName); + busID = (TextView) findViewById(R.id.busStopID); if (prefs.getBoolean(SHOW_IDENTIFIERS, SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT)) { - busID = (TextView) findViewById(R.id.busStopID); busID.setText(busStopID); busID.setVisibility(View.VISIBLE); + } else { + busID.setVisibility(View.GONE); } busStopMessage = (TextView) findViewById(R.id.busStopMessage); + busStopMessage.setVisibility(View.GONE); progBar = (ProgressBar) findViewById(R.id.busStopLoadBar); + progBar.setVisibility(View.GONE); busTimeList = (ListView) findViewById(R.id.busStopTimes); busTimeContentLayout = (LinearLayout) findViewById(R.id.busTimeContentLayout); @@ -353,6 +353,7 @@ public class BusStopActivity extends OrmLiteBaseActivity impleme busStopMessage.setVisibility(View.VISIBLE); } else { progBar.setVisibility(View.GONE); + busStopMessage.setVisibility(View.GONE); timetable = newTimetable; displayTimetable(timetable); } diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java index 5e8b195..ab1f3a7 100644 --- a/src/net/cbaines/suma/DataManager.java +++ b/src/net/cbaines/suma/DataManager.java @@ -137,13 +137,9 @@ public class DataManager { /* * Polygon poly = buildingPolys.get(dataBits[1]); * - * if (poly != null) { bdg.outline = poly; // Log.i(TAG, - * "Adding building " + key + " " + - * bdg.point.getLatitudeE6() + " " + - * bdg.point.getLongitudeE6() + " " + poly); } else { // - * Log.i(TAG, "Adding building " + key + " " + - * bdg.point.getLatitudeE6() + " " + - * bdg.point.getLongitudeE6()); } + * if (poly != null) { bdg.outline = poly; // Log.i(TAG, "Adding building " + key + " " + + * bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6() + " " + poly); } else { // Log.i(TAG, + * "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6()); } */ // Log.i(TAG, "Creating building " + bdg.id + " " + bdg.name @@ -167,13 +163,9 @@ public class DataManager { /* * Polygon poly = buildingPolys.get(dataBits[1]); * - * if (poly != null) { bdg.outline = poly; // Log.i(TAG, - * "Adding building " + key + " " + - * bdg.point.getLatitudeE6() + " " + - * bdg.point.getLongitudeE6() + " " + poly); } else { // - * Log.i(TAG, "Adding building " + key + " " + - * bdg.point.getLatitudeE6() + " " + - * bdg.point.getLongitudeE6()); } + * if (poly != null) { bdg.outline = poly; // Log.i(TAG, "Adding building " + key + " " + + * bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6() + " " + poly); } else { // Log.i(TAG, + * "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6()); } */ // Log.i(TAG, "Creating building " + bdg.id + " " + bdg.name @@ -192,17 +184,13 @@ public class DataManager { } /* - * for (Iterator iter = buildingPoints.keySet().iterator(); - * iter.hasNext();) { String key = iter.next(); + * for (Iterator iter = buildingPoints.keySet().iterator(); iter.hasNext();) { String key = iter.next(); * - * Building bdg = new Building(key, buildingPoints.get(key), false); - * Polygon poly = buildingPolys.get(key); + * Building bdg = new Building(key, buildingPoints.get(key), false); Polygon poly = buildingPolys.get(key); * - * if (poly != null) { bdg.outline = poly; // Log.i(TAG, - * "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + - * bdg.point.getLongitudeE6() + " " + poly); } else { // Log.i(TAG, - * "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + - * bdg.point.getLongitudeE6()); } + * if (poly != null) { bdg.outline = poly; // Log.i(TAG, "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + * + bdg.point.getLongitudeE6() + " " + poly); } else { // Log.i(TAG, "Adding building " + key + " " + + * bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6()); } * * buildingDao.create(bdg); } */ @@ -239,18 +227,18 @@ public class DataManager { // Log.i(TAG, "Whole " + dataBits[3] + " First bit " + // quBitsLat[0] + " last bit " + quBitsLat[1]); - double lat = Double.valueOf(quBitsLat[0]) - + Double.valueOf(quBitsLat[1].substring(0, quBitsLat[1].length() - 1)) / 60d; + double lat = Double.valueOf(quBitsLat[0]) + Double.valueOf(quBitsLat[1].substring(0, quBitsLat[1].length() - 1)) + / 60d; // Log.i(TAG, "Whole " + dataBits[4] + " First bit " + // quBitsLng[0] + " last bit " + quBitsLng[1]); - double lng = Double.valueOf(quBitsLng[0]) - + Double.valueOf(quBitsLng[1].substring(0, quBitsLng[1].length() - 1)) / 60d; + double lng = Double.valueOf(quBitsLng[0]) + Double.valueOf(quBitsLng[1].substring(0, quBitsLng[1].length() - 1)) + / 60d; GeoPoint point = new GeoPoint((int) (lat * 1e6), (int) (lng * -1e6)); // Log.i(TAG, "Lat " + point.getLatitudeE6() + " lng " + // point.getLongitudeE6()); - busStopDao.create(new BusStop(dataBits[0].replace("\"", ""), dataBits[1].replace("\"", ""), dataBits[2] - .replace("\"", ""), point)); + busStopDao.create(new BusStop(dataBits[0].replace("\"", ""), dataBits[1].replace("\"", ""), dataBits[2].replace( + "\"", ""), point)); } @@ -371,36 +359,26 @@ public class DataManager { } /* - * for (Iterator busStopIter = busStopDao.iterator(); - * busStopIter.hasNext();) { BusStop stop = busStopIter.next(); // - * Log.i(TAG, "Looking at stop " + stop.id); + * for (Iterator busStopIter = busStopDao.iterator(); busStopIter.hasNext();) { BusStop stop = + * busStopIter.next(); // Log.i(TAG, "Looking at stop " + stop.id); * * - * QueryBuilder routeStopsQueryBuilder = - * routeStopsDao.queryBuilder(); + * QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); * routeStopsQueryBuilder.where().eq(columnName, value) * - * DeleteBuilder deleteBuilder = - * busStopDao.deleteBuilder(); // only delete the rows where password is - * null deleteBuilder.where().in(RouteStops.STOP_ID_FIELD_NAME, objects) - * accountDao.delete(deleteBuilder.prepare()); + * DeleteBuilder deleteBuilder = busStopDao.deleteBuilder(); // only delete the rows where password is + * null deleteBuilder.where().in(RouteStops.STOP_ID_FIELD_NAME, objects) accountDao.delete(deleteBuilder.prepare()); * * - * QueryBuilder routeStopsQueryBuilder = - * routeStopsDao.queryBuilder(); - * routeStopsQueryBuilder.setCountOf(true); - * routeStopsQueryBuilder.where().eq(RouteStops.STOP_ID_FIELD_NAME, - * stop); + * QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); + * routeStopsQueryBuilder.setCountOf(true); routeStopsQueryBuilder.where().eq(RouteStops.STOP_ID_FIELD_NAME, stop); * - * PreparedQuery routeStopsPreparedQuery = - * routeStopsQueryBuilder.prepare(); List routeStops = - * routeStopsDao.query(routeStopsPreparedQuery); // long num = - * routeStopsDao.query(routeStopsPreparedQuery).size(); // Log.i(TAG, - * "Number is " + num); + * PreparedQuery routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); List routeStops = + * routeStopsDao.query(routeStopsPreparedQuery); // long num = routeStopsDao.query(routeStopsPreparedQuery).size(); // + * Log.i(TAG, "Number is " + num); * - * stop.uniLink = false; for (RouteStops routeStop : routeStops) { if - * (routeStop.busRoute.uniLink) { stop.uniLink = true; } } - * busStopDao.update(stop); } + * stop.uniLink = false; for (RouteStops routeStop : routeStops) { if (routeStop.busRoute.uniLink) { stop.uniLink = true; + * } } busStopDao.update(stop); } */ Log.i(TAG, "Finished loading bus data"); @@ -450,7 +428,7 @@ public class DataManager { Log.i(TAG, "Loaded sites from csv"); } - private static Stop getStop(Context context, JSONObject stopObj, Set routes, BusStop busStop) + private static Stop getStop(Context context, JSONObject stopObj, Set routes, BusStop busStop, int age) throws SQLException, JSONException { if (helper == null) @@ -484,6 +462,7 @@ public class DataManager { // + " for min"); calender.add(Calendar.MINUTE, Integer.parseInt(time.substring(0, time.length() - 1))); } + calender.add(Calendar.SECOND, age); // Log.v(TAG, "Date: " + calender.getTime()); } @@ -575,11 +554,9 @@ public class DataManager { List 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); + Log.w(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route " + route.code); } } @@ -600,9 +577,11 @@ public class DataManager { if (bus == null) { bus = new Bus(busID, route, dir); bus.destination = destStop; + bus.destinationString = destString; busDao.create(bus); } else { bus.destination = destStop; + bus.destinationString = destString; bus.route = route; bus.direction = dir; busDao.update(bus); @@ -610,6 +589,8 @@ public class DataManager { } else { bus = new Bus(null, route, dir); + bus.destinationString = destString; + bus.destination = destStop; busDao.create(bus); } @@ -618,6 +599,19 @@ public class DataManager { return stop; } + /** + * Get the timetable for the bus stop. + * + * @param context + * @param busStop + * @param keepUniLink + * @param keepNonUniLink + * @return + * @throws SQLException + * @throws ClientProtocolException + * @throws IOException + * @throws JSONException + */ public static Timetable getTimetable(Context context, String busStop, boolean keepUniLink, boolean keepNonUniLink) throws SQLException, ClientProtocolException, IOException, JSONException { @@ -637,7 +631,8 @@ public class DataManager { JSONObject routesObject = data.getJSONObject("routes"); HashSet busRoutes = new HashSet(); - for (Iterator keyIter = routesObject.keys(); keyIter.hasNext();) { + for (@SuppressWarnings("unchecked") + Iterator keyIter = routesObject.keys(); keyIter.hasNext();) { String key = keyIter.next(); Log.v(TAG, "Route Key: " + key); @@ -647,14 +642,13 @@ public class DataManager { if (route != null) { busRoutes.add(route); } else { - throw new RuntimeException("Route not found " + key.substring(key.length() - 3, key.length()) + " " - + key); + throw new RuntimeException("Route not found " + key.substring(key.length() - 3, key.length()) + " " + key); } } - Log.i(TAG, "Number of entries " + data.length()); + int age = Integer.parseInt(data.getString("age")); - Log.i(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); @@ -674,23 +668,33 @@ public class DataManager { Log.e(TAG, "BusStopObj == null"); } - Stop stop = getStop(context, stopObj, busRoutes, busStopObj); + Stop stop = getStop(context, stopObj, busRoutes, busStopObj, age); if (stop == null) { - Log.w(TAG, "Null stop, skiping"); + Log.e(TAG, "Null stop, skiping"); continue; } - Log.v(TAG, "Found stop for a unidentified " + stop.bus.toString() + " at " + stop.busStop.id + " at " - + stop.arivalTime); - timetable.add(stop); } timetable.fetchTime = new Date(System.currentTimeMillis()); + return timetable; } + /** + * + * @param context + * @param bus + * @param startStop + * @param num + * @return + * @throws SQLException + * @throws ClientProtocolException + * @throws IOException + * @throws JSONException + */ public static Timetable getTimetable(Context context, Bus bus, BusStop startStop, int num) throws SQLException, ClientProtocolException, IOException, JSONException { @@ -725,6 +729,8 @@ public class DataManager { JSONObject data = new JSONObject(file); JSONArray stopsArray = data.getJSONArray("stops"); + int age = Integer.parseInt(data.getString("age")); + HashSet busRoutes = new HashSet(); busRoutes.add(bus.route); @@ -737,15 +743,15 @@ public class DataManager { if (stopObj.getString("vehicle").equals(bus.id)) { - Stop stop = getStop(context, stopObj, busRoutes, busStop); + Stop stop = getStop(context, stopObj, busRoutes, busStop, age); if (stop == null) { Log.w(TAG, "Null stop, skiping"); 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); @@ -777,6 +783,8 @@ public class DataManager { busRouteDao.refresh(bus.route); busRoutes.add(bus.route); + int age = Integer.parseInt(data.getString("age")); + Stop stop = null; // Log.v(TAG, "Number of entries " + data.length()); @@ -789,7 +797,7 @@ public class DataManager { // Log.v(TAG, "stopObj: " + stopObj); if (stopObj.has("vehicle") && stopObj.getString("vehicle").equals(bus.id)) { - stop = getStop(context, stopObj, busRoutes, busStop); + stop = getStop(context, stopObj, busRoutes, busStop, age); break; // Log.v(TAG, "Found stop for a unidentified " + diff --git a/src/net/cbaines/suma/DatabaseHelper.java b/src/net/cbaines/suma/DatabaseHelper.java index facfe85..73f4c79 100644 --- a/src/net/cbaines/suma/DatabaseHelper.java +++ b/src/net/cbaines/suma/DatabaseHelper.java @@ -40,7 +40,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { private static final String DATABASE_PATH = "/data/data/net.cbaines.suma/databases/"; private static final String DATABASE_NAME = "data.db"; - private static final int DATABASE_VERSION = 40; + private static final int DATABASE_VERSION = 41; private static final String TAG = "DatabaseHelper"; diff --git a/src/net/cbaines/suma/MapActivity.java b/src/net/cbaines/suma/MapActivity.java index 9dd927a..1dde4be 100644 --- a/src/net/cbaines/suma/MapActivity.java +++ b/src/net/cbaines/suma/MapActivity.java @@ -76,7 +76,7 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants * Enable to use the database in the assets folder, if its not enabled, the * database is built from the csv files in the assets folder */ - private boolean useBundledDatabase = true; + private boolean useBundledDatabase = false; private MapView mapView; private MapController mapController; diff --git a/src/net/cbaines/suma/StopView.java b/src/net/cbaines/suma/StopView.java index afe8664..fa76131 100644 --- a/src/net/cbaines/suma/StopView.java +++ b/src/net/cbaines/suma/StopView.java @@ -23,6 +23,7 @@ import java.sql.SQLException; import java.text.DateFormat; import android.content.Intent; +import android.content.res.Resources; import android.net.Uri; import android.util.Log; import android.view.Gravity; @@ -49,6 +50,9 @@ public class StopView extends LinearLayout implements OnClickListener, OnLongCli private Stop stop; + private String onClickHelpMessage; + private String onClickUnidentifiedMessage; + public StopView(BusStopActivity context, Stop stop) { super(context); @@ -63,6 +67,10 @@ public class StopView extends LinearLayout implements OnClickListener, OnLongCli time.setTextSize(22f); time.setGravity(Gravity.RIGHT); + Resources resources = context.getResources(); + onClickHelpMessage = resources.getString(R.string.stop_view_on_click_toast_help_message); + onClickUnidentifiedMessage = resources.getString(R.string.stop_view_on_click_toast_unidentified_message); + setStop(stop); addView(name, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); @@ -111,14 +119,7 @@ public class StopView extends LinearLayout implements OnClickListener, OnLongCli } public void onClick(View v) { - if (context.activityToast == null) { - context.activityToast = Toast.makeText(context, onClickMessage, Toast.LENGTH_SHORT); - } else { - context.activityToast.setText(onClickMessage); - context.activityToast.setDuration(Toast.LENGTH_SHORT); - } - context.activityToast.show(); - + context.makeToast(onClickMessage, onClickHelpMessage, Toast.LENGTH_SHORT); } public boolean onLongClick(View v) { @@ -131,8 +132,7 @@ public class StopView extends LinearLayout implements OnClickListener, OnLongCli busDao.refresh(stop.bus); busRouteDao.refresh(stop.bus.route); - Log.i("StopView", "Bus route " + stop.bus.route + " Uni-Link " + stop.bus.route.uniLink + " Bus ID " - + stop.bus.id); + Log.i("StopView", "Bus route " + stop.bus.route + " Uni-Link " + stop.bus.route.uniLink + " Bus ID " + stop.bus.id); if (stop.bus.id != null && stop.bus.route.uniLink) { Uri uri = Uri.parse("http://id.southampton.ac.uk/bus/" + stop.bus.id); @@ -141,27 +141,8 @@ public class StopView extends LinearLayout implements OnClickListener, OnLongCli busStopIntent.putExtra("busStopID", stop.busStop.id); context.startActivity(busStopIntent); } else { - 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 { - 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.makeToast(onClickUnidentifiedMessage, Toast.LENGTH_SHORT); } - } catch (SQLException e) { e.printStackTrace(); } -- cgit v1.2.3 From 91a53f56aef2ed1bbbe1ae1d183136522624acec Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Thu, 1 Mar 2012 22:02:02 +0000 Subject: Transparent toasts, and more improvemens. --- src/net/cbaines/suma/BusActivity.java | 13 +- src/net/cbaines/suma/BusSpecificStopView.java | 25 ++-- src/net/cbaines/suma/BusStopActivity.java | 6 +- src/net/cbaines/suma/BusStopSpecificStopView.java | 153 +++++++++++++++++++++ .../suma/BusStopSpecificTimetableAdapter.java | 92 +++++++++++++ src/net/cbaines/suma/Stop.java | 2 +- src/net/cbaines/suma/StopView.java | 151 -------------------- src/net/cbaines/suma/TimetableAdapter.java | 92 ------------- 8 files changed, 264 insertions(+), 270 deletions(-) create mode 100644 src/net/cbaines/suma/BusStopSpecificStopView.java create mode 100644 src/net/cbaines/suma/BusStopSpecificTimetableAdapter.java delete mode 100644 src/net/cbaines/suma/StopView.java delete mode 100644 src/net/cbaines/suma/TimetableAdapter.java (limited to 'src') diff --git a/src/net/cbaines/suma/BusActivity.java b/src/net/cbaines/suma/BusActivity.java index c1519ec..3292ce8 100644 --- a/src/net/cbaines/suma/BusActivity.java +++ b/src/net/cbaines/suma/BusActivity.java @@ -20,11 +20,8 @@ import android.view.View; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; -import android.widget.Toast; -import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; - -public class BusActivity extends OrmLiteBaseActivity implements Preferences { +public class BusActivity extends ToastHelperActivity implements Preferences { final static String TAG = "BusActivity"; private TextView busIDTextView; @@ -33,8 +30,6 @@ public class BusActivity extends OrmLiteBaseActivity implements private TextView busContentMessage; private LinearLayout busActivityContentLayout; - Toast activityToast; - /** * The bus this activity is focused on */ @@ -122,11 +117,13 @@ public class BusActivity extends OrmLiteBaseActivity implements if (bus.destinationString != null) { Log.i(TAG, "Bus destination string is " + bus.destinationString); - busDestTextView.setText(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"); - busDestTextView.setVisibility(View.GONE); + busDestTextView.setText(getResources().getString(R.string.bus_activity_no_destination_message)); + busDestTextView.setVisibility(View.VISIBLE); } busStops = bus.route.getRouteSection(instance, bus.direction); diff --git a/src/net/cbaines/suma/BusSpecificStopView.java b/src/net/cbaines/suma/BusSpecificStopView.java index deaf932..5ab7cd5 100644 --- a/src/net/cbaines/suma/BusSpecificStopView.java +++ b/src/net/cbaines/suma/BusSpecificStopView.java @@ -24,6 +24,7 @@ import java.text.DateFormat; import android.app.Activity; import android.content.Intent; +import android.content.res.Resources; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; @@ -48,6 +49,9 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener private Stop stop; + private String onClickHelpMessage; + private String onClickUnidentifiedMessage; + public BusSpecificStopView(BusActivity context, Stop stop) { super(context); @@ -62,6 +66,10 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener time.setTextSize(22f); time.setGravity(Gravity.RIGHT); + Resources resources = context.getResources(); + onClickHelpMessage = resources.getString(R.string.bus_stop_view_on_click_toast_help_message); + onClickUnidentifiedMessage = resources.getString(R.string.bus_stop_view_on_click_toast_unidentified_message); + setStop(stop); addView(location, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); @@ -136,13 +144,7 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener } public void onClick(View v) { - if (context.activityToast == null) { - context.activityToast = Toast.makeText(context, onClickMessage, Toast.LENGTH_SHORT); - } else { - context.activityToast.setText(onClickMessage); - context.activityToast.setDuration(Toast.LENGTH_SHORT); - } - context.activityToast.show(); + context.makeToast(onClickMessage, onClickHelpMessage, Toast.LENGTH_SHORT); } public boolean onLongClick(View v) { // TODO @@ -159,14 +161,7 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener i.putExtra("poiPoint", stop.busStop.point.toDoubleString()); ((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); - } else { - context.activityToast.setText("Arival prediction not avalible for timetabled buses"); - context.activityToast.setDuration(Toast.LENGTH_SHORT); - } - context.activityToast.show(); + context.makeToast(onClickUnidentifiedMessage, Toast.LENGTH_SHORT); } } catch (SQLException e) { diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java index 9f422af..9c49ff7 100644 --- a/src/net/cbaines/suma/BusStopActivity.java +++ b/src/net/cbaines/suma/BusStopActivity.java @@ -484,11 +484,11 @@ public class BusStopActivity extends ToastHelperActivity implements OnCheckedCha } else { busTimeList.setVisibility(View.VISIBLE); busStopMessage.setVisibility(View.GONE); - TimetableAdapter adapter; - if ((adapter = (TimetableAdapter) busTimeList.getAdapter()) != null) { + BusStopSpecificTimetableAdapter adapter; + if ((adapter = (BusStopSpecificTimetableAdapter) busTimeList.getAdapter()) != null) { adapter.updateTimetable(visibleTimetable); } else { - adapter = new TimetableAdapter(this, visibleTimetable); + adapter = new BusStopSpecificTimetableAdapter(this, visibleTimetable); busTimeList.setAdapter(adapter); } busTimeContentLayout.setGravity(Gravity.TOP); diff --git a/src/net/cbaines/suma/BusStopSpecificStopView.java b/src/net/cbaines/suma/BusStopSpecificStopView.java new file mode 100644 index 0000000..c7f9bd8 --- /dev/null +++ b/src/net/cbaines/suma/BusStopSpecificStopView.java @@ -0,0 +1,153 @@ +/* + * 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 java.sql.SQLException; +import java.text.DateFormat; + +import android.content.Intent; +import android.content.res.Resources; +import android.net.Uri; +import android.util.Log; +import android.view.Gravity; +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; + +import com.j256.ormlite.android.apptools.OpenHelperManager; +import com.j256.ormlite.dao.Dao; + +public class BusStopSpecificStopView extends LinearLayout implements OnClickListener, OnLongClickListener { + + // private final ImageView icon; + + // private static final String TAG = "StopView"; + + private final TextView name; + private final TextView time; + + private String onClickMessage = ""; + private final BusStopActivity context; + + private Stop stop; + + private String onClickHelpMessage; + private String onClickUnidentifiedMessage; + + public BusStopSpecificStopView(BusStopActivity context, Stop stop) { + super(context); + + this.context = context; + + this.setOrientation(HORIZONTAL); + + name = new TextView(context); + name.setTextSize(22f); + + time = new TextView(context); + time.setTextSize(22f); + time.setGravity(Gravity.RIGHT); + + Resources resources = context.getResources(); + onClickHelpMessage = resources.getString(R.string.bus_stop_stop_view_on_click_toast_help_message); + onClickUnidentifiedMessage = resources.getString(R.string.bus_stop_stop_view_on_click_toast_unidentified_message); + + setStop(stop); + + addView(name, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); + addView(time, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); + } + + public void setStop(Stop stop) { + + // Log.i(TAG, "Time of arival " + stop.arivalTime); + + this.stop = stop; + + name.setText(stop.bus.getName()); + time.setText(stop.getTimeToArival()); + + DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); + + try { + Dao busDao = helper.getBusDao(); + + busDao.refresh(stop.bus); + + 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); + } + } 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); + } + } + } catch (SQLException e) { + e.printStackTrace(); + } + + this.setOnClickListener(this); + this.setOnLongClickListener(this); + } + + public void onClick(View v) { + context.makeToast(onClickMessage, onClickHelpMessage, Toast.LENGTH_SHORT); + } + + public boolean onLongClick(View v) { + DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); + + try { + Dao busDao = helper.getBusDao(); + Dao busRouteDao = helper.getBusRouteDao(); + + busDao.refresh(stop.bus); + busRouteDao.refresh(stop.bus.route); + + Log.i("StopView", "Bus route " + stop.bus.route + " Uni-Link " + stop.bus.route.uniLink + " Bus ID " + stop.bus.id); + + if (stop.bus.id != null && stop.bus.route.uniLink) { + Uri uri = Uri.parse("http://id.southampton.ac.uk/bus/" + stop.bus.id); + + Intent busStopIntent = new Intent(Intent.ACTION_VIEW, uri); + busStopIntent.putExtra("busStopID", stop.busStop.id); + context.startActivity(busStopIntent); + } else { + context.makeToast(onClickUnidentifiedMessage, Toast.LENGTH_SHORT); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return true; + } +} diff --git a/src/net/cbaines/suma/BusStopSpecificTimetableAdapter.java b/src/net/cbaines/suma/BusStopSpecificTimetableAdapter.java new file mode 100644 index 0000000..511f427 --- /dev/null +++ b/src/net/cbaines/suma/BusStopSpecificTimetableAdapter.java @@ -0,0 +1,92 @@ +/* + * 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.util.Log; +import android.view.View; +import android.view.ViewGroup; +import android.view.animation.Animation; +import android.view.animation.AnimationUtils; +import android.widget.BaseAdapter; + +public class BusStopSpecificTimetableAdapter extends BaseAdapter { + + private final BusStopActivity context; + private Timetable timetable; + private final Animation a; + private boolean[] changed; + + private static final String TAG = "TimetableAdapter"; + + public BusStopSpecificTimetableAdapter(BusStopActivity context, Timetable timetable) { + this.context = context; + this.timetable = timetable; + this.a = AnimationUtils.loadAnimation(context, R.anim.updated_stop_view); + } + + public View getView(int position, View convertView, ViewGroup parent) { + Log.i(TAG, "Returning stop " + position + " " + timetable.get(position)); + + BusStopSpecificStopView stopView; + if (convertView == null) { + stopView = new BusStopSpecificStopView(context, timetable.get(position)); + } else { + stopView = (BusStopSpecificStopView) convertView; + stopView.setStop(timetable.get(position)); + } + + if (changed == null || changed[position]) { + a.reset(); + stopView.startAnimation(a); + Log.i(TAG, "Animating it"); + } + + return stopView; + } + + public int getCount() { + return timetable.size(); + } + + public Object getItem(int position) { + return position; + } + + public long getItemId(int position) { + return position; + } + + 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 (!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/Stop.java b/src/net/cbaines/suma/Stop.java index 3221ed5..9db9978 100644 --- a/src/net/cbaines/suma/Stop.java +++ b/src/net/cbaines/suma/Stop.java @@ -47,7 +47,7 @@ public class Stop { BusStop busStop; /** - * The time that the bus is estimated to arrive + * The time that the bus is estimated to arrive, if this is null, the time is still being loaded */ Date arivalTime; diff --git a/src/net/cbaines/suma/StopView.java b/src/net/cbaines/suma/StopView.java deleted file mode 100644 index fa76131..0000000 --- a/src/net/cbaines/suma/StopView.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * 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 java.sql.SQLException; -import java.text.DateFormat; - -import android.content.Intent; -import android.content.res.Resources; -import android.net.Uri; -import android.util.Log; -import android.view.Gravity; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.View.OnLongClickListener; -import android.widget.LinearLayout; -import android.widget.TextView; -import android.widget.Toast; - -import com.j256.ormlite.android.apptools.OpenHelperManager; -import com.j256.ormlite.dao.Dao; - -public class StopView extends LinearLayout implements OnClickListener, OnLongClickListener { - - // private final ImageView icon; - - // private static final String TAG = "StopView"; - - private final TextView name; - private final TextView time; - private String onClickMessage = ""; - private final BusStopActivity context; - - private Stop stop; - - private String onClickHelpMessage; - private String onClickUnidentifiedMessage; - - public StopView(BusStopActivity context, Stop stop) { - super(context); - - this.context = context; - - this.setOrientation(HORIZONTAL); - - name = new TextView(context); - name.setTextSize(22f); - - time = new TextView(context); - time.setTextSize(22f); - time.setGravity(Gravity.RIGHT); - - Resources resources = context.getResources(); - onClickHelpMessage = resources.getString(R.string.stop_view_on_click_toast_help_message); - onClickUnidentifiedMessage = resources.getString(R.string.stop_view_on_click_toast_unidentified_message); - - setStop(stop); - - addView(name, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); - addView(time, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); - } - - public void setStop(Stop stop) { - - // Log.i(TAG, "Time of arival " + stop.arivalTime); - - this.stop = stop; - - name.setText(stop.bus.getName()); - time.setText(stop.getTimeToArival()); - - DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); - - try { - Dao busDao = helper.getBusDao(); - - busDao.refresh(stop.bus); - - 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); - } - } 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); - } - } - } catch (SQLException e) { - e.printStackTrace(); - } - - this.setOnClickListener(this); - this.setOnLongClickListener(this); - } - - public void onClick(View v) { - context.makeToast(onClickMessage, onClickHelpMessage, Toast.LENGTH_SHORT); - } - - public boolean onLongClick(View v) { - DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); - - try { - Dao busDao = helper.getBusDao(); - Dao busRouteDao = helper.getBusRouteDao(); - - busDao.refresh(stop.bus); - busRouteDao.refresh(stop.bus.route); - - Log.i("StopView", "Bus route " + stop.bus.route + " Uni-Link " + stop.bus.route.uniLink + " Bus ID " + stop.bus.id); - - if (stop.bus.id != null && stop.bus.route.uniLink) { - Uri uri = Uri.parse("http://id.southampton.ac.uk/bus/" + stop.bus.id); - - Intent busStopIntent = new Intent(Intent.ACTION_VIEW, uri); - busStopIntent.putExtra("busStopID", stop.busStop.id); - context.startActivity(busStopIntent); - } else { - context.makeToast(onClickUnidentifiedMessage, Toast.LENGTH_SHORT); - } - } catch (SQLException e) { - e.printStackTrace(); - } - return true; - } -} diff --git a/src/net/cbaines/suma/TimetableAdapter.java b/src/net/cbaines/suma/TimetableAdapter.java deleted file mode 100644 index 16b3ac9..0000000 --- a/src/net/cbaines/suma/TimetableAdapter.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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.util.Log; -import android.view.View; -import android.view.ViewGroup; -import android.view.animation.Animation; -import android.view.animation.AnimationUtils; -import android.widget.BaseAdapter; - -public class TimetableAdapter extends BaseAdapter { - - private final BusStopActivity context; - private Timetable timetable; - private final Animation a; - private boolean[] changed; - - private static final String TAG = "TimetableAdapter"; - - public TimetableAdapter(BusStopActivity context, Timetable timetable) { - this.context = context; - this.timetable = timetable; - this.a = AnimationUtils.loadAnimation(context, R.anim.updated_stop_view); - } - - public View getView(int position, View convertView, ViewGroup parent) { - Log.i(TAG, "Returning stop " + position + " " + timetable.get(position)); - - StopView stopView; - if (convertView == null) { - stopView = new StopView(context, timetable.get(position)); - } else { - stopView = (StopView) convertView; - stopView.setStop(timetable.get(position)); - } - - if (changed == null || changed[position]) { - a.reset(); - stopView.startAnimation(a); - Log.i(TAG, "Animating it"); - } - - return stopView; - } - - public int getCount() { - return timetable.size(); - } - - public Object getItem(int position) { - return position; - } - - public long getItemId(int position) { - return position; - } - - 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 (!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(); - } -} -- cgit v1.2.3 From e3be46bdee08ad5b336e143861790b705defc0bc Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Fri, 2 Mar 2012 10:45:03 +0000 Subject: More improvements to the toasts. --- src/net/cbaines/suma/BusSpecificStopView.java | 27 ++++++++++++++++++----- src/net/cbaines/suma/BusStopSpecificStopView.java | 26 +++++++++++++++++----- 2 files changed, 43 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/net/cbaines/suma/BusSpecificStopView.java b/src/net/cbaines/suma/BusSpecificStopView.java index 5ab7cd5..6d7e6af 100644 --- a/src/net/cbaines/suma/BusSpecificStopView.java +++ b/src/net/cbaines/suma/BusSpecificStopView.java @@ -25,6 +25,8 @@ import java.text.DateFormat; import android.app.Activity; import android.content.Intent; import android.content.res.Resources; +import android.net.Uri; +import android.util.Log; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; @@ -144,7 +146,19 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener } public void onClick(View v) { - context.makeToast(onClickMessage, onClickHelpMessage, Toast.LENGTH_SHORT); + DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); + try { + Dao busDao = helper.getBusDao(); + busDao.refresh(stop.bus); + } catch (SQLException e) { + e.printStackTrace(); + } + + if (stop.bus.id != null) { + context.makeToast(onClickMessage, onClickHelpMessage, Toast.LENGTH_SHORT); + } else { + context.makeToast(onClickMessage, Toast.LENGTH_SHORT); + } } public boolean onLongClick(View v) { // TODO @@ -156,10 +170,13 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener busDao.refresh(stop.bus); if (stop.bus.id != null) { - // TODO Change to URI - Intent i = new Intent(context, MapActivity.class); - i.putExtra("poiPoint", stop.busStop.point.toDoubleString()); - ((Activity) context).startActivityForResult(i, 0); + Uri uri = Uri.parse("geo:" + Util.E6IntToDouble(stop.busStop.point.getLatitudeE6()) + "," + + Util.E6IntToDouble(stop.busStop.point.getLongitudeE6()) + "?z=18"); + + Log.i(TAG, "Starting a activity for " + uri); + + Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri); + ((Activity) context).startActivity(mapIntent); } else { context.makeToast(onClickUnidentifiedMessage, Toast.LENGTH_SHORT); } diff --git a/src/net/cbaines/suma/BusStopSpecificStopView.java b/src/net/cbaines/suma/BusStopSpecificStopView.java index c7f9bd8..eade3fe 100644 --- a/src/net/cbaines/suma/BusStopSpecificStopView.java +++ b/src/net/cbaines/suma/BusStopSpecificStopView.java @@ -31,7 +31,6 @@ 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; @@ -42,7 +41,7 @@ public class BusStopSpecificStopView extends LinearLayout implements OnClickList // private final ImageView icon; - // private static final String TAG = "StopView"; + private static final String TAG = "StopView"; private final TextView name; private final TextView time; @@ -71,7 +70,8 @@ public class BusStopSpecificStopView extends LinearLayout implements OnClickList Resources resources = context.getResources(); onClickHelpMessage = resources.getString(R.string.bus_stop_stop_view_on_click_toast_help_message); - onClickUnidentifiedMessage = resources.getString(R.string.bus_stop_stop_view_on_click_toast_unidentified_message); + onClickUnidentifiedMessage = resources + .getString(R.string.bus_stop_stop_view_on_click_toast_unidentified_message); setStop(stop); @@ -121,7 +121,22 @@ public class BusStopSpecificStopView extends LinearLayout implements OnClickList } public void onClick(View v) { - context.makeToast(onClickMessage, onClickHelpMessage, Toast.LENGTH_SHORT); + Log.v(TAG, "onClick"); + DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); + try { + Dao busDao = helper.getBusDao(); + busDao.refresh(stop.bus); + } catch (SQLException e) { + e.printStackTrace(); + } + + if (stop.bus.id != null) { + Log.v(TAG, "stop.bus != null"); + context.makeToast(onClickMessage, onClickHelpMessage, Toast.LENGTH_SHORT); + } else { + Log.v(TAG, "stop.bus == null"); + context.makeToast(onClickMessage, Toast.LENGTH_SHORT); + } } public boolean onLongClick(View v) { @@ -134,7 +149,8 @@ public class BusStopSpecificStopView extends LinearLayout implements OnClickList busDao.refresh(stop.bus); busRouteDao.refresh(stop.bus.route); - Log.i("StopView", "Bus route " + stop.bus.route + " Uni-Link " + stop.bus.route.uniLink + " Bus ID " + stop.bus.id); + Log.i("StopView", "Bus route " + stop.bus.route + " Uni-Link " + stop.bus.route.uniLink + " Bus ID " + + stop.bus.id); if (stop.bus.id != null && stop.bus.route.uniLink) { Uri uri = Uri.parse("http://id.southampton.ac.uk/bus/" + stop.bus.id); -- cgit v1.2.3