Created
August 21, 2017 08:59
-
-
Save ddqd/3262054591dcd33a91b6dbab8b189e52 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ColorGenerator { | |
| public static ColorGenerator DEFAULT; | |
| public static ColorGenerator MATERIAL; | |
| static { | |
| DEFAULT = create(Arrays.asList( | |
| 0xfff16364, | |
| 0xfff58559, | |
| 0xfff9a43e, | |
| 0xffe4c62e, | |
| 0xff67bf74, | |
| 0xff59a2be, | |
| 0xff2093cd, | |
| 0xffad62a7, | |
| 0xff805781 | |
| )); | |
| MATERIAL = create(Arrays.asList( | |
| 0xffe57373, | |
| 0xfff06292, | |
| 0xff4fc3f7, | |
| 0xff4dd0e1, | |
| 0xff4db6ac, | |
| 0xff81c784, | |
| 0xffaed581, | |
| 0xffff8a65, | |
| 0xffd4e157, | |
| 0xffffd54f, | |
| 0xffffb74d, | |
| 0xffa1887f | |
| )); | |
| } | |
| private final List<Integer> mColors; | |
| private final Random mRandom; | |
| private ColorGenerator(List<Integer> colorList) { | |
| mColors = colorList; | |
| mRandom = new Random(System.currentTimeMillis()); | |
| } | |
| public static ColorGenerator create(List<Integer> colorList) { | |
| return new ColorGenerator(colorList); | |
| } | |
| public int getRandomColor() { | |
| return mColors.get(mRandom.nextInt(mColors.size())); | |
| } | |
| public int getColor(Object key) { | |
| return mColors.get(Math.abs(key.hashCode()) % mColors.size()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment