我正在查看Instances Content Provider
的安卓日历源代码,看看它是如何工作的并填充。
原因是我试图在我的应用程序中复制其工作方式,但我还没有找到它在源代码中填充的位置。
我知道Instances数据库无法写入,但是在它填充之后必须要写入它的某个地方。我只想看看他们如何对这些值进行一些计算。
关于Instances
我唯一能找到的是this,但这并没有告诉我我想知道什么,只是告诉我query
和{{1}不是值背后的代码。
有谁知道它在哪里?
答案 0 :(得分:1)
处理以content://com.android.calendar/instances/*
开头的内容提供商URI的代码位于packages/providers/CalendarProvider/src/com/android/providers/calendar/CalendarProvider2.java。
从该文件中可以查找更多实施细节。例如,许多初始化代码(如CREATE TABLE
调用)位于同一项目的CalendarDatabaseHelper.java中。
我希望这有帮助!
答案 1 :(得分:0)
实例正在 CalendarInstancesHelper.java 中的“ updateInstancesLocked ”方法中填充。另请在同一文件中查看“ performInstanceExpansion ”方法。
中链接上述方法我提供了以下方法的摘录
/**
* Updates the instances table when an event is added or updated.
* @param values The new values of the event.
* @param rowId The database row id of the event.
* @param newEvent true if the event is new.
* @param db The database
*/
private void updateInstancesLocked(ContentValues values,
long rowId,
boolean newEvent,
SQLiteDatabase db) {
// If there are no expanded Instances, then return.
MetaData.Fields fields = mMetaData.getFieldsLocked();
if (fields.maxInstance == 0) {
return;
}
Long dtstartMillis = values.getAsLong(Events.DTSTART);
if (dtstartMillis == null) {
if (newEvent) {
// must be present for a new event.
throw new RuntimeException("DTSTART missing.");
}
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "Missing DTSTART. No need to update instance.");
}
return;
}
Long lastDateMillis = values.getAsLong(Events.LAST_DATE);
Long originalInstanceTime = values.getAsLong(Events.ORIGINAL_INSTANCE_TIME);
if (!newEvent) {
// Want to do this for regular event, recurrence, or exception.
// For recurrence or exception, more deletion may happen below if we
// do an instance expansion. This deletion will suffice if the exception
// is moved outside the window, for instance.
db.delete("Instances", "event_id=?", new String[] {String.valueOf(rowId)});
}
String rrule = values.getAsString(Events.RRULE);
String rdate = values.getAsString(Events.RDATE);
String originalEvent = values.getAsString(Events.ORIGINAL_EVENT);
if (isRecurrenceEvent(rrule, rdate, originalEvent)) {
// The recurrence or exception needs to be (re-)expanded if:
// a) Exception or recurrence that falls inside window
boolean insideWindow = dtstartMillis <= fields.maxInstance &&
(lastDateMillis == null || lastDateMillis >= fields.minInstance);
// b) Exception that affects instance inside window
// These conditions match the query in getEntries
// See getEntries comment for explanation of subtracting 1 week.
boolean affectsWindow = originalInstanceTime != null &&
originalInstanceTime <= fields.maxInstance &&
originalInstanceTime >= fields.minInstance - MAX_ASSUMED_DURATION;
if (insideWindow || affectsWindow) {
updateRecurrenceInstancesLocked(values, rowId, db);
}
// TODO: an exception creation or update could be optimized by
// updating just the affected instances, instead of regenerating
// the recurrence.
return;
}
Long dtendMillis = values.getAsLong(Events.DTEND);
if (dtendMillis == null) {
dtendMillis = dtstartMillis;
}
// if the event is in the expanded range, insert
// into the instances table.
// TODO: deal with durations. currently, durations are only used in
// recurrences.
if (dtstartMillis <= fields.maxInstance && dtendMillis >= fields.minInstance) {
ContentValues instanceValues = new ContentValues();
instanceValues.put(Instances.EVENT_ID, rowId);
instanceValues.put(Instances.BEGIN, dtstartMillis);
instanceValues.put(Instances.END, dtendMillis);
boolean allDay = false;
Integer allDayInteger = values.getAsInteger(Events.ALL_DAY);
if (allDayInteger != null) {
allDay = allDayInteger != 0;
}
// Update the timezone-dependent fields.
Time local = new Time();
if (allDay) {
local.timezone = Time.TIMEZONE_UTC;
} else {
local.timezone = fields.timezone;
}
computeTimezoneDependentFields(dtstartMillis, dtendMillis, local, instanceValues);
mDbHelper.instancesInsert(instanceValues);
}
}
希望这有帮助!!!
如果您期待不同的事情,请告诉我