aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2012-02-08 15:25:29 +0000
committerChristopher Baines <cbaines8@gmail.com>2012-02-08 15:25:29 +0000
commit167ec37cd6d58e6565531603df946ca4e441ec36 (patch)
treef16cf594f44cd7583eb1e6d8c2bf3a709b0ace1a /src
parent2b70a4f77bc29afbe5e801ad2ffec89cdb84f6ae (diff)
downloadsouthamptonuniversitymap-167ec37cd6d58e6565531603df946ca4e441ec36.tar
southamptonuniversitymap-167ec37cd6d58e6565531603df946ca4e441ec36.tar.gz
Lots of changes related to the dialogs...
Diffstat (limited to 'src')
-rw-r--r--src/net/cbaines/suma/BusStopActivity.java41
-rw-r--r--src/net/cbaines/suma/FavouriteDialog.java133
-rw-r--r--src/net/cbaines/suma/POIDialog.java (renamed from src/net/cbaines/suma/BusStopDialog.java)74
-rw-r--r--src/net/cbaines/suma/SouthamptonUniversityMapActivity.java42
4 files changed, 106 insertions, 184 deletions
diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java
index 1f99b8a..b50e340 100644
--- a/src/net/cbaines/suma/BusStopActivity.java
+++ b/src/net/cbaines/suma/BusStopActivity.java
@@ -21,12 +21,14 @@ package net.cbaines.suma;
import java.io.IOException;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;
+import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -40,6 +42,8 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
@@ -53,7 +57,7 @@ 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 {
+public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> implements OnCheckedChangeListener, Preferences, OnItemClickListener {
final static String TAG = "BusTimeActivity";
@@ -90,6 +94,9 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
private CheckBox U6RouteRadioButton;
private CheckBox U9RouteRadioButton;
+ private static final int POI_DIALOG_ID = 0;
+ private POIDialog busDialog;
+
private HashSet<BusRoute> routes = new HashSet<BusRoute>();
public void onCreate(Bundle savedInstanceState) {
@@ -339,7 +346,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
Log.v(TAG, routes.size() + " routes avalible from this stop");
- HashSet<BusStop> busStops = new HashSet<BusStop>();
+ ArrayList<POI> busStops = new ArrayList<POI>();
for (BusRoute route : routes) {
try {
@@ -357,7 +364,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
if (busStops.size() == 1) {
Intent i = new Intent(this, BusStopActivity.class);
- BusStop stop = busStops.iterator().next();
+ BusStop stop = (BusStop) busStops.iterator().next();
if (stop == null) {
Log.e(TAG, "stop == null");
}
@@ -368,7 +375,16 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
i.putExtra("busStopName", stop.description);
startActivity(i);
} else {
- // Show dialog
+ showDialog(POI_DIALOG_ID);
+ if (busDialog == null) {
+ Log.e(TAG, "Very wierd, just tried to launch the favourite's dialog, but its null?");
+ return false;
+ }
+
+ busDialog.setMessage("");
+ busDialog.setItems(busStops);
+ busDialog.setTitle("Choose Bus Stop");
+
Log.i(TAG, "Showing dialog");
}
@@ -445,4 +461,21 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
}
}
}
+
+ @Override
+ protected Dialog onCreateDialog(int id) {
+ switch (id) {
+ case POI_DIALOG_ID:
+ busDialog = new POIDialog(instance);
+ busDialog.setOnItemClickListener(this);
+ return busDialog;
+ }
+ return null;
+ }
+
+ @Override
+ public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
+ // TODO Auto-generated method stub
+
+ }
}
diff --git a/src/net/cbaines/suma/FavouriteDialog.java b/src/net/cbaines/suma/FavouriteDialog.java
deleted file mode 100644
index ca39574..0000000
--- a/src/net/cbaines/suma/FavouriteDialog.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * 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 java.sql.SQLException;
-import java.util.ArrayList;
-
-
-import android.app.Dialog;
-import android.content.Context;
-import android.util.Log;
-import android.view.View;
-import android.widget.AdapterView.OnItemClickListener;
-import android.widget.AdapterView.OnItemLongClickListener;
-import android.widget.ListView;
-import android.widget.TextView;
-
-import com.j256.ormlite.android.apptools.OpenHelperManager;
-import com.j256.ormlite.dao.Dao;
-
-public class FavouriteDialog extends Dialog {
-
- private static final String TAG = "FavouriteDialog";
- private ListView listItems;
-
- private final Context context;
-
- private final TextView message;
-
- protected POIArrayAdapter adapter;
-
- private ArrayList<POI> favouriteItems;
-
- public FavouriteDialog(Context context) {
- super(context);
-
- this.context = context;
-
- setContentView(R.layout.favourite_dialog);
- setTitle("Favourite Items");
-
- message = (TextView) findViewById(R.id.favouriteDialogMessage);
-
- favouriteItems = new ArrayList<POI>();
-
- listItems = (ListView) findViewById(R.id.favouriteListItems);
-
- refresh();
- }
-
- public void refresh() {
-
- DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
-
- try {
-
- Dao<Building, String> buildingDao = helper.getBuildingDao();
- Dao<BusStop, String> busStopDao = helper.getBusStopDao();
-
- final ArrayList<POI> newFavouriteItems = new ArrayList<POI>();
-
- newFavouriteItems.addAll(buildingDao.queryForEq(POI.FAVOURITE_FIELD_NAME, true));
- newFavouriteItems.addAll(busStopDao.queryForEq(POI.FAVOURITE_FIELD_NAME, true));
-
- Log.i(TAG, "There are " + newFavouriteItems.size() + " favourites");
- if (newFavouriteItems.size() == 0) {
- Log.i(TAG, "Favourite dialog has no favourites, displaying message");
- message.post(new Runnable() {
- public void run() {
- message.setText(R.string.favourites_dialog_message);
- message.setVisibility(View.VISIBLE);
- }
- });
- listItems.post(new Runnable() {
- public void run() {
- listItems.setVisibility(View.GONE);
- adapter = null;
- favouriteItems.clear();
- }
- });
-
- } else {
- message.post(new Runnable() {
- public void run() {
- message.setVisibility(View.GONE);
- }
- });
-
- listItems.post(new Runnable() {
- public void run() {
- favouriteItems = newFavouriteItems;
- adapter = new POIArrayAdapter(context, favouriteItems);
-
- listItems.setVisibility(View.VISIBLE);
- listItems.setAdapter(adapter);
-
- }
- });
-
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- void setOnItemClickListener(OnItemClickListener item) {
- listItems.setOnItemClickListener(item);
-
- }
-
- void setOnItemLongClickListener(OnItemLongClickListener item) {
- listItems.setOnItemLongClickListener(item);
- }
-
-}
diff --git a/src/net/cbaines/suma/BusStopDialog.java b/src/net/cbaines/suma/POIDialog.java
index 670fc96..8107d06 100644
--- a/src/net/cbaines/suma/BusStopDialog.java
+++ b/src/net/cbaines/suma/POIDialog.java
@@ -19,71 +19,69 @@
package net.cbaines.suma;
-import java.sql.SQLException;
-import java.util.ArrayList;
+import java.util.List;
import android.app.Dialog;
import android.content.Context;
-import android.util.Log;
import android.view.View;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;
import android.widget.TextView;
-import com.j256.ormlite.android.apptools.OpenHelperManager;
-import com.j256.ormlite.dao.Dao;
+public class POIDialog extends Dialog {
-public class BusStopDialog extends Dialog {
-
- private static final String TAG = "BusStopDialog";
+ private static final String TAG = "POIDialog";
private ListView listItems;
private final Context context;
- protected POIArrayAdapter adapter;
+ private final TextView message;
- private ArrayList<BusStop> busStops;
+ protected POIArrayAdapter adapter;
- public BusStopDialog(Context context) {
+ public POIDialog(Context context) {
super(context);
this.context = context;
- setContentView(R.layout.bus_stop_dialog);
- setTitle("Favourite Items");
-
- busStops = new ArrayList<BusStop>();
+ setContentView(R.layout.poi_dialog);
+ message = (TextView) findViewById(R.id.favouriteDialogMessage);
listItems = (ListView) findViewById(R.id.favouriteListItems);
- refresh();
}
- public void refresh() {
-
- DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
-
- try {
-
- if (busStops.size() == 0) {
- Log.e(TAG, "Error");
- } else {
- listItems.post(new Runnable() {
- public void run() {
- adapter = new POIArrayAdapter(context, busStops);
-
- listItems.setVisibility(View.VISIBLE);
- listItems.setAdapter(adapter);
-
- }
- });
+ void setMessage(final String text) {
+ message.post(new Runnable() {
+ public void run() {
+ if (text == null || text.length() == 0) {
+ message.setVisibility(View.GONE);
+ } else {
+ message.setText(text);
+ message.setVisibility(View.VISIBLE);
+ }
+ }
+ });
+ }
+ void setItems(final List<POI> items) {
+ listItems.post(new Runnable() {
+ public void run() {
+ if (items != null) {
+ adapter = new POIArrayAdapter(context, items);
+
+ listItems.setVisibility(View.VISIBLE);
+ listItems.setAdapter(adapter);
+ } else {
+ listItems.setVisibility(View.GONE);
+ }
}
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ });
+ }
+
+ void setTitle(String title) {
+ setTitle(title);
}
void setOnItemClickListener(OnItemClickListener item) {
diff --git a/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java b/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java
index 4bfb3de..3580c60 100644
--- a/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java
+++ b/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java
@@ -136,7 +136,7 @@ public class SouthamptonUniversityMapActivity extends OrmLiteBaseActivity<Databa
private static final int UNI_LINK_BUS_STOP_OVERLAY_RANK = 4;
- private FavouriteDialog favDialog;
+ private POIDialog favDialog;
private SouthamptonUniversityMapActivity instance;
@@ -771,14 +771,15 @@ public class SouthamptonUniversityMapActivity extends OrmLiteBaseActivity<Databa
return false;
case R.id.menu_favourites:
Log.i(TAG, "Showing favourite dialog");
- boolean refreshNeeded = favDialog != null;
+
showDialog(FAVOURITE_DIALOG_ID);
- if (favDialog != null) {
- if (refreshNeeded)
- favDialog.refresh();
- } else {
+ if (favDialog == null) {
Log.e(TAG, "Very wierd, just tried to launch the favourite's dialog, but its null?");
+ return false;
}
+
+ refreshFavouriteDialog();
+
return false;
case R.id.menu_about:
Intent aboutIntent = new Intent(SouthamptonUniversityMapActivity.this, AboutActivity.class);
@@ -790,6 +791,30 @@ public class SouthamptonUniversityMapActivity extends OrmLiteBaseActivity<Databa
}
}
+ private void refreshFavouriteDialog() {
+ ArrayList<POI> newFavouriteItems = new ArrayList<POI>();
+
+ try {
+ Dao<Building, String> buildingDao = getHelper().getBuildingDao();
+ Dao<BusStop, String> busStopDao = getHelper().getBusStopDao();
+
+ newFavouriteItems.addAll(buildingDao.queryForEq(POI.FAVOURITE_FIELD_NAME, true));
+ newFavouriteItems.addAll(busStopDao.queryForEq(POI.FAVOURITE_FIELD_NAME, true));
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+
+ Log.i(TAG, "There are " + newFavouriteItems.size() + " favourites");
+ if (newFavouriteItems.size() == 0) {
+ Log.i(TAG, "Favourite dialog has no favourites, displaying message");
+ favDialog.setMessage(getResources().getString(R.string.favourites_dialog_message));
+ favDialog.setItems(null);
+ } else {
+ favDialog.setMessage("");
+ favDialog.setItems(newFavouriteItems);
+ }
+ }
+
@Override
public boolean onSearchRequested() {
Intent i = new Intent(SouthamptonUniversityMapActivity.this, FindActivity.class);
@@ -850,7 +875,7 @@ public class SouthamptonUniversityMapActivity extends OrmLiteBaseActivity<Databa
}
if (favDialog != null) {
- favDialog.refresh();
+ refreshFavouriteDialog();
}
}
}
@@ -876,11 +901,10 @@ public class SouthamptonUniversityMapActivity extends OrmLiteBaseActivity<Databa
viewDialog.setOnItemClickListener(this);
return viewDialog;
case FAVOURITE_DIALOG_ID:
- favDialog = new FavouriteDialog(instance);
+ favDialog = new POIDialog(instance);
favDialog.setOnItemClickListener(this);
favDialog.setOnItemLongClickListener(this);
return favDialog;
-
}
return null;
}