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