Calendar trigger
This commit is contained in:
parent
97a3344e81
commit
75a23c1863
@ -6,6 +6,8 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
@ -34,9 +36,10 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
|
||||
static List<AndroidCalendar> calendarsCache = null;
|
||||
static List<CalendarEvent> calendarEventsCache = null;
|
||||
|
||||
static Timer timer = null;
|
||||
static TimerTask timerTask = null;
|
||||
static Handler handler;
|
||||
static Calendar nextWakeup = null;
|
||||
static Message recheckMessage;
|
||||
static int recheckMessageId = 2130;
|
||||
|
||||
public static CalendarReceiver getInstance()
|
||||
{
|
||||
@ -264,11 +267,11 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
|
||||
|
||||
private static void armOrRearmTimer()
|
||||
{
|
||||
timerTask = new TimerTask()
|
||||
{
|
||||
handler = new Handler(){
|
||||
@Override
|
||||
public void run()
|
||||
public void handleMessage(@NonNull Message msg)
|
||||
{
|
||||
super.handleMessage(msg);
|
||||
checkForRules(Miscellaneous.getAnyContext());
|
||||
|
||||
// Set next timer
|
||||
@ -278,12 +281,11 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
|
||||
}
|
||||
};
|
||||
|
||||
if(timer != null)
|
||||
if(handler != null)
|
||||
{
|
||||
timer.cancel();
|
||||
timer.purge();
|
||||
handler.removeMessages(recheckMessageId);
|
||||
}
|
||||
timer = new Timer();
|
||||
// timer = new Timer();
|
||||
|
||||
if(nextWakeup == null)
|
||||
{
|
||||
@ -291,9 +293,14 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
|
||||
calculateNextWakeup();
|
||||
}
|
||||
|
||||
if(recheckMessage == null)
|
||||
{
|
||||
recheckMessage = new Message();
|
||||
recheckMessage.what = recheckMessageId;
|
||||
}
|
||||
// If it's now filled, go on
|
||||
if(nextWakeup != null)
|
||||
timer.schedule(timerTask, nextWakeup.getTimeInMillis());
|
||||
handler.sendMessageAtTime(recheckMessage, nextWakeup.getTimeInMillis());
|
||||
}
|
||||
|
||||
private static void calculateNextWakeup()
|
||||
|
Loading…
Reference in New Issue
Block a user