blob: 731a0f8274cbaa30ff5b3dc74247adabd3477dda (
plain)
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
|
package cgeo.calendar;
import org.eclipse.jdt.annotation.NonNull;
import android.content.Intent;
import android.text.Html;
import java.util.Date;
/**
* Add cache to calendar in Android versions 4.0 and greater using <code>Intent</code>. This does not require
* calendar permissions.
* TODO Does this work with apps other than default calendar app?
*/
class AddEntryLevel14 extends AbstractAddEntry {
public AddEntryLevel14(@NonNull final CalendarEntry entry, @NonNull final CalendarActivity activity) {
super(entry, activity);
}
@Override
protected void addEntryToCalendarInternal() {
final Date eventDate = entry.parseDate();
final String description = entry.parseDescription();
/*
* TODO These strings are available as constants starting with API 14 and can be used when
* targetSdkVersion changes to 14. For example CalendarContract.EXTRA_EVENT_BEGIN_TIME and
* Events.TITLE
*/
final Intent intent = new Intent(Intent.ACTION_INSERT)
.setData(Compatibility.getCalendarEventsProviderURI())
.putExtra("title", Html.fromHtml(entry.getName()).toString())
.putExtra("description", description)
.putExtra("hasAlarm", false)
.putExtra("eventTimezone", "UTC");
final long eventTime = eventDate.getTime();
final int entryStartTimeMinutes = entry.getStartTimeMinutes();
if (entryStartTimeMinutes >= 0) {
intent.putExtra("beginTime", eventTime + entryStartTimeMinutes * 60000L);
} else {
intent.putExtra("beginTime", eventTime);
intent.putExtra("allDay", true);
}
if (entry.getCoords().length() > 0) {
intent.putExtra("eventLocation", entry.getCoords());
}
activity.startActivity(intent);
}
}
|