diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 7eb88bedc..f7b17601f 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -10,4 +10,5 @@ We'd like to thank the following developers who have contributed to OneBusAway A * Cagri Cetin * Mike Karabushin * Aziz Batihk -* Charles Bond \ No newline at end of file +* Charles Bond +* Bridgette Eichelberger (bridgette@outlook.com) \ No newline at end of file diff --git a/onebusaway-android/src/main/java/org/onebusaway/android/tripservice/NotifierTask.java b/onebusaway-android/src/main/java/org/onebusaway/android/tripservice/NotifierTask.java index cca16c953..66dffe19f 100644 --- a/onebusaway-android/src/main/java/org/onebusaway/android/tripservice/NotifierTask.java +++ b/onebusaway-android/src/main/java/org/onebusaway/android/tripservice/NotifierTask.java @@ -16,6 +16,10 @@ */ package org.onebusaway.android.tripservice; +import org.onebusaway.android.R; +import org.onebusaway.android.provider.ObaContract; +import org.onebusaway.android.ui.ArrivalsListActivity; + import android.app.Notification; import android.app.PendingIntent; import android.content.ContentResolver; @@ -25,10 +29,6 @@ import android.net.Uri; import android.support.v4.app.NotificationCompat; -import org.onebusaway.android.R; -import org.onebusaway.android.provider.ObaContract; -import org.onebusaway.android.ui.ArrivalsListActivity; - /** * A task (thread) that is responsible for generating a Notification to remind the user of an * arriving bus. @@ -61,14 +61,18 @@ public final class NotifierTask implements Runnable { private String mNotifyText; + private String mNotifyTitle; + public NotifierTask(Context context, TaskContext taskContext, Uri uri, + String notifyTitle, String notifyText) { mContext = context; mTaskContext = taskContext; mCR = mContext.getContentResolver(); mUri = uri; + mNotifyTitle = notifyTitle; mNotifyText = notifyText; } @@ -111,7 +115,7 @@ private void notify(Cursor c) { new ArrivalsListActivity.Builder(mContext, stopId).getIntent(), PendingIntent.FLAG_UPDATE_CURRENT); - Notification notification = createNotification(mNotifyText, + Notification notification = createNotification(mNotifyTitle, mNotifyText, pendingContentIntent, pendingDeleteIntent); mTaskContext.setNotification(id, notification); @@ -132,13 +136,15 @@ private void notify(Cursor c) { * Create a notification and populate it with our latest data. This method replaces * an implementation using Notification.setLatestEventInfo((), which was deprecated (see #290). * + * @param notifyTitle notification title + * @param notifyText notification text * @param contentIntent intent to fire on click * @param deleteIntent intent to remove/delete */ - private Notification createNotification(String notifyText, + private Notification createNotification(String notifyTitle, + String notifyText, PendingIntent contentIntent, PendingIntent deleteIntent) { - final String title = mContext.getString(R.string.app_name); return new NotificationCompat.Builder(mContext) .setSmallIcon(R.drawable.ic_stat_notification) .setDefaults(Notification.DEFAULT_ALL) @@ -147,7 +153,7 @@ private Notification createNotification(String notifyText, //.setVibrate(VIBRATE_PATTERN) .setContentIntent(contentIntent) .setDeleteIntent(deleteIntent) - .setContentTitle(title) + .setContentTitle(notifyTitle) .setContentText(notifyText) .build(); diff --git a/onebusaway-android/src/main/java/org/onebusaway/android/tripservice/PollerTask.java b/onebusaway-android/src/main/java/org/onebusaway/android/tripservice/PollerTask.java index 0ef7df9c6..4b3e96256 100644 --- a/onebusaway-android/src/main/java/org/onebusaway/android/tripservice/PollerTask.java +++ b/onebusaway-android/src/main/java/org/onebusaway/android/tripservice/PollerTask.java @@ -16,12 +16,6 @@ */ package org.onebusaway.android.tripservice; -import android.content.ContentResolver; -import android.content.ContentValues; -import android.content.Context; -import android.database.Cursor; -import android.net.Uri; - import org.onebusaway.android.io.ObaApi; import org.onebusaway.android.io.elements.ObaArrivalInfo; import org.onebusaway.android.io.request.ObaArrivalInfoRequest; @@ -30,6 +24,12 @@ import org.onebusaway.android.ui.ArrivalInfo; import org.onebusaway.android.util.UIUtils; +import android.content.ContentResolver; +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.net.Uri; + /** * A task (thread) that is responsible for polling the server to determine if a Notification to * remind the user of an arriving bus should be triggered. @@ -137,11 +137,16 @@ private void poll1(Cursor c) { // Bus is within the reminder interval (or it possibly has left!) // Send off a notification. //Log.d(TAG, "Notify for trip: " + alertUri); - TripService.notifyTrip(mContext, mUri, arrivalInfo.getNotifyText()); + TripService.notifyTrip(mContext, mUri, getReminderName(tripId, stopId), arrivalInfo.getNotifyText()); } } } + private String getReminderName(String tripId, String stopId) { + final Uri uri = ObaContract.Trips.buildUri(tripId, stopId); + return UIUtils.stringForQuery(mContext, uri, ObaContract.Trips.NAME); + } + private long getReminderMin(String tripId, String stopId) { final Uri uri = ObaContract.Trips.buildUri(tripId, stopId); return (long) UIUtils.intForQuery(mContext, uri, ObaContract.Trips.REMINDER); @@ -151,7 +156,7 @@ private long getReminderMin(String tripId, String stopId) { * Checks arrivals from given ObaArrivalInfoResponse * * @param response arrival information - * @param tripId + * @param tripId trip id * @return ArrivalInfo, or return null if the arrival can't be found. */ private ArrivalInfo checkArrivals(ObaArrivalInfoResponse response, String tripId) { diff --git a/onebusaway-android/src/main/java/org/onebusaway/android/tripservice/SchedulerTask.java b/onebusaway-android/src/main/java/org/onebusaway/android/tripservice/SchedulerTask.java index ae3c8644b..17010d084 100644 --- a/onebusaway-android/src/main/java/org/onebusaway/android/tripservice/SchedulerTask.java +++ b/onebusaway-android/src/main/java/org/onebusaway/android/tripservice/SchedulerTask.java @@ -143,9 +143,9 @@ private void schedule1(Cursor c, Time tNow, long now) { } private boolean scheduleAlert(Uri uri, - String tripId, - String stopId, - long triggerTime) { + String tripId, + String stopId, + long triggerTime) { Time tmp = new Time(); tmp.set(triggerTime); diff --git a/onebusaway-android/src/main/java/org/onebusaway/android/tripservice/TripService.java b/onebusaway-android/src/main/java/org/onebusaway/android/tripservice/TripService.java index 46f933b64..246b329dd 100644 --- a/onebusaway-android/src/main/java/org/onebusaway/android/tripservice/TripService.java +++ b/onebusaway-android/src/main/java/org/onebusaway/android/tripservice/TripService.java @@ -16,6 +16,10 @@ */ package org.onebusaway.android.tripservice; +import org.onebusaway.android.BuildConfig; +import org.onebusaway.android.provider.ObaContract; +import org.onebusaway.android.util.UIUtils; + import android.app.AlarmManager; import android.app.Notification; import android.app.NotificationManager; @@ -30,10 +34,6 @@ import android.os.RemoteException; import android.util.Log; -import org.onebusaway.android.BuildConfig; -import org.onebusaway.android.provider.ObaContract; -import org.onebusaway.android.util.UIUtils; - import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -84,6 +84,8 @@ public class TripService extends Service { private static final String NOTIFY_TEXT = ".notifyText"; + private static final String NOTIFY_TITLE = ".notifyTitle"; + private ExecutorService mThreadPool; private NotificationManager mNM; @@ -181,9 +183,10 @@ private int handleCommand(Intent intent, int startId) { } else if (ACTION_NOTIFY.equals(action)) { // Create the notification + String notifyTitle = intent.getStringExtra(NOTIFY_TITLE); String notifyText = intent.getStringExtra(NOTIFY_TEXT); - mThreadPool.submit(new NotifierTask(this, taskContext, uri, notifyText)); + mThreadPool.submit(new NotifierTask(this, taskContext, uri, notifyTitle, notifyText)); return START_REDELIVER_INTENT; } else if (ACTION_CANCEL.equals(action)) { @@ -205,9 +208,9 @@ public IBinder onBind(Intent arg0) { private final IBinder mBinder = new Binder() { @Override protected boolean onTransact(int code, - Parcel data, - Parcel reply, - int flags) throws RemoteException { + Parcel data, + Parcel reply, + int flags) throws RemoteException { return super.onTransact(code, data, reply, flags); } }; @@ -233,17 +236,18 @@ public static void pollTrip(Context context, Uri alertUri, long triggerTime) { alarm.set(AlarmManager.RTC_WAKEUP, triggerTime, alarmIntent); } - public static void notifyTrip(Context context, Uri alertUri, String notifyText) { + public static void notifyTrip(Context context, Uri alertUri, String notifyTitle, String notifyText) { final Intent intent = new Intent(context, TripService.class); intent.setAction(ACTION_NOTIFY); intent.setData(alertUri); intent.putExtra(NOTIFY_TEXT, notifyText); + intent.putExtra(NOTIFY_TITLE, notifyTitle); context.startService(intent); } public static String getRouteShortName(Context context, String id) { return UIUtils.stringForQuery(context, Uri.withAppendedPath( - ObaContract.Routes.CONTENT_URI, id), + ObaContract.Routes.CONTENT_URI, id), ObaContract.Routes.SHORTNAME ); } diff --git a/onebusaway-android/src/main/res/values/strings.xml b/onebusaway-android/src/main/res/values/strings.xml index 179334c89..5fe11e61d 100644 --- a/onebusaway-android/src/main/res/values/strings.xml +++ b/onebusaway-android/src/main/res/values/strings.xml @@ -778,7 +778,8 @@ "* Cagri Cetin\n" "* Mike Karabushin\n" "* Aziz Batihk\n" - "* Charles Bond\n\n" + "* Charles Bond\n" + "* Bridgette Eichelberger\n\n" "Want to contribute to this app? Check it out on Github at https://github.com/OneBusAway/onebusaway-android.\n\n"