diff options
author | Christopher Baines <cbaines8@gmail.com> | 2012-02-28 22:22:27 +0000 |
---|---|---|
committer | Christopher Baines <cbaines8@gmail.com> | 2012-02-28 22:22:27 +0000 |
commit | 5f2b8712079aeb5b7cee476b06b36013edac4fb3 (patch) | |
tree | 99c01ccf78dc130a8ca9b8a2d19384b9f91e1768 /src/net/cbaines/suma/BusRouteActivity.java | |
parent | 0b5aefbe0ff01638dd264222c5368ad02a0fe1ee (diff) | |
download | southamptonuniversitymap-5f2b8712079aeb5b7cee476b06b36013edac4fb3.tar southamptonuniversitymap-5f2b8712079aeb5b7cee476b06b36013edac4fb3.tar.gz |
Next release, many improvements.
Diffstat (limited to 'src/net/cbaines/suma/BusRouteActivity.java')
-rw-r--r-- | src/net/cbaines/suma/BusRouteActivity.java | 110 |
1 files changed, 106 insertions, 4 deletions
diff --git a/src/net/cbaines/suma/BusRouteActivity.java b/src/net/cbaines/suma/BusRouteActivity.java index 3670c68..0a352ce 100644 --- a/src/net/cbaines/suma/BusRouteActivity.java +++ b/src/net/cbaines/suma/BusRouteActivity.java @@ -3,15 +3,24 @@ package net.cbaines.suma; import java.sql.SQLException; import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.net.Uri; import android.os.Bundle; +import android.preference.PreferenceManager; import android.util.Log; +import android.view.View; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; -public class BusRouteActivity extends OrmLiteBaseActivity<DatabaseHelper> implements Preferences { +public class BusRouteActivity extends OrmLiteBaseActivity<DatabaseHelper> implements Preferences, OnItemClickListener, + OnItemLongClickListener { final static String TAG = "BusActivity"; private TextView busRouteLabel; @@ -22,6 +31,8 @@ public class BusRouteActivity extends OrmLiteBaseActivity<DatabaseHelper> implem private ListView busRouteView; + private POIArrayAdapter arrayAdapter; + private Context instance; public void onCreate(Bundle savedInstanceState) { @@ -50,6 +61,8 @@ public class BusRouteActivity extends OrmLiteBaseActivity<DatabaseHelper> implem BusRoute busRoute = null; + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + try { busRoute = helper.getBusRouteDao().queryForId(Integer.parseInt(strBusRouteID)); @@ -59,8 +72,11 @@ public class BusRouteActivity extends OrmLiteBaseActivity<DatabaseHelper> implem busRouteCode = (TextView) findViewById(R.id.busRouteActivityCode); busRouteCode.setText(busRoute.code); - busRouteID = (TextView) findViewById(R.id.busRouteActivityID); - busRouteID.setText(String.valueOf(busRoute.id)); + if (prefs.getBoolean(SHOW_IDENTIFIERS, SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT)) { + busRouteID = (TextView) findViewById(R.id.busRouteActivityID); + busRouteID.setText(String.valueOf(busRoute.id)); + busRouteID.setVisibility(View.VISIBLE); + } busRouteView = (ListView) findViewById(R.id.busRouteBusStops); @@ -70,7 +86,93 @@ public class BusRouteActivity extends OrmLiteBaseActivity<DatabaseHelper> implem e.printStackTrace(); } - POIArrayAdapter arrayAdapter = new POIArrayAdapter(instance, busRoute.getRouteBusStops(instance)); + arrayAdapter = new POIArrayAdapter(instance, busRoute.getRouteBusStops(instance)); busRouteView.setAdapter(arrayAdapter); + busRouteView.setOnItemClickListener(this); + busRouteView.setOnItemLongClickListener(this); + } + + public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { + Log.i(TAG, "OnItemClick pos " + position + " id " + id); + + String poiId = arrayAdapter.getItemStringId(position); + + Log.i(TAG, "POI " + poiId + " selected"); + + POI poi = null; + + if (poiId != null) { + Log.i(TAG, "Got id " + poiId); + try { + poi = getHelper().getBusStopDao().queryForId(poiId); + } catch (SQLException e) { + e.printStackTrace(); + } + + if (poi == null) { + Log.e(TAG, "Could not find poi " + poiId + " in onActivityResult"); + } else { + + BusStop busStop = (BusStop) poi; + + Log.i(TAG, "Pressed " + busStop.id); + + Uri uri = Uri.parse("http://id.southampton.ac.uk/bus-stop/" + busStop.id); + + Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath()); + + Intent busStopIntent = new Intent(Intent.ACTION_VIEW, uri); + startActivity(busStopIntent); + + return true; + } + } else { + Log.i(TAG, "Got null poi id"); + + // mapController.setZoom(15); + // mapController.setCenter(new GeoPoint(50935551, -1393488)); + } + + return false; + } + + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + Log.i(TAG, "OnItemClick pos " + position + " id " + id); + + String poiId = arrayAdapter.getItemStringId(position); + + Log.i(TAG, "POI " + poiId + " selected"); + + POI poi = null; + + if (poiId != null) { + Log.i(TAG, "Got id " + poiId); + try { + poi = getHelper().getBusStopDao().queryForId(poiId); + } catch (SQLException e) { + e.printStackTrace(); + } + + if (poi == null) { + Log.e(TAG, "Could not find poi " + poiId + " in onActivityResult"); + } else { + + Log.i(TAG, "Pressed " + poi.id); + + Uri uri = Uri.parse("geo:" + Util.E6IntToDouble(poi.point.getLatitudeE6()) + "," + + Util.E6IntToDouble(poi.point.getLongitudeE6()) + "?z=18"); + + Log.i(TAG, "Starting a activity for " + uri); + + Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri); + startActivity(mapIntent); + + } + } else { + Log.i(TAG, "Got null poi id"); + + // mapController.setZoom(15); + // mapController.setCenter(new GeoPoint(50935551, -1393488)); + } } } |