forked from jens/Automation
Calendar trigger
This commit is contained in:
@ -18,9 +18,20 @@ import java.util.List;
|
||||
|
||||
public class CalendarReceiver extends BroadcastReceiver implements AutomationListenerInterface
|
||||
{
|
||||
static BroadcastReceiver calendarReceiverInstance = null;
|
||||
static CalendarReceiver calendarReceiverInstance = null;
|
||||
static boolean calendarReceiverActive = false;
|
||||
static IntentFilter calendarIntentFilter = null;
|
||||
private static AutomationService automationServiceRef;
|
||||
private static Intent calendarIntent = null;
|
||||
|
||||
public static CalendarReceiver getInstance()
|
||||
{
|
||||
if(calendarReceiverInstance == null)
|
||||
calendarReceiverInstance = new CalendarReceiver();
|
||||
|
||||
return calendarReceiverInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
@ -41,7 +52,7 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
|
||||
if(!calendarReceiverActive)
|
||||
{
|
||||
if(calendarReceiverInstance == null)
|
||||
calendarReceiverInstance = new BatteryReceiver();
|
||||
calendarReceiverInstance = new CalendarReceiver();
|
||||
|
||||
if(calendarIntentFilter == null)
|
||||
{
|
||||
@ -99,7 +110,7 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
|
||||
Cursor cursor = context.getContentResolver()
|
||||
.query(
|
||||
Uri.parse("content://com.android.calendar/events"),
|
||||
new String[] { "calendar_id", "title", "description", "dtstart", "dtend", "eventLocation", "AVAILABILITY" },
|
||||
new String[] { "calendar_id", "title", "description", "dtstart", "dtend", "eventLocation", "availability" },
|
||||
null, null, null);
|
||||
|
||||
cursor.moveToFirst();
|
||||
@ -110,19 +121,58 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
|
||||
|
||||
for (int i = 0; i < CNames.length; i++)
|
||||
{
|
||||
CalendarEvent event = new CalendarEvent();
|
||||
event.id = cursor.getString(1);
|
||||
event.title = cursor.getString(2);
|
||||
event.description = cursor.getString(3);
|
||||
event.start = Miscellaneous.calendarFromLong(Long.parseLong(cursor.getString(4)));
|
||||
event.end = Miscellaneous.calendarFromLong(Long.parseLong(cursor.getString(5)));
|
||||
event.location = cursor.getString(6);
|
||||
event.availability = cursor.getString(7)
|
||||
eventlist.add(event);
|
||||
|
||||
try
|
||||
{
|
||||
CalendarEvent event = new CalendarEvent();
|
||||
event.id = cursor.getString(1);
|
||||
event.title = cursor.getString(2);
|
||||
event.description = cursor.getString(3);
|
||||
event.start = Miscellaneous.calendarFromLong(Long.parseLong(cursor.getString(4)));
|
||||
event.end = Miscellaneous.calendarFromLong(Long.parseLong(cursor.getString(5)));
|
||||
event.location = cursor.getString(6);
|
||||
event.availability = cursor.getString(7);
|
||||
eventlist.add(event);
|
||||
}
|
||||
catch (Exception e)
|
||||
{}
|
||||
cursor.moveToNext();
|
||||
}
|
||||
|
||||
return eventlist;
|
||||
}
|
||||
|
||||
public static void startCalendarReceiver(final AutomationService automationServiceRef)
|
||||
{
|
||||
if (!calendarReceiverActive)
|
||||
{
|
||||
CalendarReceiver.automationServiceRef = automationServiceRef;
|
||||
|
||||
if (calendarReceiverInstance == null)
|
||||
calendarReceiverInstance = new CalendarReceiver();
|
||||
|
||||
if (calendarIntentFilter == null)
|
||||
{
|
||||
calendarIntentFilter = new IntentFilter();
|
||||
calendarIntentFilter.addAction(Intent.ACTION_PROVIDER_CHANGED);
|
||||
}
|
||||
|
||||
calendarIntent = automationServiceRef.registerReceiver(calendarReceiverInstance, calendarIntentFilter);
|
||||
|
||||
calendarReceiverActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void stopScreenStateReceiver()
|
||||
{
|
||||
if (calendarReceiverActive)
|
||||
{
|
||||
if (calendarReceiverInstance != null)
|
||||
{
|
||||
automationServiceRef.unregisterReceiver(calendarReceiverInstance);
|
||||
calendarReceiverInstance = null;
|
||||
}
|
||||
|
||||
calendarReceiverActive = false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user