diff options
author | Christopher Baines <cbaines8@gmail.com> | 2012-01-24 23:03:08 +0000 |
---|---|---|
committer | Christopher Baines <cbaines8@gmail.com> | 2012-01-24 23:03:08 +0000 |
commit | efb193d6fbea2423d03eebf30e2359a6612134c1 (patch) | |
tree | 4dc77e89cae8c8154b6646583035492675eb21d4 /src | |
parent | f13680dc5ca55401484ea23fc9493a938cb8ae73 (diff) | |
download | southamptonuniversitymap-efb193d6fbea2423d03eebf30e2359a6612134c1.tar southamptonuniversitymap-efb193d6fbea2423d03eebf30e2359a6612134c1.tar.gz |
Many changes, began working on implementing filtering and route navigation within BusTimeActivity.
Diffstat (limited to 'src')
22 files changed, 193 insertions, 59 deletions
diff --git a/src/net/cbaines/suma/Building.java b/src/net/cbaines/suma/Building.java index df8c303..8747a78 100644 --- a/src/net/cbaines/suma/Building.java +++ b/src/net/cbaines/suma/Building.java @@ -34,7 +34,7 @@ public class Building extends POI { @DatabaseField(canBeNull = false) public String name; @DatabaseField(canBeNull = false) - boolean residential; + public boolean residential; @DatabaseField(dataType = DataType.SERIALIZABLE, canBeNull = true) Polygon outline; @@ -46,7 +46,7 @@ public class Building extends POI { this.type = POI.BUILDING; } - Building(String id, GeoPoint point, boolean residential, String name) { + public Building(String id, GeoPoint point, boolean residential, String name) { this(id, point, residential, name, null); } diff --git a/src/net/cbaines/suma/BuildingNumOverlay.java b/src/net/cbaines/suma/BuildingNumOverlay.java index 080cdc6..4bd5f3a 100644 --- a/src/net/cbaines/suma/BuildingNumOverlay.java +++ b/src/net/cbaines/suma/BuildingNumOverlay.java @@ -25,6 +25,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; + import org.osmdroid.views.MapView; import org.osmdroid.views.MapView.Projection; import org.osmdroid.views.overlay.Overlay; diff --git a/src/net/cbaines/suma/Bus.java b/src/net/cbaines/suma/Bus.java index ff71df4..426ee3b 100644 --- a/src/net/cbaines/suma/Bus.java +++ b/src/net/cbaines/suma/Bus.java @@ -26,7 +26,7 @@ import com.j256.ormlite.table.DatabaseTable; public class Bus { @DatabaseField(id = true) - int id; + public int id; @DatabaseField(canBeNull = true, foreign = true) Stop lastKnownStop; @@ -46,7 +46,7 @@ public class Bus { this.lastKnownStop = lastKnownStop; } - Bus(int id, BusRoute lastKnownRoute) { + public Bus(int id, BusRoute lastKnownRoute) { this(id, lastKnownRoute, null); } diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java index 016f3bd..43a5375 100644 --- a/src/net/cbaines/suma/BusRoute.java +++ b/src/net/cbaines/suma/BusRoute.java @@ -48,10 +48,10 @@ public class BusRoute { private static final String TAG = "BusRoute"; @DatabaseField(id = true) - int id; + public int id; @DatabaseField - String code; + public String code; @DatabaseField String label; @@ -59,7 +59,7 @@ public class BusRoute { BusRoute() { } - BusRoute(Integer id, String code, String label) { + public BusRoute(Integer id, String code, String label) { this.id = id.intValue(); this.code = code; this.label = label; @@ -183,4 +183,26 @@ public class BusRoute { } } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + id; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + BusRoute other = (BusRoute) obj; + if (id != other.id) + return false; + return true; + } + } diff --git a/src/net/cbaines/suma/BusStop.java b/src/net/cbaines/suma/BusStop.java index 8e13f27..21f2dd9 100644 --- a/src/net/cbaines/suma/BusStop.java +++ b/src/net/cbaines/suma/BusStop.java @@ -37,9 +37,9 @@ public class BusStop extends POI { // Used to speed up accessing the relevent uni link routes for a bus stop, if == 0, this is not a uni link stop @DatabaseField(canBeNull = false) - byte routes; + public byte routes; - BusStop(String location, String description, String bay, GeoPoint point) { + public BusStop(String location, String description, String bay, GeoPoint point) { this.id = location; this.description = description; this.bay = bay; diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java index 1495258..7fc78ce 100644 --- a/src/net/cbaines/suma/BusStopActivity.java +++ b/src/net/cbaines/suma/BusStopActivity.java @@ -20,6 +20,7 @@ package net.cbaines.suma; import java.sql.SQLException; +import java.util.Iterator; import android.content.Context; import android.content.SharedPreferences; @@ -29,6 +30,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.CheckBox; import android.widget.CompoundButton; @@ -73,6 +76,12 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme private Handler mHandler; private Runnable refreshData; + private CheckBox U1RouteRadioButton; + private CheckBox U1NRouteRadioButton; + private CheckBox U2RouteRadioButton; + private CheckBox U6RouteRadioButton; + private CheckBox U9RouteRadioButton; + public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.bustimes); @@ -84,11 +93,17 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme busStopID = getIntent().getExtras().getString("busStopID"); busStopName = getIntent().getExtras().getString("busStopName"); - TextView U1RouteTextView = (TextView) findViewById(R.id.busStopU1); - TextView U1NRouteTextView = (TextView) findViewById(R.id.busStopU1N); - TextView U2RouteTextView = (TextView) findViewById(R.id.busStopU2); - TextView U6RouteTextView = (TextView) findViewById(R.id.busStopU6); - TextView U9RouteTextView = (TextView) findViewById(R.id.busStopU9); + U1RouteRadioButton = (CheckBox) findViewById(R.id.radio_u1); + U1NRouteRadioButton = (CheckBox) findViewById(R.id.radio_u1n); + U2RouteRadioButton = (CheckBox) findViewById(R.id.radio_u2); + U6RouteRadioButton = (CheckBox) findViewById(R.id.radio_u6); + U9RouteRadioButton = (CheckBox) findViewById(R.id.radio_u9); + + U1RouteRadioButton.setOnCheckedChangeListener(this); + U1NRouteRadioButton.setOnCheckedChangeListener(this); + U2RouteRadioButton.setOnCheckedChangeListener(this); + U6RouteRadioButton.setOnCheckedChangeListener(this); + U9RouteRadioButton.setOnCheckedChangeListener(this); try { Dao<BusRoute, Integer> busRouteDao = helper.getBusRouteDao(); @@ -105,33 +120,33 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme if (route.code.equals("U1")) { if (count != 0) { - U1RouteTextView.setVisibility(View.VISIBLE); + U1RouteRadioButton.setVisibility(View.VISIBLE); } else { - U1RouteTextView.setVisibility(View.GONE); + U1RouteRadioButton.setVisibility(View.GONE); } } else if (route.code.equals("U1N")) { if (count != 0) { - U1NRouteTextView.setVisibility(View.VISIBLE); + U1NRouteRadioButton.setVisibility(View.VISIBLE); } else { - U1NRouteTextView.setVisibility(View.GONE); + U1NRouteRadioButton.setVisibility(View.GONE); } } else if (route.code.equals("U2")) { if (count != 0) { - U2RouteTextView.setVisibility(View.VISIBLE); + U2RouteRadioButton.setVisibility(View.VISIBLE); } else { - U2RouteTextView.setVisibility(View.GONE); + U2RouteRadioButton.setVisibility(View.GONE); } } else if (route.code.equals("U6")) { if (count != 0) { - U6RouteTextView.setVisibility(View.VISIBLE); + U6RouteRadioButton.setVisibility(View.VISIBLE); } else { - U6RouteTextView.setVisibility(View.GONE); + U6RouteRadioButton.setVisibility(View.GONE); } } else if (route.code.equals("U9")) { if (count != 0) { - U9RouteTextView.setVisibility(View.VISIBLE); + U9RouteRadioButton.setVisibility(View.VISIBLE); } else { - U9RouteTextView.setVisibility(View.GONE); + U9RouteRadioButton.setVisibility(View.GONE); } } else { Log.e(TAG, "Error unknown route " + route.code); @@ -221,13 +236,21 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme super.finish(); } - public void onCheckedChanged(CompoundButton arg0, boolean arg1) { - busStop.favourite = arg1; - try { - busStopDao.update(busStop); - dataChanged = true; - } catch (SQLException e) { - e.printStackTrace(); + public void onCheckedChanged(CompoundButton button, boolean checked) { + if (button.equals(busFavourite)) { + busStop.favourite = checked; + try { + busStopDao.update(busStop); + dataChanged = true; + } catch (SQLException e) { + e.printStackTrace(); + } + } else { + + Log.i(TAG, "Route radio button made " + checked); + + displayTimetable(timetable); + } } @@ -262,25 +285,70 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme } } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.stop_menu, menu); + return true; + } + private void displayTimetable(Timetable timetable) { - Log.i(TAG, "It contains " + timetable.size() + " stops"); + Timetable timetableToDisplay = (Timetable) timetable.clone(); + + Log.i(TAG, "It contains " + timetableToDisplay.size() + " stops"); if (timetable.size() == 0) { progBar.setVisibility(View.GONE); busStopMessage.setText("No Busses"); busStopMessage.setVisibility(View.VISIBLE); + busTimeContentLayout.setGravity(Gravity.CENTER); } else { - progBar.setVisibility(View.GONE); - busStopMessage.setVisibility(View.GONE); - TimetableAdapter adapter; - if ((adapter = (TimetableAdapter) busTimeList.getAdapter()) != null) { - adapter.updateTimetable(timetable); + + for (Iterator<Stop> stopIter = timetableToDisplay.iterator(); stopIter.hasNext();) { + Stop stop = stopIter.next(); + Log.i(TAG, "Begin filtering, looking at " + stop + " with route " + stop.route.code); + if (stop.route.code.equals("U1")) { + if (!U1RouteRadioButton.isChecked()) { + stopIter.remove(); + } + } else if (stop.route.code.equals("U1N")) { + if (!U1NRouteRadioButton.isChecked()) { + stopIter.remove(); + } + } else if (stop.route.code.equals("U2")) { + if (!U2RouteRadioButton.isChecked()) { + stopIter.remove(); + } + } else if (stop.route.code.equals("U6")) { + if (!U6RouteRadioButton.isChecked()) { + stopIter.remove(); + } + } else if (stop.route.code.equals("U9")) { + if (!U9RouteRadioButton.isChecked()) { + stopIter.remove(); + } + } + } + + if (timetableToDisplay.size() == 0) { + busTimeContentLayout.setGravity(Gravity.CENTER); + progBar.setVisibility(View.GONE); + busStopMessage.setText("No Busses (With the current enabled routes)"); + busStopMessage.setVisibility(View.VISIBLE); + busTimeList.setVisibility(View.GONE); } else { - adapter = new TimetableAdapter(this, timetable); - busTimeList.setAdapter(adapter); + busTimeList.setVisibility(View.VISIBLE); + progBar.setVisibility(View.GONE); + busStopMessage.setVisibility(View.GONE); + TimetableAdapter adapter; + if ((adapter = (TimetableAdapter) busTimeList.getAdapter()) != null) { + adapter.updateTimetable(timetableToDisplay); + } else { + adapter = new TimetableAdapter(this, timetableToDisplay); + busTimeList.setAdapter(adapter); + } + busTimeContentLayout.setGravity(Gravity.TOP); } - busTimeContentLayout.setGravity(Gravity.TOP); } } - } diff --git a/src/net/cbaines/suma/BusStopOverlay.java b/src/net/cbaines/suma/BusStopOverlay.java index 83b10c1..e77e862 100644 --- a/src/net/cbaines/suma/BusStopOverlay.java +++ b/src/net/cbaines/suma/BusStopOverlay.java @@ -23,6 +23,7 @@ import java.sql.SQLException; import java.util.Collections; import java.util.List; + import org.osmdroid.views.MapView; import org.osmdroid.views.MapView.Projection; import org.osmdroid.views.overlay.Overlay; diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java index e910c8e..d54b25b 100644 --- a/src/net/cbaines/suma/DataManager.java +++ b/src/net/cbaines/suma/DataManager.java @@ -29,6 +29,7 @@ import java.util.Date; import java.util.GregorianCalendar; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; @@ -517,6 +518,7 @@ public class DataManager { Date now = new Date(System.currentTimeMillis()); stop = new Stop(stopObj.getString("name"), busStop, destStop, bus, calender.getTime(), now); + stop.route = route; /* * if (bus.lastKnownStop != null) { stopDao.delete(bus.lastKnownStop); // TODO Crude, might delete useful data @@ -540,6 +542,7 @@ public class DataManager { } else { stop = new Stop(stopObj.getString("name"), busStop, destStop, calender.getTime(), new Date(System.currentTimeMillis())); + stop.route = route; } diff --git a/src/net/cbaines/suma/DatabaseConfigUtil.java b/src/net/cbaines/suma/DatabaseConfigUtil.java new file mode 100644 index 0000000..831e8cb --- /dev/null +++ b/src/net/cbaines/suma/DatabaseConfigUtil.java @@ -0,0 +1,28 @@ +/* + * 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 com.j256.ormlite.android.apptools.OrmLiteConfigUtil; + +public class DatabaseConfigUtil extends OrmLiteConfigUtil { + public static void main(String[] args) throws Exception { + writeConfigFile("ormlite_config.txt"); + } +} diff --git a/src/net/cbaines/suma/FavouriteDialog.java b/src/net/cbaines/suma/FavouriteDialog.java index e95ead2..ca39574 100644 --- a/src/net/cbaines/suma/FavouriteDialog.java +++ b/src/net/cbaines/suma/FavouriteDialog.java @@ -22,6 +22,7 @@ package net.cbaines.suma; import java.sql.SQLException; import java.util.ArrayList; + import android.app.Dialog; import android.content.Context; import android.util.Log; diff --git a/src/net/cbaines/suma/FindActivity.java b/src/net/cbaines/suma/FindActivity.java index 68db3c5..f0a16ac 100644 --- a/src/net/cbaines/suma/FindActivity.java +++ b/src/net/cbaines/suma/FindActivity.java @@ -25,6 +25,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; + import org.osmdroid.util.GeoPoint; import android.content.Context; diff --git a/src/net/cbaines/suma/POI.java b/src/net/cbaines/suma/POI.java index 37d6aaf..dba7924 100644 --- a/src/net/cbaines/suma/POI.java +++ b/src/net/cbaines/suma/POI.java @@ -51,7 +51,7 @@ public abstract class POI { @DatabaseField(canBeNull = false) public boolean favourite; // This field is not assessed by equals - int distTo = -1; // Used by the comparator to store distances, then later by the gui to display them. + public int distTo = -1; // Used by the comparator to store distances, then later by the gui to display them. public String type; diff --git a/src/net/cbaines/suma/POIArrayAdapter.java b/src/net/cbaines/suma/POIArrayAdapter.java index 83ee517..e35acf4 100644 --- a/src/net/cbaines/suma/POIArrayAdapter.java +++ b/src/net/cbaines/suma/POIArrayAdapter.java @@ -21,6 +21,7 @@ package net.cbaines.suma; import java.util.List; + import android.content.Context; import android.view.View; import android.view.ViewGroup; diff --git a/src/net/cbaines/suma/Polygon.java b/src/net/cbaines/suma/Polygon.java index 5020a33..b10fbc4 100644 --- a/src/net/cbaines/suma/Polygon.java +++ b/src/net/cbaines/suma/Polygon.java @@ -29,13 +29,13 @@ public class Polygon implements Serializable { */ private static final long serialVersionUID = 3029139596630651715L; - final GeoPoint[] points; + public final GeoPoint[] points; Polygon() { points = null; } - Polygon(GeoPoint[] points) { + public Polygon(GeoPoint[] points) { this.points = points; } diff --git a/src/net/cbaines/suma/RouteOverlayItem.java b/src/net/cbaines/suma/RouteOverlayItem.java index 77df6dc..98c4d28 100644 --- a/src/net/cbaines/suma/RouteOverlayItem.java +++ b/src/net/cbaines/suma/RouteOverlayItem.java @@ -21,6 +21,7 @@ package net.cbaines.suma; import java.util.ArrayList; + import org.osmdroid.util.GeoPoint; import org.osmdroid.views.overlay.OverlayItem; diff --git a/src/net/cbaines/suma/Site.java b/src/net/cbaines/suma/Site.java index 0447d8a..b13b9ae 100644 --- a/src/net/cbaines/suma/Site.java +++ b/src/net/cbaines/suma/Site.java @@ -27,17 +27,17 @@ import com.j256.ormlite.table.DatabaseTable; @DatabaseTable(tableName = "sites") public class Site extends POI { - + public static final String NAME_FIELD_NAME = "name"; public static final String OUTLINE_FIELD_NAME = "outline"; @DatabaseField(canBeNull = false) - String name; + public String name; @DatabaseField(dataType = DataType.SERIALIZABLE, canBeNull = true) - Polygon outline; + public Polygon outline; - Site(String id, String name, GeoPoint point, Polygon outline) { + public Site(String id, String name, GeoPoint point, Polygon outline) { super(id, point); this.name = name; this.outline = outline; diff --git a/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java b/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java index f183542..0461fdf 100644 --- a/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java +++ b/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java @@ -27,9 +27,9 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; + import org.osmdroid.DefaultResourceProxyImpl; import org.osmdroid.ResourceProxy; -import org.osmdroid.tileprovider.MapTileProviderArray; import org.osmdroid.tileprovider.tilesource.TileSourceFactory; import org.osmdroid.util.GeoPoint; import org.osmdroid.views.MapController; @@ -714,7 +714,6 @@ public class SouthamptonUniversityMapActivity extends OrmLiteBaseActivity<Databa MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.map_menu, menu); return true; - } @Override diff --git a/src/net/cbaines/suma/Stop.java b/src/net/cbaines/suma/Stop.java index 2fa8d33..04eb118 100644 --- a/src/net/cbaines/suma/Stop.java +++ b/src/net/cbaines/suma/Stop.java @@ -33,28 +33,30 @@ public class Stop { int id; @DatabaseField(canBeNull = false) - String name; + public String name; @DatabaseField(canBeNull = false, foreign = true) BusStop destStop; @DatabaseField(canBeNull = true, foreign = true) - Bus bus; + public Bus bus; @DatabaseField(canBeNull = false, foreign = true) - BusStop busStop; + public BusStop busStop; @DatabaseField(canBeNull = false) - Date arivalTime; + public Date arivalTime; @DatabaseField(canBeNull = false) Date timeOfFetch; + BusRoute route; + Stop() { } - Stop(String name, BusStop busStop, BusStop dest, Bus bus, Date arivalTime, Date timeOfFetch) { + public Stop(String name, BusStop busStop, BusStop dest, Bus bus, Date arivalTime, Date timeOfFetch) { this.name = name; this.busStop = busStop; this.destStop = dest; @@ -63,7 +65,7 @@ public class Stop { this.timeOfFetch = timeOfFetch; } - Stop(String name, BusStop busStop, BusStop dest, Date arivalTime, Date timeOfFetch) { + public Stop(String name, BusStop busStop, BusStop dest, Date arivalTime, Date timeOfFetch) { this(name, busStop, dest, null, arivalTime, timeOfFetch); } diff --git a/src/net/cbaines/suma/StopView.java b/src/net/cbaines/suma/StopView.java index 9e58eb4..e36b3d9 100644 --- a/src/net/cbaines/suma/StopView.java +++ b/src/net/cbaines/suma/StopView.java @@ -20,6 +20,7 @@ package net.cbaines.suma; import java.sql.SQLException; +import java.text.DateFormat; import android.content.Context; import android.view.Gravity; @@ -78,12 +79,11 @@ public class StopView extends LinearLayout implements OnClickListener { busDao.refresh(stop.bus); if (stop.bus != null) { - onClickMessage = "Bus " + stop.bus.toString(); + onClickMessage = "Bus " + stop.bus.toString() + " at " + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime); } else { - onClickMessage = "Unidentified bus"; + onClickMessage = "Unidentified bus at " + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime); } } catch (SQLException e) { - // TODO Auto-generated catch block e.printStackTrace(); } diff --git a/src/net/cbaines/suma/StringDistanceComparator.java b/src/net/cbaines/suma/StringDistanceComparator.java index 0d19f53..9230f1c 100644 --- a/src/net/cbaines/suma/StringDistanceComparator.java +++ b/src/net/cbaines/suma/StringDistanceComparator.java @@ -21,6 +21,7 @@ package net.cbaines.suma; import java.util.Comparator; + public class StringDistanceComparator implements Comparator<POI> { private String userString; diff --git a/src/net/cbaines/suma/TimetableAdapter.java b/src/net/cbaines/suma/TimetableAdapter.java index 19ca5a5..b4dfab5 100644 --- a/src/net/cbaines/suma/TimetableAdapter.java +++ b/src/net/cbaines/suma/TimetableAdapter.java @@ -43,6 +43,8 @@ public class TimetableAdapter extends BaseAdapter { } public View getView(int position, View convertView, ViewGroup parent) { + Log.i(TAG, "Returning stop " + position + " " + timetable.get(position)); + StopView stopView; if (convertView == null) { stopView = new StopView(context, timetable.get(position)); @@ -52,7 +54,9 @@ public class TimetableAdapter extends BaseAdapter { } if (changed == null || changed[position]) { + a.reset(); stopView.startAnimation(a); + Log.i(TAG, "Animating it"); } return stopView; diff --git a/src/net/cbaines/suma/Util.java b/src/net/cbaines/suma/Util.java index 7efbcbf..420d848 100644 --- a/src/net/cbaines/suma/Util.java +++ b/src/net/cbaines/suma/Util.java @@ -21,6 +21,7 @@ package net.cbaines.suma; import java.util.ArrayList; + import org.osmdroid.util.GeoPoint; import android.location.Location; |