diff options
author | Christopher Baines <cbaines8@gmail.com> | 2012-02-08 15:25:29 +0000 |
---|---|---|
committer | Christopher Baines <cbaines8@gmail.com> | 2012-02-08 15:25:29 +0000 |
commit | 167ec37cd6d58e6565531603df946ca4e441ec36 (patch) | |
tree | f16cf594f44cd7583eb1e6d8c2bf3a709b0ace1a | |
parent | 2b70a4f77bc29afbe5e801ad2ffec89cdb84f6ae (diff) | |
download | southamptonuniversitymap-167ec37cd6d58e6565531603df946ca4e441ec36.tar southamptonuniversitymap-167ec37cd6d58e6565531603df946ca4e441ec36.tar.gz |
Lots of changes related to the dialogs...
-rw-r--r-- | gen/net/cbaines/suma/R.java | 20 | ||||
-rw-r--r-- | res/layout/poi_dialog.xml (renamed from res/layout/favourite_dialog.xml) | 0 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusStopActivity.java | 41 | ||||
-rw-r--r-- | src/net/cbaines/suma/FavouriteDialog.java | 133 | ||||
-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.java | 42 |
6 files changed, 116 insertions, 194 deletions
diff --git a/gen/net/cbaines/suma/R.java b/gen/net/cbaines/suma/R.java index c08b7d0..130b154 100644 --- a/gen/net/cbaines/suma/R.java +++ b/gen/net/cbaines/suma/R.java @@ -71,16 +71,16 @@ public final class R { public static final int donateDialogMessageLayout=0x7f0a0017; public static final int donateDialogProgress=0x7f0a0016; public static final int favouriteCheckBox=0x7f0a000d; - public static final int favouriteDialogMessage=0x7f0a001a; - public static final int favouriteListItems=0x7f0a001b; - public static final int findContentLayout=0x7f0a001d; - public static final int findListItems=0x7f0a001f; - public static final int findLoadBar=0x7f0a001e; + public static final int favouriteDialogMessage=0x7f0a001f; + public static final int favouriteListItems=0x7f0a0020; + public static final int findContentLayout=0x7f0a001b; + public static final int findListItems=0x7f0a001d; + public static final int findLoadBar=0x7f0a001c; public static final int helpExpandableListView=0x7f0a0002; public static final int layout_root=0x7f0a0004; public static final int linearLayout1=0x7f0a0007; public static final int linearLayout2=0x7f0a0014; - public static final int mapview=0x7f0a0020; + public static final int mapview=0x7f0a001e; public static final int menu_about=0x7f0a0028; public static final int menu_favourites=0x7f0a0029; public static final int menu_find=0x7f0a0024; @@ -95,7 +95,7 @@ public final class R { public static final int radio_u2=0x7f0a000a; public static final int radio_u6=0x7f0a000b; public static final int radio_u9=0x7f0a000c; - public static final int searchBar=0x7f0a001c; + public static final int searchBar=0x7f0a001a; public static final int textView1=0x7f0a0000; public static final int textView2=0x7f0a0001; public static final int view_list=0x7f0a0023; @@ -105,9 +105,9 @@ public final class R { public static final int bus_stop_dialog=0x7f030001; public static final int bustimes=0x7f030002; public static final int donate_dialog=0x7f030003; - public static final int favourite_dialog=0x7f030004; - public static final int find=0x7f030005; - public static final int main=0x7f030006; + public static final int find=0x7f030004; + public static final int main=0x7f030005; + public static final int poi_dialog=0x7f030006; public static final int view_child_row=0x7f030007; public static final int view_dialog=0x7f030008; public static final int view_group_row=0x7f030009; diff --git a/res/layout/favourite_dialog.xml b/res/layout/poi_dialog.xml index 44cb02a..44cb02a 100644 --- a/res/layout/favourite_dialog.xml +++ b/res/layout/poi_dialog.xml 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; } |