From 1b2872b6e53791cf5619a016d2b22d015544c2c8 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 6 Mar 2012 15:44:49 +0000 Subject: Better BusActivity. --- gen/net/cbaines/suma/R.java | Bin 14562 -> 14743 bytes res/menu/bus_menu.xml | 9 ++++++ res/menu/bus_stop_menu.xml | 17 +++++++++++ res/menu/stop_menu.xml | 17 ----------- res/values/strings.xml | 3 +- src/net/cbaines/suma/BusActivity.java | 23 ++++++++++---- src/net/cbaines/suma/BusSpecificStopView.java | 33 ++++++++++----------- .../cbaines/suma/BusSpecificTimetableAdapter.java | 4 +-- src/net/cbaines/suma/BusStopActivity.java | 14 ++++----- 9 files changed, 71 insertions(+), 49 deletions(-) create mode 100644 res/menu/bus_menu.xml create mode 100644 res/menu/bus_stop_menu.xml delete mode 100644 res/menu/stop_menu.xml diff --git a/gen/net/cbaines/suma/R.java b/gen/net/cbaines/suma/R.java index 49cba3e..3163564 100644 Binary files a/gen/net/cbaines/suma/R.java and b/gen/net/cbaines/suma/R.java differ diff --git a/res/menu/bus_menu.xml b/res/menu/bus_menu.xml new file mode 100644 index 0000000..5e22663 --- /dev/null +++ b/res/menu/bus_menu.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/res/menu/bus_stop_menu.xml b/res/menu/bus_stop_menu.xml new file mode 100644 index 0000000..c44efa2 --- /dev/null +++ b/res/menu/bus_stop_menu.xml @@ -0,0 +1,17 @@ + + + + + + + + \ No newline at end of file diff --git a/res/menu/stop_menu.xml b/res/menu/stop_menu.xml deleted file mode 100644 index c44efa2..0000000 --- a/res/menu/stop_menu.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index e17ab11..521f04c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -102,6 +102,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.< Previous Next Refresh + Refresh About @@ -139,7 +140,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.< Bus schedules not available for unidentified buses - Hold to view the bus stop + Hold to view the bus stop on the map Arrival prediction not available for timetabled buses diff --git a/src/net/cbaines/suma/BusActivity.java b/src/net/cbaines/suma/BusActivity.java index 3292ce8..f2cf133 100644 --- a/src/net/cbaines/suma/BusActivity.java +++ b/src/net/cbaines/suma/BusActivity.java @@ -16,6 +16,8 @@ import android.os.Handler; import android.preference.PreferenceManager; import android.util.Log; import android.view.Gravity; +import android.view.Menu; +import android.view.MenuInflater; import android.view.View; import android.widget.LinearLayout; import android.widget.ListView; @@ -117,8 +119,8 @@ public class BusActivity extends ToastHelperActivity implements Preferences { if (bus.destinationString != null) { Log.i(TAG, "Bus destination string is " + bus.destinationString); - busDestTextView - .setText(getResources().getString(R.string.bus_activity_destination_label) + bus.destinationString); + busDestTextView.setText(getResources().getString(R.string.bus_activity_destination_label) + + bus.destinationString); busDestTextView.setVisibility(View.VISIBLE); } else { Log.i(TAG, "Bus destination string is null"); @@ -137,12 +139,14 @@ public class BusActivity extends ToastHelperActivity implements Preferences { refreshData = new Runnable() { public void run() { - for (int num = timetableView.getFirstVisiblePosition(); num < timetableView.getLastVisiblePosition(); num++) { + 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 (stop.timeOfFetch == null + || (stop.timeOfFetch.getTime() - System.currentTimeMillis()) > 20000) { if (task != null) { if (task.getStatus() == AsyncTask.Status.FINISHED) { task = null; @@ -166,6 +170,13 @@ public class BusActivity extends ToastHelperActivity implements Preferences { } } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.bus_menu, menu); + return true; + } + public void onResume() { super.onResume(); @@ -296,7 +307,9 @@ public class BusActivity extends ToastHelperActivity implements Preferences { adapter = new BusSpecificTimetableAdapter(this, visibleTimetable); timetableView.setAdapter(adapter); if (busStop != null) { - Log.i(TAG, "Moving to position of " + busStop.description + " which is " + busStops.indexOf(busStop)); + Log.i(TAG, + "Moving to position of " + busStop.description + " which is " + + busStops.indexOf(busStop)); timetableView.setSelection(busStops.indexOf(busStop)); } } diff --git a/src/net/cbaines/suma/BusSpecificStopView.java b/src/net/cbaines/suma/BusSpecificStopView.java index 6d7e6af..fdb6f56 100644 --- a/src/net/cbaines/suma/BusSpecificStopView.java +++ b/src/net/cbaines/suma/BusSpecificStopView.java @@ -28,10 +28,12 @@ import android.content.res.Resources; import android.net.Uri; import android.util.Log; import android.view.Gravity; +import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; import android.widget.LinearLayout; +import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; @@ -46,6 +48,8 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener private final TextView location; private final TextView time; + private final ProgressBar timeProgress; + private String onClickMessage = ""; private final BusActivity context; @@ -68,6 +72,8 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener time.setTextSize(22f); time.setGravity(Gravity.RIGHT); + timeProgress = new ProgressBar(context, null, android.R.attr.progressBarStyleSmall); + 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); @@ -76,7 +82,7 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener addView(location, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); addView(time, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); - + addView(timeProgress, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); } public void setStop(Stop stop) { @@ -92,8 +98,12 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener } if (stop.arivalTime != null) { time.setText(stop.getShortTimeToArival()); + time.setVisibility(View.VISIBLE); + timeProgress.setVisibility(View.GONE); } else { + time.setVisibility(View.GONE); time.setText(""); + timeProgress.setVisibility(View.VISIBLE); } DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); @@ -104,23 +114,12 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener busDao.refresh(stop.bus); if (stop.arivalTime != null) { - - if (stop.bus.id != null) { - if (stop.live) { - onClickMessage = "Bus " + stop.bus.toString() + " at " - + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime); - } else { - onClickMessage = "Timetabled bus " + stop.bus.toString() + " at " - + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime); - } + if (stop.live) { + onClickMessage = stop.busStop.description + " at " + + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime); } else { - if (stop.live) { - onClickMessage = "Unidentified bus (" + stop.bus.getName() + ") at " - + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime); - } else { - onClickMessage = "Timetabled bus (" + stop.bus.getName() + ") at " - + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime); - } + onClickMessage = stop.busStop.description + " at " + + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime) + " (timetabled)"; } } else { if (stop.bus.id != null) { diff --git a/src/net/cbaines/suma/BusSpecificTimetableAdapter.java b/src/net/cbaines/suma/BusSpecificTimetableAdapter.java index 7bcb560..96fe713 100644 --- a/src/net/cbaines/suma/BusSpecificTimetableAdapter.java +++ b/src/net/cbaines/suma/BusSpecificTimetableAdapter.java @@ -60,8 +60,8 @@ public class BusSpecificTimetableAdapter extends BaseAdapter { } if (changed == null || changed[position]) { - a.reset(); - stopView.startAnimation(a); + // a.reset(); + // stopView.startAnimation(a); // Log.i(TAG, "Animating it"); } diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java index 9c49ff7..429f103 100644 --- a/src/net/cbaines/suma/BusStopActivity.java +++ b/src/net/cbaines/suma/BusStopActivity.java @@ -59,8 +59,8 @@ import com.j256.ormlite.dao.Dao; import com.j256.ormlite.stmt.PreparedQuery; import com.j256.ormlite.stmt.QueryBuilder; -public class BusStopActivity extends ToastHelperActivity implements OnCheckedChangeListener, Preferences, OnItemClickListener, - OnLongClickListener { +public class BusStopActivity extends ToastHelperActivity implements OnCheckedChangeListener, Preferences, + OnItemClickListener, OnLongClickListener { final static String TAG = "BusTimeActivity"; @@ -320,10 +320,10 @@ public class BusStopActivity extends ToastHelperActivity implements OnCheckedCha try { final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(instance); - newTimetable = DataManager - .getTimetable(instance, busStop.id, sharedPrefs.getBoolean(MapActivity.UNI_LINK_BUS_TIMES, - MapActivity.UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT), sharedPrefs.getBoolean( - MapActivity.NON_UNI_LINK_BUS_TIMES, MapActivity.NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT)); + newTimetable = DataManager.getTimetable(instance, busStop.id, sharedPrefs.getBoolean( + MapActivity.UNI_LINK_BUS_TIMES, MapActivity.UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT), sharedPrefs + .getBoolean(MapActivity.NON_UNI_LINK_BUS_TIMES, + MapActivity.NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT)); } catch (SQLException e) { errorMessage = "Error message regarding SQL?"; e.printStackTrace(); @@ -363,7 +363,7 @@ public class BusStopActivity extends ToastHelperActivity implements OnCheckedCha @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.stop_menu, menu); + inflater.inflate(R.menu.bus_stop_menu, menu); return true; } -- cgit v1.2.3