Skip to content

Commit

Permalink
- Get notified when a new event has come.
Browse files Browse the repository at this point in the history
  • Loading branch information
xsoh committed Oct 23, 2018
1 parent 8ba585b commit 2c3667a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@

<service android:name="com.android.calendar.alerts.InitAlarmsService" />

<service android:name="com.android.calendar.alerts.ProviderChangedReceiverAsJob"
android:permission="android.permission.BIND_JOB_SERVICE" />

<!-- Declarations for the widget -->
<receiver android:name="com.android.calendar.widget.CalendarAppWidgetProvider" android:label="@string/gadget_title">
<intent-filter>
Expand Down
3 changes: 3 additions & 0 deletions src/com/android/calendar/AllInOneActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import com.android.calendar.CalendarController.EventType;
import com.android.calendar.CalendarController.ViewType;
import com.android.calendar.agenda.AgendaFragment;
import com.android.calendar.alerts.ProviderChangedReceiverAsJob;
import com.android.calendar.month.MonthByWeekFragment;
import com.android.calendar.selectcalendars.SelectVisibleCalendarsFragment;
import com.android.datetimepicker.date.DatePickerDialog;
Expand Down Expand Up @@ -273,6 +274,8 @@ protected void onCreate(Bundle icicle) {
}, null, null /* selection args */, null /* sort order */);
}

ProviderChangedReceiverAsJob.schedule(this);

// This needs to be created before setContentView
mController = CalendarController.getInstance(this);

Expand Down
54 changes: 54 additions & 0 deletions src/com/android/calendar/alerts/ProviderChangedReceiverAsJob.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.android.calendar.alerts;

import android.annotation.TargetApi;
import android.app.job.JobInfo;
import android.app.job.JobParameters;
import android.app.job.JobScheduler;
import android.app.job.JobService;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.provider.CalendarContract;
import android.widget.Toast;

import com.android.calendar.widget.CalendarAppWidgetProvider;
import com.android.calendar.widget.CalendarAppWidgetService;

@TargetApi(Build.VERSION_CODES.N)
public class ProviderChangedReceiverAsJob extends JobService {
private static final int mJobId = 1005; //Job Id
final Handler mHandler = new Handler(); //Just to display Toasts

public static void schedule(Context oContext) {
ComponentName oComponentName = new ComponentName(oContext, ProviderChangedReceiverAsJob.class);
JobInfo.Builder oJobInfoBuilder = new JobInfo.Builder(mJobId, oComponentName);
final Uri CALENDAR_URI = Uri.parse("content://" + CalendarContract.AUTHORITY + "/");
oJobInfoBuilder.addTriggerContentUri(new JobInfo.TriggerContentUri(CalendarContract.CONTENT_URI, JobInfo.TriggerContentUri.FLAG_NOTIFY_FOR_DESCENDANTS));
oJobInfoBuilder.addTriggerContentUri(new JobInfo.TriggerContentUri(CALENDAR_URI, 0));
JobScheduler jobScheduler = (JobScheduler) oContext.getSystemService(Context.JOB_SCHEDULER_SERVICE);
jobScheduler.schedule(oJobInfoBuilder.build());
}


@Override
public boolean onStartJob(JobParameters params) {
//Toast.makeText(getApplicationContext(), "Update The widget!", Toast.LENGTH_SHORT).show();

//TODO: Here should be the update of the widgets.


schedule(this); //Reschedule to receive future changes
return (false);
}


@Override
synchronized public boolean onStopJob(JobParameters params) {
return (false);
}

}

0 comments on commit 2c3667a

Please sign in to comment.