2015-05-27 08:48:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright © 2013 – 2015 Ricki Hirner (bitfire web engineering).
|
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
|
* are made available under the terms of the GNU Public License v3.0
|
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
|
* http://www.gnu.org/licenses/gpl.html
|
|
|
|
|
*/
|
|
|
|
|
|
2015-05-25 17:54:16 +00:00
|
|
|
|
package at.bitfire.davdroid;
|
|
|
|
|
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
2015-10-10 13:47:44 +00:00
|
|
|
|
public class DavUtils {
|
2015-08-03 10:16:40 +00:00
|
|
|
|
public static final int calendarGreen = 0xFFC3EA6E;
|
|
|
|
|
|
2015-05-25 17:54:16 +00:00
|
|
|
|
public static int CalDAVtoARGBColor(String davColor) {
|
2015-08-03 10:16:40 +00:00
|
|
|
|
int color = calendarGreen; // fallback: "DAVdroid green"
|
2015-05-25 17:54:16 +00:00
|
|
|
|
if (davColor != null) {
|
|
|
|
|
Pattern p = Pattern.compile("#?(\\p{XDigit}{6})(\\p{XDigit}{2})?");
|
|
|
|
|
Matcher m = p.matcher(davColor);
|
|
|
|
|
if (m.find()) {
|
|
|
|
|
int color_rgb = Integer.parseInt(m.group(1), 16);
|
|
|
|
|
int color_alpha = m.group(2) != null ? (Integer.parseInt(m.group(2), 16) & 0xFF) : 0xFF;
|
|
|
|
|
color = (color_alpha << 24) | color_rgb;
|
2015-08-02 06:57:03 +00:00
|
|
|
|
} else
|
2015-10-10 13:47:44 +00:00
|
|
|
|
Constants.log.warn("Couldn't parse color " + davColor + ", using DAVdroid green");
|
2015-05-25 17:54:16 +00:00
|
|
|
|
}
|
|
|
|
|
return color;
|
|
|
|
|
}
|
|
|
|
|
}
|