diff --git a/enabler/src/de/schildbach/pte/dto/Style.java b/enabler/src/de/schildbach/pte/dto/Style.java index 5e93ec3b..92787599 100644 --- a/enabler/src/de/schildbach/pte/dto/Style.java +++ b/enabler/src/de/schildbach/pte/dto/Style.java @@ -110,4 +110,19 @@ public class Style implements Serializable { return (0xFF << 24) | (red << 16) | (green << 8) | blue; } + + public static int red(final int color) + { + return (color >> 16) & 0xff; + } + + public static int green(final int color) + { + return (color >> 8) & 0xff; + } + + public static int blue(final int color) + { + return color & 0xff; + } } diff --git a/enabler/test/de/schildbach/pte/dto/StyleTest.java b/enabler/test/de/schildbach/pte/dto/StyleTest.java new file mode 100644 index 00000000..29a1320a --- /dev/null +++ b/enabler/test/de/schildbach/pte/dto/StyleTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2014 the original author or authors. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package de.schildbach.pte.dto; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +/** + * @author Andreas Schildbach + */ +public class StyleTest +{ + @Test + public void roundTripRGB() + { + final int color = Style.parseColor("#123456"); + assertEquals(color, Style.rgb(Style.red(color), Style.green(color), Style.blue(color))); + } +}