mirror of
https://github.com/bspeice/UNCCGameDay
synced 2024-11-04 23:28:12 -05:00
Add initial code to show alerts
This commit is contained in:
parent
9fc974402b
commit
0fb498a306
@ -5,7 +5,7 @@
|
||||
android:versionName="1.0" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="8"
|
||||
android:minSdkVersion="11"
|
||||
android:targetSdkVersion="17" />
|
||||
|
||||
<application
|
||||
|
@ -5,7 +5,7 @@
|
||||
android:versionName="1.0" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="8"
|
||||
android:minSdkVersion="11"
|
||||
android:targetSdkVersion="17" />
|
||||
|
||||
<application
|
||||
|
@ -1,20 +1,37 @@
|
||||
package com.uncc.gameday.activities;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.uncc.gameday.R;
|
||||
import com.uncc.gameday.alerts.AlertFetcher;
|
||||
import com.uncc.gameday.alerts.AlertService;
|
||||
|
||||
public class Home extends MenuActivity {
|
||||
|
||||
private final long alarmRate = 300000; // 5 Minutes
|
||||
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_home);
|
||||
|
||||
Context ctx = getApplicationContext();
|
||||
|
||||
// Start up the AlarmManager to fetch alerts in the background
|
||||
AlarmManager am = (AlarmManager) this.getSystemService(ALARM_SERVICE);
|
||||
Intent alertFetcher = new Intent(this, AlertService.class);
|
||||
PendingIntent pendingAlertFetcher = PendingIntent.getService(ctx, 0, alertFetcher, 0);
|
||||
|
||||
// Cancel any previous alarm managers, and start the new one
|
||||
am.cancel(pendingAlertFetcher);
|
||||
am.setRepeating(0, this.alarmRate, this.alarmRate, pendingAlertFetcher);
|
||||
|
||||
// Double check if we need to do any first-run code
|
||||
this.onFirstRun(ctx);
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user