1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
public void ajout_agenda () {
LayoutInflater factory = LayoutInflater.from(this);
final View alertDialogView = factory.inflate(R.layout.agendadlg, null);
AlertDialog.Builder ad = new AlertDialog.Builder(this);
ad.setTitle("Confirmation");
ad.setView(alertDialogView);
TextView messagedlg = ((TextView) alertDialogView.findViewById(R.id.TextViewAg1));
messagedlg.setText("Voulez vous ajouter la date du prochain changement de lentilles (" + String.valueOf(DateFormat.format("dd MMMM yyyy",Pro_Date))
+ ") l'agenda de votre téléphone ?");
ad.setNegativeButton("Non",
new android.content.DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int arg1) {
//OK
}
}
);
ad.setPositiveButton("Oui",
new android.content.DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int arg1) {
ContentResolver contentResolver = getApplicationContext().getContentResolver();
String[] projection = new String[] { "_id", "name" };
Uri calendars = Uri.parse("content://com.android.calendar/calendars");
Cursor managedCursor = managedQuery(calendars, projection, null, null, null);
if (managedCursor.moveToFirst()) {
String name;
String id;
int nameColumn = managedCursor.getColumnIndex("name");
int idColumn = managedCursor.getColumnIndex("_id");
do {
name = managedCursor.getString(nameColumn);
id = managedCursor.getString(idColumn);
} while (managedCursor.moveToNext());
}
long now = Pro_Date.getTime();
long startTime = now + 24 * 60 *60*1000;
long endTime = now + 60*60*1000 + 24 * 60 *60 *1000;
ContentValues event = new ContentValues();
event.put("calendar_id", 1);
event.put("title", "Gestion de vos lentilles");
event.put("description", "Il est temps de changer vos lentilles");
event.put("dtstart", startTime);
event.put("dtend", endTime);
event.put("visibility", 0);
event.put("allDay", 1);
event.put("hasAlarm", 1);
Uri newEvent = contentResolver.insert(Uri.parse("content://com.android.calendar/events"), event);
if (newEvent != null) {
long id = Long.parseLong( newEvent.getLastPathSegment() );
ContentValues values = new ContentValues();
values.put( "event_id", id );
values.put( "method", 1 );
values.put( "minutes", 15 );
contentResolver.insert( Uri.parse( "content://com.android.calendar/reminders" ), values );
}
}
}
);
ad.show();
} |
Partager