Add initial code to show alerts

This commit is contained in:
bspeice
2013-10-09 20:20:04 -04:00
parent 9fc974402b
commit 0fb498a306
6 changed files with 64 additions and 2 deletions

View File

@ -2,6 +2,16 @@ package com.uncc.gameday.alerts;
import java.util.Date;
import com.uncc.gameday.R;
import com.uncc.gameday.activities.Home;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
public class Alert {
private Date alarmDate;
@ -27,5 +37,22 @@ public class Alert {
public void setShown(boolean shown) {
this.shown = shown;
}
public void displayNotification(Context ctx) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("GameDay Alert")
.setContentText(this.getMessage());
Intent resultIntent = new Intent(ctx, Home.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(ctx);
stackBuilder.addParentStack(Home.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(resultPendingIntent);
NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, builder.build());
}
}

View File

@ -31,4 +31,9 @@ public class AlertDB {
public void deleteAlerts(List<Alert> alerts) {
// Remove multiple dates from the database
}
public List<Alert> fetchUnread() {
// Fetch all unread alerts
return null;
}
}

View File

@ -1,6 +1,11 @@
package com.uncc.gameday.alerts;
import java.util.List;
import com.uncc.gameday.GameDay;
import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
public class AlertService extends IntentService {
@ -13,6 +18,14 @@ public class AlertService extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
// Go fetch all the alerts!
Context appContext = GameDay.getAppContext();
AlertDB dbHandle = new AlertDB();
List<Alert> alerts = dbHandle.fetchUnread();
// And then display all of them!
for (Alert a: alerts) {
a.displayNotification(appContext);
}
}
}