diff options
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/cbaines/suma/BuildingNumOverlay.java | 37 | ||||
-rw-r--r-- | src/net/cbaines/suma/Bus.java | 194 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusActivity.java | 104 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusRoute.java | 34 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusSpecificStopView.java | 55 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusStopActivity.java | 21 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusStopOverlay.java | 47 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusStopSpecificStopView.java (renamed from src/net/cbaines/suma/StopView.java) | 57 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusStopSpecificTimetableAdapter.java (renamed from src/net/cbaines/suma/TimetableAdapter.java) | 10 | ||||
-rw-r--r-- | src/net/cbaines/suma/DataManager.java | 148 | ||||
-rw-r--r-- | src/net/cbaines/suma/DatabaseHelper.java | 2 | ||||
-rw-r--r-- | src/net/cbaines/suma/MapActivity.java | 162 | ||||
-rw-r--r-- | src/net/cbaines/suma/Stop.java | 2 | ||||
-rw-r--r-- | src/net/cbaines/suma/ToastHelperActivity.java | 45 |
14 files changed, 488 insertions, 430 deletions
diff --git a/src/net/cbaines/suma/BuildingNumOverlay.java b/src/net/cbaines/suma/BuildingNumOverlay.java index a4cf556..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<Building> 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,14 +215,12 @@ 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 + ")"); + String str = building.name; + if (showIdentifiers) { + str += " (" + building.id + ")"; } - context.activityToast.show(); + context.makeToast(str, context.getResources().getString(R.string.map_activity_toast_help_message), + Toast.LENGTH_SHORT); return true; } @@ -262,24 +266,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/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 5368bd4..ae209f4 100644 --- a/src/net/cbaines/suma/BusActivity.java +++ b/src/net/cbaines/suma/BusActivity.java @@ -20,20 +20,16 @@ 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<DatabaseHelper> implements Preferences { +public class BusActivity extends ToastHelperActivity implements Preferences { final static String TAG = "BusActivity"; private TextView busIDTextView; + private TextView busDestTextView; private TextView busContentMessage; private LinearLayout busActivityContentLayout; - Toast activityToast; - /** * The bus this activity is focused on */ @@ -64,28 +60,22 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> 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<Bus> buses = helper.getBusDao().queryForEq(Bus.ID_FIELD_NAME, busID); + bus = null; if (buses.size() == 0) { Log.e(TAG, "Bus " + busID + " not found!"); @@ -110,6 +100,7 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> 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 +115,55 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> 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(getResources().getString(R.string.bus_activity_destination_label) + bus.destinationString); + busDestTextView.setVisibility(View.VISIBLE); + } else { + Log.i(TAG, "Bus destination string is null"); + busDestTextView.setText(getResources().getString(R.string.bus_activity_no_destination_message)); + busDestTextView.setVisibility(View.VISIBLE); + } - busStops = bus.route.getRouteSection(instance, bus.direction); - Log.i(TAG, "Got " + busStops.size() + " bus stops for this bus"); + 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"); + } - /* - * 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; + 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; + } } - } - 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/BusRoute.java b/src/net/cbaines/suma/BusRoute.java index ff80c66..793cc24 100644 --- a/src/net/cbaines/suma/BusRoute.java +++ b/src/net/cbaines/suma/BusRoute.java @@ -132,7 +132,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 for some + * movements, the destination stop is ambiguous. * * @param context * @param busStop @@ -161,11 +162,12 @@ public class BusRoute { List<RouteStop> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); Collections.sort(routeStopsFound); + // Starting from 1, as the data does :( Set<Integer> stopIndexs = new HashSet<Integer>(); for (RouteStop routeStop : routeStopsFound) { if (routeStop.busStop.id.equals(busStop.id)) { - stopIndexs.add(routeStop.sequence - 1); + stopIndexs.add(routeStop.sequence); } } @@ -174,33 +176,33 @@ 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) { + 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) % 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,7 +383,7 @@ public class BusRoute { "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); } diff --git a/src/net/cbaines/suma/BusSpecificStopView.java b/src/net/cbaines/suma/BusSpecificStopView.java index 06bd267..f0fc273 100644 --- a/src/net/cbaines/suma/BusSpecificStopView.java +++ b/src/net/cbaines/suma/BusSpecificStopView.java @@ -24,6 +24,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; @@ -49,6 +51,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); @@ -63,6 +68,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)); @@ -76,16 +85,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 { @@ -147,13 +146,19 @@ 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); + DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); + try { + Dao<Bus, Integer> 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.activityToast.setText(onClickMessage); - context.activityToast.setDuration(Toast.LENGTH_SHORT); + context.makeToast(onClickMessage, Toast.LENGTH_SHORT); } - context.activityToast.show(); } public boolean onLongClick(View v) { // TODO @@ -165,19 +170,15 @@ 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 { - 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 d1f725e..f432803 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<DatabaseHelper> 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<DatabaseHelper> impleme private HashSet<BusRoute> routes = new HashSet<BusRoute>(); - 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<DatabaseHelper> 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<DatabaseHelper> impleme busStopMessage.setVisibility(View.VISIBLE); } else { progBar.setVisibility(View.GONE); + busStopMessage.setVisibility(View.GONE); timetable = newTimetable; displayTimetable(timetable); } @@ -482,11 +483,11 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme } 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/BusStopOverlay.java b/src/net/cbaines/suma/BusStopOverlay.java index b8f1077..778b306 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<BusStop> 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(); + context.makeToast(str, context.getResources().getString(R.string.map_activity_toast_help_message), + 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/StopView.java b/src/net/cbaines/suma/BusStopSpecificStopView.java index 9a0dcd3..b7a16cb 100644 --- a/src/net/cbaines/suma/StopView.java +++ b/src/net/cbaines/suma/BusStopSpecificStopView.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; @@ -36,20 +37,24 @@ 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 { +public class BusStopSpecificStopView extends LinearLayout implements OnClickListener, OnLongClickListener { // private final ImageView icon; - // private static final String TAG = "StopView"; + private static final String TAG = "StopView"; private final TextView name; private final TextView time; + private String onClickMessage = ""; private final BusStopActivity context; private Stop stop; - public StopView(BusStopActivity context, Stop stop) { + private String onClickHelpMessage; + private String onClickUnidentifiedMessage; + + public BusStopSpecificStopView(BusStopActivity context, Stop stop) { super(context); this.context = context; @@ -63,6 +68,11 @@ public class StopView extends LinearLayout implements OnClickListener, OnLongCli 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)); @@ -111,14 +121,22 @@ 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); + Log.v(TAG, "onClick"); + DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); + try { + Dao<Bus, Integer> busDao = helper.getBusDao(); + busDao.refresh(stop.bus); + } catch (SQLException e) { + e.printStackTrace(); } - context.activityToast.show(); + 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) { @@ -140,27 +158,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(); } diff --git a/src/net/cbaines/suma/TimetableAdapter.java b/src/net/cbaines/suma/BusStopSpecificTimetableAdapter.java index 16b3ac9..511f427 100644 --- a/src/net/cbaines/suma/TimetableAdapter.java +++ b/src/net/cbaines/suma/BusStopSpecificTimetableAdapter.java @@ -26,7 +26,7 @@ import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.BaseAdapter; -public class TimetableAdapter extends BaseAdapter { +public class BusStopSpecificTimetableAdapter extends BaseAdapter { private final BusStopActivity context; private Timetable timetable; @@ -35,7 +35,7 @@ public class TimetableAdapter extends BaseAdapter { private static final String TAG = "TimetableAdapter"; - public TimetableAdapter(BusStopActivity context, Timetable timetable) { + public BusStopSpecificTimetableAdapter(BusStopActivity context, Timetable timetable) { this.context = context; this.timetable = timetable; this.a = AnimationUtils.loadAnimation(context, R.anim.updated_stop_view); @@ -44,11 +44,11 @@ public class TimetableAdapter extends BaseAdapter { public View getView(int position, View convertView, ViewGroup parent) { Log.i(TAG, "Returning stop " + position + " " + timetable.get(position)); - StopView stopView; + BusStopSpecificStopView stopView; if (convertView == null) { - stopView = new StopView(context, timetable.get(position)); + stopView = new BusStopSpecificStopView(context, timetable.get(position)); } else { - stopView = (StopView) convertView; + stopView = (BusStopSpecificStopView) convertView; stopView.setStop(timetable.get(position)); } 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<String> iter = buildingPoints.keySet().iterator(); - * iter.hasNext();) { String key = iter.next(); + * for (Iterator<String> 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<BusStop> busStopIter = busStopDao.iterator(); - * busStopIter.hasNext();) { BusStop stop = busStopIter.next(); // - * Log.i(TAG, "Looking at stop " + stop.id); + * for (Iterator<BusStop> busStopIter = busStopDao.iterator(); busStopIter.hasNext();) { BusStop stop = + * busStopIter.next(); // Log.i(TAG, "Looking at stop " + stop.id); * * - * QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = - * routeStopsDao.queryBuilder(); + * QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder(); * routeStopsQueryBuilder.where().eq(columnName, value) * - * DeleteBuilder<BusStop, String> 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<BusStop, String> 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<RouteStops, Integer> routeStopsQueryBuilder = - * routeStopsDao.queryBuilder(); - * routeStopsQueryBuilder.setCountOf(true); - * routeStopsQueryBuilder.where().eq(RouteStops.STOP_ID_FIELD_NAME, - * stop); + * QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder(); + * routeStopsQueryBuilder.setCountOf(true); routeStopsQueryBuilder.where().eq(RouteStops.STOP_ID_FIELD_NAME, stop); * - * PreparedQuery<RouteStops> routeStopsPreparedQuery = - * routeStopsQueryBuilder.prepare(); List<RouteStops> routeStops = - * routeStopsDao.query(routeStopsPreparedQuery); // long num = - * routeStopsDao.query(routeStopsPreparedQuery).size(); // Log.i(TAG, - * "Number is " + num); + * PreparedQuery<RouteStops> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); List<RouteStops> 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<BusRoute> routes, BusStop busStop) + private static Stop getStop(Context context, JSONObject stopObj, Set<BusRoute> 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<RouteStop> routeStops = routeStopsDao.query(routeStopsPreparedQuery); if (routeStops.size() > 0) { - Log.i(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route " - + route.code); + Log.i(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route " + route.code); } else { - Log.w(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route " - + route.code); + 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<BusRoute> busRoutes = new HashSet<BusRoute>(); - for (Iterator<String> keyIter = routesObject.keys(); keyIter.hasNext();) { + for (@SuppressWarnings("unchecked") + Iterator<String> 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<BusRoute> busRoutes = new HashSet<BusRoute>(); 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 501e00d..9dd927a 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,12 +69,12 @@ import com.j256.ormlite.dao.Dao; * @author Christopher Baines <cbaines8@gmail.com> * */ -public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements MapViewConstants, Runnable, RouteColorConstants, +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 database is built from the csv files in the assets - * folder + * 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; @@ -126,10 +124,11 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements private static final int NON_UNI_LINK_BUS_STOP_OVERLAY_RANK = 4; // -- Site Overlays - static final String[] SITE_NAMES = { "Highfield Campus", "Boldrewood Campus", "Avenue Campus", "Winchester School of Art", - "The University of Southampton Science Park", "National Oceanography Centre Campus", "Boat House", - "Southampton General Hospital", "Royal South Hants Hospital", "Belgrave Industrial Site", "Highfield Hall", - "Glen Eyre Hall", "South Hill Hall", "Chamberlain Hall", "Hartley Grove", "Bencraft Hall", "Connaught Hall", + static final String[] SITE_NAMES = { "Highfield Campus", "Boldrewood Campus", "Avenue Campus", + "Winchester School of Art", "The University of Southampton Science Park", + "National Oceanography Centre Campus", "Boat House", "Southampton General Hospital", + "Royal South Hants Hospital", "Belgrave Industrial Site", "Highfield Hall", "Glen Eyre Hall", + "South Hill Hall", "Chamberlain Hall", "Hartley Grove", "Bencraft Hall", "Connaught Hall", "Montefiore Hall", "Stoneham Hall", "Erasmus Park" }; private static final String SITE_OVERLAYS = "siteOverlays:"; @@ -167,17 +166,12 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements // Uni-Link routes static final String[] UNI_LINK_ROUTES = { "U1", "U1N", "U2", "U6", "U9" }; - static final String[] PREFERENCES_GROUPS = { BUS_STOP_OVERLAYS, BUS_ROUTE_OVERLAYS, BUILDING_OVERLAYS, SITE_OVERLAYS, - OTHER_OVERLAYS }; + static final String[] PREFERENCES_GROUPS = { BUS_STOP_OVERLAYS, BUS_ROUTE_OVERLAYS, BUILDING_OVERLAYS, + SITE_OVERLAYS, OTHER_OVERLAYS }; 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"; @@ -205,8 +199,10 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements pastOverlays = (HashMap<String, Overlay>) getLastNonConfigurationInstance(); /* - * SensorManager mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); This code in the following - * constructor causes problems in some emulators, disable sensors to fix. + * SensorManager mSensorManager = (SensorManager) + * getSystemService(Context.SENSOR_SERVICE); This code in the following + * constructor causes problems in some emulators, disable sensors to + * fix. */ Log.i(TAG, "Starting creating myLocationOverlay"); myLocationOverlay = new MyLocationOverlay(instance, mapView); @@ -297,6 +293,7 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements 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(); @@ -305,6 +302,7 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements sharedPrefs.registerOnSharedPreferenceChangeListener(this); activityPrefs.registerOnSharedPreferenceChangeListener(this); } + Log.i(TAG, "Finished OnResume"); } public void onPause() { @@ -518,7 +516,8 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements if (scaleBarOverlay != null) { Log.v(TAG, "ScaleBarOverlay is already created"); } else { - if (pastOverlays != null && (scaleBarOverlay = (ScaleBarOverlay) pastOverlays.get(SCALE_BAR_OVERLAY)) != null) { + if (pastOverlays != null + && (scaleBarOverlay = (ScaleBarOverlay) pastOverlays.get(SCALE_BAR_OVERLAY)) != null) { Log.i(TAG, "Finished restoring utility overlays " + (System.currentTimeMillis() - startTime)); } else { scaleBarOverlay = new ScaleBarOverlay(instance); @@ -547,7 +546,8 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements private void showRouteOverlay(final BusRoute route) { new Thread(new Runnable() { public void run() { - Log.i(TAG, "Begining showing route " + route.code + " overlay at " + (System.currentTimeMillis() - startTime)); + Log.i(TAG, "Begining showing route " + route.code + " overlay at " + + (System.currentTimeMillis() - startTime)); final SharedPreferences activityPrefs = getPreferences(0); final OverlayRankComparator comparator = new OverlayRankComparator(getPreferences(0)); @@ -572,8 +572,8 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements // TODO Is this a route like U1N or, something else, // this hack works somewhat for now? - PathOverlay routeOverlayU1E = DataManager.getRoutePath(getResources().openRawResource(R.raw.u1e), - colour, mResourceProxy); + PathOverlay routeOverlayU1E = DataManager.getRoutePath( + getResources().openRawResource(R.raw.u1e), colour, mResourceProxy); routeOverlayU1E.getPaint().setAntiAlias(true); routeOverlayU1E.getPaint().setAlpha(145); routeOverlayU1E.getPaint().setStrokeWidth(12); @@ -628,7 +628,8 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements mapView.postInvalidate(); - Log.i(TAG, "Finished showing route " + route.code + " overlay at " + (System.currentTimeMillis() - startTime)); + Log.i(TAG, "Finished showing route " + route.code + " overlay at " + + (System.currentTimeMillis() - startTime)); } }).start(); } @@ -637,7 +638,8 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements new Thread(new Runnable() { public void run() { - Log.i(TAG, "Begining showing site " + site.name + " overlay at " + (System.currentTimeMillis() - startTime)); + Log.i(TAG, "Begining showing site " + site.name + " overlay at " + + (System.currentTimeMillis() - startTime)); final SharedPreferences activityPrefs = getPreferences(0); final OverlayRankComparator comparator = new OverlayRankComparator(getPreferences(0)); @@ -646,7 +648,8 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements if ((siteOverlay = siteOverlays.get(site)) != null) { } else { - if (pastOverlays != null && (siteOverlay = (PathOverlay) pastOverlays.get(SITE_OVERLAYS + site.name)) != null) { + if (pastOverlays != null + && (siteOverlay = (PathOverlay) pastOverlays.get(SITE_OVERLAYS + site.name)) != null) { Log.i(TAG, "Restored " + site.name + " site overlay"); } else { @@ -672,11 +675,13 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements } } - siteOverlay.setEnabled(activityPrefs.getBoolean(SITE_OVERLAYS + site.name, SITE_OVERLAYS_ENABLED_BY_DEFAULT)); + siteOverlay.setEnabled(activityPrefs.getBoolean(SITE_OVERLAYS + site.name, + SITE_OVERLAYS_ENABLED_BY_DEFAULT)); mapView.postInvalidate(); - Log.i(TAG, "Finished showing site " + site.name + " overlay at " + (System.currentTimeMillis() - startTime)); + Log.i(TAG, "Finished showing site " + site.name + " overlay at " + + (System.currentTimeMillis() - startTime)); } }).start(); } @@ -693,8 +698,10 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements } else { if (pastOverlays != null - && (residentialBuildingOverlay = (BuildingNumOverlay) pastOverlays.get(RESIDENTIAL_BUILDING_OVERLAY)) != null) { - nonResidentialBuildingOverlay = (BuildingNumOverlay) pastOverlays.get(NON_RESIDENTIAL_BUILDING_OVERLAY); + && (residentialBuildingOverlay = (BuildingNumOverlay) pastOverlays + .get(RESIDENTIAL_BUILDING_OVERLAY)) != null) { + nonResidentialBuildingOverlay = (BuildingNumOverlay) pastOverlays + .get(NON_RESIDENTIAL_BUILDING_OVERLAY); Log.i(TAG, "Restored building overlays"); } else { @@ -709,7 +716,8 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements buildingDao = getHelper().getBuildingDao(); - final SharedPreferences favouritesPrefs = getSharedPreferences(FAVOURITES_PREFERENCES, MODE_PRIVATE); + final SharedPreferences favouritesPrefs = getSharedPreferences(FAVOURITES_PREFERENCES, + MODE_PRIVATE); for (Building building : buildingDao) { if (building.residential == true) { @@ -747,8 +755,8 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements } } - residentialBuildingOverlay.setEnabled(activityPrefs.getBoolean(BUILDING_OVERLAYS + RESIDENTIAL_BUILDING_OVERLAY, - RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT)); + residentialBuildingOverlay.setEnabled(activityPrefs.getBoolean(BUILDING_OVERLAYS + + RESIDENTIAL_BUILDING_OVERLAY, RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT)); nonResidentialBuildingOverlay.setEnabled(activityPrefs.getBoolean(BUILDING_OVERLAYS + NON_RESIDENTIAL_BUILDING_OVERLAY, NON_RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT)); @@ -768,11 +776,16 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements final OverlayRankComparator comparator = new OverlayRankComparator(getPreferences(0)); if (uniLinkBusStopOverlay != null) { - if (!activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) - && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) - && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) - && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) - && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) { + if (!activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) + && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) + && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) + && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) + && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) { Log.i(TAG, "Uni-Link bus stop overlay not needed"); overlays.remove(UNI_LINK_BUS_STOP_OVERLAY); @@ -783,25 +796,31 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements uniLinkBusStopOverlay = null; } else { - uniLinkBusStopOverlay.setRoutes(0, - activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); - uniLinkBusStopOverlay.setRoutes(1, - activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); - uniLinkBusStopOverlay.setRoutes(2, - activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); - uniLinkBusStopOverlay.setRoutes(3, - activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); - uniLinkBusStopOverlay.setRoutes(4, - activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); + uniLinkBusStopOverlay.setRoutes(0, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); + uniLinkBusStopOverlay.setRoutes(1, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); + uniLinkBusStopOverlay.setRoutes(2, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); + uniLinkBusStopOverlay.setRoutes(3, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); + uniLinkBusStopOverlay.setRoutes(4, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); } } else { - if (activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) - || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) - || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) - || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) - || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) { + if (activityPrefs + .getBoolean(BUS_STOP_OVERLAYS + "U1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) + || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) + || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) + || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) + || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) { if (pastOverlays != null - && (uniLinkBusStopOverlay = (BusStopOverlay) pastOverlays.get(UNI_LINK_BUS_STOP_OVERLAY)) != null) { + && (uniLinkBusStopOverlay = (BusStopOverlay) pastOverlays + .get(UNI_LINK_BUS_STOP_OVERLAY)) != null) { Log.i(TAG, "Restored Uni-Link bus stop overlay"); } else { @@ -819,16 +838,16 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements } } - uniLinkBusStopOverlay.setRoutes(0, - activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); - uniLinkBusStopOverlay.setRoutes(1, - activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); - uniLinkBusStopOverlay.setRoutes(2, - activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); - uniLinkBusStopOverlay.setRoutes(3, - activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); - uniLinkBusStopOverlay.setRoutes(4, - activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); + uniLinkBusStopOverlay.setRoutes(0, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); + uniLinkBusStopOverlay.setRoutes(1, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); + uniLinkBusStopOverlay.setRoutes(2, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); + uniLinkBusStopOverlay.setRoutes(3, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); + uniLinkBusStopOverlay.setRoutes(4, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); overlays.put(UNI_LINK_BUS_STOP_OVERLAY, uniLinkBusStopOverlay); @@ -851,7 +870,8 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements private void showNonUniLinkBusStopOverlay() { new Thread(new Runnable() { public void run() { - Log.i(TAG, "Begining showing non uni link bus stop overlays at " + (System.currentTimeMillis() - startTime)); + Log.i(TAG, "Begining showing non uni link bus stop overlays at " + + (System.currentTimeMillis() - startTime)); // final SharedPreferences activityPrefs = getPreferences(0); final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(instance); @@ -868,12 +888,14 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements } else if (sharedPrefs.getBoolean(NON_UNI_LINK_BUS_STOPS_OVERLAY, NON_UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) { if (pastOverlays != null - && (nonUniLinkBusStopOverlay = (BusStopOverlay) pastOverlays.get(NON_UNI_LINK_BUS_STOPS_OVERLAY)) != null) { + && (nonUniLinkBusStopOverlay = (BusStopOverlay) pastOverlays + .get(NON_UNI_LINK_BUS_STOPS_OVERLAY)) != null) { Log.i(TAG, "Restored non Uni-Link bus stop overlays"); } else { try { List<BusStop> busStops; - Log.v(TAG, "Begin fetching non Uni-Link BusStops at " + (System.currentTimeMillis() - startTime)); + Log.v(TAG, "Begin fetching non Uni-Link BusStops at " + + (System.currentTimeMillis() - startTime)); busStops = getHelper().getBusStopDao().queryForEq(BusStop.UNI_LINK_FIELD_NAME, false); @@ -903,7 +925,8 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements mapView.postInvalidate(); - Log.i(TAG, "Finished showing non Uni-Link bus stop overlays at " + (System.currentTimeMillis() - startTime)); + Log.i(TAG, "Finished showing non Uni-Link bus stop overlays at " + + (System.currentTimeMillis() - startTime)); } }).start(); } @@ -965,8 +988,9 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements }; AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setMessage("GPS is not enabled, do you wish to enable it?").setPositiveButton("Yes", dialogClickListener) - .setNegativeButton("No", dialogClickListener).show(); + builder.setMessage("GPS is not enabled, do you wish to enable it?") + .setPositiveButton("Yes", dialogClickListener).setNegativeButton("No", dialogClickListener) + .show(); } return true; 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/ToastHelperActivity.java b/src/net/cbaines/suma/ToastHelperActivity.java new file mode 100644 index 0000000..a7997e9 --- /dev/null +++ b/src/net/cbaines/suma/ToastHelperActivity.java @@ -0,0 +1,45 @@ +package net.cbaines.suma; + +import android.view.View; +import android.widget.TextView; +import android.widget.Toast; + +import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; + +public class ToastHelperActivity extends OrmLiteBaseActivity<DatabaseHelper> { + + 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 = (View) getLayoutInflater().inflate(R.layout.toast_view, null); + } + 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(); + } + +} |