├── .gitignore
├── README.md
├── build.gradle
├── example
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── github
│ │ └── lzyzsd
│ │ └── randomcolor
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── github
│ │ └── lzyzsd
│ │ └── randomcolorexample
│ │ ├── MainActivity.java
│ │ ├── RandomUseNameActivity.java
│ │ └── RoundView.java
│ └── res
│ ├── layout
│ ├── activity_main.xml
│ └── activity_random_use_name.xml
│ ├── menu
│ ├── menu_main.xml
│ └── menu_random_use_name.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── github
│ │ └── lzyzsd
│ │ └── randomcolor
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── github
│ │ └── lzyzsd
│ │ └── randomcolor
│ │ ├── ColorInfo.java
│ │ ├── RandomColor.java
│ │ └── Range.java
│ └── res
│ └── values
│ └── strings.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | #built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 |
15 | # Local configuration file (sdk path, etc)
16 | local.properties
17 |
18 | # Windows thumbnail db
19 | Thumbs.db
20 |
21 | # OSX files
22 | .DS_Store
23 |
24 | # Eclipse project files
25 | .classpath
26 | .project
27 |
28 | # Android Studio
29 | .idea
30 | #.idea/workspace.xml - remove # and delete .idea if it better suit your needs.
31 | .gradle
32 | build/
33 |
34 | # Signing files
35 | .signing/
36 |
37 | # User-specific configurations
38 | .idea/libraries/
39 | .idea/workspace.xml
40 | .idea/tasks.xml
41 | .idea/.name
42 | .idea/compiler.xml
43 | .idea/copyright/profiles_settings.xml
44 | .idea/encodings.xml
45 | .idea/misc.xml
46 | .idea/modules.xml
47 | .idea/scopes/scope_settings.xml
48 | .idea/vcs.xml
49 | *.iml
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android Random Color
2 |
3 | Inspired by David Merfield's [randomColor.js](https://github.com/davidmerfield/randomColor) and onevcat's [RandomColorSwift](https://github.com/onevcat/RandomColorSwift).
4 | It is a ported version to Android. You can use the library to generate attractive random colors on Android.
5 |
6 | See the [demo and site](http://llllll.li/randomColor/) to know why does this exist.
7 |
8 | [](http://llllll.li/randomColor)
9 |
10 | ## Install
11 |
12 | gradle
13 |
14 | ```groovy
15 | dependencies {
16 | compile 'com.github.lzyzsd.randomcolor:library:1.0.0'
17 | }
18 | ```
19 |
20 | ## Example
21 |
22 | ```java
23 |
24 | // Returns a random int color value
25 |
26 | RandomColor randomColor = new RandomColor();
27 | int color = randomColor.randomColor();
28 |
29 | // Returns an array of 10 random color values
30 |
31 | RandomColor randomColor = new RandomColor();
32 | int[] color = randomColor.randomColor(10);
33 |
34 | //This lib also predefine some colors, so than you can random color by these predefined colors
35 |
36 | // Returns an array of ten green colors
37 |
38 | randomColor.random(RandomColor.Color.GREEN, 10);
39 |
40 | // Returns a random color use hue, saturation, luminosity
41 | // saturation has two kinds of value: RANDOM, MONOCHROME
42 | // luminosity has for kinds of value: BRIGHT, LIGHT, DARK, RANDOM
43 |
44 | randomColor(int value, SaturationType saturationType, Luminosity luminosity)
45 |
46 | ```
47 |
48 | There is also a demo project in this repo.
49 |
50 | ## Acknowledgements
51 |
52 | Thanks for David Merfield bringing us randomColor.js, which is a great utility.
53 |
54 | The demo project is using Chirag Mehta's [Name the Color](http://chir.ag/projects/name-that-color) JavaScript library to extract name of color.
55 |
56 | ## License
57 |
58 | This project is licensed under the terms of the MIT license.
59 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.0.1'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | classpath 'com.github.dcendents:android-maven-plugin:1.2'
13 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | jcenter()
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/example/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 21
5 | buildToolsVersion "21.1.2"
6 |
7 | defaultConfig {
8 | applicationId "com.github.lzyzsd.randomcolorexample"
9 | minSdkVersion 14
10 | targetSdkVersion 21
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile project(":library")
24 | compile 'com.android.support:appcompat-v7:21.0.3'
25 | compile 'org.apmem.tools:layouts:1.8@aar'
26 | }
27 |
--------------------------------------------------------------------------------
/example/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/bruce/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/example/src/androidTest/java/com/github/lzyzsd/randomcolor/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.github.lzyzsd.randomcolor;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/example/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/example/src/main/java/com/github/lzyzsd/randomcolorexample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.github.lzyzsd.randomcolorexample;
2 |
3 | import android.content.Intent;
4 | import android.support.v7.app.ActionBarActivity;
5 | import android.os.Bundle;
6 | import android.util.Log;
7 | import android.view.Menu;
8 | import android.view.MenuItem;
9 |
10 | import com.github.lzyzsd.randomcolor.RandomColor;
11 |
12 | import org.apmem.tools.layouts.FlowLayout;
13 |
14 |
15 | public class MainActivity extends ActionBarActivity {
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 | FlowLayout container = (FlowLayout) findViewById(R.id.container);
22 | RandomColor randomColor = new RandomColor();
23 | int[] colors = randomColor.randomColor(100);
24 | for (int i = 0; i < colors.length; i++) {
25 | RoundView roundView = new RoundView(this);
26 | roundView.setLayoutParams(new FlowLayout.LayoutParams(180, 180));
27 | roundView.setPadding(20, 20, 20, 20);
28 | int color = colors[i];
29 | Log.d("RandomColor", "color: " + color);
30 | roundView.setRoundColor(color);
31 | container.addView(roundView);
32 | }
33 | }
34 |
35 |
36 | @Override
37 | public boolean onCreateOptionsMenu(Menu menu) {
38 | // Inflate the menu; this adds items to the action bar if it is present.
39 | getMenuInflater().inflate(R.menu.menu_main, menu);
40 | return true;
41 | }
42 |
43 | @Override
44 | public boolean onOptionsItemSelected(MenuItem item) {
45 | // Handle action bar item clicks here. The action bar will
46 | // automatically handle clicks on the Home/Up button, so long
47 | // as you specify a parent activity in AndroidManifest.xml.
48 | int id = item.getItemId();
49 |
50 | //noinspection SimplifiableIfStatement
51 | if (id == R.id.action_random_name) {
52 | startActivity(new Intent(this, RandomUseNameActivity.class));
53 | return true;
54 | }
55 |
56 | return super.onOptionsItemSelected(item);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/example/src/main/java/com/github/lzyzsd/randomcolorexample/RandomUseNameActivity.java:
--------------------------------------------------------------------------------
1 | package com.github.lzyzsd.randomcolorexample;
2 |
3 | import android.support.v7.app.ActionBarActivity;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import android.view.Menu;
7 | import android.view.MenuItem;
8 | import android.view.ViewGroup;
9 | import android.widget.LinearLayout;
10 | import android.widget.TextView;
11 |
12 | import com.github.lzyzsd.randomcolor.RandomColor;
13 |
14 | import org.apmem.tools.layouts.FlowLayout;
15 |
16 |
17 | public class RandomUseNameActivity extends ActionBarActivity {
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_random_use_name);
23 |
24 | LinearLayout container = (LinearLayout) findViewById(R.id.container);
25 | RandomColor randomColor = new RandomColor();
26 | for (RandomColor.Color color : RandomColor.Color.values()) {
27 | if (color == RandomColor.Color.MONOCHROME) {
28 | continue;
29 | }
30 | TextView textView = new TextView(this);
31 | textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
32 | textView.setText("randomColor.random(" + color + ", 15)");
33 | textView.setTextSize(18);
34 | textView.setPadding(15, 6, 15, 6);
35 | container.addView(textView);
36 | FlowLayout flowLayout = new FlowLayout(this);
37 | flowLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
38 | int[] colors = randomColor.random(color, 15);
39 | for (int i = 0; i < colors.length; i++) {
40 | RoundView roundView = new RoundView(this);
41 | roundView.setLayoutParams(new FlowLayout.LayoutParams(180, 180));
42 | roundView.setPadding(20, 20, 20, 20);
43 | int c = colors[i];
44 | Log.d("RandomUseNameActivity", "color: " + c);
45 | roundView.setRoundColor(c);
46 | flowLayout.addView(roundView);
47 | }
48 | container.addView(flowLayout);
49 | }
50 | }
51 |
52 |
53 | @Override
54 | public boolean onCreateOptionsMenu(Menu menu) {
55 | // Inflate the menu; this adds items to the action bar if it is present.
56 | getMenuInflater().inflate(R.menu.menu_random_use_name, menu);
57 | return true;
58 | }
59 |
60 | @Override
61 | public boolean onOptionsItemSelected(MenuItem item) {
62 | // Handle action bar item clicks here. The action bar will
63 | // automatically handle clicks on the Home/Up button, so long
64 | // as you specify a parent activity in AndroidManifest.xml.
65 | int id = item.getItemId();
66 |
67 | //noinspection SimplifiableIfStatement
68 | if (id == R.id.action_settings) {
69 | return true;
70 | }
71 |
72 | return super.onOptionsItemSelected(item);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/example/src/main/java/com/github/lzyzsd/randomcolorexample/RoundView.java:
--------------------------------------------------------------------------------
1 | package com.github.lzyzsd.randomcolorexample;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.graphics.Paint;
6 | import android.util.AttributeSet;
7 | import android.view.View;
8 |
9 | /**
10 | * Created by bruce on 15/2/9.
11 | */
12 | public class RoundView extends View {
13 | private int roundColor = Color.GREEN;
14 | Paint paint = new Paint();
15 | public RoundView(Context context) {
16 | super(context);
17 | }
18 |
19 | public RoundView(Context context, AttributeSet attrs) {
20 | super(context, attrs);
21 | }
22 |
23 | public RoundView(Context context, AttributeSet attrs, int defStyle) {
24 | super(context, attrs, defStyle);
25 | }
26 |
27 | public int getRoundColor() {
28 | return roundColor;
29 | }
30 |
31 | public void setRoundColor(int roundColor) {
32 | this.roundColor = roundColor;
33 | }
34 |
35 | protected void onDraw(android.graphics.Canvas canvas)
36 | {
37 | paint.setColor(this.roundColor);
38 | paint.setAntiAlias(true);
39 | canvas.drawCircle(getWidth()/2 - getPaddingLeft(), getHeight()/2 - getPaddingLeft(), getWidth()/2 - getPaddingLeft(), paint);
40 | }
41 | }
--------------------------------------------------------------------------------
/example/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
5 |
13 |
14 |
--------------------------------------------------------------------------------
/example/src/main/res/layout/activity_random_use_name.xml:
--------------------------------------------------------------------------------
1 |
5 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/example/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/example/src/main/res/menu/menu_random_use_name.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uknownothingsnow/AndroidRandomColor/b917daa06399666c903f2260210cadded8203a37/example/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uknownothingsnow/AndroidRandomColor/b917daa06399666c903f2260210cadded8203a37/example/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uknownothingsnow/AndroidRandomColor/b917daa06399666c903f2260210cadded8203a37/example/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uknownothingsnow/AndroidRandomColor/b917daa06399666c903f2260210cadded8203a37/example/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/example/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/example/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroidRandomColor
3 |
4 | Hello world!
5 | Settings
6 | RandomUseNameActivity
7 |
8 |
--------------------------------------------------------------------------------
/example/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uknownothingsnow/AndroidRandomColor/b917daa06399666c903f2260210cadded8203a37/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | apply plugin: 'com.jfrog.bintray'
4 |
5 | version = "1.0.0"
6 |
7 | android {
8 | compileSdkVersion 21
9 | buildToolsVersion "21.1.2"
10 |
11 | defaultConfig {
12 | minSdkVersion 9
13 | targetSdkVersion 21
14 | versionCode 1
15 | versionName version
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(dir: 'libs', include: ['*.jar'])
27 | }
28 |
29 | def siteUrl = 'https://github.com/lzyzsd/AndroidRandomColor' // 项目的主页
30 | def gitUrl = 'https://github.com/lzyzsd/AndroidRandomColor.git' // Git仓库的url
31 | group = "com.github.lzyzsd.randomcolor" // Maven Group ID for the artifact,一般填你唯一的包名
32 | install {
33 | repositories.mavenInstaller {
34 | // This generates POM.xml with proper parameters
35 | pom {
36 | project {
37 | packaging 'aar'
38 | // Add your description here
39 | name 'Android Random Color Generator' //项目描述
40 | url siteUrl
41 | // Set your license
42 | licenses {
43 | license {
44 | name 'MIT'
45 | url 'http://opensource.org/licenses/MIT'
46 | }
47 | }
48 | developers {
49 | developer {
50 | id 'lzyzsd' //填写的一些基本信息
51 | name 'Bruce Lee'
52 | email 'bruceinpeking@gmail.com'
53 | }
54 | }
55 | scm {
56 | connection gitUrl
57 | developerConnection gitUrl
58 | url siteUrl
59 | }
60 | }
61 | }
62 | }
63 | }
64 | task sourcesJar(type: Jar) {
65 | from android.sourceSets.main.java.srcDirs
66 | classifier = 'sources'
67 | }
68 | task javadoc(type: Javadoc) {
69 | source = android.sourceSets.main.java.srcDirs
70 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
71 | }
72 | task javadocJar(type: Jar, dependsOn: javadoc) {
73 | classifier = 'javadoc'
74 | from javadoc.destinationDir
75 | }
76 | artifacts {
77 | archives javadocJar
78 | archives sourcesJar
79 | }
80 | Properties properties = new Properties()
81 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
82 | bintray {
83 | user = properties.getProperty("bintray.user")
84 | key = properties.getProperty("bintray.apikey")
85 | configurations = ['archives']
86 | pkg {
87 | repo = "maven"
88 | name = "AndroidRandomColor" //发布到JCenter上的项目名字
89 | websiteUrl = siteUrl
90 | vcsUrl = gitUrl
91 | licenses = ["MIT"]
92 | publish = true
93 | }
94 | }
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/bruce/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/github/lzyzsd/randomcolor/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.github.lzyzsd.randomcolor;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
--------------------------------------------------------------------------------
/library/src/main/java/com/github/lzyzsd/randomcolor/ColorInfo.java:
--------------------------------------------------------------------------------
1 | package com.github.lzyzsd.randomcolor;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by bruce on 15/2/9.
7 | */
8 | public class ColorInfo {
9 | Range hueRange;
10 | Range saturationRange;
11 | Range brightnessRange;
12 | List lowerBounds;
13 |
14 | public ColorInfo(Range hueRange, Range saturationRange, Range brightnessRange, List lowerBounds) {
15 | this.hueRange = hueRange;
16 | this.saturationRange = saturationRange;
17 | this.brightnessRange = brightnessRange;
18 | this.lowerBounds = lowerBounds;
19 | }
20 |
21 | public Range getHueRange() {
22 | return hueRange;
23 | }
24 |
25 | public void setHueRange(Range hueRange) {
26 | this.hueRange = hueRange;
27 | }
28 |
29 | public Range getSaturationRange() {
30 | return saturationRange;
31 | }
32 |
33 | public void setSaturationRange(Range saturationRange) {
34 | this.saturationRange = saturationRange;
35 | }
36 |
37 | public Range getBrightnessRange() {
38 | return brightnessRange;
39 | }
40 |
41 | public void setBrightnessRange(Range brightnessRange) {
42 | this.brightnessRange = brightnessRange;
43 | }
44 |
45 | public List getLowerBounds() {
46 | return lowerBounds;
47 | }
48 |
49 | public void setLowerBounds(List lowerBounds) {
50 | this.lowerBounds = lowerBounds;
51 | }
52 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/github/lzyzsd/randomcolor/RandomColor.java:
--------------------------------------------------------------------------------
1 | package com.github.lzyzsd.randomcolor;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.List;
6 |
7 | /**
8 | * Created by bruce on 15/2/5.
9 | */
10 | public class RandomColor {
11 | private static final String TAG = "RandomColor";
12 | private Random random;
13 |
14 | public static enum SaturationType {
15 | RANDOM, MONOCHROME
16 | }
17 |
18 | public static enum Luminosity {
19 | BRIGHT, LIGHT, DARK, RANDOM
20 | }
21 |
22 | public static class Options {
23 | int hue;
24 | SaturationType saturationType;
25 | Luminosity luminosity;
26 |
27 | public int getHue() {
28 | return hue;
29 | }
30 |
31 | public void setHue(int hue) {
32 | this.hue = hue;
33 | }
34 |
35 | public SaturationType getSaturationType() {
36 | return saturationType;
37 | }
38 |
39 | public void setSaturationType(SaturationType saturationType) {
40 | this.saturationType = saturationType;
41 | }
42 |
43 | public Luminosity getLuminosity() {
44 | return luminosity;
45 | }
46 |
47 | public void setLuminosity(Luminosity luminosity) {
48 | this.luminosity = luminosity;
49 | }
50 | }
51 |
52 | private HashMap colors = new HashMap<>();
53 |
54 | public RandomColor() {
55 | loadColorBounds();
56 | random = new Random();
57 | }
58 |
59 | public RandomColor(long seed){
60 | loadColorBounds();
61 | random = new Random();
62 | random.setSeed(seed);
63 | }
64 |
65 | private int getColor(int hue, int saturation, int brightness) {
66 | return android.graphics.Color.HSVToColor(new float[] {hue, saturation, brightness});
67 | }
68 |
69 | public int randomColor() {
70 | return randomColor(0, null, null);
71 | }
72 |
73 | public int randomColor(int value, SaturationType saturationType, Luminosity luminosity) {
74 | int hue = value;
75 | hue = pickHue(hue);
76 | int saturation = pickSaturation(hue, saturationType, luminosity);
77 | int brightness = pickBrightness(hue, saturation, luminosity);
78 |
79 | int color = getColor(hue, saturation, brightness);
80 | return color;
81 | }
82 |
83 | public int[] randomColor(int count) {
84 | if (count <= 0) {
85 | throw new IllegalArgumentException("count must be greater than 0");
86 | }
87 |
88 | int[] colors = new int[count];
89 | for (int i = 0; i < count; i++) {
90 | colors[i] = randomColor();
91 | }
92 |
93 | return colors;
94 | }
95 |
96 | public int randomColor(Color color) {
97 | int hue = pickHue(color.name());
98 | int saturation = pickSaturation(color, null, null);
99 | int brightness = pickBrightness(color, saturation, null);
100 |
101 | int colorValue = getColor(hue, saturation, brightness);
102 | return colorValue;
103 | }
104 |
105 | public int[] random(Color color, int count) {
106 | if (count <= 0) {
107 | throw new IllegalArgumentException("count must be greater than 0");
108 | }
109 |
110 | int[] colors = new int[count];
111 | for (int i = 0; i < count; i++) {
112 | colors[i] = randomColor(color);
113 | }
114 |
115 | return colors;
116 | }
117 |
118 | private int pickHue(int hue) {
119 | Range hueRange = getHueRange(hue);
120 | return doPickHue(hueRange);
121 | }
122 |
123 | private int doPickHue(Range hueRange) {
124 | int hue = randomWithin(hueRange);
125 |
126 | // Instead of storing red as two seperate ranges,
127 | // we group them, using negative numbers
128 | if (hue < 0) {
129 | hue = 360 + hue;
130 | }
131 |
132 | return hue;
133 | }
134 |
135 | private int pickHue(String name) {
136 | Range hueRange = getHueRange(name);
137 | return doPickHue(hueRange);
138 | }
139 |
140 | private Range getHueRange(int number) {
141 | if (number < 360 && number > 0) {
142 | return new Range(number, number);
143 | }
144 |
145 | return new Range(0, 360);
146 | }
147 |
148 | private Range getHueRange(String name) {
149 | if (colors.containsKey(name)) {
150 | return colors.get(name).getHueRange();
151 | }
152 |
153 | return new Range(0, 360);
154 | }
155 |
156 | private int pickSaturation(int hue, SaturationType saturationType, Luminosity luminosity) {
157 | return pickSaturation(getColorInfo(hue), saturationType, luminosity);
158 | }
159 |
160 | private int pickSaturation(Color color, SaturationType saturationType, Luminosity luminosity) {
161 | ColorInfo colorInfo = colors.get(color.name());
162 | return pickSaturation(colorInfo, saturationType, luminosity);
163 | }
164 |
165 | private int pickSaturation(ColorInfo colorInfo, SaturationType saturationType, Luminosity luminosity) {
166 | if (saturationType != null) {
167 | switch (saturationType) {
168 | case RANDOM:
169 | return randomWithin(new Range(0, 100));
170 | case MONOCHROME:
171 | return 0;
172 | }
173 | }
174 |
175 | if (colorInfo == null) {
176 | return 0;
177 | }
178 |
179 | Range saturationRange = colorInfo.getSaturationRange();
180 |
181 | int min = saturationRange.start;
182 | int max = saturationRange.end;
183 |
184 | if (luminosity != null) {
185 | switch (luminosity) {
186 | case LIGHT:
187 | min = 55;
188 | break;
189 | case BRIGHT:
190 | min = max - 10;
191 | break;
192 | case DARK:
193 | max = 55;
194 | break;
195 | }
196 | }
197 |
198 | return randomWithin(new Range(min, max));
199 | }
200 |
201 | private int pickBrightness(int hue, int saturation, Luminosity luminosity) {
202 | ColorInfo colorInfo = getColorInfo(hue);
203 |
204 | return pickBrightness(colorInfo, saturation, luminosity);
205 | }
206 |
207 | private int pickBrightness(Color color, int saturation, Luminosity luminosity) {
208 | ColorInfo colorInfo = colors.get(color.name());
209 |
210 | return pickBrightness(colorInfo, saturation, luminosity);
211 | }
212 |
213 | private int pickBrightness(ColorInfo colorInfo, int saturation, Luminosity luminosity) {
214 | int min = getMinimumBrightness(colorInfo, saturation),
215 | max = 100;
216 |
217 | if (luminosity != null) {
218 | switch (luminosity) {
219 |
220 | case DARK:
221 | max = min + 20;
222 | break;
223 |
224 | case LIGHT:
225 | min = (max + min) / 2;
226 | break;
227 |
228 | case RANDOM:
229 | min = 0;
230 | max = 100;
231 | break;
232 | }
233 | }
234 |
235 | return randomWithin(new Range(min, max));
236 | }
237 |
238 | private int getMinimumBrightness(ColorInfo colorInfo, int saturation) {
239 | if (colorInfo == null) {
240 | return 0;
241 | }
242 |
243 | List lowerBounds = colorInfo.getLowerBounds();
244 | for (int i = 0; i < lowerBounds.size() - 1; i++) {
245 |
246 | int s1 = lowerBounds.get(i).start,
247 | v1 = lowerBounds.get(i).end;
248 |
249 | if (i == lowerBounds.size() - 1) {
250 | break;
251 | }
252 | int s2 = lowerBounds.get(i + 1).start,
253 | v2 = lowerBounds.get(i + 1).end;
254 |
255 | if (saturation >= s1 && saturation <= s2) {
256 |
257 | float m = (v2 - v1)/(float) (s2 - s1),
258 | b = v1 - m*s1;
259 |
260 | return (int) (m*saturation + b);
261 | }
262 |
263 | }
264 |
265 | return 0;
266 | }
267 |
268 | private ColorInfo getColorInfo(int hue) {
269 | // Maps red colors to make picking hue easier
270 | if (hue >= 334 && hue <= 360) {
271 | hue-= 360;
272 | }
273 |
274 | for(String key : colors.keySet()) {
275 | ColorInfo colorInfo = colors.get(key);
276 | if (colorInfo.getHueRange() != null && colorInfo.getHueRange().contain(hue)) {
277 | return colorInfo;
278 | }
279 | }
280 |
281 | return null;
282 | }
283 |
284 | private int randomWithin (Range range) {
285 | return (int) Math.floor(range.start + random.nextDouble()*(range.end + 1 - range.start));
286 | }
287 |
288 | public void defineColor(String name, Range hueRange, List lowerBounds) {
289 | int sMin = lowerBounds.get(0).start;
290 | int sMax = lowerBounds.get(lowerBounds.size() - 1).start;
291 | int bMin = lowerBounds.get(lowerBounds.size() - 1).end;
292 | int bMax = lowerBounds.get(0).end;
293 |
294 | colors.put(name, new ColorInfo(hueRange, new Range(sMin, sMax), new Range(bMin, bMax), lowerBounds));
295 | }
296 |
297 | private void loadColorBounds() {
298 | List lowerBounds1 = new ArrayList<>();
299 | lowerBounds1.add(new Range(0, 0));
300 | lowerBounds1.add(new Range(100, 0));
301 | defineColor(
302 | Color.MONOCHROME.name(),
303 | null,
304 | lowerBounds1
305 | );
306 |
307 | List lowerBounds2 = new ArrayList<>();
308 | lowerBounds2.add(new Range(20, 100));
309 | lowerBounds2.add(new Range(30, 92));
310 | lowerBounds2.add(new Range(40, 89));
311 | lowerBounds2.add(new Range(50, 85));
312 | lowerBounds2.add(new Range(60, 78));
313 | lowerBounds2.add(new Range(70, 70));
314 | lowerBounds2.add(new Range(80, 60));
315 | lowerBounds2.add(new Range(90, 55));
316 | lowerBounds2.add(new Range(100, 50));
317 | defineColor(
318 | Color.RED.name(),
319 | new Range(-26, 18),
320 | lowerBounds2
321 | );
322 |
323 | List lowerBounds3 = new ArrayList();
324 | lowerBounds3.add(new Range(20, 100));
325 | lowerBounds3.add(new Range(30, 93));
326 | lowerBounds3.add(new Range(40, 88));
327 | lowerBounds3.add(new Range(50, 86));
328 | lowerBounds3.add(new Range(60, 85));
329 | lowerBounds3.add(new Range(70, 70));
330 | lowerBounds3.add(new Range(100, 70));
331 | defineColor(
332 | Color.ORANGE.name(),
333 | new Range(19, 46),
334 | lowerBounds3
335 | );
336 |
337 | List lowerBounds4 = new ArrayList<>();
338 | lowerBounds4.add(new Range(25, 100));
339 | lowerBounds4.add(new Range(40, 94));
340 | lowerBounds4.add(new Range(50, 89));
341 | lowerBounds4.add(new Range(60, 86));
342 | lowerBounds4.add(new Range(70, 84));
343 | lowerBounds4.add(new Range(80, 82));
344 | lowerBounds4.add(new Range(90, 80));
345 | lowerBounds4.add(new Range(100, 75));
346 |
347 | defineColor(
348 | Color.YELLOW.name(),
349 | new Range(47, 62),
350 | lowerBounds4
351 | );
352 |
353 | List lowerBounds5 = new ArrayList<>();
354 | lowerBounds5.add(new Range(30, 100));
355 | lowerBounds5.add(new Range(40, 90));
356 | lowerBounds5.add(new Range(50, 85));
357 | lowerBounds5.add(new Range(60, 81));
358 | lowerBounds5.add(new Range(70, 74));
359 | lowerBounds5.add(new Range(80, 64));
360 | lowerBounds5.add(new Range(90, 50));
361 | lowerBounds5.add(new Range(100, 40));
362 |
363 | defineColor(
364 | Color.GREEN.name(),
365 | new Range(63,178),
366 | lowerBounds5
367 | );
368 |
369 | List lowerBounds6 = new ArrayList<>();
370 | lowerBounds6.add(new Range(20, 100));
371 | lowerBounds6.add(new Range(30, 86));
372 | lowerBounds6.add(new Range(40, 80));
373 | lowerBounds6.add(new Range(50, 74));
374 | lowerBounds6.add(new Range(60, 60));
375 | lowerBounds6.add(new Range(70, 52));
376 | lowerBounds6.add(new Range(80, 44));
377 | lowerBounds6.add(new Range(90, 39));
378 | lowerBounds6.add(new Range(100, 35));
379 |
380 | defineColor(
381 | Color.BLUE.name(),
382 | new Range(179, 257),
383 | lowerBounds6
384 | );
385 |
386 | List lowerBounds7 = new ArrayList<>();
387 | lowerBounds7.add(new Range(20, 100));
388 | lowerBounds7.add(new Range(30, 87));
389 | lowerBounds7.add(new Range(40, 79));
390 | lowerBounds7.add(new Range(50, 70));
391 | lowerBounds7.add(new Range(60, 65));
392 | lowerBounds7.add(new Range(70, 59));
393 | lowerBounds7.add(new Range(80, 52));
394 | lowerBounds7.add(new Range(90, 45));
395 | lowerBounds7.add(new Range(100, 42));
396 |
397 | defineColor(
398 | Color.PURPLE.name(),
399 | new Range(258, 282),
400 | lowerBounds7
401 | );
402 |
403 | List lowerBounds8 = new ArrayList<>();
404 | lowerBounds8.add(new Range(20, 100));
405 | lowerBounds8.add(new Range(30, 90));
406 | lowerBounds8.add(new Range(40, 86));
407 | lowerBounds8.add(new Range(60, 84));
408 | lowerBounds8.add(new Range(80, 80));
409 | lowerBounds8.add(new Range(90, 75));
410 | lowerBounds8.add(new Range(100, 73));
411 |
412 | defineColor(
413 | Color.PINK.name(),
414 | new Range(283, 334),
415 | lowerBounds8
416 | );
417 | }
418 |
419 | public static enum Color {
420 | MONOCHROME, RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE, PINK
421 | }
422 | }
423 |
--------------------------------------------------------------------------------
/library/src/main/java/com/github/lzyzsd/randomcolor/Range.java:
--------------------------------------------------------------------------------
1 | package com.github.lzyzsd.randomcolor;
2 |
3 | /**
4 | * Created by bruce on 15/2/9.
5 | */
6 | public class Range {
7 | int start;
8 | int end;
9 |
10 | public Range(int start, int end) {
11 | this.start = start;
12 | this.end = end;
13 | }
14 |
15 | public boolean contain(int value) {
16 | return value >= start && value <= end;
17 | }
18 |
19 | @Override
20 | public String toString() {
21 | return "start: " + start + " end: " + end;
22 | }
23 | }
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | library
3 |
4 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':example', ':library'
2 |
--------------------------------------------------------------------------------