From b374a50fb6f3bd0866bc1f75f7592abb0a6b8cc1 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sat, 18 Feb 2012 20:38:19 +0000 Subject: Fixed a bug in the constructor of BusRoute, and rebuild the database acordingly. Also made improvements to the preferences system. --- src/net/cbaines/suma/ViewDialog.java | 127 +++++++++++++++-------------------- 1 file changed, 53 insertions(+), 74 deletions(-) (limited to 'src/net/cbaines/suma/ViewDialog.java') diff --git a/src/net/cbaines/suma/ViewDialog.java b/src/net/cbaines/suma/ViewDialog.java index a8e36ed..432fec1 100644 --- a/src/net/cbaines/suma/ViewDialog.java +++ b/src/net/cbaines/suma/ViewDialog.java @@ -19,9 +19,6 @@ package net.cbaines.suma; -import java.sql.SQLException; -import java.util.ArrayList; - import android.app.Dialog; import android.content.Context; import android.content.SharedPreferences; @@ -37,8 +34,6 @@ import android.widget.ExpandableListView; import android.widget.ExpandableListView.OnChildClickListener; import android.widget.TextView; -import com.j256.ormlite.android.apptools.OpenHelperManager; - class ViewDialog extends Dialog implements OnChildClickListener { private final ExpandableListView epView; @@ -49,8 +44,6 @@ class ViewDialog extends Dialog implements OnChildClickListener { private OnChildClickListener listener; - private DatabaseHelper helper; - private String[] busRoutes; private String[] buildingTypes; private String[] other; @@ -64,31 +57,12 @@ class ViewDialog extends Dialog implements OnChildClickListener { this.context = context; - helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); - - int size; - try { - size = (int) helper.getSiteDao().countOf(); - - ArrayList sites = new ArrayList(size); - - try { - sites.addAll(helper.getSiteDao().queryForAll()); - } catch (SQLException e) { - e.printStackTrace(); - } - siteNames = new String[size]; - for (int i = 0; i < size; i++) { - siteNames[i] = sites.get(i).name; - } - } catch (SQLException e1) { - e1.printStackTrace(); - } - busRoutes = context.getResources().getStringArray(R.array.uniLinkBusRoutes); buildingTypes = context.getResources().getStringArray(R.array.buildingTypes); other = context.getResources().getStringArray(R.array.utilityOverlays); groupHeadings = context.getResources().getStringArray(R.array.preferencesHeadings); + siteNames = MapActivity.SITE_NAMES; // TODO: Temp hack, should be included in the strings res for translation + // purposes? setContentView(R.layout.view_dialog); setTitle("Select the map elements to display"); @@ -118,46 +92,46 @@ class ViewDialog extends Dialog implements OnChildClickListener { private static final String TAG = "MyExpandableListAdapter"; - // Bus Stops (0) - // |_ U1 (0:0) - // |_ U1N (0:1) - // |_ U2 (0:2) - // |_ U6 (0:3) - // |_ U9 (0:4) - // Bus Routes (1) - // |_ U1 (1:0) - // |_ U1N (1:1) - // |_ U2 (1:2) - // |_ U6 (1:3) - // |_ U9 (1:4) - // Buildings (2) - // |_ Residential (2:0) - // |_ Non-Residential (2:1) - // Site Outlines (3) - // |_ Highfield Campus (3:0) - // |_ Boldrewood Campus (3:1) - // |_ Avenue Campus (3:2) - // |_ Winchester School of Art (3:3) - // |_ The University of Southampton Science Park (3:4) - // |_ National Oceanography Centre Campus (3:5) - // |_ Boat House (3:6) - // |_ Southampton General Hospital (3:0) - // |_ Royal South Hants Hospital (3:0) - // |_ Belgrave Industrial Site (3:0) - // |_ Highfield Hall (3:0) - // |_ Glen Eyre Hall (3:0) - // |_ South Hill Hall (3:0) - // |_ Chamberlain Hall (3:0) - // |_ Hartley Grove1 (3:0) - // |_ Bencraft Hall (3:0) - // |_ Connaught Hall (3:0) - // |_ Montefiore Hall (3:0) - // |_ Stoneham Hall (3:0) - // |_ Erasmus Park (3:0) - // Other (4) - // |_ Scale Bar (4:0) - // |_ Compass (4:1) - // |_ My Location (4:2) + // Bus Stops + // |_ U1 + // |_ U1N + // |_ U2 + // |_ U6 + // |_ U9 + // Bus Routes + // |_ U1 + // |_ U1N + // |_ U2 + // |_ U6 + // |_ U9 + // Buildings + // |_ Residential + // |_ Non-Residential + // Site Outlines + // |_ Highfield Campus + // |_ Boldrewood Campus + // |_ Avenue Campus + // |_ Winchester School of Art + // |_ The University of Southampton Science Park + // |_ National Oceanography Centre Campus + // |_ Boat House + // |_ Southampton General Hospital + // |_ Royal South Hants Hospital + // |_ Belgrave Industrial Site + // |_ Highfield Hall + // |_ Glen Eyre Hall + // |_ South Hill Hall + // |_ Chamberlain Hall + // |_ Hartley Grove + // |_ Bencraft Hall + // |_ Connaught Hall + // |_ Montefiore Hall + // |_ Stoneham Hall + // |_ Erasmus Park + // Other + // |_ Scale Bar + // |_ Compass + // |_ My Location MyExpandableListAdapter(Context context) { inflater = LayoutInflater.from(context); @@ -182,7 +156,8 @@ class ViewDialog extends Dialog implements OnChildClickListener { return groupPosition * 50 + childPosition; } - public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { + public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, + ViewGroup parent) { View v = null; if (convertView != null) v = convertView; @@ -200,17 +175,20 @@ class ViewDialog extends Dialog implements OnChildClickListener { } SharedPreferences activityPrefs = context.getPreferences(0); - String str = groupPosition + ":" + childPosition; + String str = MapActivity.PREFERENCES_GROUPS[groupPosition] + + MapActivity.PREFERENCES_CHILDREN[groupPosition][childPosition]; if (groupPosition == 0) { cb.setChecked(activityPrefs.getBoolean(str, MapActivity.UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); } else if (groupPosition == 1) { - cb.setChecked(activityPrefs.getBoolean(str, MapActivity.ROUTE_OVERLAYS_ENABLED_BY_DEFAULT)); + cb.setChecked(activityPrefs.getBoolean(str, MapActivity.BUS_ROUTE_OVERLAYS_ENABLED_BY_DEFAULT)); } else if (groupPosition == 2) { if (childPosition == 0) { - cb.setChecked(activityPrefs.getBoolean(str, MapActivity.RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT)); + cb.setChecked(activityPrefs.getBoolean(str, + MapActivity.RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT)); } else { - cb.setChecked(activityPrefs.getBoolean(str, MapActivity.NON_RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT)); + cb.setChecked(activityPrefs.getBoolean(str, + MapActivity.NON_RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT)); } } else if (groupPosition == 3) { cb.setChecked(activityPrefs.getBoolean(str, MapActivity.SITE_OVERLAYS_ENABLED_BY_DEFAULT)); @@ -277,7 +255,8 @@ class ViewDialog extends Dialog implements OnChildClickListener { CheckBox cb = (CheckBox) v.findViewById(R.id.check1); - String str = groupPosition + ":" + childPosition; + String str = MapActivity.PREFERENCES_GROUPS[groupPosition] + + MapActivity.PREFERENCES_CHILDREN[groupPosition][childPosition]; editor.putBoolean(str, !cb.isChecked()); -- cgit v1.2.3