mirror of
https://github.com/etesync/android
synced 2025-02-16 17:42:03 +00:00
import Apple calendar-color with r,g,b,a (see issue #31)
This commit is contained in:
parent
f8f10be3ba
commit
1e00ed217f
@ -11,6 +11,8 @@ import java.net.URISyntaxException;
|
|||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.fortuna.ical4j.model.Parameter;
|
import net.fortuna.ical4j.model.Parameter;
|
||||||
@ -91,13 +93,16 @@ public class LocalCalendar extends LocalCollection<Event> {
|
|||||||
public static void create(Account account, ContentResolver resolver, ServerInfo.ResourceInfo info) throws RemoteException {
|
public static void create(Account account, ContentResolver resolver, ServerInfo.ResourceInfo info) throws RemoteException {
|
||||||
ContentProviderClient client = resolver.acquireContentProviderClient(CalendarContract.AUTHORITY);
|
ContentProviderClient client = resolver.acquireContentProviderClient(CalendarContract.AUTHORITY);
|
||||||
|
|
||||||
int color = 0xFFC3EA6E;
|
int color = 0xFFC3EA6E; // fallback: "DAVdroid green"
|
||||||
if (info.getColor() != null)
|
if (info.getColor() != null) {
|
||||||
try {
|
Pattern p = Pattern.compile("#(\\p{XDigit}{6})(\\p{XDigit}{2})?");
|
||||||
color = Integer.decode(info.getColor());
|
Matcher m = p.matcher(info.getColor());
|
||||||
} catch(Exception ex) {
|
if (m.find()) {
|
||||||
Log.w(TAG, "Couldn't parse calendar color " + info.getColor());
|
int color_rgb = Integer.parseInt(m.group(1), 16);
|
||||||
|
byte color_alpha = m.group(2) != null ? Byte.parseByte(m.group(2), 16) : -1;
|
||||||
|
color = (color_alpha << 24) | color_rgb;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(Calendars.ACCOUNT_NAME, account.name);
|
values.put(Calendars.ACCOUNT_NAME, account.name);
|
||||||
|
Loading…
Reference in New Issue
Block a user