Departure listing adapts to screen size

This commit is contained in:
Doug Keen 2013-03-25 12:48:46 -07:00
parent fcc9f2ba21
commit b652b491bd
5 changed files with 139 additions and 40 deletions

View File

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:height="45dp" android:width="15dp" />
android:shape="rectangle" >
<size android:width="15dp" />
</shape>

View File

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bart="http://schemas.android.com/apk/res/com.dougkeen.bart"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/destinationColorBar"
android:layout_width="wrap_content"
android:layout_height="64dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/basic_rectangle" />
<LinearLayout
android:id="@+id/topRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/destinationColorBar" >
<TextView
android:id="@+id/destinationText"
style="@style/DepartureDestinationText"
android:layout_weight="1"
android:ellipsize="marquee"
android:singleLine="true" />
<ImageView
android:id="@+id/bikeIcon"
style="@style/BikeIcon" />
<com.dougkeen.bart.controls.CountdownTextView
android:id="@+id/countdown"
style="@style/DepartureCountdownText"
android:gravity="right"
android:width="90dp"
bart:tickInterval="1" />
</LinearLayout>
<ImageView
android:id="@+id/xferIcon"
style="@style/XferIcon"
android:layout_alignParentRight="true"
android:layout_below="@id/topRow"
android:src="@drawable/xfer" />
<TextView
android:id="@+id/trainLengthText"
style="@style/DepartureUncertaintyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/topRow"
android:layout_toRightOf="@id/destinationColorBar" />
<TextView
android:id="@+id/uncertainty"
style="@style/DepartureUncertaintyText"
android:layout_alignParentRight="true"
android:layout_below="@id/topRow" />
<TextView
android:id="@+id/estimatedArrival"
style="@style/DepartureUncertaintyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/trainLengthText"
android:layout_toRightOf="@id/destinationColorBar" />
<TextView
android:id="@+id/departureTime"
style="@style/DepartureUncertaintyText"
android:layout_alignParentRight="true"
android:layout_below="@id/uncertainty" />
</merge>

View File

@ -7,7 +7,7 @@
<ImageView
android:id="@+id/destinationColorBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/basic_rectangle" />

View File

@ -28,7 +28,7 @@
<ImageView
android:id="@+id/yourTrainDestinationColorBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_below="@id/yourTrainHeader"
android:src="@drawable/basic_rectangle" />

View File

@ -89,37 +89,48 @@ public class DepartureArrayAdapter extends ArrayAdapter<Departure> {
((TextView) view.findViewById(R.id.destinationText)).setText(departure
.getTrainDestination().toString());
TimedTextSwitcher textSwitcher = (TimedTextSwitcher) view
.findViewById(R.id.trainLengthText);
initTextSwitcher(textSwitcher, R.layout.train_length_arrival_textview);
final String arrivesAtDestinationPrefix = getContext().getString(
R.string.arrives_at_destination);
final String estimatedArrivalTimeText = departure
.getEstimatedArrivalTimeText(getContext());
if (!StringUtils.isBlank(estimatedArrivalTimeText)) {
textSwitcher.setCurrentText(arrivesAtDestinationPrefix
TextView estimatedArrival = (TextView) view
.findViewById(R.id.estimatedArrival);
if (estimatedArrival != null) {
((TextView) view.findViewById(R.id.trainLengthText))
.setText(departure.getTrainLengthText());
estimatedArrival.setText(arrivesAtDestinationPrefix
+ estimatedArrivalTimeText);
} else {
textSwitcher.setCurrentText(departure.getTrainLengthText());
}
textSwitcher.setTextProvider(new TextProvider() {
@Override
public String getText(long tickNumber) {
if (tickNumber % 4 == 0) {
return departure.getTrainLengthText();
} else {
final String estimatedArrivalTimeText = departure
.getEstimatedArrivalTimeText(getContext());
if (StringUtils.isBlank(estimatedArrivalTimeText)) {
return "";
TimedTextSwitcher textSwitcher = (TimedTextSwitcher) view
.findViewById(R.id.trainLengthText);
initTextSwitcher(textSwitcher,
R.layout.train_length_arrival_textview);
if (!StringUtils.isBlank(estimatedArrivalTimeText)) {
textSwitcher.setCurrentText(arrivesAtDestinationPrefix
+ estimatedArrivalTimeText);
} else {
textSwitcher.setCurrentText(departure.getTrainLengthText());
}
textSwitcher.setTextProvider(new TextProvider() {
@Override
public String getText(long tickNumber) {
if (tickNumber % 4 == 0) {
return departure.getTrainLengthText();
} else {
return arrivesAtDestinationPrefix
+ estimatedArrivalTimeText;
final String estimatedArrivalTimeText = departure
.getEstimatedArrivalTimeText(getContext());
if (StringUtils.isBlank(estimatedArrivalTimeText)) {
return "";
} else {
return arrivesAtDestinationPrefix
+ estimatedArrivalTimeText;
}
}
}
}
});
});
}
ImageView colorBar = (ImageView) view
.findViewById(R.id.destinationColorBar);
@ -135,21 +146,31 @@ public class DepartureArrayAdapter extends ArrayAdapter<Departure> {
}
});
TimedTextSwitcher uncertaintySwitcher = (TimedTextSwitcher) view
.findViewById(R.id.uncertainty);
initTextSwitcher(uncertaintySwitcher, R.layout.uncertainty_textview);
TextView departureTime = (TextView) view
.findViewById(R.id.departureTime);
uncertaintySwitcher.setTextProvider(new TextProvider() {
@Override
public String getText(long tickNumber) {
if (tickNumber % 4 == 0) {
return departure.getUncertaintyText();
} else {
return departure
.getEstimatedDepartureTimeText(getContext());
if (departureTime != null) {
((TextView) view.findViewById(R.id.uncertainty)).setText(departure
.getUncertaintyText());
departureTime.setText(departure
.getEstimatedDepartureTimeText(getContext()));
} else {
TimedTextSwitcher uncertaintySwitcher = (TimedTextSwitcher) view
.findViewById(R.id.uncertainty);
initTextSwitcher(uncertaintySwitcher, R.layout.uncertainty_textview);
uncertaintySwitcher.setTextProvider(new TextProvider() {
@Override
public String getText(long tickNumber) {
if (tickNumber % 4 == 0) {
return departure.getUncertaintyText();
} else {
return departure
.getEstimatedDepartureTimeText(getContext());
}
}
}
});
});
}
ImageView bikeIcon = (ImageView) view.findViewById(R.id.bikeIcon);
if (departure.isBikeAllowed()) {