diff options
Diffstat (limited to 'src/net/cbaines/suma')
-rw-r--r-- | src/net/cbaines/suma/BusActivity.java | 60 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusSpecificStopView.java | 75 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusStopActivity.java | 1 | ||||
-rw-r--r-- | src/net/cbaines/suma/StopView.java | 74 |
4 files changed, 73 insertions, 137 deletions
diff --git a/src/net/cbaines/suma/BusActivity.java b/src/net/cbaines/suma/BusActivity.java index 2b76176..e7ddc30 100644 --- a/src/net/cbaines/suma/BusActivity.java +++ b/src/net/cbaines/suma/BusActivity.java @@ -24,8 +24,7 @@ import android.widget.Toast; import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; -public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements - Preferences { +public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements Preferences { final static String TAG = "BusActivity"; private TextView U1RouteTextView; @@ -76,8 +75,7 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements final DatabaseHelper helper = getHelper(); try { - List<Bus> buses = helper.getBusDao().queryForEq(Bus.ID_FIELD_NAME, - busID); + List<Bus> buses = helper.getBusDao().queryForEq(Bus.ID_FIELD_NAME, busID); bus = null; if (buses.size() == 0) { Log.e(TAG, "Bus " + busID + " not found!"); @@ -91,8 +89,7 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements busStop = null; if (busStopID != null) { - List<BusStop> busStops = helper.getBusStopDao().queryForEq( - BusStop.ID_FIELD_NAME, busStopID); + List<BusStop> busStops = helper.getBusStopDao().queryForEq(BusStop.ID_FIELD_NAME, busStopID); if (busStops.size() == 0) { Log.e(TAG, "BusStop " + busStopID + " not found!"); } else if (busStops.size() == 1) { @@ -115,8 +112,7 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements timetableView = (ListView) findViewById(R.id.busActivityTimes); if (bus.id != null) { - Log.i(TAG, "Bus id is not null (" + bus.id - + ") setting busIDTextView"); + Log.i(TAG, "Bus id is not null (" + bus.id + ") setting busIDTextView"); busIDTextView.setText(bus.id + " " + bus.getName()); } else { Log.w(TAG, "Bus id is null?"); @@ -165,29 +161,23 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements } /* - * for (int i = 0;; i++) { BusStop nextStop = - * bus.route.moveInRoute(instance, busStops.get(i), bus.direction, 1); + * for (int i = 0;; i++) { BusStop nextStop = bus.route.moveInRoute(instance, busStops.get(i), bus.direction, 1); * - * if (nextStop.equals(busStop) || (bus.destination != null && - * bus.destination.equals(nextStop))) { break; } + * 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; } } + * 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++) { + 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; @@ -212,12 +202,9 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements public void onResume() { super.onResume(); - SharedPreferences sharedPrefs = PreferenceManager - .getDefaultSharedPreferences(this); - if (sharedPrefs.getBoolean(UNI_LINK_BUS_TIMES, - UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT) - || sharedPrefs.getBoolean(NON_UNI_LINK_BUS_TIMES, - NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT)) { + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); + if (sharedPrefs.getBoolean(UNI_LINK_BUS_TIMES, UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT) + || sharedPrefs.getBoolean(NON_UNI_LINK_BUS_TIMES, NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT)) { Log.i(TAG, "Live Times enabled"); timetable = (Timetable) getLastNonConfigurationInstance(); @@ -227,8 +214,7 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements Log.i(TAG, "No Previous timetable"); timetable = new Timetable(); for (int i = 0; i < busStops.size(); i++) { - timetable.add(new Stop(bus, busStops.get(i), null, null, - false)); + timetable.add(new Stop(bus, busStops.get(i), null, null, false)); } Log.v(TAG, "Finished adding placeholder stops"); } else { @@ -261,8 +247,7 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements super.onPause(); } - private class GetTimetableStopTask extends - AsyncTask<BusStop, Integer, Stop> { + private class GetTimetableStopTask extends AsyncTask<BusStop, Integer, Stop> { private String errorMessage; private BusStop busStop; @@ -321,9 +306,6 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements private void displayTimetable(Timetable timetable) { visibleTimetable = (Timetable) timetable.clone(); - // Log.i(TAG, "Displaying timetable, it contains " + - // visibleTimetable.size() + " stops"); - if (timetable.size() == 0) { busContentMessage.setText("No Busses"); busContentMessage.setVisibility(View.VISIBLE); @@ -331,26 +313,20 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements } else { if (visibleTimetable.size() == 0) { busActivityContentLayout.setGravity(Gravity.CENTER); - busContentMessage - .setText("No Busses (With the current enabled routes)"); + busContentMessage.setText("No Busses (With the current enabled routes)"); busContentMessage.setVisibility(View.VISIBLE); timetableView.setVisibility(View.GONE); } else { timetableView.setVisibility(View.VISIBLE); busContentMessage.setVisibility(View.GONE); BusSpecificTimetableAdapter adapter; - if ((adapter = (BusSpecificTimetableAdapter) timetableView - .getAdapter()) != null) { + if ((adapter = (BusSpecificTimetableAdapter) timetableView.getAdapter()) != null) { adapter.updateTimetable(visibleTimetable); } else { - adapter = new BusSpecificTimetableAdapter(this, - visibleTimetable); + 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 bdebcba..4cac19a 100644 --- a/src/net/cbaines/suma/BusSpecificStopView.java +++ b/src/net/cbaines/suma/BusSpecificStopView.java @@ -36,8 +36,7 @@ import android.widget.Toast; import com.j256.ormlite.android.apptools.OpenHelperManager; import com.j256.ormlite.dao.Dao; -public class BusSpecificStopView extends LinearLayout implements - OnClickListener, OnLongClickListener { +public class BusSpecificStopView extends LinearLayout implements OnClickListener, OnLongClickListener { private static final String TAG = "BusSpecificStopView"; @@ -66,10 +65,8 @@ public class BusSpecificStopView extends LinearLayout implements setStop(stop); - addView(location, new LayoutParams(LayoutParams.WRAP_CONTENT, - LayoutParams.WRAP_CONTENT)); - addView(time, new LayoutParams(LayoutParams.FILL_PARENT, - LayoutParams.WRAP_CONTENT)); + addView(location, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); + addView(time, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); } @@ -100,8 +97,7 @@ public class BusSpecificStopView extends LinearLayout implements time.setText(""); } - DatabaseHelper helper = OpenHelperManager.getHelper(context, - DatabaseHelper.class); + DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); try { Dao<Bus, Integer> busDao = helper.getBusDao(); @@ -112,31 +108,21 @@ public class BusSpecificStopView extends LinearLayout implements if (stop.bus.id != null) { if (stop.live) { - onClickMessage = "Bus " - + stop.bus.toString() - + " at " - + DateFormat.getTimeInstance(DateFormat.SHORT) - .format(stop.arivalTime); + + 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); + 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); + 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 = "Timetabled bus (" + stop.bus.getName() + ") at " + + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime); + } } } else { @@ -144,16 +130,15 @@ public class BusSpecificStopView extends LinearLayout implements if (stop.live) { onClickMessage = "Bus " + stop.bus.toString(); } else { - onClickMessage = "Timetabled bus " - + stop.bus.toString(); + + onClickMessage = "Timetabled bus " + stop.bus.toString(); } } else { if (stop.live) { - onClickMessage = "Unidentified bus (" - + stop.bus.getName() + ")"; + onClickMessage = "Unidentified bus (" + stop.bus.getName() + ")"; } else { - onClickMessage = "Timetabled bus (" - + stop.bus.getName() + ")"; + onClickMessage = "Timetabled bus (" + stop.bus.getName() + ")"; + } } } @@ -167,8 +152,9 @@ public class BusSpecificStopView extends LinearLayout implements public void onClick(View v) { if (context.activityToast == null) { - context.activityToast = Toast.makeText(context, onClickMessage, - Toast.LENGTH_SHORT); + + context.activityToast = Toast.makeText(context, onClickMessage, Toast.LENGTH_SHORT); + } else { context.activityToast.setText(onClickMessage); context.activityToast.setDuration(Toast.LENGTH_SHORT); @@ -177,8 +163,8 @@ public class BusSpecificStopView extends LinearLayout implements } public boolean onLongClick(View v) { // TODO - DatabaseHelper helper = OpenHelperManager.getHelper(context, - DatabaseHelper.class); + + DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); try { Dao<Bus, Integer> busDao = helper.getBusDao(); @@ -191,14 +177,12 @@ public class BusSpecificStopView extends LinearLayout implements ((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); + + 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.setText("Arival prediction not avalible for timetabled buses"); + context.activityToast.setDuration(Toast.LENGTH_SHORT); } context.activityToast.show(); @@ -209,5 +193,4 @@ public class BusSpecificStopView extends LinearLayout implements } return false; } - } diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java index bc8e22e..07dd45c 100644 --- a/src/net/cbaines/suma/BusStopActivity.java +++ b/src/net/cbaines/suma/BusStopActivity.java @@ -368,7 +368,6 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme e.printStackTrace(); } } - Log.i(TAG, "stops " + busStops); if (busStops.size() == 1) { diff --git a/src/net/cbaines/suma/StopView.java b/src/net/cbaines/suma/StopView.java index f942137..27c3a4c 100644 --- a/src/net/cbaines/suma/StopView.java +++ b/src/net/cbaines/suma/StopView.java @@ -36,8 +36,7 @@ import android.widget.Toast; import com.j256.ormlite.android.apptools.OpenHelperManager; import com.j256.ormlite.dao.Dao; -public class StopView extends LinearLayout implements OnClickListener, - OnLongClickListener { +public class StopView extends LinearLayout implements OnClickListener, OnLongClickListener { // private final ImageView icon; @@ -66,10 +65,8 @@ public class StopView extends LinearLayout implements OnClickListener, setStop(stop); - addView(name, new LayoutParams(LayoutParams.WRAP_CONTENT, - LayoutParams.WRAP_CONTENT)); - addView(time, new LayoutParams(LayoutParams.FILL_PARENT, - LayoutParams.WRAP_CONTENT)); + 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) { @@ -81,8 +78,7 @@ public class StopView extends LinearLayout implements OnClickListener, name.setText(stop.bus.getName()); time.setText(stop.getTimeToArival()); - DatabaseHelper helper = OpenHelperManager.getHelper(context, - DatabaseHelper.class); + DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); try { Dao<Bus, Integer> busDao = helper.getBusDao(); @@ -91,31 +87,20 @@ public class StopView extends LinearLayout implements OnClickListener, if (stop.bus.id != null) { if (stop.live) { - onClickMessage = "Bus " - + stop.bus.toString() - + " at " - + DateFormat.getTimeInstance(DateFormat.SHORT) - .format(stop.arivalTime); + + 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); + 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); + 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 = "Timetabled bus (" + stop.bus.getName() + ") at " + + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime); } } } catch (SQLException e) { @@ -128,8 +113,8 @@ public class StopView extends LinearLayout implements OnClickListener, public void onClick(View v) { if (context.activityToast == null) { - context.activityToast = Toast.makeText(context, onClickMessage, - Toast.LENGTH_SHORT); + + context.activityToast = Toast.makeText(context, onClickMessage, Toast.LENGTH_SHORT); } else { context.activityToast.setText(onClickMessage); context.activityToast.setDuration(Toast.LENGTH_SHORT); @@ -139,8 +124,8 @@ public class StopView extends LinearLayout implements OnClickListener, } public boolean onLongClick(View v) { - DatabaseHelper helper = OpenHelperManager.getHelper(context, - DatabaseHelper.class); + + DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); try { Dao<Bus, Integer> busDao = helper.getBusDao(); @@ -149,8 +134,7 @@ public class StopView extends LinearLayout implements OnClickListener, 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) { Intent i = new Intent(context, BusActivity.class); @@ -160,27 +144,21 @@ public class StopView extends LinearLayout implements OnClickListener, } 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); + + 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.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); + + 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.setText("Bus schedules not avalible for unidentified buses"); context.activityToast.setDuration(Toast.LENGTH_SHORT); } context.activityToast.show(); |