aboutsummaryrefslogtreecommitdiff
path: root/src/net/cbaines/suma/POIView.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/cbaines/suma/POIView.java')
-rw-r--r--src/net/cbaines/suma/POIView.java165
1 files changed, 91 insertions, 74 deletions
diff --git a/src/net/cbaines/suma/POIView.java b/src/net/cbaines/suma/POIView.java
index fb8a6c6..95c571c 100644
--- a/src/net/cbaines/suma/POIView.java
+++ b/src/net/cbaines/suma/POIView.java
@@ -20,6 +20,7 @@
package net.cbaines.suma;
import android.content.Context;
+import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
@@ -27,98 +28,114 @@ import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
-public class POIView extends LinearLayout {
+public class POIView extends LinearLayout implements Preferences {
- private final static String TAG = "POIView";
+ private final static String TAG = "POIView";
- private final TextView name;
- private final TextView dist;
- private final BusRoutesView routes;
+ private final TextView name;
+ private final TextView dist;
+ private final BusRoutesView routes;
- private LayoutParams textLayoutParams;
+ private LayoutParams textLayoutParams;
- final int width;
+ private boolean identifiersEnabled;
- public POIView(Context context, POI poi) {
- this(context, poi, -1);
- }
+ final int width;
- public POIView(Context context, POI poi, int distInM) {
- super(context);
-
- Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
- width = display.getWidth();
- // int height = display.getHeight();
-
- this.setOrientation(HORIZONTAL);
-
- name = new TextView(context);
- name.setTextSize(16f);
- name.setGravity(Gravity.LEFT);
-
- dist = new TextView(context);
- dist.setTextSize(16f);
- dist.setGravity(Gravity.RIGHT);
-
- routes = new BusRoutesView(context, (byte) 0);
-
- textLayoutParams = new LayoutParams(width - (width / 4), LayoutParams.WRAP_CONTENT);
- LayoutParams distLayoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
- LayoutParams busRouteLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
-
- setPOIAndDist(poi, distInM);
-
- addView(routes, busRouteLayoutParams);
- addView(name, textLayoutParams);
- addView(dist, distLayoutParams);
- }
-
- public void setPOI(POI poi) {
- setPOIAndDist(poi, -1);
- }
-
- public void setPOIAndDist(POI poi, int distInM) {
+ public POIView(Context context, POI poi) {
+ this(context, poi, -1);
+ }
- // Log.i(TAG, "Looking at poi " + poi.id);
+ public POIView(Context context, POI poi, int distInM) {
+ super(context);
- if (poi.type == POI.BUILDING) {
- Building building = (Building) poi;
- // Log.i(TAG, "Its a building of name " + building.name);
+ identifiersEnabled = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SHOW_IDENTIFIERS,
+ SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT);
- name.setText(building.name + " (" + building.id + ")");
- } else if (poi.type == POI.BUS_STOP) {
+ Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
+ width = display.getWidth();
+ // int height = display.getHeight();
- BusStop busStop = (BusStop) poi;
- // Log.i(TAG, "Its a bus stop of description " + busStop.description);
+ this.setOrientation(HORIZONTAL);
- name.setText(busStop.description + " (" + busStop.id + ")");
+ name = new TextView(context);
+ name.setTextSize(16f);
+ name.setGravity(Gravity.LEFT);
- routes.setRoutes(busStop.routes);
+ dist = new TextView(context);
+ dist.setTextSize(16f);
+ dist.setGravity(Gravity.RIGHT);
- } else if (poi.type == POI.SITE) {
+ routes = new BusRoutesView(context, (byte) 0);
- Site site = (Site) poi;
- // Log.i(TAG, "Its a site of name " + site.name);
+ textLayoutParams = new LayoutParams(width - (width / 4), LayoutParams.WRAP_CONTENT);
+ LayoutParams distLayoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
+ LayoutParams busRouteLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
- name.setText(site.name + " (" + site.id + ")");
- } else {
- Log.w(TAG, "Cant identify " + poi.type);
+ setPOIAndDist(poi, distInM);
- name.setText(poi.id);
+ addView(routes, busRouteLayoutParams);
+ addView(name, textLayoutParams);
+ addView(dist, distLayoutParams);
}
- textLayoutParams = new LayoutParams(width - (width / 4), LayoutParams.WRAP_CONTENT);
-
- if (distInM != -1) {
- textLayoutParams.width = width - (width / 4);
- name.requestLayout();
- dist.setText(String.valueOf(distInM) + "m");
- } else {
- textLayoutParams.width = LayoutParams.FILL_PARENT;
- name.requestLayout();
- dist.setText("");
- // Log.w("POIView", "No dist avalible for S" + poi.id);
+ public void setPOI(POI poi) {
+ setPOIAndDist(poi, -1);
}
- }
+ public void setPOIAndDist(POI poi, int distInM) {
+
+ // Log.i(TAG, "Looking at poi " + poi.id);
+
+ if (poi.type == POI.BUILDING) {
+ Building building = (Building) poi;
+ // Log.i(TAG, "Its a building of name " + building.name);
+
+ if (identifiersEnabled) {
+ name.setText(building.name + " (" + building.id + ")");
+ } else {
+ name.setText(building.name);
+ }
+ } else if (poi.type == POI.BUS_STOP) {
+
+ BusStop busStop = (BusStop) poi;
+ // Log.i(TAG, "Its a bus stop of description " +
+ // busStop.description);
+
+ if (identifiersEnabled) {
+ name.setText(busStop.description + " (" + busStop.id + ")");
+ } else {
+ name.setText(busStop.description);
+ }
+
+ routes.setRoutes(busStop.routes);
+
+ } else if (poi.type == POI.SITE) {
+
+ Site site = (Site) poi;
+ // Log.i(TAG, "Its a site of name " + site.name);
+ if (identifiersEnabled) {
+ name.setText(site.name + " (" + site.id + ")");
+ } else {
+ name.setText(site.name);
+ }
+ } else {
+ Log.w(TAG, "Cant identify " + poi.type);
+
+ name.setText(poi.id);
+ }
+
+ textLayoutParams = new LayoutParams(width - (width / 4), LayoutParams.WRAP_CONTENT);
+
+ if (distInM != -1) {
+ textLayoutParams.width = width - (width / 4);
+ name.requestLayout();
+ dist.setText(String.valueOf(distInM) + "m");
+ } else {
+ textLayoutParams.width = LayoutParams.FILL_PARENT;
+ name.requestLayout();
+ dist.setText("");
+ // Log.w("POIView", "No dist avalible for S" + poi.id);
+ }
+ }
} \ No newline at end of file