>
<!-- Notification receiver -->
- <receiver android:process=":remote" android:name=".accountAccess.checkout.NotificationReceiver"></receiver>
+ <receiver android:process=":remote" android:name=".services.NotificationReceiver"></receiver>
<!-- Receiver to reinit notifications on reboot -->
- <receiver android:name=".accountAccess.checkout.RebootReceiver">
+ <receiver android:name=".services.RebootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
+ <receiver android:name=".services.PeriodicServiceBroadcastReceiver">
+ <intent-filter>
+ <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
+ </intent-filter>
+ </receiver>
+ <service android:name=".services.ScheduledIntentService"></service>
<activity
<item>Matches exactly</item>
</string-array>
- <string-array name="notification_preferences_list_values">
+ <integer-array name="notification_preferences_list_values">
<item >1</item>
<item >2</item>
<item >3</item>
<item >5</item>
<item >6</item>
<item >7</item>
- </string-array>
+ </integer-array>
<string-array name="notification_preferences_list_entries">
<item >1 Day</item>
}
overdueItems.setText(" " + overdueNo);
-
- // set alarms or renew them
- setNotificationAlarms(circRecords);
progressDialog.dismiss();
}
- public void setNotificationAlarms(ArrayList<CircRecord> records) {
-
-
- DefaultDAO<NotificationAlert> daoNotifications = DatabaseManager.getDAOInstance(context, NotificationAlert.class, NotificationAlert.tableName);
- daoNotifications.open();
-
- // Fetch all alarms
- List<NotificationAlert> alarms = daoNotifications.fetchAll("");
-
- System.out.println(" Alarms " + alarms.size());
-
- for(int i=0;i<alarms.size();i++){
- System.out.println("notification " + alarms.get(i));
- }
- for (int i = 0; i < records.size(); i++) {
-
- CircRecord checkoutRecord = records.get(i);
-
- Date dueDate = checkoutRecord.getDueDateObject();
-
- // if due date in the future
- if (currentDate.compareTo(dueDate) <= 0) {
-
- // get a Calendar object with current time
- Calendar cal = Calendar.getInstance();
-
-
- cal.setTime(dueDate);
-
- System.out.println("Cal :" + cal.get(Calendar.DAY_OF_MONTH) + " " + cal.get(Calendar.YEAR) + " " + cal.get(Calendar.MONTH));
- System.out.println("Date " + new Date(cal.getTimeInMillis()) );
- //just for test
- cal.add(Calendar.HOUR, 4);
- cal.add(Calendar.MINUTE, 37);
-
- NotificationAlert notifications = daoNotifications.fetch(checkoutRecord.circ_id);
- NotificationAlert newNotificationInf = new NotificationAlert(checkoutRecord.circ_id, NotificationAlert.NOTIFICATION_INTENT
- + checkoutRecord.circ_id, cal.getTime(), "Checkout " + checkoutRecord.getAuthor() + " expires on " + checkoutRecord.getDueDate());
-
- if(notifications == null){
- daoNotifications.insert(newNotificationInf, false);
- }
- else{
- //update info in database
- daoNotifications.update(newNotificationInf, checkoutRecord.circ_id);
- }
-
- Intent intent = new Intent(context, NotificationReceiver.class);
-
- System.out.println("Set due date " + cal.getTime()
- + " with intent val " + NotificationAlert.NOTIFICATION_INTENT
- + checkoutRecord.circ_id);
- intent.putExtra("checkoutMessage", "The item " + checkoutRecord.getAuthor() + " is about to expire on " +checkoutRecord.getDueDate() );
-
- // update the current intent if it exists
- PendingIntent sender = PendingIntent.getBroadcast(this,
- NotificationAlert.NOTIFICATION_INTENT + checkoutRecord.circ_id, intent,
- PendingIntent.FLAG_UPDATE_CURRENT);
-
- // Get the AlarmManager service
- AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
- am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
- }
- }
- daoNotifications.close();
-
- }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
+++ /dev/null
-package org.evergreen.android.accountAccess.checkout;
-
-import java.util.Date;
-
-import org.androwrapee.db.DatabaseClass;
-import org.androwrapee.db.DatabaseField;
-import org.androwrapee.db.IdField;
-
-@DatabaseClass
-public class NotificationAlert {
-
- public static final String tableName = "notifications";
-
- public static final int NOTIFICATION_INTENT = 123456;
-
- @IdField
- public long id;
-
- @DatabaseField
- public int intent_val;
-
- @DatabaseField
- public Date triggerDate;
-
- @DatabaseField
- public String message;
-
- //required constructor for DAO
- public NotificationAlert(){
-
- }
-
- public NotificationAlert(int id, int intent_val, Date triggerDate, String message ){
-
- this.id = id;
- this.intent_val = intent_val;
- this.triggerDate = triggerDate;
- this.message = message;
- }
-
-
- @Override
- public String toString() {
-
- return " Notification:[ id: " + id+ "; intent_val: "+intent_val+"; triggerDate : "+triggerDate+"; message: "+message+"]";
- }
-}
+++ /dev/null
-package org.evergreen.android.accountAccess.checkout;
-
-import org.evergreen.android.views.splashscreen.SplashActivity;
-
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-import android.util.Log;
-
-public class NotificationReceiver extends BroadcastReceiver {
-
- private String TAG = "NotificationManager";
- public static final int NOTIFICATION_ID = 1;
-
- @Override
- public void onReceive(Context context, Intent intent) {
-
- String ns = Context.NOTIFICATION_SERVICE;
- NotificationManager mNotificationManager = (NotificationManager) context
- .getSystemService(ns);
-
- Bundle bundle = intent.getExtras();
- String checkoutMessage = bundle.getString("checkoutMessage");
-
- Log.d(TAG, "The " + checkoutMessage + " is about to expire");
- // send notification
-
- int icon = android.R.drawable.ic_dialog_alert;
- CharSequence tickerText = "Checkout item due date";
- long when = System.currentTimeMillis();
-
- Notification notification = new Notification(icon, tickerText, when);
-
- CharSequence contentTitle = "EG - checkout item due date";
- CharSequence contentText = checkoutMessage;
- // start evergreen
- Intent notificationIntent = new Intent(context, SplashActivity.class);
- notificationIntent.putExtra("jump", "checkout_items");
-
- PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
- notificationIntent, 0);
-
- notification.setLatestEventInfo(context, contentTitle, contentText,
- contentIntent);
-
- mNotificationManager.notify(NOTIFICATION_ID, notification);
-
- }
-
-}
+++ /dev/null
-package org.evergreen.android.accountAccess.checkout;
-
-import java.util.Calendar;
-import java.util.List;
-
-import org.androwrapee.db.DefaultDAO;
-import org.evergreen.android.database.DatabaseManager;
-
-import android.app.Activity;
-import android.app.AlarmManager;
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-
-
-public class RebootReceiver extends BroadcastReceiver{
-
- @Override
- public void onReceive(Context context, Intent arg1) {
- //reinitialize notifications
-
- DefaultDAO<NotificationAlert> daoNotifications = DatabaseManager.getDAOInstance(context, NotificationAlert.class, NotificationAlert.tableName);
- daoNotifications.open();
-
- // Fetch all alarms
- List<NotificationAlert> alarms = daoNotifications.fetchAll("");
-
- System.out.println(" Alarms " + alarms.size());
-
- for(int i=0;i<alarms.size();i++){
- System.out.println("notification " + alarms.get(i));
-
- Calendar cal = Calendar.getInstance();
- cal.setTime(alarms.get(i).triggerDate);
-
- Intent intent = new Intent(context, NotificationReceiver.class);
-
- System.out.println("Set Notification with message " + alarms.get(i).message + " on time :" + cal.getTime());
- intent.putExtra("checkoutMessage", alarms.get(i).message);
-
- // In reality, you would want to have a static variable for the
-
- PendingIntent sender = PendingIntent.getBroadcast(context, alarms.get(i).intent_val, intent,
- PendingIntent.FLAG_UPDATE_CURRENT);
-
- // Get the AlarmManager service
- AlarmManager am = (AlarmManager) context.getSystemService(Activity.ALARM_SERVICE);
- am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
-
- }
-
- daoNotifications.close();
-
- }
-
-}
import org.androwrapee.db.DefaultDatabaseHelper;
import org.androwrapee.db.IllegalClassStructureException;
import org.androwrapee.db.ReflectionManager;
-import org.evergreen.android.accountAccess.checkout.NotificationAlert;
+import org.evergreen.android.services.NotificationAlert;
import android.content.Context;
import android.util.Log;
public class GlobalConfigs {
+ public static String IDL_FILE_FROM_ROOT = "/reports/fm_IDL.xml";
+
public static String httpAddress = "";
private boolean init = false;
public void loadIDLFile(){
- String idlFile = "/reports/fm_IDL.xml";
+
try{
Log.d("debug","Read fm");
- InputStream in_IDL = Utils.getNetInputStream(httpAddress + idlFile);
+ InputStream in_IDL = Utils.getNetInputStream(httpAddress + IDL_FILE_FROM_ROOT);
IDLParser parser = new IDLParser(in_IDL);
parser.parse();
}catch(Exception e){
- System.err.println("Error in parsing IDL file " + idlFile + " " + e.getMessage());
+ System.err.println("Error in parsing IDL file " + IDL_FILE_FROM_ROOT + " " + e.getMessage());
};
loadedIDL = true;
--- /dev/null
+package org.evergreen.android.services;
+
+import java.util.Date;
+
+import org.androwrapee.db.DatabaseClass;
+import org.androwrapee.db.DatabaseField;
+import org.androwrapee.db.IdField;
+
+@DatabaseClass
+public class NotificationAlert {
+
+ public static final String tableName = "notifications";
+
+ public static final int NOTIFICATION_INTENT = 123456;
+
+ @IdField
+ public long id;
+
+ @DatabaseField
+ public int intent_val;
+
+ @DatabaseField
+ public Date triggerDate;
+
+ @DatabaseField
+ public String message;
+
+ //required constructor for DAO
+ public NotificationAlert(){
+
+ }
+
+ public NotificationAlert(int id, int intent_val, Date triggerDate, String message ){
+
+ this.id = id;
+ this.intent_val = intent_val;
+ this.triggerDate = triggerDate;
+ this.message = message;
+ }
+
+
+ @Override
+ public String toString() {
+
+ return " Notification:[ id: " + id+ "; intent_val: "+intent_val+"; triggerDate : "+triggerDate+"; message: "+message+"]";
+ }
+}
--- /dev/null
+package org.evergreen.android.services;
+
+import org.evergreen.android.views.splashscreen.SplashActivity;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+
+public class NotificationReceiver extends BroadcastReceiver {
+
+ private String TAG = "NotificationManager";
+ public static final int NOTIFICATION_ID = 1;
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+
+ String ns = Context.NOTIFICATION_SERVICE;
+ NotificationManager mNotificationManager = (NotificationManager) context
+ .getSystemService(ns);
+
+
+ String checkoutMessage = intent.getStringExtra("checkoutMesage");
+
+ Log.d(TAG, "Message " + checkoutMessage);
+ // send notification
+
+ int icon = android.R.drawable.ic_dialog_alert;
+ CharSequence tickerText = "Checkout item due date";
+ long when = System.currentTimeMillis();
+
+ Notification notification = new Notification(icon, tickerText, when);
+
+ notification.defaults |= Notification.FLAG_AUTO_CANCEL;
+
+ CharSequence contentTitle = "EG - checkout item due date";
+ CharSequence contentText = checkoutMessage;
+ // start evergreen
+ Intent notificationIntent = new Intent(context, SplashActivity.class);
+ notificationIntent.putExtra("jump", "checkout_items");
+
+ PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
+ notificationIntent, 0);
+
+ notification.setLatestEventInfo(context, contentTitle, contentText,
+ contentIntent);
+
+ mNotificationManager.notify(NOTIFICATION_ID, notification);
+
+ }
+
+}
--- /dev/null
+package org.evergreen.android.services;
+
+import java.util.Calendar;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.preference.PreferenceManager;
+import android.util.Log;
+
+public class PeriodicServiceBroadcastReceiver extends BroadcastReceiver {
+
+ public static final int INTENT_ID = 123;
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+
+ // do update logic
+ boolean mustDoUpdate = false;
+
+ SharedPreferences prefs = PreferenceManager
+ .getDefaultSharedPreferences(context);
+
+ // determine if to use alerts or not
+ boolean use_notifications = prefs.getBoolean("notifications_enabled",
+ false);
+
+ if (use_notifications) {
+ // if no updates have been made
+ Calendar current = Calendar.getInstance();
+ Calendar lastUpdateTime = Calendar.getInstance();
+ lastUpdateTime
+ .setTimeInMillis(prefs.getLong("lastUpdateTime", 0));
+
+ lastUpdateTime.add(Calendar.DAY_OF_MONTH,
+ ScheduledIntentService.SCHEDULE_TIME_INTERVAL);
+
+ // if the last update time + elapsed scheduled time < current
+ // time we must do an update
+ if (lastUpdateTime.compareTo(current) == -1) {
+ mustDoUpdate = true;
+ }
+
+
+ Log.d("app", "Network connectivity change or alarm must do update "
+ + mustDoUpdate);
+
+ ConnectivityManager connMgr = (ConnectivityManager) context
+ .getSystemService(Context.CONNECTIVITY_SERVICE);
+
+ NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
+ // if internet available
+ if (networkInfo != null && networkInfo.isConnected()) {
+
+ if (mustDoUpdate == true) {
+ Intent intentService = new Intent(context,
+ ScheduledIntentService.class);
+ context.startService(intentService);
+ }
+ }
+
+ }
+
+ }
+
+}
--- /dev/null
+package org.evergreen.android.services;
+
+import java.util.Calendar;
+
+import android.app.Activity;
+import android.app.AlarmManager;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
+import android.widget.Toast;
+
+public class RebootReceiver extends BroadcastReceiver{
+
+ @Override
+ public void onReceive(Context context, Intent arg1) {
+ //reinitialize notifications
+
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
+
+ if(sharedPreferences.getBoolean("notifications_enabled", false)){
+
+ Toast.makeText(context, "Set up notification updates", Toast.LENGTH_SHORT).show();
+ //if enabled register the update service to run once per day
+ // get a Calendar object with current time
+ Calendar cal = Calendar.getInstance();
+
+ Intent bRecvIntent = new Intent(context,PeriodicServiceBroadcastReceiver.class);
+ bRecvIntent.setAction(ScheduledIntentService.ACTION);
+ // update the current intent if it exists
+ PendingIntent sender = PendingIntent.getBroadcast(context,
+ NotificationAlert.NOTIFICATION_INTENT + PeriodicServiceBroadcastReceiver.INTENT_ID, bRecvIntent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+
+ // Get the AlarmManager service
+ AlarmManager am = (AlarmManager) context.getSystemService(Activity.ALARM_SERVICE);
+ am.setRepeating(AlarmManager.RTC, cal.getTimeInMillis(), 10000 * ScheduledIntentService.SCHEDULE_TIME_INTERVAL, sender);
+ }
+
+ }
+
+}
--- /dev/null
+package org.evergreen.android.services;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import org.androwrapee.db.DefaultDAO;
+import org.evergreen.android.accountAccess.AccountAccess;
+import org.evergreen.android.accountAccess.SessionNotFoundException;
+import org.evergreen.android.accountAccess.checkout.CircRecord;
+import org.evergreen.android.database.DatabaseManager;
+import org.evergreen.android.globals.GlobalConfigs;
+import org.evergreen.android.globals.NoAccessToServer;
+import org.evergreen.android.globals.NoNetworkAccessException;
+import org.evergreen.android.globals.Utils;
+import org.open_ils.idl.IDLParser;
+
+import android.app.AlarmManager;
+import android.app.IntentService;
+import android.app.PendingIntent;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.net.ConnectivityManager;
+import android.preference.PreferenceManager;
+import android.util.Log;
+
+public class ScheduledIntentService extends IntentService{
+
+ public static Date lastUpdateServiceDate;
+
+ public static String TAG = "ScheduledIntentService";
+
+ public static String ACTION = "org.evergreen.updateservice";
+
+ //fire up once a day
+ public static int SCHEDULE_TIME_INTERVAL = 1;
+
+ public ScheduledIntentService(){
+ super("EvergreenIntentService");
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ Log.d(TAG, "Start service");
+
+ return super.onStartCommand(intent, flags, startId);
+ }
+
+ @Override
+ protected void onHandleIntent(Intent intent) {
+
+ Date currentDate = new Date(System.currentTimeMillis());
+
+ Log.d(TAG, "Notifications service started");
+
+ /* Download the necessary IDL files for checkout items operations like au (for auth), circ, mvr and acp
+ */
+ String idlFile = GlobalConfigs.IDL_FILE_FROM_ROOT + "?class=circ&class=au&class=mvr&class=acp";
+ try{
+ Log.d("debug","Read fm");
+ InputStream in_IDL = Utils.getNetInputStream(GlobalConfigs.httpAddress + idlFile);
+ IDLParser parser = new IDLParser(in_IDL);
+ parser.parse();
+ }catch(Exception e){
+ System.err.println("Error in parsing IDL file " + idlFile + " " + e.getMessage());
+ };
+
+ //login with the user credentials
+ AccountAccess accountAccess = AccountAccess.getAccountAccess(GlobalConfigs.httpAddress, (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE));
+ boolean auth = true;
+ try {
+ accountAccess.authenticate();
+ } catch (NoNetworkAccessException e) {
+ auth=false;
+ e.printStackTrace();
+ } catch (NoAccessToServer e) {
+ auth = false;
+ e.printStackTrace();
+ }
+
+ //if we managed to authenticate we start
+ if(auth){
+
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+ //int daysBeforeDueDate = sharedPreferences.getInt("notifications_days_before_expiration", 2);
+ //TODO
+ int daysBeforeDueDate = 2;
+ ArrayList<CircRecord> circRecords = new ArrayList<CircRecord>();
+
+ //get the circ records
+ try {
+ circRecords = accountAccess.getItemsCheckedOut();
+ } catch (NoNetworkAccessException e) {
+ //not suppose to happen
+ } catch (NoAccessToServer e) {
+ //not suppose to happen
+ } catch (SessionNotFoundException e) {
+ //auth just earlier realized, not supose to happen
+ }
+
+ DefaultDAO<NotificationAlert> daoNotifications = DatabaseManager.getDAOInstance(this, NotificationAlert.class, NotificationAlert.tableName);
+ daoNotifications.open();
+
+ // Fetch all alarms from database
+ List<NotificationAlert> alarms = daoNotifications.fetchAll("");
+
+ for(int i=0;i<alarms.size();i++){
+ System.out.println("notification " + alarms.get(i));
+ Log.d(TAG, "Notification " + alarms.get(i));
+ }
+ for (int i = 0; i < circRecords.size(); i++) {
+
+ CircRecord checkoutRecord = circRecords.get(i);
+
+ Date dueDate = checkoutRecord.getDueDateObject();
+
+ Calendar notificationDate = Calendar.getInstance();
+ notificationDate.setTime(dueDate);
+
+
+ notificationDate.add(Calendar.DAY_OF_MONTH, -daysBeforeDueDate);
+ Log.d(TAG, " notification time start "+notificationDate.getTime() + " current date " + currentDate + " date between " + currentDate);
+
+
+ // if due date in the future
+ if (currentDate.compareTo(notificationDate.getTime()) >= 0) {
+
+ // get a Calendar object with current time
+ Calendar cal = Calendar.getInstance();
+
+ cal.setTime(dueDate);
+
+ //just for test
+ cal.add(Calendar.HOUR, 4);
+ cal.add(Calendar.MINUTE, 37);
+
+ Log.d(TAG, "Set notification in " + cal.getTime());
+
+ NotificationAlert notifications = daoNotifications.fetch(checkoutRecord.circ_id);
+ NotificationAlert newNotificationInf = new NotificationAlert(checkoutRecord.circ_id, NotificationAlert.NOTIFICATION_INTENT
+ + checkoutRecord.circ_id, cal.getTime(), "Checkout " + checkoutRecord.getAuthor() + " expires on " + checkoutRecord.getDueDate());
+
+ if(notifications == null){
+ daoNotifications.insert(newNotificationInf, false);
+ }
+ else{
+ //update info in database
+ daoNotifications.update(newNotificationInf, checkoutRecord.circ_id);
+ }
+
+ Intent intentNotification = new Intent(this, NotificationReceiver.class);
+
+ Log.d(TAG, "Set due date alarm at" + cal.getTime() + " for " + newNotificationInf.id + " intent_val: "+ newNotificationInf.intent_val);
+
+ intentNotification.putExtra("checkoutMessage", "The item " + checkoutRecord.getAuthor() + " is about to expire on " +checkoutRecord.getDueDate() );
+ // update the current intent if it exists
+ PendingIntent sender = PendingIntent.getBroadcast(this,
+ NotificationAlert.NOTIFICATION_INTENT + checkoutRecord.circ_id, intentNotification,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+
+ // Get the AlarmManager service
+ AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
+ am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
+ }
+ }
+ daoNotifications.close();
+
+
+ lastUpdateServiceDate = currentDate;
+ SharedPreferences.Editor editor = sharedPreferences.edit();
+ editor.putLong("lastUpdateTime", lastUpdateServiceDate.getTime());
+ editor.commit();
+
+ Log.d(TAG, "set last service update date " + lastUpdateServiceDate);
+ }
+
+ }
+
+}
package org.evergreen.android.views;
+import java.util.Calendar;
+
import org.evergreen.android.R;
import org.evergreen.android.accountAccess.AccountAccess;
import org.evergreen.android.globals.GlobalConfigs;
import org.evergreen.android.globals.NoAccessToServer;
import org.evergreen.android.globals.NoNetworkAccessException;
import org.evergreen.android.globals.Utils;
+import org.evergreen.android.services.NotificationAlert;
+import org.evergreen.android.services.NotificationReceiver;
+import org.evergreen.android.services.PeriodicServiceBroadcastReceiver;
+import org.evergreen.android.services.ScheduledIntentService;
+import android.app.AlarmManager;
import android.app.AlertDialog;
+import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
//wait for execution
}
+ if(key.equals("notifications_enabled")){
+
+ if(sharedPreferences.getBoolean("notifications_enabled", false)){
+
+ Toast.makeText(context, "Set up notification updates", Toast.LENGTH_SHORT).show();
+ //if enabled register the update service to run once per day
+ // get a Calendar object with current time
+ Calendar cal = Calendar.getInstance();
+
+ Intent bRecvIntent = new Intent(this,PeriodicServiceBroadcastReceiver.class);
+ bRecvIntent.setAction(ScheduledIntentService.ACTION);
+ // update the current intent if it exists
+ PendingIntent sender = PendingIntent.getBroadcast(this,
+ NotificationAlert.NOTIFICATION_INTENT + PeriodicServiceBroadcastReceiver.INTENT_ID, bRecvIntent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+
+ // Get the AlarmManager service
+ AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
+ am.setRepeating(AlarmManager.RTC, cal.getTimeInMillis(), 10000 * ScheduledIntentService.SCHEDULE_TIME_INTERVAL, sender);
+ }
+ else
+ {
+ Toast.makeText(context, "Disable notification updates", Toast.LENGTH_SHORT).show();
+ //cancel the service
+
+ Intent bRecvIntent = new Intent(this,PeriodicServiceBroadcastReceiver.class);
+
+ // update the current intent if it exists
+ PendingIntent sender = PendingIntent.getBroadcast(this,
+ NotificationAlert.NOTIFICATION_INTENT + PeriodicServiceBroadcastReceiver.INTENT_ID, bRecvIntent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+
+ // Get the AlarmManager service
+ AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
+ //cancel the service
+ am.cancel(sender);
+ }
+ //register the
+
+ }
//test connection
if(!isFinishing() && httpAddressChange == false && checkConnection == true){