mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-18 16:29:51 +00:00
Add methods for extracting red, green and blue color portions from an int color.
This commit is contained in:
parent
a8efe538c1
commit
aee3fba9cf
2 changed files with 50 additions and 0 deletions
|
@ -110,4 +110,19 @@ public class Style implements Serializable
|
||||||
{
|
{
|
||||||
return (0xFF << 24) | (red << 16) | (green << 8) | blue;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
35
enabler/test/de/schildbach/pte/dto/StyleTest.java
Normal file
35
enabler/test/de/schildbach/pte/dto/StyleTest.java
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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)));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue