diff options
author | Christopher Baines <cbaines8@gmail.com> | 2012-01-30 23:46:57 +0000 |
---|---|---|
committer | Christopher Baines <cbaines8@gmail.com> | 2012-01-30 23:46:57 +0000 |
commit | fb831b1e33d4b988b97e95493336e076c7f799ab (patch) | |
tree | a12dbb905b0addeaf7c050f02d43469c9053d81b /src | |
parent | fd1a757037a079278c2bf3e393d35bfee6b4c684 (diff) | |
download | southamptonuniversitymap-fb831b1e33d4b988b97e95493336e076c7f799ab.tar southamptonuniversitymap-fb831b1e33d4b988b97e95493336e076c7f799ab.tar.gz |
Improved about menu, removed the stop navigation (for the time being).
Diffstat (limited to 'src')
-rw-r--r-- | src/net/cbaines/suma/AboutActivity.java | 149 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusStopActivity.java | 153 |
2 files changed, 82 insertions, 220 deletions
diff --git a/src/net/cbaines/suma/AboutActivity.java b/src/net/cbaines/suma/AboutActivity.java index b330596..9c479c8 100644 --- a/src/net/cbaines/suma/AboutActivity.java +++ b/src/net/cbaines/suma/AboutActivity.java @@ -19,122 +19,65 @@ package net.cbaines.suma; -import android.app.Activity; import android.app.Dialog; -import android.content.Context; +import android.content.Intent; +import android.net.Uri; import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.ViewGroup; -import android.widget.BaseExpandableListAdapter; -import android.widget.Button; -import android.widget.ExpandableListView; -import android.widget.TextView; +import android.preference.Preference; +import android.preference.PreferenceActivity; +import android.preference.PreferenceScreen; -public class AboutActivity extends Activity implements OnClickListener { +public class AboutActivity extends PreferenceActivity { static final int DONATE_DIALOG_ID = 0; + private static final String KEY_ABOUT_LICENSE = "about_license"; + private static final String KEY_ABOUT_PROJECT = "about_project"; + private static final String KEY_ABOUT_DEVELOPER = "about_developer"; + private static final String KEY_ABOUT_DATA = "about_data"; + private static final String KEY_ABOUT_ANDROID_MARKET = "about_android_market"; + private static final String KEY_ABOUT_MAP_DATA = "about_map_data"; + private static final String KEY_ABOUT_MAP_ICONS = "about_map_icons"; + private static final String KEY_ABOUT_OSM_MAP = "about_osm_map"; + private static final String KEY_ABOUT_DATABASE = "about_database"; + private static final String KEY_ABOUT_DONATE = "about_donate"; + public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.about_dialog); - - ExpandableListView epView = (ExpandableListView) findViewById(R.id.helpExpandableListView); - AboutListAdapter mAdapter = new AboutListAdapter(this); - epView.setAdapter(mAdapter); - - Button donateButton = (Button) findViewById(R.id.donateButton); - donateButton.setOnClickListener(this); + addPreferencesFromResource(R.xml.about); } - class AboutListAdapter extends BaseExpandableListAdapter { - private String[] groups = { "Map", "Find", "Preferences", "Find my Location", "View", "About", "Favourites", "Licence", "Credits" }; - private LayoutInflater inflater; - private Context cxt; - - public AboutListAdapter(Context cxt) { - inflater = LayoutInflater.from(cxt); - this.cxt = cxt; - } - - public Object getChild(int groupPos, int childPos) { - if (groupPos == 0) { - return cxt.getResources().getString(R.string.map_help_message); - } else if (groupPos == 1) { - return cxt.getResources().getString(R.string.find_help_message); - } else if (groupPos == 1) { - return cxt.getResources().getString(R.string.preferences_help_message); - } else if (groupPos == 2) { - return cxt.getResources().getString(R.string.findmylocation_help_message); - } else if (groupPos == 3) { - return cxt.getResources().getString(R.string.view_help_message); - } else if (groupPos == 4) { - return cxt.getResources().getString(R.string.about_help_message); - } else if (groupPos == 5) { - return cxt.getResources().getString(R.string.favourites_help_message); - } else if (groupPos == 6) { - return cxt.getResources().getString(R.string.favourites_help_message); - } else if (groupPos == 7) { - return cxt.getResources().getString(R.string.licence_help_message); - } else if (groupPos == 8) { - return cxt.getResources().getString(R.string.credits_help_message); - } - return null; - } - - public long getChildId(int groupPos, int childPos) { - return childPos; - } - - public View getChildView(int groupPos, int childPos, boolean isLastChild, View convertView, ViewGroup parent) { - TextView tv = new TextView(cxt); - tv.setText(getChild(groupPos, childPos).toString()); - return tv; - } - - public int getChildrenCount(int groupPos) { - return 1; - } - - public Object getGroup(int groupPos) { - return groups[groupPos]; - } - - public int getGroupCount() { - return groups.length; - } - - public long getGroupId(int groupPos) { - return groupPos; - } - - public View getGroupView(int groupPos, boolean isExpanded, View convertView, ViewGroup parent) { - View v = null; - if (convertView != null) - v = convertView; - else - v = inflater.inflate(R.layout.view_group_row, parent, false); - String gt = (String) getGroup(groupPos); - TextView colorGroup = (TextView) v.findViewById(R.id.childname); - if (gt != null) - colorGroup.setText(gt); - return v; + @Override + public boolean onPreferenceTreeClick(final PreferenceScreen preferenceScreen, final Preference preference) { + final String key = preference.getKey(); + if (KEY_ABOUT_LICENSE.equals(key)) { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.gnu.org/licenses/gpl-2.0.html"))); + } else if (KEY_ABOUT_PROJECT.equals(key)) { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/cbaines/SouthamptonUniversityMap"))); + } else if (KEY_ABOUT_DEVELOPER.equals(key)) { + Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); + emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "cbaines8@gmail.com" }); + emailIntent.setType("text/plain"); + + startActivity(Intent.createChooser(emailIntent, "Email the developer")); + } else if (KEY_ABOUT_DATA.equals(key)) { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://data.southampton.ac.uk/bus-routes.html"))); + } else if (KEY_ABOUT_ANDROID_MARKET.equals(key)) { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(""))); + } else if (KEY_ABOUT_MAP_DATA.equals(key)) { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("http://data.southampton.ac.uk/places.html")))); + } else if (KEY_ABOUT_MAP_ICONS.equals(key)) { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://mapicons.nicolasmollet.com/"))); + } else if (KEY_ABOUT_OSM_MAP.equals(key)) { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.openstreetmap.org/"))); + } else if (KEY_ABOUT_DATABASE.equals(key)) { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("http://ormlite.com/")))); + } else if (KEY_ABOUT_DONATE.equals(key)) { + showDialog(DONATE_DIALOG_ID); } - public boolean hasStableIds() { - return true; - } - - public boolean isChildSelectable(int groupPos, int childPos) { - return true; - } - - } - - public void onClick(View arg0) { - showDialog(DONATE_DIALOG_ID); + return false; } protected Dialog onCreateDialog(int id) { diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java index ad26c41..93f4ae6 100644 --- a/src/net/cbaines/suma/BusStopActivity.java +++ b/src/net/cbaines/suma/BusStopActivity.java @@ -30,7 +30,6 @@ import org.json.JSONException; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.graphics.Path.Direction; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; @@ -91,6 +90,8 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme private CheckBox U6RouteRadioButton; private CheckBox U9RouteRadioButton; + private HashSet<BusRoute> routes = new HashSet<BusRoute>(); + public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.bustimes); @@ -130,30 +131,35 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme if (route.code.equals("U1")) { if (count != 0) { U1RouteRadioButton.setVisibility(View.VISIBLE); + routes.add(route); } else { U1RouteRadioButton.setVisibility(View.GONE); } } else if (route.code.equals("U1N")) { if (count != 0) { U1NRouteRadioButton.setVisibility(View.VISIBLE); + routes.add(route); } else { U1NRouteRadioButton.setVisibility(View.GONE); } } else if (route.code.equals("U2")) { if (count != 0) { U2RouteRadioButton.setVisibility(View.VISIBLE); + routes.add(route); } else { U2RouteRadioButton.setVisibility(View.GONE); } } else if (route.code.equals("U6")) { if (count != 0) { U6RouteRadioButton.setVisibility(View.VISIBLE); + routes.add(route); } else { U6RouteRadioButton.setVisibility(View.GONE); } } else if (route.code.equals("U9")) { if (count != 0) { U9RouteRadioButton.setVisibility(View.VISIBLE); + routes.add(route); } else { U9RouteRadioButton.setVisibility(View.GONE); } @@ -324,131 +330,44 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection - if (item.getItemId() == R.id.menu_previous_stop || item.getItemId() == R.id.menu_next_stop) { + if (false) { // (item.getItemId() == R.id.menu_previous_stop || item.getItemId() == R.id.menu_next_stop) { Log.v(TAG, "Got a request for the stop movement"); - if (visibleTimetable.size() != 0) { - HashSet<BusRoute> routes = new HashSet<BusRoute>(); - HashSet<String> directions = new HashSet<String>(); - - for (Stop stop : visibleTimetable) { - routes.add(stop.bus.route); - } - Log.i(TAG, "routes " + routes); - Log.v(TAG, routes.size() + " routes in the visible timetable"); + Log.v(TAG, routes.size() + " routes avalible from this stop"); - for (Stop stop : visibleTimetable) { - directions.add(stop.bus.direction); - } - - Log.i(TAG, "directions " + directions); - - if (routes.size() == 1) { - - Log.v(TAG, directions.size() + " directions in the visible timetable"); - - String direction; - if (directions.size() <= 1) { - if (directions.size() == 0) { - direction = null; - } else { - direction = directions.iterator().next(); - } - - try { - BusStop stop; - if (item.getItemId() == R.id.menu_next_stop) { - stop = routes.iterator().next().moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), direction, 1); - } else { - stop = routes.iterator().next().moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), direction, -1); - } - Intent i = new Intent(this, BusStopActivity.class); - if (stop.id == null) { - Log.e(TAG, "next.id == null"); - } - i.putExtra("busStopID", stop.id); - i.putExtra("busStopName", stop.description); - startActivity(i); - } catch (SQLException e) { - e.printStackTrace(); - } - } else { // Same route, different directions? - // ATM, this is not considered possible? - Log.e(TAG, "Big mistake in onOptionsItemSelected in BusStopActivity"); - } - } else { - HashSet<BusStop> stops = new HashSet<BusStop>(); - - if (directions.size() <= 1) { - - for (BusRoute route : routes) { - try { - if (item.getItemId() == R.id.menu_next_stop) { - stops.add(route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), directions.iterator().next(), 1)); - } else { - stops.add(route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), directions.iterator().next(), -1)); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } - - Log.i(TAG, "stops " + stops); - - if (stops.size() == 1) { - Intent i = new Intent(this, BusStopActivity.class); - BusStop stop = stops.iterator().next(); - if (stop.id == null) { - Log.e(TAG, "next.id == null"); - } - i.putExtra("busStopID", stop.id); - i.putExtra("busStopName", stop.description); - startActivity(i); - } else { - // Show dialog - Log.i(TAG, "Showing dialog"); - } + HashSet<BusStop> busStops = new HashSet<BusStop>(); + for (BusRoute route : routes) { + try { + if (false) { // (item.getItemId() == R.id.menu_next_stop) { + busStops.add(route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), null, 1)); } else { + busStops.add(route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), null, -1)); + } + } catch (SQLException e) { + e.printStackTrace(); + } + } - for (String direction : directions) { - - for (BusRoute route : routes) { - try { - BusStop stop; - if (item.getItemId() == R.id.menu_next_stop) { - stop = route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), direction, 1); - } else { - stop = route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), direction, -1); - } - if (stop != null) { - stops.add(stop); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } - } - - Log.i(TAG, "stops " + stops); - - if (stops.size() == 1) { - Intent i = new Intent(this, BusStopActivity.class); - BusStop stop = stops.iterator().next(); - if (stop.id == null) { - Log.e(TAG, "next.id == null"); - } - i.putExtra("busStopID", stop.id); - i.putExtra("busStopName", stop.description); - startActivity(i); - } else { - // Show dialog - Log.i(TAG, "Showing dialog"); - } + Log.i(TAG, "stops " + busStops); - } + if (busStops.size() == 1) { + Intent i = new Intent(this, BusStopActivity.class); + BusStop stop = busStops.iterator().next(); + if (stop == null) { + Log.e(TAG, "stop == null"); } + if (stop.id == null) { + Log.e(TAG, "stop.id == null"); + } + i.putExtra("busStopID", stop.id); + i.putExtra("busStopName", stop.description); + startActivity(i); + } else { + // Show dialog + Log.i(TAG, "Showing dialog"); } + } else if (item.getItemId() == R.id.menu_refresh_stop) { if (mHandler != null) { // BusTimes are enabled mHandler.removeCallbacks(refreshData); |