2011-05-27 21:06:58 +00:00
|
|
|
package com.dougkeen.bart;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Color;
|
|
|
|
import android.graphics.drawable.GradientDrawable;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2011-06-05 18:13:21 +00:00
|
|
|
import com.dougkeen.bart.data.Departure;
|
2011-05-27 21:06:58 +00:00
|
|
|
|
2011-06-05 18:13:21 +00:00
|
|
|
public class DepartureArrayAdapter extends ArrayAdapter<Departure> {
|
2011-05-27 21:06:58 +00:00
|
|
|
|
2011-06-05 18:13:21 +00:00
|
|
|
public DepartureArrayAdapter(Context context, int textViewResourceId,
|
|
|
|
Departure[] objects) {
|
2011-05-27 21:06:58 +00:00
|
|
|
super(context, textViewResourceId, objects);
|
|
|
|
}
|
|
|
|
|
2011-06-05 18:13:21 +00:00
|
|
|
public DepartureArrayAdapter(Context context, int resource,
|
|
|
|
int textViewResourceId, Departure[] objects) {
|
2011-05-27 21:06:58 +00:00
|
|
|
super(context, resource, textViewResourceId, objects);
|
|
|
|
}
|
|
|
|
|
2011-06-05 18:13:21 +00:00
|
|
|
public DepartureArrayAdapter(Context context, int resource,
|
|
|
|
int textViewResourceId, List<Departure> objects) {
|
2011-05-27 21:06:58 +00:00
|
|
|
super(context, resource, textViewResourceId, objects);
|
|
|
|
}
|
|
|
|
|
2011-06-05 18:13:21 +00:00
|
|
|
public DepartureArrayAdapter(Context context, int resource,
|
2011-05-27 21:06:58 +00:00
|
|
|
int textViewResourceId) {
|
|
|
|
super(context, resource, textViewResourceId);
|
|
|
|
}
|
|
|
|
|
2011-06-05 18:13:21 +00:00
|
|
|
public DepartureArrayAdapter(Context context, int textViewResourceId,
|
|
|
|
List<Departure> objects) {
|
2011-05-27 21:06:58 +00:00
|
|
|
super(context, textViewResourceId, objects);
|
|
|
|
}
|
|
|
|
|
2011-06-05 18:13:21 +00:00
|
|
|
public DepartureArrayAdapter(Context context, int textViewResourceId) {
|
2011-05-27 21:06:58 +00:00
|
|
|
super(context, textViewResourceId);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
|
View view;
|
|
|
|
if (convertView != null && convertView instanceof RelativeLayout) {
|
|
|
|
view = convertView;
|
|
|
|
} else {
|
|
|
|
LayoutInflater inflater = LayoutInflater.from(getContext());
|
2011-06-05 18:13:21 +00:00
|
|
|
view = inflater.inflate(R.layout.departure_listing, parent, false);
|
2011-05-27 21:06:58 +00:00
|
|
|
}
|
|
|
|
|
2011-06-05 18:13:21 +00:00
|
|
|
Departure departure = getItem(position);
|
|
|
|
((TextView) view.findViewById(R.id.destinationText)).setText(departure
|
2011-05-27 21:06:58 +00:00
|
|
|
.getDestination().toString());
|
2011-06-05 18:13:21 +00:00
|
|
|
((TextView) view.findViewById(R.id.trainLengthText)).setText(departure
|
2011-05-27 21:06:58 +00:00
|
|
|
.getTrainLengthText());
|
|
|
|
ImageView colorBar = (ImageView) view
|
|
|
|
.findViewById(R.id.destinationColorBar);
|
|
|
|
((GradientDrawable) colorBar.getDrawable()).setColor(Color
|
2011-06-05 18:13:21 +00:00
|
|
|
.parseColor(departure.getDestinationColor()));
|
|
|
|
((TextView) view.findViewById(R.id.countdown)).setText(departure
|
2011-05-27 21:06:58 +00:00
|
|
|
.getCountdownText());
|
2011-06-05 18:13:21 +00:00
|
|
|
((TextView) view.findViewById(R.id.uncertainty)).setText(departure
|
2011-05-27 21:06:58 +00:00
|
|
|
.getUncertaintyText());
|
2011-06-05 18:13:21 +00:00
|
|
|
if (departure.isBikeAllowed()) {
|
2011-05-27 21:06:58 +00:00
|
|
|
((ImageView) view.findViewById(R.id.bikeIcon))
|
|
|
|
.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
((ImageView) view.findViewById(R.id.bikeIcon))
|
|
|
|
.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
2011-06-05 18:13:21 +00:00
|
|
|
if (departure.getRequiresTransfer()) {
|
2011-05-27 21:06:58 +00:00
|
|
|
((ImageView) view.findViewById(R.id.xferIcon))
|
|
|
|
.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
((ImageView) view.findViewById(R.id.xferIcon))
|
|
|
|
.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|