From 2481f0c229c4c3b280b254beced25bb6ec58bab0 Mon Sep 17 00:00:00 2001 From: Danny Weinberg Date: Wed, 12 Aug 2015 07:41:16 -0700 Subject: [PATCH] Reorganize the your_train and departure_listing layouts (and corresponding custom views) for easier editing, greater flexibility for different screens, and to fix a layout bug that was introduced when updating the libraries where the "Your Train" section would be too wide. General code cleanup, warnings fixes, and readability improvements. --- .../activities/ViewDeparturesActivity.java | 18 +- .../bart/controls/CheckableLinearLayout.java | 46 +++++ .../controls/DepartureListItemLayout.java | 42 ----- .../bart/controls/TimedTextSwitcher.java | 3 +- .../bart/controls/YourTrainLayout.java | 90 +++++----- .../bart/data/DepartureArrayAdapter.java | 78 +++------ .../com/dougkeen/bart/model/Departure.java | 52 +++--- .../services/BoardedDepartureService.java | 9 +- .../main/java/com/dougkeen/util/Assert.java | 13 ++ .../res/layout-h480dp/departure_listing.xml | 138 +++++++++------ app/src/main/res/layout/departure_listing.xml | 112 +++++++----- app/src/main/res/layout/your_train.xml | 161 +++++++++++------- app/src/main/res/values/styles.xml | 12 +- 13 files changed, 424 insertions(+), 350 deletions(-) create mode 100644 app/src/main/java/com/dougkeen/bart/controls/CheckableLinearLayout.java delete mode 100644 app/src/main/java/com/dougkeen/bart/controls/DepartureListItemLayout.java create mode 100644 app/src/main/java/com/dougkeen/util/Assert.java diff --git a/app/src/main/java/com/dougkeen/bart/activities/ViewDeparturesActivity.java b/app/src/main/java/com/dougkeen/bart/activities/ViewDeparturesActivity.java index a8bf3e2..3adfdd1 100644 --- a/app/src/main/java/com/dougkeen/bart/activities/ViewDeparturesActivity.java +++ b/app/src/main/java/com/dougkeen/bart/activities/ViewDeparturesActivity.java @@ -17,6 +17,7 @@ import android.os.Handler; import android.os.IBinder; import android.os.Parcelable; import android.os.Vibrator; +import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.view.ActionMode; import android.text.format.DateFormat; @@ -48,6 +49,7 @@ import com.dougkeen.bart.services.EtdService; import com.dougkeen.bart.services.EtdService.EtdServiceBinder; import com.dougkeen.bart.services.EtdService.EtdServiceListener; import com.dougkeen.bart.services.EtdService_; +import com.dougkeen.util.Assert; import com.dougkeen.util.Observer; import com.dougkeen.util.WakeLocker; @@ -86,8 +88,7 @@ public class ViewDeparturesActivity extends AppCompatActivity implements mProgress = (ProgressBar) findViewById(android.R.id.progress); - mDeparturesAdapter = new DepartureArrayAdapter(this, - R.layout.departure_listing); + mDeparturesAdapter = new DepartureArrayAdapter(this); setListAdapter(mDeparturesAdapter); final ListView listView = getListView(); @@ -127,9 +128,9 @@ public class ViewDeparturesActivity extends AppCompatActivity implements } if (savedInstanceState != null) { - if (savedInstanceState.containsKey("departures")) { - for (Parcelable departure : savedInstanceState - .getParcelableArray("departures")) { + Parcelable[] departuresArray = savedInstanceState.getParcelableArray("departures"); + if (departuresArray != null) { + for (Parcelable departure : departuresArray) { mDeparturesAdapter.add((Departure) departure); } mDeparturesAdapter.notifyDataSetChanged(); @@ -151,8 +152,9 @@ public class ViewDeparturesActivity extends AppCompatActivity implements } refreshBoardedDeparture(false); - getSupportActionBar().setHomeButtonEnabled(true); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); + ActionBar supportActionBar = Assert.notNull(getSupportActionBar()); + supportActionBar.setHomeButtonEnabled(true); + supportActionBar.setDisplayHomeAsUpEnabled(true); if (bartRunnerApplication.shouldPlayAlarmRingtone()) { soundTheAlarm(); @@ -440,7 +442,7 @@ public class ViewDeparturesActivity extends AppCompatActivity implements return; } - mYourTrainSection.updateFromBoardedDeparture(); + mYourTrainSection.updateFromBoardedDeparture(boardedDeparture); if (currentVisibility != View.VISIBLE) { showYourTrainSection(animate); diff --git a/app/src/main/java/com/dougkeen/bart/controls/CheckableLinearLayout.java b/app/src/main/java/com/dougkeen/bart/controls/CheckableLinearLayout.java new file mode 100644 index 0000000..731c6fd --- /dev/null +++ b/app/src/main/java/com/dougkeen/bart/controls/CheckableLinearLayout.java @@ -0,0 +1,46 @@ +package com.dougkeen.bart.controls; + +import android.content.Context; +import android.support.v7.widget.LinearLayoutCompat; +import android.util.AttributeSet; +import android.widget.Checkable; + +import com.dougkeen.bart.R; + +/** + * A {@link android.widget.LinearLayout} that implements {@link Checkable} and changes + * its background color when checked. + */ +public class CheckableLinearLayout extends LinearLayoutCompat implements Checkable { + + private boolean mChecked; + + public CheckableLinearLayout(Context context) { + super(context); + } + + public CheckableLinearLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public CheckableLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Override + public boolean isChecked() { + return mChecked; + } + + @Override + public void setChecked(boolean checked) { + mChecked = checked; + int colorRes = isChecked() ? R.color.blue_selection : android.R.color.transparent; + setBackgroundResource(colorRes); + } + + @Override + public void toggle() { + setChecked(!isChecked()); + } +} diff --git a/app/src/main/java/com/dougkeen/bart/controls/DepartureListItemLayout.java b/app/src/main/java/com/dougkeen/bart/controls/DepartureListItemLayout.java deleted file mode 100644 index 04059d9..0000000 --- a/app/src/main/java/com/dougkeen/bart/controls/DepartureListItemLayout.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.dougkeen.bart.controls; - -import android.content.Context; -import android.view.LayoutInflater; -import android.widget.Checkable; -import android.widget.RelativeLayout; - -import com.dougkeen.bart.R; - -public class DepartureListItemLayout extends RelativeLayout implements - Checkable { - - public DepartureListItemLayout(Context context) { - super(context); - LayoutInflater.from(context).inflate(R.layout.departure_listing, this, - true); - } - - private boolean mChecked; - - @Override - public boolean isChecked() { - return mChecked; - } - - @Override - public void setChecked(boolean checked) { - mChecked = checked; - if (isChecked()) { - setBackgroundDrawable(getContext().getResources().getDrawable( - R.color.blue_selection)); - } else { - setBackgroundDrawable(getContext().getResources().getDrawable( - android.R.color.transparent)); - } - } - - @Override - public void toggle() { - setChecked(!isChecked()); - } -} diff --git a/app/src/main/java/com/dougkeen/bart/controls/TimedTextSwitcher.java b/app/src/main/java/com/dougkeen/bart/controls/TimedTextSwitcher.java index fc09f1e..a2d86eb 100644 --- a/app/src/main/java/com/dougkeen/bart/controls/TimedTextSwitcher.java +++ b/app/src/main/java/com/dougkeen/bart/controls/TimedTextSwitcher.java @@ -10,8 +10,7 @@ import android.widget.TextSwitcher; import com.dougkeen.bart.R; import com.dougkeen.bart.model.TextProvider; -public class TimedTextSwitcher extends TextSwitcher implements - Ticker.TickSubscriber { +public class TimedTextSwitcher extends TextSwitcher implements Ticker.TickSubscriber { public TimedTextSwitcher(Context context, AttributeSet attrs) { super(context, attrs); diff --git a/app/src/main/java/com/dougkeen/bart/controls/YourTrainLayout.java b/app/src/main/java/com/dougkeen/bart/controls/YourTrainLayout.java index d5d6ee4..59ca8ea 100644 --- a/app/src/main/java/com/dougkeen/bart/controls/YourTrainLayout.java +++ b/app/src/main/java/com/dougkeen/bart/controls/YourTrainLayout.java @@ -2,41 +2,51 @@ package com.dougkeen.bart.controls; import android.app.Activity; import android.content.Context; -import android.graphics.Color; -import android.graphics.drawable.GradientDrawable; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.Checkable; +import android.widget.FrameLayout; import android.widget.ImageView; -import android.widget.RelativeLayout; import android.widget.TextView; -import com.dougkeen.bart.BartRunnerApplication; import com.dougkeen.bart.R; import com.dougkeen.bart.model.Departure; import com.dougkeen.bart.model.TextProvider; import com.dougkeen.util.Observer; -public class YourTrainLayout extends RelativeLayout implements Checkable { +public class YourTrainLayout extends FrameLayout implements Checkable { + + private final TextView destinationText; + private final TextView trainLength; + private final View colorBar; + private final ImageView bikeIcon; + private final View xferIcon; + private final CountdownTextView departureCountdown; + private final CountdownTextView arrivalCountdown; + private final TextView alarmText; public YourTrainLayout(Context context) { - super(context); - assignLayout(context); + this(context, null); + } + + public YourTrainLayout(Context context, AttributeSet attrs) { + this(context, attrs, 0); } public YourTrainLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); - assignLayout(context); - } - public YourTrainLayout(Context context, AttributeSet attrs) { - super(context, attrs); - assignLayout(context); - } - - public void assignLayout(Context context) { LayoutInflater.from(context).inflate(R.layout.your_train, this, true); + + destinationText = (TextView) findViewById(R.id.yourTrainDestinationText); + trainLength = (TextView) findViewById(R.id.yourTrainTrainLengthText); + colorBar = findViewById(R.id.yourTrainDestinationColorBar); + bikeIcon = (ImageView) findViewById(R.id.yourTrainBikeIcon); + xferIcon = findViewById(R.id.yourTrainXferIcon); + departureCountdown = (CountdownTextView) findViewById(R.id.yourTrainDepartureCountdown); + arrivalCountdown = (CountdownTextView) findViewById(R.id.yourTrainArrivalCountdown); + alarmText = (TextView) findViewById(R.id.alarmText); } private boolean mChecked; @@ -75,13 +85,8 @@ public class YourTrainLayout extends RelativeLayout implements Checkable { } private void setBackground() { - if (isChecked()) { - setBackgroundDrawable(getContext().getResources().getDrawable( - R.color.blue_selection)); - } else { - setBackgroundDrawable(getContext().getResources().getDrawable( - R.color.gray)); - } + int colorRes = isChecked() ? R.color.blue_selection : R.color.gray; + setBackgroundResource(colorRes); } @Override @@ -89,11 +94,10 @@ public class YourTrainLayout extends RelativeLayout implements Checkable { setChecked(!isChecked()); } - public void updateFromBoardedDeparture() { - final Departure boardedDeparture = ((BartRunnerApplication) ((Activity) getContext()) - .getApplication()).getBoardedDeparture(); - if (boardedDeparture == null) + public void updateFromBoardedDeparture(final Departure boardedDeparture) { + if (boardedDeparture == null) { return; + } if (!boardedDeparture.equals(mDeparture)) { if (mDeparture != null) { @@ -110,36 +114,23 @@ public class YourTrainLayout extends RelativeLayout implements Checkable { mDeparture = boardedDeparture; - ((TextView) findViewById(R.id.yourTrainDestinationText)) - .setText(boardedDeparture.getTrainDestination().toString()); + destinationText.setText(boardedDeparture.getTrainDestination().toString()); + trainLength.setText(boardedDeparture.getTrainLengthAndPlatform()); - ((TextView) findViewById(R.id.yourTrainTrainLengthText)) - .setText(boardedDeparture.getTrainLengthAndPlatform()); - - ImageView colorBar = (ImageView) findViewById(R.id.yourTrainDestinationColorBar); - ((GradientDrawable) colorBar.getDrawable()).setColor(Color - .parseColor(boardedDeparture.getTrainDestinationColor())); - ImageView bikeIcon = (ImageView) findViewById(R.id.yourTrainBikeIcon); + colorBar.setBackgroundColor(boardedDeparture.getTrainDestinationColor()); if (boardedDeparture.isBikeAllowed()) { - bikeIcon.setImageDrawable(getResources().getDrawable( - R.drawable.bike)); + bikeIcon.setImageResource(R.drawable.bike); } else { - bikeIcon.setImageDrawable(getResources().getDrawable( - R.drawable.nobike)); + bikeIcon.setImageResource(R.drawable.nobike); } if (boardedDeparture.getRequiresTransfer()) { - findViewById(R.id.yourTrainXferIcon) - .setVisibility(View.VISIBLE); + xferIcon.setVisibility(View.VISIBLE); } else { - findViewById(R.id.yourTrainXferIcon) - .setVisibility(View.INVISIBLE); + xferIcon.setVisibility(View.INVISIBLE); } updateAlarmIndicator(); - CountdownTextView departureCountdown = (CountdownTextView) findViewById(R.id.yourTrainDepartureCountdown); - CountdownTextView arrivalCountdown = (CountdownTextView) findViewById(R.id.yourTrainArrivalCountdown); - final TextProvider textProvider = new TextProvider() { @Override public String getText(long tickNumber) { @@ -169,11 +160,10 @@ public class YourTrainLayout extends RelativeLayout implements Checkable { private void updateAlarmIndicator() { if (!mDeparture.isAlarmPending()) { - findViewById(R.id.alarmText).setVisibility(GONE); + alarmText.setVisibility(GONE); } else { - findViewById(R.id.alarmText).setVisibility(VISIBLE); - ((TextView) findViewById(R.id.alarmText)).setText(String - .valueOf(mDeparture.getAlarmLeadTimeMinutes())); + alarmText.setVisibility(VISIBLE); + alarmText.setText(String.valueOf(mDeparture.getAlarmLeadTimeMinutes())); } } diff --git a/app/src/main/java/com/dougkeen/bart/data/DepartureArrayAdapter.java b/app/src/main/java/com/dougkeen/bart/data/DepartureArrayAdapter.java index 2ec32f4..48c5ea6 100644 --- a/app/src/main/java/com/dougkeen/bart/data/DepartureArrayAdapter.java +++ b/app/src/main/java/com/dougkeen/bart/data/DepartureArrayAdapter.java @@ -1,13 +1,8 @@ package com.dougkeen.bart.data; -import java.util.List; - -import org.apache.commons.lang3.StringUtils; - import android.content.Context; -import android.graphics.Color; +import android.content.res.Resources; import android.graphics.drawable.Drawable; -import android.graphics.drawable.GradientDrawable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -21,65 +16,36 @@ import android.widget.ViewSwitcher.ViewFactory; import com.dougkeen.bart.R; import com.dougkeen.bart.controls.CountdownTextView; -import com.dougkeen.bart.controls.DepartureListItemLayout; +import com.dougkeen.bart.controls.CheckableLinearLayout; import com.dougkeen.bart.controls.TimedTextSwitcher; import com.dougkeen.bart.model.Departure; import com.dougkeen.bart.model.TextProvider; +import org.apache.commons.lang3.StringUtils; + public class DepartureArrayAdapter extends ArrayAdapter { private Drawable noBikeDrawable; private Drawable bikeDrawable; - public DepartureArrayAdapter(Context context, int textViewResourceId, - Departure[] objects) { - super(context, textViewResourceId, objects); - assignBikeDrawables(); - } - - private void assignBikeDrawables() { - noBikeDrawable = getContext().getResources().getDrawable( - R.drawable.nobike); - bikeDrawable = getContext().getResources().getDrawable(R.drawable.bike); - } - - public DepartureArrayAdapter(Context context, int resource, - int textViewResourceId, Departure[] objects) { - super(context, resource, textViewResourceId, objects); - assignBikeDrawables(); - } - - public DepartureArrayAdapter(Context context, int resource, - int textViewResourceId, List objects) { - super(context, resource, textViewResourceId, objects); - assignBikeDrawables(); - } - - public DepartureArrayAdapter(Context context, int resource, - int textViewResourceId) { - super(context, resource, textViewResourceId); - assignBikeDrawables(); - } - - public DepartureArrayAdapter(Context context, int textViewResourceId, - List objects) { - super(context, textViewResourceId, objects); - assignBikeDrawables(); - } - - public DepartureArrayAdapter(Context context, int textViewResourceId) { - super(context, textViewResourceId); - assignBikeDrawables(); + @SuppressWarnings("deprecation") + public DepartureArrayAdapter(Context context) { + super(context, 0 /* resource, unused since we override getView */); + Resources resources = context.getResources(); + // We need to use the deprecated getDrawable since the newer version that + // replaces it was only made available in API 21. + noBikeDrawable = resources.getDrawable(R.drawable.nobike); + bikeDrawable = resources.getDrawable(R.drawable.bike); } @Override public View getView(int position, View convertView, ViewGroup parent) { View view; - if (convertView != null - && convertView instanceof DepartureListItemLayout) { + if (convertView != null && convertView instanceof CheckableLinearLayout) { view = convertView; } else { - view = new DepartureListItemLayout(getContext()); + view = LayoutInflater.from(getContext()).inflate( + R.layout.departure_listing, parent, false /* attachToRoot */); } final Departure departure = getItem(position); @@ -132,10 +98,8 @@ public class DepartureArrayAdapter extends ArrayAdapter { }); } - ImageView colorBar = (ImageView) view - .findViewById(R.id.destinationColorBar); - ((GradientDrawable) colorBar.getDrawable()).setColor(Color - .parseColor(departure.getTrainDestinationColor())); + view.findViewById(R.id.destinationColorBar) + .setBackgroundColor(departure.getTrainDestinationColor()); CountdownTextView countdownTextView = (CountdownTextView) view .findViewById(R.id.countdown); countdownTextView.setText(departure.getCountdownText()); @@ -171,7 +135,7 @@ public class DepartureArrayAdapter extends ArrayAdapter { } }); } - + ImageView bikeIcon = (ImageView) view.findViewById(R.id.bikeIcon); if (departure.isBikeAllowed()) { bikeIcon.setImageDrawable(bikeDrawable); @@ -179,11 +143,9 @@ public class DepartureArrayAdapter extends ArrayAdapter { bikeIcon.setImageDrawable(noBikeDrawable); } if (departure.getRequiresTransfer()) { - view.findViewById(R.id.xferIcon) - .setVisibility(View.VISIBLE); + view.findViewById(R.id.xferIcon).setVisibility(View.VISIBLE); } else { - view.findViewById(R.id.xferIcon) - .setVisibility(View.INVISIBLE); + view.findViewById(R.id.xferIcon).setVisibility(View.INVISIBLE); } return view; diff --git a/app/src/main/java/com/dougkeen/bart/model/Departure.java b/app/src/main/java/com/dougkeen/bart/model/Departure.java index 1a4da62..8d3fa3f 100644 --- a/app/src/main/java/com/dougkeen/bart/model/Departure.java +++ b/app/src/main/java/com/dougkeen/bart/model/Departure.java @@ -1,18 +1,14 @@ package com.dougkeen.bart.model; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; - -import org.apache.commons.lang3.time.DateFormatUtils; - import android.app.AlarmManager; import android.app.Notification; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; +import android.graphics.Color; import android.os.Parcel; import android.os.Parcelable; +import android.support.annotation.ColorInt; import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat.Builder; import android.util.Log; @@ -23,6 +19,12 @@ import com.dougkeen.bart.activities.ViewDeparturesActivity; import com.dougkeen.bart.services.BoardedDepartureService; import com.dougkeen.util.Observable; +import org.apache.commons.lang3.time.DateFormatUtils; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + public class Departure implements Parcelable, Comparable { private static final int MINIMUM_MERGE_OVERLAP_MILLIS = 5000; private static final int EXPIRE_MINUTES_AFTER_ARRIVAL = 1; @@ -133,8 +135,9 @@ public class Departure implements Parcelable, Comparable { this.line = line; } - public String getTrainDestinationColor() { - return destinationColor; + @ColorInt + public int getTrainDestinationColor() { + return Color.parseColor(destinationColor); } public void setTrainDestinationColor(String destinationColor) { @@ -627,33 +630,36 @@ public class Departure implements Parcelable, Comparable { final Intent cancelAlarmIntent = new Intent(context, BoardedDepartureService.class); cancelAlarmIntent.putExtra("cancelNotifications", true); + String title = getOrigin().shortName + " to " + getPassengerDestination().shortName; + Builder notificationBuilder = new NotificationCompat.Builder(context) .setOngoing(true) .setSmallIcon(R.drawable.ic_stat_notification) - .setContentTitle( - getOrigin().shortName + " to " - + getPassengerDestination().shortName) + .setContentTitle(title) .setContentIntent(getNotificationIntent(context)).setWhen(0); + if (android.os.Build.VERSION.SDK_INT >= 16) { - notificationBuilder.setPriority(NotificationCompat.PRIORITY_HIGH) + notificationBuilder + .setPriority(NotificationCompat.PRIORITY_HIGH) .setContentText(minutesText + " until departure"); + if (isAlarmPending()) { - notificationBuilder.addAction( - R.drawable.ic_action_cancel_alarm, - "Cancel alarm", - PendingIntent.getService(context, 0, cancelAlarmIntent, - PendingIntent.FLAG_UPDATE_CURRENT)).setSubText( - "Alarm " + getAlarmLeadTimeMinutes() - + " minutes before departure"); + PendingIntent pendingIntent = PendingIntent.getService( + context, 0, cancelAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); + String subText = "Alarm " + getAlarmLeadTimeMinutes() + " minutes before departure"; + + notificationBuilder + .addAction(R.drawable.ic_action_cancel_alarm, "Cancel alarm", pendingIntent) + .setSubText(subText); } } else if (isAlarmPending()) { - notificationBuilder.setContentText(minutesText + String text = minutesText + " to departure (alarm at " + getAlarmLeadTimeMinutes() + " min" + ((getAlarmLeadTimeMinutes() == 1) ? "" : "s") - + ")"); + + ")"; + notificationBuilder.setContentText(text); } else { - notificationBuilder - .setContentText(minutesText + " until departure"); + notificationBuilder.setContentText(minutesText + " until departure"); } return notificationBuilder.build(); diff --git a/app/src/main/java/com/dougkeen/bart/services/BoardedDepartureService.java b/app/src/main/java/com/dougkeen/bart/services/BoardedDepartureService.java index 38463ec..0303650 100644 --- a/app/src/main/java/com/dougkeen/bart/services/BoardedDepartureService.java +++ b/app/src/main/java/com/dougkeen/bart/services/BoardedDepartureService.java @@ -4,7 +4,6 @@ import java.lang.ref.WeakReference; import java.util.List; import android.app.AlarmManager; -import android.app.NotificationManager; import android.app.Service; import android.content.ComponentName; import android.content.Context; @@ -15,6 +14,7 @@ import android.os.HandlerThread; import android.os.IBinder; import android.os.Looper; import android.os.Message; +import android.support.v4.app.NotificationManagerCompat; import com.dougkeen.bart.BartRunnerApplication; import com.dougkeen.bart.model.Departure; @@ -34,7 +34,7 @@ public class BoardedDepartureService extends Service implements private boolean mBound = false; private EtdService mEtdService; private StationPair mStationPair; - private NotificationManager mNotificationManager; + private NotificationManagerCompat mNotificationManager; private AlarmManager mAlarmManager; private Handler mHandler; private boolean mHasShutDown = false; @@ -91,7 +91,7 @@ public class BoardedDepartureService extends Service implements bindService(EtdService_.intent(this).get(), mConnection, Context.BIND_AUTO_CREATE); - mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + mNotificationManager = NotificationManagerCompat.from(this); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mHandler = new Handler(); super.onCreate(); @@ -302,8 +302,7 @@ public class BoardedDepartureService extends Service implements .getBoardedDeparture(); if (boardedDeparture != null) { mNotificationManager.notify(DEPARTURE_NOTIFICATION_ID, - boardedDeparture - .createNotification(getApplicationContext())); + boardedDeparture.createNotification(getApplicationContext())); } } diff --git a/app/src/main/java/com/dougkeen/util/Assert.java b/app/src/main/java/com/dougkeen/util/Assert.java new file mode 100644 index 0000000..5be6b46 --- /dev/null +++ b/app/src/main/java/com/dougkeen/util/Assert.java @@ -0,0 +1,13 @@ +package com.dougkeen.util; + +public final class Assert { + // Uninstantiable + private Assert() {} + + public static T notNull(T obj) { + if (obj == null) { + throw new AssertionError("Expected object to be non-null"); + } + return obj; + } +} diff --git a/app/src/main/res/layout-h480dp/departure_listing.xml b/app/src/main/res/layout-h480dp/departure_listing.xml index 2e5070d..6bdb503 100644 --- a/app/src/main/res/layout-h480dp/departure_listing.xml +++ b/app/src/main/res/layout-h480dp/departure_listing.xml @@ -1,77 +1,111 @@ - + android:layout_height="fill_parent" + android:gravity="center_vertical" + android:orientation="horizontal" + > - = 480 dp, eg usually in portrait mode. --> + + + tools:background="#F00" + /> + + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:layout_weight="1" + android:orientation="vertical" + > + android:singleLine="true" + tools:text="Richmond" + /> + + + + + + + + + + style="@style/TrainInfoIcon" + tools:src="@drawable/bike" + /> + + + + + + + + android:gravity="right" + bart:tickInterval="1" + tools:text="9m, 57s" + /> + + + + + - - - - - - - - - - - + diff --git a/app/src/main/res/layout/departure_listing.xml b/app/src/main/res/layout/departure_listing.xml index 722b0d3..d6e8a10 100644 --- a/app/src/main/res/layout/departure_listing.xml +++ b/app/src/main/res/layout/departure_listing.xml @@ -1,64 +1,98 @@ - + android:layout_height="fill_parent" + android:gravity="center_vertical" + android:orientation="horizontal" + > - + + + tools:background="#F00" + /> + + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:layout_weight="1" + android:orientation="vertical" + > + android:singleLine="true" + tools:text="Richmond" + /> + + + + + + + + style="@style/TrainInfoIcon" + tools:src="@drawable/bike" + /> + + + + + + + + android:gravity="right" + bart:tickInterval="1" + tools:text="9m, 57s" + /> + + + - - - - - - - + diff --git a/app/src/main/res/layout/your_train.xml b/app/src/main/res/layout/your_train.xml index 4814a8b..7982ccb 100644 --- a/app/src/main/res/layout/your_train.xml +++ b/app/src/main/res/layout/your_train.xml @@ -1,82 +1,121 @@ - + xmlns:bart="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="vertical" + > - + + + + + + + + + + + android:orientation="horizontal" + > - + - + + - + - + - + - + + + + + + + + + + + bart:tickInterval="1" + tools:text="Leaves in 15 min, 20s (+8s)" + /> + bart:tickInterval="5" + tools:text="Arrives ~11:12 AM (20 mins)" + /> - + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 899317d..fc7208f 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -92,18 +92,10 @@ center - - -