2011-05-27 21:06:58 +00:00
|
|
|
package com.dougkeen.bart;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
2012-04-13 22:05:30 +00:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
2011-05-27 21:06:58 +00:00
|
|
|
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-07-17 20:43:42 +00:00
|
|
|
import com.dougkeen.bart.controls.CountdownTextView;
|
|
|
|
import com.dougkeen.bart.controls.TimedTextSwitcher;
|
2012-04-13 01:07:55 +00:00
|
|
|
import com.dougkeen.bart.model.Departure;
|
2012-07-17 20:43:42 +00:00
|
|
|
import com.dougkeen.bart.model.TextProvider;
|
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
|
|
|
}
|
|
|
|
|
2012-07-17 20:43:42 +00:00
|
|
|
final Departure departure = getItem(position);
|
2011-06-05 18:13:21 +00:00
|
|
|
((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
|
|
|
|
2012-07-17 20:43:42 +00:00
|
|
|
TimedTextSwitcher textSwitcher = (TimedTextSwitcher) view
|
2012-04-13 01:07:55 +00:00
|
|
|
.findViewById(R.id.trainLengthText);
|
|
|
|
initTextSwitcher(textSwitcher);
|
|
|
|
|
2012-07-17 20:43:42 +00:00
|
|
|
textSwitcher.setCurrentText(departure.getTrainLengthText());
|
2012-09-07 05:47:27 +00:00
|
|
|
textSwitcher.setTextProvider(new TextProvider() {
|
2012-07-17 20:43:42 +00:00
|
|
|
@Override
|
2012-09-07 05:47:27 +00:00
|
|
|
public String getText(long tickNumber) {
|
|
|
|
if (tickNumber % 4 == 0) {
|
|
|
|
return departure.getTrainLengthText();
|
2012-07-17 20:43:42 +00:00
|
|
|
} else {
|
2012-09-07 05:47:27 +00:00
|
|
|
final String estimatedArrivalTimeText = departure
|
|
|
|
.getEstimatedArrivalTimeText(getContext());
|
|
|
|
if (StringUtils.isBlank(estimatedArrivalTimeText)) {
|
|
|
|
return "";
|
|
|
|
} else {
|
|
|
|
return "Est. arrival " + estimatedArrivalTimeText;
|
|
|
|
}
|
2012-07-17 20:43:42 +00:00
|
|
|
}
|
2012-04-13 01:07:55 +00:00
|
|
|
}
|
2012-09-07 05:47:27 +00:00
|
|
|
});
|
2012-07-17 20:43:42 +00:00
|
|
|
|
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()));
|
2012-07-17 20:43:42 +00:00
|
|
|
CountdownTextView countdownTextView = (CountdownTextView) view
|
|
|
|
.findViewById(R.id.countdown);
|
|
|
|
countdownTextView.setText(departure.getCountdownText());
|
|
|
|
countdownTextView.setTextProvider(new TextProvider() {
|
|
|
|
@Override
|
2012-09-07 05:47:27 +00:00
|
|
|
public String getText(long tickNumber) {
|
2012-07-17 20:43:42 +00:00
|
|
|
return departure.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(
|
2012-07-17 20:43:42 +00:00
|
|
|
getContext(), android.R.anim.slide_in_left));
|
|
|
|
textSwitcher.setOutAnimation(AnimationUtils.loadAnimation(
|
|
|
|
getContext(), android.R.anim.slide_out_right));
|
2012-04-13 01:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-27 21:06:58 +00:00
|
|
|
}
|