2013-10-01 19:39:20 -04:00
|
|
|
package com.uncc.gameday.activities;
|
|
|
|
|
2013-11-21 14:03:23 -05:00
|
|
|
import java.util.List;
|
|
|
|
|
2013-10-09 20:20:04 -04:00
|
|
|
import android.app.AlarmManager;
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
import android.content.Intent;
|
2013-10-09 19:39:20 -04:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.SharedPreferences.Editor;
|
2013-10-04 21:17:50 -04:00
|
|
|
import android.os.Bundle;
|
2013-11-21 14:03:23 -05:00
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.ListView;
|
2013-10-30 14:34:22 -04:00
|
|
|
|
|
|
|
|
2013-10-04 21:17:50 -04:00
|
|
|
|
|
|
|
import com.uncc.gameday.R;
|
2013-11-21 14:03:23 -05:00
|
|
|
import com.uncc.gameday.alerts.Alert;
|
|
|
|
import com.uncc.gameday.alerts.AlertDB;
|
2013-10-09 20:20:04 -04:00
|
|
|
import com.uncc.gameday.alerts.AlertService;
|
2013-10-01 19:39:20 -04:00
|
|
|
|
2013-11-20 11:55:39 -05:00
|
|
|
// TODO: Auto-generated Javadoc
|
|
|
|
/**
|
|
|
|
* The Class Home.
|
|
|
|
*/
|
2013-10-04 21:17:50 -04:00
|
|
|
public class Home extends MenuActivity {
|
2013-10-30 14:34:22 -04:00
|
|
|
|
|
|
|
|
2013-10-30 14:15:38 -04:00
|
|
|
|
2013-11-20 11:55:39 -05:00
|
|
|
/** The alarm rate. */
|
2013-10-09 20:20:04 -04:00
|
|
|
private final long alarmRate = 300000; // 5 Minutes
|
|
|
|
|
2013-11-20 11:55:39 -05:00
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see com.uncc.gameday.activities.MenuActivity#onCreate(android.os.Bundle)
|
|
|
|
*/
|
2013-10-04 21:17:50 -04:00
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_home);
|
|
|
|
|
2013-10-30 14:15:38 -04:00
|
|
|
|
|
|
|
|
2013-10-09 20:20:04 -04:00
|
|
|
// Start up the AlarmManager to fetch alerts in the background
|
|
|
|
AlarmManager am = (AlarmManager) this.getSystemService(ALARM_SERVICE);
|
|
|
|
Intent alertFetcher = new Intent(this, AlertService.class);
|
2013-10-16 11:02:18 -04:00
|
|
|
PendingIntent pendingAlertFetcher = PendingIntent.getService(this, 0, alertFetcher, 0);
|
2013-10-09 20:20:04 -04:00
|
|
|
|
|
|
|
// 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
|
2013-10-16 11:02:18 -04:00
|
|
|
this.onFirstRun();
|
2013-11-21 14:03:23 -05:00
|
|
|
|
|
|
|
this.displayList();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void displayList()
|
|
|
|
{
|
|
|
|
|
|
|
|
List<Alert> alerts = new AlertDB(this).fetchAll();
|
|
|
|
|
|
|
|
String[] printArray = new String[alerts.size()];
|
|
|
|
|
|
|
|
//get message from each alert and put in printArray
|
|
|
|
for(int i = 0; i < alerts.size(); i++)
|
|
|
|
{
|
|
|
|
printArray[i] = alerts.get(i).getMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
ListView listView = (ListView)findViewById(R.id.alertsListView);
|
|
|
|
ArrayAdapter<String> adapter =
|
|
|
|
new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, printArray);
|
|
|
|
listView.setAdapter(adapter);
|
2013-10-09 19:39:20 -04:00
|
|
|
}
|
|
|
|
|
2013-11-20 11:55:39 -05:00
|
|
|
/**
|
|
|
|
* On first run.
|
|
|
|
*/
|
2013-10-16 11:02:18 -04:00
|
|
|
protected void onFirstRun() {
|
2013-10-09 19:39:20 -04:00
|
|
|
SharedPreferences settings = this.getPreferences(MODE_PRIVATE);
|
|
|
|
if (settings.getBoolean("FIRST_RUN", true)) {
|
|
|
|
// First run code
|
|
|
|
|
|
|
|
Editor editor = settings.edit();
|
|
|
|
editor.putBoolean("FIRST_RUN", false);
|
|
|
|
editor.commit();
|
|
|
|
}
|
2013-10-04 21:17:50 -04:00
|
|
|
}
|
2013-10-01 19:39:20 -04:00
|
|
|
}
|