Android的CalendarProvider事件颜色颜色、事件、Android、CalendarProvider

2023-09-07 08:35:15 作者:流泪 Tearsゆ

我如何使用颜色在Android CalendarProvider最困惑。我能好吗添加事件,但是当我尝试用一​​种特定的颜色插入一个,这preference似乎被忽略的默认日历颜色(浅蓝色)。

I'm most confused on how to use Colors in the Android CalendarProvider. I can add events alright, but when I try to insert one with a particular color, this preference seems to be ignored for the default calendar color (light blue).

我想我不太确定如何颜色使用。我不知道是否有人能这么好心摆脱对此事的一些情况。

I guess I'm not exactly sure on how colors are used. I wonder if someone could be so kind as to shed some light on the matter.

同时,这里是我的code(事件参数的自定义类,我知道这个名字变得混乱):

Meanwhile, here's my code (Event parameter is a custom class, I know the name gets confusing):

public long insert(Event event) throws ParseException{

    ContentValues eventValues = new ContentValues();
    eventValues.put("calendar_id", 1); 
    eventValues.put(Events.SYNC_DATA1, event.getId());
    eventValues.put(Events.TITLE, event.getTitle());
    eventValues.put(Events.DESCRIPTION, event.getTitle());
    eventValues.put(Events.EVENT_COLOR, Color.RED);
    eventValues.put(Events.EVENT_TIMEZONE, "Europe/Rome");

    eventValues.put(Events.DTSTART, event.getStart().getTime());
    eventValues.put(Events.DTEND, event.getEnd().getTime());

    Uri eventUri = mContentResolver.insert(Uri.parse(eventUriString).buildUpon().appendQueryParameter(android.provider.CalendarContract.CALLER_IS_SYNCADAPTER,"true").appendQueryParameter(Calendars.ACCOUNT_NAME, "DUMMY").appendQueryParameter(Calendars.ACCOUNT_TYPE, "accountType").build(), eventValues);
    return Long.parseLong(eventUri.getLastPathSegment());
}

感谢你。

推荐答案

嗯,我想我被烧坏了的晚上。然而,万一别人结束了这里,给在Calendar->活动相互作用的简要说明,只要我得到了它是唯一公平的。

Well, I guess I was burned out the other night. Yet, in case someone else ends up here, it's only fair to give a brief explanation on the Calendar->Events interaction as far as I got it.

长话短说:事件的颜色取决于你把他们的日历时为什么会出现一个events_color列,如果它得到的日历颜色覆盖?我哗哗我知道。

Long story short: event colors depend upon the calendar you put them in. Why is there an events_color column if it gets overridden by the Calendar colour? I whish I knew.

所以,一旦你建立你的想象syncadapter,用户等,你需要创建一个新的日历:

So, once you set up your fancy syncadapter, user etc. you need to create a new calendar:

public long insertCalendar(EventType eventType) {

    Uri calUri = CalendarContract.Calendars.CONTENT_URI;
    ContentValues cv = new ContentValues();
    cv.put(CalendarContract.Calendars.ACCOUNT_NAME, "DUMMY");
    cv.put(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL);
    cv.put(CalendarContract.Calendars.NAME, eventType.getDescription());
    cv.put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, eventType.getDescription());
    cv.put(CalendarContract.Calendars.CALENDAR_COLOR, Color.parseColor(eventType.getColor()));
    cv.put(CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL, CalendarContract.Calendars.CAL_ACCESS_OWNER);
    cv.put(CalendarContract.Calendars.OWNER_ACCOUNT, true);
    cv.put(CalendarContract.Calendars.VISIBLE, 1);
    cv.put(CalendarContract.Calendars.SYNC_EVENTS, 1);
    //cv.put(CalendarContract.Calendars.CAL_SYNC1, eventType.getId());

    calUri = calUri.buildUpon()
        .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
        .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, "DUMMY")
        .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL)
        .build();

    Uri result = mContentResolver.insert(calUri, cv);
    return Long.parseLong(result.getLastPathSegment());
}

请注意我把颜色在CALENDAR_COLOR列,在这种情况下,我分析是这样#000000到Color.BLACK。还要注意里面ACCOUNT_TYPE值。从我收集的,似乎没有要解决这个另一种方式。

Please notice I'm putting a color in the CALENDAR_COLOR column, in this case I'm parsing something like #000000 into Color.BLACK. Also notice the value inside ACCOUNT_TYPE. From what I gathered there doesn't seem to be another way around this.

public long insert(Event event, long calendarID) throws ParseException {

    EventTypeDal adapter = new EventTypeDal();
    EventType et = adapter.GetEventTypeById(event.getFkEventType());

    ContentValues eventValues = new ContentValues();

    eventValues.put("calendar_id", calendarID); 
    //eventValues.put(Events.SYNC_DATA1, event.getId());
    eventValues.put(Events.TITLE, event.getTitle());
    eventValues.put(Events.DESCRIPTION, et.getDescription());

    eventValues.put(Events.EVENT_TIMEZONE, "Europe/Rome");

    eventValues.put(Events.DTSTART, event.getStart().getTime());
    eventValues.put(Events.DTEND, event.getEnd().getTime());

    Uri eventUri = mContentResolver.insert(Uri.parse(eventUriString).buildUpon().appendQueryParameter(android.provider.CalendarContract.CALLER_IS_SYNCADAPTER,"true").appendQueryParameter(Calendars.ACCOUNT_NAME, "DUMMY").appendQueryParameter(Calendars.ACCOUNT_TYPE, "accountType").build(), eventValues);
    return Long.parseLong(eventUri.getLastPathSegment());
}

现在我把日历(calendarID参数)内的事件。此事件将显示带有日历的颜色。

Now I'm putting an event inside a calendar (calendarID param). This event will be displayed with the calendar's color.

 
精彩推荐
图片推荐