package com.loopbook.cuhk_loopbook;

import java.util.Calendar;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.os.SystemClock;
import android.content.Intent; 
import android.widget.Toast;
import android.content.Context;

public class CheckSched {
    public static void scheduleNotification(Context context) {
        Intent notificationIntent = new Intent(context, DueChecker.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(
                context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        AlarmManager alarmMgr = (AlarmManager) (context.getSystemService(Context.ALARM_SERVICE));

        if (BuildInfo.DEBUG) {
            int delaySec = 5;
            long futureInMillis = SystemClock.elapsedRealtime() + delaySec * 1000;
            alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, futureInMillis, pendingIntent);
        } else {
            // Set the alarm to start at approximately ?:??.
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(System.currentTimeMillis());
            calendar.set(Calendar.HOUR_OF_DAY, 15);
            calendar.set(Calendar.MINUTE, 36);

            alarmMgr.setInexactRepeating(
                    AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
                    AlarmManager.INTERVAL_HALF_DAY, pendingIntent);
        }
    }
}

@@ -660,16 +660,68 @@
 RVICE));
+%0A        Calendar calendar = Calendar.getInstance();
 %0A%0A      
@@ -761,48 +761,23 @@
     
-int delaySec = 5;%0A            long futur
+calendar.setTim
 eInM
@@ -785,58 +785,43 @@
 llis
- = 
+(
 System
-Clock.elapsedRealtime() + delaySec * 1
+.currentTimeMillis() + 5
 000
+)
 ;%0A  
@@ -846,61 +846,156 @@
 .set
-(AlarmManager.ELAPSED_REALTIME_WAKEUP, futureInMillis
+InexactRepeating(%0A                    AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),%0A                    AlarmManager.INTERVAL_FIFTEEN_MINUTES
 , pe
@@ -1090,64 +1090,8 @@
 ??.%0A
-            Calendar calendar = Calendar.getInstance();%0A
     

use reapeated alarm for debugging