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. --- gen/net/cbaines/suma/R.java | 8 +++-- res/layout/toast_view.xml | 7 ++++ res/values/strings.xml | 1 + 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 +++++++++++++++ 7 files changed, 65 insertions(+), 65 deletions(-) create mode 100644 res/layout/toast_view.xml create mode 100644 src/net/cbaines/suma/ToastHelperActivity.java diff --git a/gen/net/cbaines/suma/R.java b/gen/net/cbaines/suma/R.java index f7f3034..4633e09 100644 --- a/gen/net/cbaines/suma/R.java +++ b/gen/net/cbaines/suma/R.java @@ -127,9 +127,10 @@ public final class R { public static final int find_activity=0x7f030007; public static final int map_activity=0x7f030008; public static final int poi_dialog=0x7f030009; - public static final int view_child_row=0x7f03000a; - public static final int view_dialog=0x7f03000b; - public static final int view_group_row=0x7f03000c; + public static final int toast_view=0x7f03000a; + public static final int view_child_row=0x7f03000b; + public static final int view_dialog=0x7f03000c; + public static final int view_group_row=0x7f03000d; } public static final class menu { public static final int map_menu=0x7f090000; @@ -201,6 +202,7 @@ public final class R { public static final int findmylocation_help_message=0x7f070014; public static final int legal_message=0x7f070005; public static final int licence_help_message=0x7f070018; + public static final int map_activity_toast_help_message=0x7f070054; /** Help Messages */ public static final int map_help_message=0x7f070011; diff --git a/res/layout/toast_view.xml b/res/layout/toast_view.xml new file mode 100644 index 0000000..fab39b6 --- /dev/null +++ b/res/layout/toast_view.xml @@ -0,0 +1,7 @@ + + diff --git a/res/values/strings.xml b/res/values/strings.xml index f3850a3..3b57955 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -132,5 +132,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.< Donate Make a personal donation to the developer through Bitcoin. Image of the Building + Double tap the map icons for more info \ No newline at end of file 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. --- gen/net/cbaines/suma/R.java | 27 ++++++++++++++------------ res/layout/toast_view.xml | 28 ++++++++++++++++++++++----- res/values/strings.xml | 2 +- src/net/cbaines/suma/BuildingNumOverlay.java | 13 ++++++++++++- src/net/cbaines/suma/BusStopOverlay.java | 4 ++-- src/net/cbaines/suma/ToastHelperActivity.java | 27 ++++++++++++++++++++++---- 6 files changed, 76 insertions(+), 25 deletions(-) diff --git a/gen/net/cbaines/suma/R.java b/gen/net/cbaines/suma/R.java index 4633e09..8a2fd53 100644 --- a/gen/net/cbaines/suma/R.java +++ b/gen/net/cbaines/suma/R.java @@ -78,8 +78,8 @@ public final class R { public static final int busStopTimes=0x7f0a001f; public static final int busTimeContentLayout=0x7f0a001d; public static final int centerLoadBar=0x7f0a0020; - public static final int check1=0x7f0a0032; - public static final int childname=0x7f0a0031; + public static final int check1=0x7f0a0035; + public static final int childname=0x7f0a0034; public static final int donateBitcoinAddress=0x7f0a0029; public static final int donateButton=0x7f0a0003; public static final int donateDialogErrorMessage=0x7f0a0028; @@ -97,15 +97,15 @@ public final class R { public static final int linearLayout1=0x7f0a0015; public static final int linearLayout2=0x7f0a0024; public static final int mapview=0x7f0a002e; - public static final int menu_about=0x7f0a0038; - public static final int menu_favourites=0x7f0a0039; - public static final int menu_find=0x7f0a0034; - public static final int menu_find_my_location=0x7f0a0036; - public static final int menu_next_stop=0x7f0a003c; - public static final int menu_preferences=0x7f0a0035; - public static final int menu_previous_stop=0x7f0a003a; - public static final int menu_refresh_stop=0x7f0a003b; - public static final int menu_view=0x7f0a0037; + public static final int menu_about=0x7f0a003b; + public static final int menu_favourites=0x7f0a003c; + public static final int menu_find=0x7f0a0037; + public static final int menu_find_my_location=0x7f0a0039; + public static final int menu_next_stop=0x7f0a003f; + public static final int menu_preferences=0x7f0a0038; + public static final int menu_previous_stop=0x7f0a003d; + public static final int menu_refresh_stop=0x7f0a003e; + public static final int menu_view=0x7f0a003a; public static final int radio_u1=0x7f0a0016; public static final int radio_u1n=0x7f0a0017; public static final int radio_u2=0x7f0a0018; @@ -114,7 +114,10 @@ public final class R { public static final int searchBar=0x7f0a002a; public static final int textView1=0x7f0a0000; public static final int textView2=0x7f0a0001; - public static final int view_list=0x7f0a0033; + public static final int toastViewLinearLayout=0x7f0a0031; + public static final int toastViewSubMessage=0x7f0a0033; + public static final int toastViewText=0x7f0a0032; + public static final int view_list=0x7f0a0036; } public static final class layout { public static final int about_dialog=0x7f030000; diff --git a/res/layout/toast_view.xml b/res/layout/toast_view.xml index fab39b6..6431e6b 100644 --- a/res/layout/toast_view.xml +++ b/res/layout/toast_view.xml @@ -1,7 +1,25 @@ - + android:gravity="center_horizontal" + android:orientation="vertical" + android:padding="10dp" > + + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 3b57955..34ee0c5 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -132,6 +132,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.< Donate Make a personal donation to the developer through Bitcoin. Image of the Building - Double tap the map icons for more info + Double tap for more info \ No newline at end of file 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 7191f6188d1ce02599430544f0af69d76e74a1ba Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Thu, 1 Mar 2012 10:45:46 +0000 Subject: Updated libs. --- libs/ormlite-android-4.33.jar | Bin 44784 -> 0 bytes libs/ormlite-core-4.33.jar | Bin 256726 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 libs/ormlite-android-4.33.jar delete mode 100644 libs/ormlite-core-4.33.jar diff --git a/libs/ormlite-android-4.33.jar b/libs/ormlite-android-4.33.jar deleted file mode 100644 index 76001fa..0000000 Binary files a/libs/ormlite-android-4.33.jar and /dev/null differ diff --git a/libs/ormlite-core-4.33.jar b/libs/ormlite-core-4.33.jar deleted file mode 100644 index 6d1e059..0000000 Binary files a/libs/ormlite-core-4.33.jar and /dev/null differ -- 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. --- AndroidManifest.xml | 4 +++- libs/ormlite-android-4.35.jar | Bin 0 -> 45744 bytes libs/ormlite-core-4.35.jar | Bin 0 -> 256811 bytes project.properties | 2 +- src/net/cbaines/suma/MapActivity.java | 2 ++ 5 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 libs/ormlite-android-4.35.jar create mode 100644 libs/ormlite-core-4.35.jar diff --git a/AndroidManifest.xml b/AndroidManifest.xml index af78fdb..09fd9e7 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -4,7 +4,9 @@ android:versionCode="8" android:versionName="0.5 (alpha)" > - + diff --git a/libs/ormlite-android-4.35.jar b/libs/ormlite-android-4.35.jar new file mode 100644 index 0000000..e2e0547 Binary files /dev/null and b/libs/ormlite-android-4.35.jar differ diff --git a/libs/ormlite-core-4.35.jar b/libs/ormlite-core-4.35.jar new file mode 100644 index 0000000..1a5dd5c Binary files /dev/null and b/libs/ormlite-core-4.35.jar differ diff --git a/project.properties b/project.properties index 5a70945..f049142 100644 --- a/project.properties +++ b/project.properties @@ -8,4 +8,4 @@ # project structure. # Project target. -target=android-7 +target=android-10 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 --- gen/net/cbaines/suma/R.java | 6 ++--- res/layout/bus_stop_activity.xml | 14 +++++------ src/net/cbaines/suma/BusRoute.java | 42 +++++++++++++++++-------------- src/net/cbaines/suma/BusStopActivity.java | 33 ++++++++++-------------- 4 files changed, 46 insertions(+), 49 deletions(-) diff --git a/gen/net/cbaines/suma/R.java b/gen/net/cbaines/suma/R.java index 8a2fd53..7cbd954 100644 --- a/gen/net/cbaines/suma/R.java +++ b/gen/net/cbaines/suma/R.java @@ -73,11 +73,11 @@ public final class R { public static final int busStopID=0x7f0a001c; public static final int busStopListItems=0x7f0a0023; public static final int busStopLoadBar=0x7f0a0021; - public static final int busStopMessage=0x7f0a001e; + public static final int busStopMessage=0x7f0a0020; public static final int busStopName=0x7f0a0014; - public static final int busStopTimes=0x7f0a001f; + public static final int busStopTimes=0x7f0a001e; public static final int busTimeContentLayout=0x7f0a001d; - public static final int centerLoadBar=0x7f0a0020; + public static final int centerLoadBar=0x7f0a001f; public static final int check1=0x7f0a0035; public static final int childname=0x7f0a0034; public static final int donateBitcoinAddress=0x7f0a0029; diff --git a/res/layout/bus_stop_activity.xml b/res/layout/bus_stop_activity.xml index 3f4dc98..7875852 100644 --- a/res/layout/bus_stop_activity.xml +++ b/res/layout/bus_stop_activity.xml @@ -107,13 +107,6 @@ android:gravity="center" android:orientation="vertical" > - - + + *
  • 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. --- AndroidManifest.xml | 4 ++-- res/values/strings.xml | 2 +- src/net/cbaines/suma/BusRoute.java | 38 ++++++++++++++++++-------------------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 09fd9e7..89ae86d 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="9" + android:versionName="0.6 (alpha)" > About Version - 0.5 (alpha) + 0.6 (alpha) Copyright © 2012, Christopher Baines License 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. --- gen/net/cbaines/suma/R.java | 109 ++++++++------- res/layout/bus_activity.xml | 8 +- res/values/strings.xml | 4 + 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 ++---- 11 files changed, 310 insertions(+), 319 deletions(-) diff --git a/gen/net/cbaines/suma/R.java b/gen/net/cbaines/suma/R.java index 7cbd954..ea2dbeb 100644 --- a/gen/net/cbaines/suma/R.java +++ b/gen/net/cbaines/suma/R.java @@ -60,64 +60,65 @@ public final class R { public static final int buildingActivityLoadBarLayout=0x7f0a0007; public static final int buildingActivityMessage=0x7f0a0009; public static final int buildingActivityName=0x7f0a0004; + public static final int busActivityBusDestination=0x7f0a000c; public static final int busActivityBusID=0x7f0a000b; - public static final int busActivityContentLayout=0x7f0a000c; + public static final int busActivityContentLayout=0x7f0a000d; public static final int busActivityHeaderLayout=0x7f0a000a; - public static final int busActivityMessage=0x7f0a000d; - public static final int busActivityTimes=0x7f0a000e; - public static final int busRouteActivityCode=0x7f0a000f; - public static final int busRouteActivityHeaderLayout=0x7f0a0010; - public static final int busRouteActivityID=0x7f0a0012; - public static final int busRouteActivityLabel=0x7f0a0011; - public static final int busRouteBusStops=0x7f0a0013; - public static final int busStopID=0x7f0a001c; - public static final int busStopListItems=0x7f0a0023; - public static final int busStopLoadBar=0x7f0a0021; - public static final int busStopMessage=0x7f0a0020; - public static final int busStopName=0x7f0a0014; - public static final int busStopTimes=0x7f0a001e; - public static final int busTimeContentLayout=0x7f0a001d; - public static final int centerLoadBar=0x7f0a001f; - public static final int check1=0x7f0a0035; - public static final int childname=0x7f0a0034; - public static final int donateBitcoinAddress=0x7f0a0029; + public static final int busActivityMessage=0x7f0a000e; + public static final int busActivityTimes=0x7f0a000f; + public static final int busRouteActivityCode=0x7f0a0010; + public static final int busRouteActivityHeaderLayout=0x7f0a0011; + public static final int busRouteActivityID=0x7f0a0013; + public static final int busRouteActivityLabel=0x7f0a0012; + public static final int busRouteBusStops=0x7f0a0014; + public static final int busStopID=0x7f0a001d; + public static final int busStopListItems=0x7f0a0024; + public static final int busStopLoadBar=0x7f0a0022; + public static final int busStopMessage=0x7f0a0021; + public static final int busStopName=0x7f0a0015; + public static final int busStopTimes=0x7f0a001f; + public static final int busTimeContentLayout=0x7f0a001e; + public static final int centerLoadBar=0x7f0a0020; + public static final int check1=0x7f0a0036; + public static final int childname=0x7f0a0035; + public static final int donateBitcoinAddress=0x7f0a002a; public static final int donateButton=0x7f0a0003; - public static final int donateDialogErrorMessage=0x7f0a0028; - public static final int donateDialogMessage=0x7f0a0025; - public static final int donateDialogMessageLayout=0x7f0a0027; - public static final int donateDialogProgress=0x7f0a0026; - public static final int favouriteCheckBox=0x7f0a001b; - public static final int favouriteDialogMessage=0x7f0a002f; - public static final int favouriteListItems=0x7f0a0030; - public static final int findContentLayout=0x7f0a002b; - public static final int findListItems=0x7f0a002d; - public static final int findLoadBar=0x7f0a002c; + public static final int donateDialogErrorMessage=0x7f0a0029; + public static final int donateDialogMessage=0x7f0a0026; + public static final int donateDialogMessageLayout=0x7f0a0028; + public static final int donateDialogProgress=0x7f0a0027; + public static final int favouriteCheckBox=0x7f0a001c; + public static final int favouriteDialogMessage=0x7f0a0030; + public static final int favouriteListItems=0x7f0a0031; + public static final int findContentLayout=0x7f0a002c; + public static final int findListItems=0x7f0a002e; + public static final int findLoadBar=0x7f0a002d; public static final int helpExpandableListView=0x7f0a0002; - public static final int layout_root=0x7f0a0022; - public static final int linearLayout1=0x7f0a0015; - public static final int linearLayout2=0x7f0a0024; - public static final int mapview=0x7f0a002e; - public static final int menu_about=0x7f0a003b; - public static final int menu_favourites=0x7f0a003c; - public static final int menu_find=0x7f0a0037; - public static final int menu_find_my_location=0x7f0a0039; - public static final int menu_next_stop=0x7f0a003f; - public static final int menu_preferences=0x7f0a0038; - public static final int menu_previous_stop=0x7f0a003d; - public static final int menu_refresh_stop=0x7f0a003e; - public static final int menu_view=0x7f0a003a; - public static final int radio_u1=0x7f0a0016; - public static final int radio_u1n=0x7f0a0017; - public static final int radio_u2=0x7f0a0018; - public static final int radio_u6=0x7f0a0019; - public static final int radio_u9=0x7f0a001a; - public static final int searchBar=0x7f0a002a; + public static final int layout_root=0x7f0a0023; + public static final int linearLayout1=0x7f0a0016; + public static final int linearLayout2=0x7f0a0025; + public static final int mapview=0x7f0a002f; + public static final int menu_about=0x7f0a003c; + public static final int menu_favourites=0x7f0a003d; + public static final int menu_find=0x7f0a0038; + public static final int menu_find_my_location=0x7f0a003a; + public static final int menu_next_stop=0x7f0a0040; + public static final int menu_preferences=0x7f0a0039; + public static final int menu_previous_stop=0x7f0a003e; + public static final int menu_refresh_stop=0x7f0a003f; + public static final int menu_view=0x7f0a003b; + public static final int radio_u1=0x7f0a0017; + public static final int radio_u1n=0x7f0a0018; + public static final int radio_u2=0x7f0a0019; + public static final int radio_u6=0x7f0a001a; + public static final int radio_u9=0x7f0a001b; + public static final int searchBar=0x7f0a002b; public static final int textView1=0x7f0a0000; public static final int textView2=0x7f0a0001; - public static final int toastViewLinearLayout=0x7f0a0031; - public static final int toastViewSubMessage=0x7f0a0033; - public static final int toastViewText=0x7f0a0032; - public static final int view_list=0x7f0a0036; + public static final int toastViewLinearLayout=0x7f0a0032; + public static final int toastViewSubMessage=0x7f0a0034; + public static final int toastViewText=0x7f0a0033; + public static final int view_list=0x7f0a0037; } public static final class layout { public static final int about_dialog=0x7f030000; @@ -242,6 +243,10 @@ public final class R { public static final int preferences_uni_link_live_bus_times=0x7f070027; public static final int preferences_uni_link_live_bus_times_disabled=0x7f070029; public static final int preferences_uni_link_live_bus_times_enabled=0x7f070028; + /** Stop View Strings + */ + public static final int stop_view_on_click_toast_help_message=0x7f070055; + public static final int stop_view_on_click_toast_unidentified_message=0x7f070056; public static final int view_help_message=0x7f070015; } public static final class xml { diff --git a/res/layout/bus_activity.xml b/res/layout/bus_activity.xml index f8bbe59..d8b26f6 100644 --- a/res/layout/bus_activity.xml +++ b/res/layout/bus_activity.xml @@ -14,11 +14,17 @@ + + Image of the Building Double tap for more info + + Hold to view the bus schedule + Bus schedules not available for unidentified buses + \ No newline at end of file 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. --- gen/net/cbaines/suma/R.java | 16 ++- res/layout/toast_view.xml | 2 +- res/values/strings.xml | 14 +- 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 ------------- 11 files changed, 288 insertions(+), 278 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 diff --git a/gen/net/cbaines/suma/R.java b/gen/net/cbaines/suma/R.java index ea2dbeb..49cba3e 100644 --- a/gen/net/cbaines/suma/R.java +++ b/gen/net/cbaines/suma/R.java @@ -194,6 +194,18 @@ public final class R { public static final int buildingImageDescription=0x7f070053; public static final int building_non_residential=0x7f070007; public static final int building_residential=0x7f070006; + /** Bus Activity + */ + public static final int bus_activity_destination_label=0x7f070059; + public static final int bus_activity_no_destination_message=0x7f07005a; + /** Bus Stop Specific Stop View Strings + */ + public static final int bus_stop_stop_view_on_click_toast_help_message=0x7f070055; + public static final int bus_stop_stop_view_on_click_toast_unidentified_message=0x7f070056; + /** Bus Specific Stop View Strings + */ + public static final int bus_stop_view_on_click_toast_help_message=0x7f070057; + public static final int bus_stop_view_on_click_toast_unidentified_message=0x7f070058; public static final int bustimes_favourite_checkbox_label=0x7f070032; public static final int credits_help_message=0x7f070019; public static final int donate_button=0x7f07001a; @@ -243,10 +255,6 @@ public final class R { public static final int preferences_uni_link_live_bus_times=0x7f070027; public static final int preferences_uni_link_live_bus_times_disabled=0x7f070029; public static final int preferences_uni_link_live_bus_times_enabled=0x7f070028; - /** Stop View Strings - */ - public static final int stop_view_on_click_toast_help_message=0x7f070055; - public static final int stop_view_on_click_toast_unidentified_message=0x7f070056; public static final int view_help_message=0x7f070015; } public static final class xml { diff --git a/res/layout/toast_view.xml b/res/layout/toast_view.xml index 6431e6b..51d7561 100644 --- a/res/layout/toast_view.xml +++ b/res/layout/toast_view.xml @@ -3,7 +3,7 @@ android:id="@+id/toastViewLinearLayout" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:background="#000000" + android:background="#F01D1D1D" android:gravity="center_horizontal" android:orientation="vertical" android:padding="10dp" > diff --git a/res/values/strings.xml b/res/values/strings.xml index da4a2cc..05ed277 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -134,8 +134,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.< Image of the Building Double tap for more info - - Hold to view the bus schedule - Bus schedules not available for unidentified buses + + Hold to view the bus schedule + Bus schedules not available for unidentified buses + + + Hold to view the bus stop + Arrival prediction not available for timetabled buses + + + Destination:\u0020 + No given destination \ No newline at end of file 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 63d909ab022fb01a1364feffee6bd71d1c48c077 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Fri, 2 Mar 2012 10:14:02 +0000 Subject: Updated database. --- assets/data.db | Bin 490496 -> 490496 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/assets/data.db b/assets/data.db index a423ad8..856725d 100644 Binary files a/assets/data.db and b/assets/data.db differ -- 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. --- res/layout/bus_stop_activity.xml | 28 +++++++++++++---------- src/net/cbaines/suma/BusSpecificStopView.java | 27 ++++++++++++++++++---- src/net/cbaines/suma/BusStopSpecificStopView.java | 26 +++++++++++++++++---- 3 files changed, 59 insertions(+), 22 deletions(-) diff --git a/res/layout/bus_stop_activity.xml b/res/layout/bus_stop_activity.xml index 7875852..66da2f6 100644 --- a/res/layout/bus_stop_activity.xml +++ b/res/layout/bus_stop_activity.xml @@ -21,11 +21,12 @@ android:id="@+id/radio_u1" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginRight="2dp" android:background="@drawable/u1_radio_button" android:button="@drawable/empty" android:checked="true" - android:paddingLeft="5dp" - android:paddingRight="5dp" + android:paddingLeft="3dp" + android:paddingRight="3dp" android:text="@string/U1" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#FFFFFF" /> @@ -34,11 +35,12 @@ android:id="@+id/radio_u1n" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginRight="2dp" android:background="@drawable/u1n_radio_button" android:button="@drawable/empty" android:checked="true" - android:paddingLeft="5dp" - android:paddingRight="5dp" + android:paddingLeft="3dp" + android:paddingRight="3dp" android:text="@string/U1N" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#FFFFFF" /> @@ -47,11 +49,12 @@ android:id="@+id/radio_u2" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginRight="2dp" android:background="@drawable/u2_radio_button" android:button="@drawable/empty" android:checked="true" - android:paddingLeft="5dp" - android:paddingRight="5dp" + android:paddingLeft="3dp" + android:paddingRight="3dp" android:text="@string/U2" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#FFFFFF" /> @@ -60,11 +63,12 @@ android:id="@+id/radio_u6" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginRight="2dp" android:background="@drawable/u6_radio_button" android:button="@drawable/empty" android:checked="true" - android:paddingLeft="5dp" - android:paddingRight="5dp" + android:paddingLeft="3dp" + android:paddingRight="3dp" android:text="@string/U6" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#FFFFFF" /> @@ -73,11 +77,12 @@ android:id="@+id/radio_u9" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginRight="2dp" android:background="@drawable/u9_radio_button" android:button="@drawable/empty" android:checked="true" - android:paddingLeft="5dp" - android:paddingRight="5dp" + android:paddingLeft="3dp" + android:paddingRight="3dp" android:text="@string/U9" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#FFFFFF" /> @@ -86,6 +91,7 @@ android:id="@+id/favouriteCheckBox" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginRight="2dp" android:text="@string/bustimes_favourite_checkbox_label" android:textAppearance="?android:attr/textAppearanceMedium" /> @@ -93,8 +99,6 @@ android:id="@+id/busStopID" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:paddingLeft="5dp" - android:paddingRight="5dp" android:textAppearance="?android:attr/textAppearanceSmall" android:visibility="gone" /> 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