├── .gitignore
├── README.md
├── Screen
├── 1.gif
├── 2.gif
├── 3.png
├── 4.png
├── 5.png
├── 6.png
├── 7.png
├── 8.png
└── simple.apk
├── build.gradle
├── proguard-rules.pro
└── src
├── main
├── AndroidManifest.xml
├── java
│ └── labelnet
│ │ └── cn
│ │ └── patterncolordemo
│ │ ├── DrawableActivity.java
│ │ ├── MainActivity.java
│ │ ├── PaletteUtil.java
│ │ ├── PatternUtilActivity.java
│ │ └── other
│ │ └── DrawableUtil.java
└── res
│ ├── drawable
│ └── back_shape_color.xml
│ ├── layout
│ ├── activity_drawable.xml
│ ├── activity_main.xml
│ └── activity_pattern_util.xml
│ ├── menu
│ └── main_menu.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ ├── ic_launcher.png
│ ├── icon_app.png
│ ├── icon_enght.png
│ ├── icon_five.png
│ ├── icon_four.png
│ ├── icon_nine.png
│ ├── icon_one.png
│ ├── icon_seven.png
│ ├── icon_six.png
│ ├── icon_ten.png
│ ├── icon_ten1.png
│ ├── icon_ten2.png
│ ├── icon_ten3.png
│ ├── icon_ten4.png
│ ├── icon_ten5.png
│ ├── icon_ten6.png
│ ├── icon_three.png
│ └── icon_two.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
└── test
└── java
└── labelnet
└── cn
└── patterncolordemo
└── ExampleUnitTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | *.iml
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PaletteColorDemo
2 | 探索Palette 与 生成 渐变背景色
3 |
4 | # BackGround:
5 |
6 | 根据图标生成其渐变背景颜色
7 | (Generates its gradient background color according to the icon)
8 |
9 | # Screen Recrode
10 |
11 | 
12 | 
13 |
14 | # Test1- 源码运行观看 (clone simple source code )
15 |
16 | * (1) 打开Android Studio ,新建工程 ,打开新建工程所在的文件夹,在其跟目录下进行clone
17 | * (2) git clone https://github.com/LABELNET/PaletteColorDemo.git
18 | * (3) 配置新建工程下的settings.gradle , 添加 include ':palettecolordemo' 执行即可
19 | * (4) 注意:出错的话,注意修改v7包的版本;
20 |
21 | # Test2- 下载与安装 APK (Download and Install simple.apk file)
22 |
23 | [Download SimpleApk](https://github.com/LABELNET/PaletteColorDemo/blob/master/Screen/simple.apk)
24 |
25 | # Gradle Dependency 使用
26 | * Don't Gradle Dependency, You can learn from [ here](http://blog.csdn.net/LABLENET/article/details/52340634)
27 | * [ Android - 一个似神器而非神器之Palette探索与实践](http://blog.csdn.net/LABLENET/article/details/52340634)
28 |
29 | # Sample Usage
30 |
31 | **使用方法 :**
32 |
33 | **(1)** *init(Resource res,int resId,callback)* 方式
34 |
35 | ```
36 | PaletteUtil.getInstance()
37 | .init(getResources()
38 | ,R.mipmap.icon_one
39 | ,new PaletteUtil.PatternCallBack() {
40 | @Override
41 | public void onCallBack(Drawable drawable, int titleColor) {
42 | tv.setTextColor(titleColor);
43 | tv.setBackgroundDrawable(drawable);
44 | }
45 | });
46 | ```
47 | **(2)** *init(bitmap,callback)* 方式
48 |
49 | ```
50 | Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.mipmap.icon_one);
51 | PaletteUtil.getInstance().init(bitmap, new PaletteUtil.PatternCallBack() {
52 | @Override
53 | public void onCallBack(Drawable drawable, int titleColor) {
54 |
55 | }
56 | });
57 |
--------------------------------------------------------------------------------
/Screen/1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/Screen/1.gif
--------------------------------------------------------------------------------
/Screen/2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/Screen/2.gif
--------------------------------------------------------------------------------
/Screen/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/Screen/3.png
--------------------------------------------------------------------------------
/Screen/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/Screen/4.png
--------------------------------------------------------------------------------
/Screen/5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/Screen/5.png
--------------------------------------------------------------------------------
/Screen/6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/Screen/6.png
--------------------------------------------------------------------------------
/Screen/7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/Screen/7.png
--------------------------------------------------------------------------------
/Screen/8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/Screen/8.png
--------------------------------------------------------------------------------
/Screen/simple.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/Screen/simple.apk
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "labelnet.cn.patterncolordemo"
9 | minSdkVersion 15
10 | targetSdkVersion 23
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 | testOptions {
22 | unitTests.returnDefaultValues = true
23 | }
24 |
25 | }
26 |
27 | dependencies {
28 | compile fileTree(dir: 'libs', include: ['*.jar'])
29 | testCompile 'junit:junit:4.12'
30 | compile 'com.android.support:appcompat-v7:23.4.0'
31 | compile 'com.android.support:palette-v7:23.4.0'
32 | }
33 |
--------------------------------------------------------------------------------
/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 E:\android-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 |
--------------------------------------------------------------------------------
/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/main/java/labelnet/cn/patterncolordemo/DrawableActivity.java:
--------------------------------------------------------------------------------
1 | package labelnet.cn.patterncolordemo;
2 |
3 | import android.graphics.drawable.Drawable;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.widget.TextView;
7 |
8 | import labelnet.cn.patterncolordemo.other.DrawableUtil;
9 |
10 | public class DrawableActivity extends AppCompatActivity {
11 |
12 |
13 | TextView tv_drawable;
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_drawable);
19 | tv_drawable= (TextView) findViewById(R.id.tv_drawable);
20 | Drawable drawable = DrawableUtil.changedImageViewShape(getResources().getColor(R.color.js_one)
21 | , getResources().getColor(R.color.js_two));
22 | tv_drawable.setBackground(drawable);
23 |
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/labelnet/cn/patterncolordemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package labelnet.cn.patterncolordemo;
2 |
3 | import android.content.Intent;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Color;
7 | import android.graphics.drawable.Drawable;
8 | import android.graphics.drawable.GradientDrawable;
9 | import android.os.Bundle;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.support.v7.graphics.Palette;
12 | import android.util.Log;
13 | import android.view.Menu;
14 | import android.view.MenuItem;
15 | import android.view.View;
16 | import android.widget.TextView;
17 |
18 | public class MainActivity extends AppCompatActivity {
19 |
20 |
21 | private TextView tv1;
22 | private TextView tv2;
23 | private TextView tv3;
24 | private TextView tv4;
25 | private TextView tv5;
26 | private TextView tv6;
27 | private TextView tv7;
28 | int index=0;
29 |
30 | private int [] imageIds=new int[]{
31 | R.mipmap.icon_one,
32 | R.mipmap.icon_two,
33 | R.mipmap.icon_three,
34 | R.mipmap.icon_three,
35 | R.mipmap.icon_four,
36 | R.mipmap.icon_five,
37 | R.mipmap.icon_six,
38 | R.mipmap.icon_seven,
39 | R.mipmap.icon_enght,
40 | R.mipmap.icon_nine,
41 | R.mipmap.icon_ten,
42 | R.mipmap.icon_ten1,
43 | R.mipmap.icon_ten2,
44 | R.mipmap.icon_ten3,
45 | R.mipmap.icon_ten4,
46 | R.mipmap.icon_ten5,
47 | R.mipmap.icon_ten6
48 | };
49 |
50 |
51 | @Override
52 | protected void onCreate(Bundle savedInstanceState) {
53 | super.onCreate(savedInstanceState);
54 | setContentView(R.layout.activity_main);
55 | tv1= (TextView) findViewById(R.id.tv1);
56 | tv2= (TextView) findViewById(R.id.tv2);
57 | tv3= (TextView) findViewById(R.id.tv3);
58 | tv4= (TextView) findViewById(R.id.tv4);
59 | tv5= (TextView) findViewById(R.id.tv5);
60 | tv6= (TextView) findViewById(R.id.tv6);
61 | tv7= (TextView) findViewById(R.id.tv7);
62 | initTextView();
63 | }
64 |
65 | private void initTextView() {
66 |
67 | Bitmap bitmap = BitmapFactory.decodeResource(getResources(),imageIds[index]);
68 | initBackColor(bitmap);
69 |
70 | tv7.setOnClickListener(new View.OnClickListener() {
71 | @Override
72 | public void onClick(View v) {
73 | index++;
74 | if(index==imageIds.length){
75 | index=0;
76 | }
77 | Bitmap bitmap = BitmapFactory.decodeResource(getResources(),imageIds[index]);
78 | initBackColor(bitmap);
79 | setTitle(getString(R.string.app_name)+" | "+index);
80 | }
81 | });
82 |
83 | }
84 |
85 | @Override
86 | public boolean onCreateOptionsMenu(Menu menu) {
87 | getMenuInflater().inflate(R.menu.main_menu,menu);
88 | return true;
89 | }
90 |
91 | @Override
92 | public boolean onOptionsItemSelected(MenuItem item) {
93 | if(item.getItemId()==R.id.test_palette){
94 | startActivity(new Intent(MainActivity.this,PatternUtilActivity.class));
95 | }else if(item.getItemId()==R.id.test_drawable){
96 | startActivity(new Intent(MainActivity.this,DrawableActivity.class));
97 | }
98 | return true;
99 | }
100 |
101 | private void initBackColor(Bitmap bitmap) {
102 |
103 | Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
104 | @Override
105 | public void onGenerated(Palette palette) {
106 |
107 | //1
108 | Palette.Swatch a = palette.getVibrantSwatch();
109 |
110 | for(float f:a.getHsl()) {
111 | Log.v("Main", " pop : " + f);
112 | }
113 |
114 | if(a!=null){
115 | tv1.setBackgroundColor(a.getRgb());
116 | tv1.setTextColor(a.getTitleTextColor());
117 | }else{
118 | Log.v("Main","a 为 null");
119 | tv1.setBackgroundColor(Color.WHITE);
120 | tv1.setTextColor(Color.YELLOW);
121 | }
122 |
123 | //2
124 | Palette.Swatch b=palette.getLightVibrantSwatch();
125 |
126 | if(b!=null){
127 |
128 | tv2.setBackgroundColor(b.getRgb());
129 | tv2.setTextColor(b.getTitleTextColor());
130 |
131 | }else{
132 | Log.v("Main","b 为 null");
133 | tv2.setBackgroundColor(Color.WHITE);
134 | tv2.setTextColor(Color.YELLOW);
135 | }
136 |
137 |
138 |
139 | //3
140 | Palette.Swatch c = palette.getDarkVibrantSwatch();
141 | if(c!=null){
142 | tv3.setBackgroundColor(c.getRgb());
143 | tv3.setTextColor(c.getTitleTextColor());
144 | }else{
145 | Log.v("Main","c 为 null");
146 | tv3.setBackgroundColor(Color.WHITE);
147 | tv3.setTextColor(Color.YELLOW);
148 | }
149 |
150 |
151 | //4
152 | Palette.Swatch d = palette.getMutedSwatch();
153 | if(d!=null){
154 |
155 | tv4.setBackgroundColor(d.getRgb());
156 | tv4.setTextColor(d.getTitleTextColor());
157 |
158 | }else{
159 | Log.v("Main","d 为 null");
160 | tv4.setBackgroundColor(Color.WHITE);
161 | tv4.setTextColor(Color.YELLOW);
162 | }
163 |
164 | //5
165 | Palette.Swatch e = palette.getLightMutedSwatch();
166 | if(e!=null){
167 |
168 | tv5.setBackgroundColor(e.getRgb());
169 | tv5.setTextColor(e.getTitleTextColor());
170 |
171 | }else{
172 | Log.v("Main","e 为 null");
173 | tv5.setBackgroundColor(Color.WHITE);
174 | tv5.setTextColor(Color.YELLOW);
175 |
176 | }
177 |
178 | //6
179 | Palette.Swatch f = palette.getDarkMutedSwatch();
180 | if(f!=null){
181 |
182 | tv6.setBackgroundColor(f.getRgb());
183 | tv6.setTextColor(f.getTitleTextColor());
184 |
185 | }else{
186 | Log.v("Main","f 为 null");
187 | tv6.setBackgroundColor(Color.WHITE);
188 | tv6.setTextColor(Color.YELLOW);
189 | }
190 |
191 | int two=0;
192 | if(b!=null){
193 | two=b.getRgb();
194 | }
195 |
196 | tv7.setBackgroundDrawable(changedImageViewShape(a.getRgb(),two));
197 | tv7.setTextColor(a.getTitleTextColor());
198 |
199 | }
200 | });
201 | }
202 |
203 |
204 | /**
205 | * 创建Drawable对象
206 | * @param RGBValues
207 | * @param two
208 | * @return
209 | */
210 | private Drawable changedImageViewShape(int RGBValues,int two){
211 | if(two==0){
212 | two=colorEasy(RGBValues);
213 | }else {
214 | two = colorBurn(two);
215 | }
216 | GradientDrawable shape = new GradientDrawable(GradientDrawable.Orientation.TL_BR
217 | ,new int[]{RGBValues,two});
218 | shape.setShape(GradientDrawable.RECTANGLE);
219 | //设置渐变方式
220 | shape.setGradientType(GradientDrawable.LINEAR_GRADIENT);
221 | //圆角
222 | shape.setCornerRadius(8);
223 | return shape;
224 | }
225 |
226 |
227 | /**
228 | * 颜色变浅处理
229 | * @param RGBValues
230 | * @return
231 | */
232 | private int colorEasy(int RGBValues) {
233 | int red = RGBValues >> 16 & 0xff;
234 | int green = RGBValues >> 8 & 0xff;
235 | int blue = RGBValues & 0xff;
236 | if(red==0){
237 | red=10;
238 | }
239 | if(green==0){
240 | green=10;
241 | }
242 | if(blue==0){
243 | blue=10;
244 | }
245 | Log.v("Main","Red : "+ red);
246 | Log.v("Main","Green : "+ green);
247 | Log.v("Main","Blue : "+ blue);
248 | red = (int) Math.floor(red * (1 + 0.1));
249 | green = (int) Math.floor(green * (1 + 0.1));
250 | blue = (int) Math.floor(blue * (1 + 0.1));
251 | return Color.rgb(red, green, blue);
252 | }
253 |
254 | /**
255 | * 颜色加深处理
256 | * @param RGBValues
257 | * @return
258 | */
259 | private int colorBurn(int RGBValues) {
260 | int red = RGBValues >> 16 & 0xff;
261 | int green = RGBValues >> 8 & 0xff;
262 | int blue = RGBValues & 0xff;
263 | Log.v("Main","Red : "+ red);
264 | Log.v("Main","Green : "+ green);
265 | Log.v("Main","Blue : "+ blue);
266 | red = (int) Math.floor(red * (1 - 0.1));
267 | green = (int) Math.floor(green * (1 - 0.1));
268 | blue = (int) Math.floor(blue * (1 - 0.1));
269 | return Color.rgb(red, green, blue);
270 | }
271 |
272 | }
273 |
--------------------------------------------------------------------------------
/src/main/java/labelnet/cn/patterncolordemo/PaletteUtil.java:
--------------------------------------------------------------------------------
1 | package labelnet.cn.patterncolordemo;
2 |
3 | import android.content.res.Resources;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Color;
7 | import android.graphics.drawable.Drawable;
8 | import android.graphics.drawable.GradientDrawable;
9 | import android.support.v7.graphics.Palette;
10 |
11 | /**
12 | * Created by yuan on 2016/8/28.
13 | * 获取图片背景色
14 | */
15 | public class PaletteUtil implements Palette.PaletteAsyncListener{
16 |
17 | private static PaletteUtil instance;
18 |
19 | private PatternCallBack patternCallBack;
20 |
21 | public static PaletteUtil getInstance(){
22 | if(instance==null){
23 | instance=new PaletteUtil();
24 | }
25 | return instance;
26 | }
27 |
28 | public synchronized void init(Bitmap bitmap,PatternCallBack patternCallBack){
29 | Palette.from(bitmap).generate(this);
30 | this.patternCallBack=patternCallBack;
31 | }
32 |
33 | public synchronized void init(Resources resources, int resourceId,PatternCallBack patternCallBack){
34 | Bitmap bitmap = BitmapFactory.decodeResource(resources,resourceId);
35 | Palette.from(bitmap).generate(this);
36 | this.patternCallBack=patternCallBack;
37 | }
38 |
39 | @Override
40 | public synchronized void onGenerated(Palette palette) {
41 | Palette.Swatch a = palette.getVibrantSwatch();
42 | Palette.Swatch b=palette.getLightVibrantSwatch();
43 | int colorEasy=0;
44 | if(b!=null){
45 | colorEasy=b.getRgb();
46 | }
47 | patternCallBack.onCallBack(changedImageViewShape(a.getRgb(),colorEasy)
48 | ,a.getTitleTextColor());
49 | }
50 |
51 | /**
52 | * 创建Drawable对象
53 | * @param RGBValues
54 | * @param two
55 | * @return
56 | */
57 | private Drawable changedImageViewShape(int RGBValues, int two){
58 | if(two==0){
59 | two=colorEasy(RGBValues);
60 | }else {
61 | two = colorBurn(two);
62 | }
63 | GradientDrawable shape = new GradientDrawable(GradientDrawable.Orientation.TL_BR
64 | ,new int[]{RGBValues,two});
65 | shape.setShape(GradientDrawable.RECTANGLE);
66 | //设置渐变方式
67 | shape.setGradientType(GradientDrawable.LINEAR_GRADIENT);
68 | //圆角
69 | shape.setCornerRadius(8);
70 | return shape;
71 | }
72 |
73 |
74 | /**
75 | * 颜色变浅处理
76 | * @param RGBValues
77 | * @return
78 | */
79 | private int colorEasy(int RGBValues) {
80 | int red = RGBValues >> 16 & 0xff;
81 | int green = RGBValues >> 8 & 0xff;
82 | int blue = RGBValues & 0xff;
83 | if(red==0){
84 | red=10;
85 | }
86 | if(green==0){
87 | green=10;
88 | }
89 | if(blue==0){
90 | blue=10;
91 | }
92 | red = (int) Math.floor(red * (1 + 0.1));
93 | green = (int) Math.floor(green * (1 + 0.1));
94 | blue = (int) Math.floor(blue * (1 + 0.1));
95 | return Color.rgb(red, green, blue);
96 | }
97 |
98 | /**
99 | * 颜色加深处理
100 | * @param RGBValues
101 | * @return
102 | */
103 | private int colorBurn(int RGBValues) {
104 | int red = RGBValues >> 16 & 0xff;
105 | int green = RGBValues >> 8 & 0xff;
106 | int blue = RGBValues & 0xff;
107 | red = (int) Math.floor(red * (1 - 0.1));
108 | green = (int) Math.floor(green * (1 - 0.1));
109 | blue = (int) Math.floor(blue * (1 - 0.1));
110 | return Color.rgb(red, green, blue);
111 | }
112 |
113 |
114 | public interface PatternCallBack{
115 | void onCallBack(Drawable drawable,int titleColor);
116 | }
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/src/main/java/labelnet/cn/patterncolordemo/PatternUtilActivity.java:
--------------------------------------------------------------------------------
1 | package labelnet.cn.patterncolordemo;
2 |
3 | import android.annotation.TargetApi;
4 | import android.graphics.drawable.Drawable;
5 | import android.os.Build;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.os.Bundle;
8 | import android.view.View;
9 | import android.widget.ImageView;
10 | import android.widget.TextView;
11 |
12 | public class PatternUtilActivity extends AppCompatActivity {
13 |
14 |
15 | TextView tvPalette;
16 | ImageView ivPalette;
17 | int index=0;
18 |
19 | private int [] imageIds=new int[]{
20 | R.mipmap.icon_one,
21 | R.mipmap.icon_two,
22 | R.mipmap.icon_three,
23 | R.mipmap.icon_three,
24 | R.mipmap.icon_four,
25 | R.mipmap.icon_five,
26 | R.mipmap.icon_six,
27 | R.mipmap.icon_seven,
28 | R.mipmap.icon_enght,
29 | R.mipmap.icon_nine,
30 | R.mipmap.icon_ten,
31 | R.mipmap.icon_ten1,
32 | R.mipmap.icon_ten2,
33 | R.mipmap.icon_ten3,
34 | R.mipmap.icon_ten4,
35 | R.mipmap.icon_ten5,
36 | R.mipmap.icon_ten6
37 | };
38 |
39 | @Override
40 | protected void onCreate(Bundle savedInstanceState) {
41 | super.onCreate(savedInstanceState);
42 | setContentView(R.layout.activity_pattern_util);
43 | tvPalette= (TextView) findViewById(R.id.tv_palette);
44 | ivPalette= (ImageView) findViewById(R.id.iv_icon);
45 |
46 | initView(index);
47 |
48 | tvPalette.setOnClickListener(new View.OnClickListener() {
49 | @Override
50 | public void onClick(View v) {
51 | index++;
52 | if(index==imageIds.length){
53 | index=0;
54 | }
55 | initView(index);
56 | }
57 | });
58 | }
59 |
60 | private void initView(int index) {
61 | ivPalette.setImageResource(imageIds[index]);
62 | PaletteUtil.getInstance()
63 | .init(getResources()
64 | ,imageIds[index]
65 | ,new PaletteUtil.PatternCallBack() {
66 | @Override
67 | public void onCallBack(Drawable drawable, int titleColor) {
68 | tvPalette.setTextColor(titleColor);
69 | tvPalette.setBackgroundDrawable(drawable);
70 | }
71 | });
72 |
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/labelnet/cn/patterncolordemo/other/DrawableUtil.java:
--------------------------------------------------------------------------------
1 | package labelnet.cn.patterncolordemo.other;
2 |
3 | import android.graphics.drawable.Drawable;
4 | import android.graphics.drawable.GradientDrawable;
5 |
6 | /**
7 | * Created by yuan on 2016/8/29.
8 | * 生成Drawable背景资源
9 | */
10 | public class DrawableUtil {
11 |
12 | public static Drawable changedImageViewShape(int RGBOne, int RGBTwo){
13 | GradientDrawable shape = new GradientDrawable(GradientDrawable.Orientation.TL_BR
14 | ,new int[]{RGBOne,RGBTwo});
15 | shape.setShape(GradientDrawable.RECTANGLE);
16 | //设置渐变方式
17 | shape.setGradientType(GradientDrawable.LINEAR_GRADIENT);
18 | //圆角
19 | shape.setCornerRadius(8);
20 | return shape;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/res/drawable/back_shape_color.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
18 |
19 |
20 |
27 |
28 |
36 |
37 |
45 |
46 |
47 |
55 |
56 |
57 |
58 |
66 |
67 |
75 |
76 |
84 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_pattern_util.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
17 |
18 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/main/res/menu/main_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxhdpi/icon_app.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-xxhdpi/icon_app.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxhdpi/icon_enght.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-xxhdpi/icon_enght.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxhdpi/icon_five.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-xxhdpi/icon_five.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxhdpi/icon_four.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-xxhdpi/icon_four.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxhdpi/icon_nine.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-xxhdpi/icon_nine.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxhdpi/icon_one.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-xxhdpi/icon_one.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxhdpi/icon_seven.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-xxhdpi/icon_seven.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxhdpi/icon_six.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-xxhdpi/icon_six.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxhdpi/icon_ten.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-xxhdpi/icon_ten.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxhdpi/icon_ten1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-xxhdpi/icon_ten1.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxhdpi/icon_ten2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-xxhdpi/icon_ten2.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxhdpi/icon_ten3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-xxhdpi/icon_ten3.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxhdpi/icon_ten4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-xxhdpi/icon_ten4.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxhdpi/icon_ten5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-xxhdpi/icon_ten5.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxhdpi/icon_ten6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-xxhdpi/icon_ten6.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxhdpi/icon_three.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-xxhdpi/icon_three.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxhdpi/icon_two.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-xxhdpi/icon_two.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LABELNET/PaletteColorDemo/1532d6a87e30c83d0f2d3ef570197129db81ba57/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #003b8f
8 | #197b9a
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PatternColorDemo
3 |
4 |
--------------------------------------------------------------------------------
/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/test/java/labelnet/cn/patterncolordemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package labelnet.cn.patterncolordemo;
2 |
3 | import android.graphics.Color;
4 | import android.support.v4.graphics.ColorUtils;
5 |
6 | import org.junit.Test;
7 |
8 | import labelnet.cn.patterncolordemo.other.ColorUtil;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
14 | */
15 | public class ExampleUnitTest {
16 | @Test
17 | public void addition_isCorrect() throws Exception {
18 | assertEquals(4, 2 + 2);
19 | }
20 |
21 |
22 | @Test
23 | public void test_ColorUtil(){
24 | }
25 |
26 | }
--------------------------------------------------------------------------------