diff options
Diffstat (limited to 'org.fox.ttrss/src/main/java/com/amulyakhare/textdrawable/util')
-rw-r--r-- | org.fox.ttrss/src/main/java/com/amulyakhare/textdrawable/util/ColorGenerator.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/org.fox.ttrss/src/main/java/com/amulyakhare/textdrawable/util/ColorGenerator.java b/org.fox.ttrss/src/main/java/com/amulyakhare/textdrawable/util/ColorGenerator.java new file mode 100644 index 00000000..99e7467f --- /dev/null +++ b/org.fox.ttrss/src/main/java/com/amulyakhare/textdrawable/util/ColorGenerator.java @@ -0,0 +1,48 @@ +package com.amulyakhare.textdrawable.util; + +import java.util.Arrays; +import java.util.List; +import java.util.Random; + +/** + * @author amulya + * @datetime 14 Oct 2014, 5:20 PM + */ +public class ColorGenerator { + + public static ColorGenerator DEFAULT; + + static { + DEFAULT = create(Arrays.asList( + 0xfff16364, + 0xfff58559, + 0xfff9a43e, + 0xffe4c62e, + 0xff67bf74, + 0xff59a2be, + 0xff2093cd, + 0xffad62a7, + 0xff805781 + )); + } + + private final List<Integer> mColors; + private final Random mRandom; + + public static ColorGenerator create(List<Integer> colorList) { + return new ColorGenerator(colorList); + } + + private ColorGenerator(List<Integer> colorList) { + mColors = colorList; + mRandom = new Random(System.currentTimeMillis()); + } + + public int getRandomColor() { + return mColors.get(mRandom.nextInt(mColors.size())); + } + + public int getColor(Object key) { + return mColors.get(Math.abs(key.hashCode()) % mColors.size()); + } +} |