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 | |
parent | 0b5aefbe0ff01638dd264222c5368ad02a0fe1ee (diff) | |
download | southamptonuniversitymap-5f2b8712079aeb5b7cee476b06b36013edac4fb3.tar southamptonuniversitymap-5f2b8712079aeb5b7cee476b06b36013edac4fb3.tar.gz |
Next release, many improvements.
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/cbaines/suma/BuildingActivity.java | 148 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusActivity.java | 37 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusRouteActivity.java | 110 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusStopActivity.java | 21 | ||||
-rw-r--r-- | src/net/cbaines/suma/FindActivity.java | 2 | ||||
-rw-r--r-- | src/net/cbaines/suma/MapActivity.java | 2 |
6 files changed, 202 insertions, 118 deletions
diff --git a/src/net/cbaines/suma/BuildingActivity.java b/src/net/cbaines/suma/BuildingActivity.java index d9baa95..509bc41 100644 --- a/src/net/cbaines/suma/BuildingActivity.java +++ b/src/net/cbaines/suma/BuildingActivity.java @@ -28,6 +28,7 @@ import java.sql.SQLException; import android.content.Context; import android.content.SharedPreferences; import android.graphics.drawable.Drawable; +import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.view.Display; @@ -38,13 +39,13 @@ import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.ImageButton; import android.widget.ImageView.ScaleType; +import android.widget.ProgressBar; import android.widget.TextView; import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; import com.j256.ormlite.dao.Dao; -public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implements OnCheckedChangeListener, - Preferences { +public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implements OnCheckedChangeListener, Preferences { final static String TAG = "BusTimeActivity"; @@ -53,10 +54,12 @@ public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implem private ImageButton imageButton; private TextView buildingName; - private TextView buildingID; private Building building; + private ProgressBar progressBar; + private TextView message; + private CheckBox favouritesCheckBox; public void onCreate(Bundle savedInstanceState) { @@ -85,7 +88,9 @@ public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implem favouritesCheckBox.setOnCheckedChangeListener(this); buildingName = (TextView) findViewById(R.id.buildingActivityName); - buildingID = (TextView) findViewById(R.id.buildingActivityID); + + progressBar = (ProgressBar) findViewById(R.id.buildingActivityLoadBar); + message = (TextView) findViewById(R.id.buildingActivityMessage); Log.i(TAG, "Building id " + ID); @@ -94,83 +99,92 @@ public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implem building = buildingDao.queryForId(ID); - buildingName.setText(building.name); + buildingName.setText("Building " + building.id + " - " + building.name); } catch (SQLException e1) { - // TODO Auto-generated catch block e1.printStackTrace(); } - buildingID.setText(ID); - try { + GetBuildingImageTask buildingImageTask = new GetBuildingImageTask(); + buildingImageTask.execute(building); - /* First, get the Display from the WindowManager */ - Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); - - /* Now we can retrieve all display-related infos */ - int orientation = display.getOrientation(); - Log.i(TAG, "orientation " + orientation); - Log.i(TAG, "width " + display.getWidth() + " height " + display.getHeight()); - int width; - // if (orientation == 0) { - width = display.getWidth(); - // } else { - // width = display.getHeight(); - // } - - URL imageURL; - Log.i(TAG, "Screen width " + width); - if (width >= 1000) { - imageURL = new URL("http://data.southampton.ac.uk/images/buildings/1000/" + ID + ".jpg"); - } else if (width >= 800) { - imageURL = new URL("http://data.southampton.ac.uk/images/buildings/1000/" + ID + ".jpg"); - } else if (width >= 600) { - imageURL = new URL("http://data.southampton.ac.uk/images/buildings/600/" + ID + ".jpg"); - } else if (width >= 400) { - imageURL = new URL("http://data.southampton.ac.uk/images/buildings/600/" + ID + ".jpg"); - } else if (width >= 300) { - imageURL = new URL("http://data.southampton.ac.uk/images/buildings/300/" + ID + ".jpg"); - } else if (width >= 200) { - imageURL = new URL("http://data.southampton.ac.uk/images/buildings/200/" + ID + ".jpg"); - } else { - imageURL = new URL("http://data.southampton.ac.uk/images/buildings/100/" + ID + ".jpg"); - } - Log.i(TAG, "URL " + imageURL); + } + + class GetBuildingImageTask extends AsyncTask<Building, Integer, Drawable> { + String errorMessage; + + @Override + protected Drawable doInBackground(Building... buildings) { + Building building = buildings[0]; + + Log.i(TAG, "Getting image for " + building); + + try { + + Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); + + int orientation = display.getOrientation(); + Log.i(TAG, "orientation " + orientation); + Log.i(TAG, "width " + display.getWidth() + " height " + display.getHeight()); + int width; + width = display.getWidth(); + + URL imageURL; + Log.i(TAG, "Screen width " + width); + if (width >= 1000) { + imageURL = new URL("http://data.southampton.ac.uk/images/buildings/1000/" + building.id + ".jpg"); + } else if (width >= 800) { + imageURL = new URL("http://data.southampton.ac.uk/images/buildings/1000/" + building.id + ".jpg"); + } else if (width >= 600) { + imageURL = new URL("http://data.southampton.ac.uk/images/buildings/600/" + building.id + ".jpg"); + } else if (width >= 400) { + imageURL = new URL("http://data.southampton.ac.uk/images/buildings/600/" + building.id + ".jpg"); + } else if (width >= 300) { + imageURL = new URL("http://data.southampton.ac.uk/images/buildings/300/" + building.id + ".jpg"); + } else if (width >= 200) { + imageURL = new URL("http://data.southampton.ac.uk/images/buildings/200/" + building.id + ".jpg"); + } else { + imageURL = new URL("http://data.southampton.ac.uk/images/buildings/100/" + building.id + ".jpg"); + } + Log.i(TAG, "URL " + imageURL); - InputStream is = (InputStream) imageURL.getContent(); - Drawable image = Drawable.createFromStream(is, "src"); + InputStream is = (InputStream) imageURL.getContent(); + Drawable image = Drawable.createFromStream(is, "src"); - imageButton = new ImageButton(this); - imageButton = (ImageButton) findViewById(R.id.buildingActivityImage); - imageButton.setImageDrawable(image); - imageButton.setScaleType(ScaleType.CENTER_INSIDE); - imageButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { + return image; - } - }); - - } catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + } catch (MalformedURLException e) { + e.printStackTrace(); + errorMessage = "MalformedURLException"; + } catch (IOException e) { + e.printStackTrace(); + errorMessage = "IOException"; + } + + return null; } - } + protected void onPostExecute(Drawable image) { + progressBar.setVisibility(View.GONE); - public void onResume() { - super.onResume(); - } + if (image != null) { + Log.i(TAG, "Got a image for " + building + ", now displaying it"); - public void onPause() { - super.onPause(); - } + imageButton = (ImageButton) findViewById(R.id.buildingActivityImage); + imageButton.setImageDrawable(image); + imageButton.setScaleType(ScaleType.CENTER_INSIDE); + imageButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { - public void finish() { - setResult(RESULT_OK, getIntent()); - super.finish(); + } + }); + } else { + Log.e(TAG, "Error, null image, " + errorMessage); + + message.setText(errorMessage); + message.setVisibility(View.VISIBLE); + } + } } @Override diff --git a/src/net/cbaines/suma/BusActivity.java b/src/net/cbaines/suma/BusActivity.java index f4edc3f..1a8baf9 100644 --- a/src/net/cbaines/suma/BusActivity.java +++ b/src/net/cbaines/suma/BusActivity.java @@ -27,12 +27,6 @@ import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements Preferences { final static String TAG = "BusActivity"; - private TextView U1RouteTextView; - private TextView U1NRouteTextView; - private TextView U2RouteTextView; - private TextView U6RouteTextView; - private TextView U9RouteTextView; - private TextView busIDTextView; private TextView busContentMessage; @@ -115,12 +109,6 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements } } - U1RouteTextView = (TextView) findViewById(R.id.busActivityU1); - U1NRouteTextView = (TextView) findViewById(R.id.busActivityU1N); - U2RouteTextView = (TextView) findViewById(R.id.busActivityU2); - U6RouteTextView = (TextView) findViewById(R.id.busActivityU6); - U9RouteTextView = (TextView) findViewById(R.id.busActivityU9); - busIDTextView = (TextView) findViewById(R.id.busActivityBusID); busContentMessage = (TextView) findViewById(R.id.busActivityMessage); @@ -136,31 +124,6 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements busIDTextView.setText("Unidentified"); } - U1RouteTextView.setVisibility(View.GONE); - U1NRouteTextView.setVisibility(View.GONE); - U2RouteTextView.setVisibility(View.GONE); - U6RouteTextView.setVisibility(View.GONE); - U9RouteTextView.setVisibility(View.GONE); - - // if (bus.route.uniLink) { - Log.i(TAG, "Bus is uniLink"); - if (bus.route.code.equals("U1")) { - U1RouteTextView.setVisibility(View.VISIBLE); - } else if (bus.route.code.equals("U1N")) { - U1NRouteTextView.setVisibility(View.VISIBLE); - } else if (bus.route.code.equals("U2")) { - U2RouteTextView.setVisibility(View.VISIBLE); - } else if (bus.route.code.equals("U6")) { - U6RouteTextView.setVisibility(View.VISIBLE); - } else if (bus.route.code.equals("U9")) { - U9RouteTextView.setVisibility(View.VISIBLE); - } else { - Log.e(TAG, "Route not found " + bus.route.code); - } - // } else { - // Log.i(TAG, "Bus is not uniLink"); - // } - } catch (NumberFormatException e) { e.printStackTrace(); } catch (SQLException e) { 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)); + } } } diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java index 8bded40..cab81b1 100644 --- a/src/net/cbaines/suma/BusStopActivity.java +++ b/src/net/cbaines/suma/BusStopActivity.java @@ -61,8 +61,8 @@ import com.j256.ormlite.dao.Dao; import com.j256.ormlite.stmt.PreparedQuery; import com.j256.ormlite.stmt.QueryBuilder; -public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> implements OnCheckedChangeListener, - Preferences, OnItemClickListener, OnLongClickListener { +public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> implements OnCheckedChangeListener, Preferences, + OnItemClickListener, OnLongClickListener { final static String TAG = "BusTimeActivity"; @@ -123,6 +123,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme final DatabaseHelper helper = getHelper(); SharedPreferences favouritesPreferences = getSharedPreferences(FAVOURITES_PREFERENCES, 0); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); instance = this; @@ -212,7 +213,12 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme } busName = (TextView) findViewById(R.id.busStopName); - busID = (TextView) findViewById(R.id.busStopID); + + if (prefs.getBoolean(SHOW_IDENTIFIERS, SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT)) { + busID = (TextView) findViewById(R.id.busStopID); + busID.setText(busStopID); + busID.setVisibility(View.VISIBLE); + } busStopMessage = (TextView) findViewById(R.id.busStopMessage); progBar = (ProgressBar) findViewById(R.id.busStopLoadBar); @@ -222,7 +228,6 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme Log.i(TAG, "Got busstop id " + busStopID); busName.setText(busStop.description); - busID.setText(busStopID); } public void onResume() { @@ -315,10 +320,10 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme 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(); diff --git a/src/net/cbaines/suma/FindActivity.java b/src/net/cbaines/suma/FindActivity.java index 1af350a..669249c 100644 --- a/src/net/cbaines/suma/FindActivity.java +++ b/src/net/cbaines/suma/FindActivity.java @@ -241,7 +241,7 @@ public class FindActivity extends OrmLiteBaseActivity<DatabaseHelper> implements /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.find); + setContentView(R.layout.find_activity); searchBar = (EditText) findViewById(R.id.searchBar); searchBar.addTextChangedListener(this); diff --git a/src/net/cbaines/suma/MapActivity.java b/src/net/cbaines/suma/MapActivity.java index e2b9d66..8a7a39a 100644 --- a/src/net/cbaines/suma/MapActivity.java +++ b/src/net/cbaines/suma/MapActivity.java @@ -196,7 +196,7 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements Thread databaseThread = new Thread(this); // Start the database thread databaseThread.start(); - setContentView(R.layout.main); + setContentView(R.layout.map_activity); Log.i(TAG, "Finished setting content view " + (System.currentTimeMillis() - startTime)); |