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;
|
2012-04-13 01:07:55 +00:00
|
|
|
import android.view.animation.AnimationUtils;
|
2011-05-27 21:06:58 +00:00
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.RelativeLayout;
|
2012-04-13 01:07:55 +00:00
|
|
|
import android.widget.TextSwitcher;
|
2011-05-27 21:06:58 +00:00
|
|
|
import android.widget.TextView;
|
2012-04-13 01:07:55 +00:00
|
|
|
import android.widget.ViewSwitcher.ViewFactory;
|
2011-05-27 21:06:58 +00:00
|
|
|
|
2012-04-13 01:07:55 +00:00
|
|
|
import com.dougkeen.bart.model.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);
|
|
|
|
}
|
|
|
|
|
2012-04-13 01:07:55 +00:00
|
|
|
private String currentViewSwitcherText;
|
|
|
|
|
2011-05-27 21:06:58 +00:00
|
|
|
@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());
|
2012-04-13 01:07:55 +00:00
|
|
|
|
|
|
|
TextSwitcher textSwitcher = (TextSwitcher) view
|
|
|
|
.findViewById(R.id.trainLengthText);
|
|
|
|
initTextSwitcher(textSwitcher);
|
|
|
|
|
|
|
|
if (System.currentTimeMillis() % 6000 > 3000) {
|
|
|
|
String trainLengthText = departure.getTrainLengthText();
|
|
|
|
if (currentViewSwitcherText == null
|
|
|
|
|| !currentViewSwitcherText.equals(trainLengthText)) {
|
|
|
|
textSwitcher.setText(trainLengthText);
|
|
|
|
currentViewSwitcherText = trainLengthText;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
String arrivalText = "Est. arrival "
|
|
|
|
+ departure.getEstimatedArrivalTimeText(getContext());
|
|
|
|
if (currentViewSwitcherText == null
|
|
|
|
|| !currentViewSwitcherText.equals(arrivalText)) {
|
|
|
|
textSwitcher.setText(arrivalText);
|
|
|
|
currentViewSwitcherText = arrivalText;
|
|
|
|
}
|
|
|
|
}
|
2011-05-27 21:06:58 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-04-13 01:07:55 +00:00
|
|
|
private void initTextSwitcher(TextSwitcher textSwitcher) {
|
|
|
|
if (textSwitcher.getInAnimation() == null) {
|
|
|
|
textSwitcher.setFactory(new ViewFactory() {
|
|
|
|
public View makeView() {
|
|
|
|
return LayoutInflater.from(getContext()).inflate(
|
|
|
|
R.layout.train_length_arrival_textview, null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
textSwitcher.setInAnimation(AnimationUtils.loadAnimation(
|
|
|
|
getContext(), android.R.anim.slide_in_left));
|
|
|
|
textSwitcher.setOutAnimation(AnimationUtils.loadAnimation(
|
|
|
|
getContext(), android.R.anim.slide_out_right));
|
|
|
|
}
|
|
|
|
}
|
2011-05-27 21:06:58 +00:00
|
|
|
}
|