aboutsummaryrefslogtreecommitdiff
path: root/src/net/cbaines/suma/POIView.java
blob: d312f376d66a2c88af88aa58eb71bca97b7625c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 * 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 android.content.Context;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.TableLayout.LayoutParams;

public class POIView extends LinearLayout {

    private final static String TAG = "POIView";

    private final TextView name;
    private final TextView dist;
    private final BusRoutesView routes;

    private LayoutParams textLayoutParams;

    final int width;

    public POIView(Context context, POI poi) {
	this(context, poi, -1);
    }

    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) {

	// 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);

	    name.setText(building.name + " (" + building.id + ")");
	} else if (poi.type == POI.BUS_STOP) {

	    BusStop busStop = (BusStop) poi;
	    // Log.i(TAG, "Its a bus stop of description " + busStop.description);

	    name.setText(busStop.description + " (" + busStop.id + ")");

	    routes.setRoutes(busStop.routes);

	} else if (poi.type == POI.SITE) {

	    Site site = (Site) poi;
	    // Log.i(TAG, "Its a site of name " + site.name);

	    name.setText(site.name + " (" + site.id + ")");
	} 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);
	}
    }

}