2

我正在查看 android 日历源代码,Instances Content Provider以了解它是如何工作和填充的。

原因是我试图在我的应用程序中复制它的工作原理,但我还没有找到它从源中填充的位置。

我知道 Instances 数据库不能被写入,但是自从它被填充后,它必须被写入某个地方。我只是想看看他们如何对这些值进行一些计算。

我唯一能找到的Instances就是这个 ,但这并没有告诉我我想知道什么,只是告诉我值背后的代码query而不是代码。uri's

有谁知道它在哪里?

4

2 回答 2

1

处理以开头的 Content Provider URI 的代码content://com.android.calendar/instances/*位于packages/providers/CalendarProvider/src/com/android/providers/calendar/CalendarProvider2.java中。

从该文件中可以查找进一步的实现细节。例如,很多初始化代码,比如CREATE TABLE调用,都在同一个项目的CalendarDatabaseHelper.java中。

我希望这有帮助!

于 2013-04-08T08:57:04.157 回答
0

在CalendarInstancesHelper.java中的“ updateInstancesLocked ”方法中填充了实例。另请检查同一文件中的“ performInstanceExpansion ”方法。

链接到GrepCode中的上述方法

我提供了以下方法的片段

  /**
 * 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);
    }
}

希望这可以帮助!!!

让我知道你是否期待不同的东西

于 2013-04-09T20:44:41.143 回答