├── .gitignore
├── .idea
├── caches
│ └── build_file_checksums.ser
├── codeStyles
│ └── Project.xml
├── gradle.xml
├── jarRepositories.xml
├── misc.xml
├── modules.xml
└── vcs.xml
├── README.md
├── a.png
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── mrwang
│ │ └── shapeviewcustom
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── mrwang
│ │ │ └── shapeviewcustom
│ │ │ ├── MainActivity.java
│ │ │ └── ShapeActivity.java
│ └── res
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── activity_shape.xml
│ │ └── linear_layout.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── mrwang
│ └── shapeviewcustom
│ └── ExampleUnitTest.java
├── b.png
├── build.gradle
├── buildSrc
├── .gitignore
├── build.gradle
└── src
│ └── main
│ ├── groovy
│ └── com
│ │ └── mrwang
│ │ └── plugin
│ │ └── PluginImpl.groovy
│ └── resources
│ └── META-INF
│ └── gradle-plugins
│ └── com.mrwang.plugin.properties
├── c.png
├── d.png
├── e.png
├── f.png
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── shapeview
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
├── androidTest
└── java
│ └── com
│ └── mrwang
│ └── shapeview
│ └── ExampleInstrumentedTest.java
├── main
├── AndroidManifest.xml
├── java
│ └── com
│ │ ├── inject
│ │ ├── ShapeBuilder.java
│ │ └── ShapeInject.java
│ │ └── mrwang
│ │ ├── GradientDrawableBuilder.java
│ │ ├── NumberTextView.java
│ │ ├── ShapeConstraintLayout.java
│ │ ├── ShapeFrameLayout.java
│ │ ├── ShapeLinearLayout.java
│ │ ├── ShapeNumberTextView.java
│ │ ├── ShapeRelativeLayout.java
│ │ ├── ShapeTextView.java
│ │ ├── ShapeView.java
│ │ └── ShapeViewProxy.java
└── res
│ └── values
│ ├── attrs.xml
│ └── strings.xml
└── test
└── java
└── com
└── mrwang
└── shapeview
└── ExampleUnitTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mr-wangyong/ShapeView/acbde00f6d45c6c72f9db0b401c9c3b31e034523/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | xmlns:android
32 |
33 | ^$
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | xmlns:.*
43 |
44 | ^$
45 |
46 |
47 | BY_NAME
48 |
49 |
50 |
51 |
52 |
53 |
54 | .*:id
55 |
56 | http://schemas.android.com/apk/res/android
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 | .*:name
66 |
67 | http://schemas.android.com/apk/res/android
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | name
77 |
78 | ^$
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 | style
88 |
89 | ^$
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 | .*
99 |
100 | ^$
101 |
102 |
103 | BY_NAME
104 |
105 |
106 |
107 |
108 |
109 |
110 | .*
111 |
112 | http://schemas.android.com/apk/res/android
113 |
114 |
115 | ANDROID_ATTRIBUTE_ORDER
116 |
117 |
118 |
119 |
120 |
121 |
122 | .*
123 |
124 | .*
125 |
126 |
127 | BY_NAME
128 |
129 |
130 |
131 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ShapeView
2 | ## V2.0 重大更新:通过代理方式 支持 ViewGroup,一行代码扩展至任意 View
3 |
4 | 简洁,核心代码不到100行,支持任意 View
5 |
6 | ##### 添加依赖库
7 |
8 | ```
9 | project build.gradle 中加入jitpack
10 |
11 | allprojects {
12 | repositories {
13 | ...
14 | maven { url "https://jitpack.io" }
15 | }
16 | }
17 |
18 | 项目的build.gradle加入
19 | compile 'com.github.Mr-wangyong:ShapeView:v2.0'
20 | ```
21 |
22 |
23 |
24 | ##### 1. 支持所有 ViewGroup ,再也不用通过叠加的方式去实现了,常见
25 |
26 |
27 |
28 | ```
29 | 1. LinearLayout --> ShapeLiearLayout
30 | 2. RelativeLayout --> ShapeRelativeLayout
31 | 3. FrameLayout --> ShapeFrameLayout
32 | 4. ConstraintLayout --> ShapeConstraintLayout
33 | ```
34 |
35 | ##### 2. 可一行代码扩展至任意 View及各种自定义 View
36 |
37 | 看最简单的 FrameLayout 实现
38 |
39 | ```
40 | public class ShapeFrameLayout extends FrameLayout {
41 | public ShapeFrameLayout(@NonNull Context context) {
42 | this(context, null);
43 | }
44 |
45 | public ShapeFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
46 | this(context, null,0);
47 | }
48 |
49 | public ShapeFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
50 | super(context, attrs, defStyleAttr);
51 | ShapeViewProxy.proxyShapeAttributes(this, context, attrs, defStyleAttr);
52 | }
53 | }
54 | ```
55 |
56 |
57 | 比如,我有一个 **NumberTextView** 自定义 View 需要扩展支持 shape
58 |
59 | ```
60 | public class ShapeNumberTextView extends NumberTextView {
61 | public ShapeNumberTextView(Context context) {
62 | this(context,null);
63 | }
64 |
65 | public ShapeNumberTextView(Context context, AttributeSet attrs) {
66 | this(context, attrs,0);
67 | }
68 |
69 | public ShapeNumberTextView(Context context, AttributeSet attrs, int defStyleAttr) {
70 | super(context, attrs, defStyleAttr);
71 | ShapeViewProxy.proxyShapeAttributes(this, context, attrs, defStyleAttr);
72 | }
73 | }
74 | ```
75 |
76 | xml 中直接引用这个 View 即可
77 |
78 |
79 | ##### 3. fix **strokeWidth和strokeColor与com.android.support:design:28.0.0冲突**
80 |
81 |
82 | ##### 4. 最后 贴一张全家福 ViewGroup,和普通的一模一样
83 |
84 | 
85 |
86 | ## 历史版本:
87 |
88 |
89 |
90 | #### V1.0
91 |
92 | #### 1. 项目说明
93 |
94 | 系统自带的 shape 虽然很方便的实现各种效果,但由于是 用`XML drawable `定义的,导致**灵活度差**,改个颜色必须得重新复制一份新的 `XML` 文件, 最后导致`xml drawable`中文件爆炸(我司`XML shape` 文件已超过500个),
95 |
96 | 类似于这样:
97 |
98 | ```
99 | bg_wolf_game_check.xml
100 | bg_wolf_game_guard.xml
101 | bg_wolf_game_poison.xml
102 | bg_wolf_game_raid.xml
103 | bg_wolf_game_rescue.xml
104 | bg_wolf_game_revenge.xml
105 | black_5_oval_rectangle_stroke_shape.xml
106 | black_5_oval_shape.xml
107 | black_5_oval_stroke_shape.xml
108 | black_15_oval_shape.xml
109 | black_15_oval_stroke_shape.xml
110 | ```
111 |
112 | 项目初衷就是用自定义属性实现 shape 效果,改个颜色,
113 |
114 | 再也不用写 XML 写到**蛋疼**;
115 |
116 |
117 |
118 |
119 | #### 3. 开始使用
120 |
121 | 本项目采用自定义 View 实现 XML shape效果,**属性字段和系统 XML 一样**,更加灵活使用,
122 |
123 | 1. 圆角,描边, shape, 填充(这也是开发中最常用的):
124 |
125 | ````
126 |
138 | ````
139 |
140 | 
141 |
142 | 2. 带虚线的边框
143 |
144 | ```
145 |
155 | ```
156 |
157 | 
158 |
159 | 3. 线性渐变:
160 |
161 | ```
162 |
174 | ```
175 |
176 | 
177 |
178 | 4. 放射渐变:
179 |
180 | ```
181 |
191 | ```
192 |
193 | 
194 |
195 |
196 |
197 | 5. 扫描渐变:
198 |
199 | ```
200 |
210 | ```
211 |
212 | 
213 |
214 | 最后来一张全家福:
215 |
216 | 
217 |
--------------------------------------------------------------------------------
/a.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mr-wangyong/ShapeView/acbde00f6d45c6c72f9db0b401c9c3b31e034523/a.png
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'com.mrwang.plugin'
3 |
4 | android {
5 | compileSdkVersion 25
6 | buildToolsVersion "25.0.2"
7 | defaultConfig {
8 | applicationId "com.mrwang.shapeviewcustom"
9 | minSdkVersion 15
10 | targetSdkVersion 25
11 | versionCode 1
12 | versionName "1.0"
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 |
24 |
25 | dependencies {
26 | implementation fileTree(include: ['*.jar'], dir: 'libs')
27 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
28 | exclude group: 'com.android.support', module: 'support-annotations'
29 | })
30 | implementation 'com.android.support:appcompat-v7:25.3.1'
31 | testCompile 'junit:junit:4.12'
32 | api project(':shapeview')
33 | }
34 |
--------------------------------------------------------------------------------
/app/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/chengwangyong/Downloads/android-sdk-macosx/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/mrwang/shapeviewcustom/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.mrwang.shapeviewcustom;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.mrwang.shapeviewcustom", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mrwang/shapeviewcustom/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.mrwang.shapeviewcustom;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 |
6 | public class MainActivity extends AppCompatActivity {
7 |
8 | @Override
9 | protected void onCreate(Bundle savedInstanceState) {
10 | super.onCreate(savedInstanceState);
11 | setContentView(R.layout.activity_main);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mrwang/shapeviewcustom/ShapeActivity.java:
--------------------------------------------------------------------------------
1 | package com.mrwang.shapeviewcustom;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 |
6 | public class ShapeActivity extends AppCompatActivity {
7 |
8 | @Override
9 | protected void onCreate(Bundle savedInstanceState) {
10 | super.onCreate(savedInstanceState);
11 | setContentView(R.layout.linear_layout);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
28 |
29 |
40 |
41 |
42 |
52 |
53 |
54 |
55 |
56 |
62 |
63 |
73 |
74 |
84 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/linear_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
28 |
29 |
40 |
41 |
42 |
52 |
53 |
54 |
55 |
56 |
62 |
63 |
73 |
74 |
84 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mr-wangyong/ShapeView/acbde00f6d45c6c72f9db0b401c9c3b31e034523/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mr-wangyong/ShapeView/acbde00f6d45c6c72f9db0b401c9c3b31e034523/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mr-wangyong/ShapeView/acbde00f6d45c6c72f9db0b401c9c3b31e034523/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mr-wangyong/ShapeView/acbde00f6d45c6c72f9db0b401c9c3b31e034523/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mr-wangyong/ShapeView/acbde00f6d45c6c72f9db0b401c9c3b31e034523/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mr-wangyong/ShapeView/acbde00f6d45c6c72f9db0b401c9c3b31e034523/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mr-wangyong/ShapeView/acbde00f6d45c6c72f9db0b401c9c3b31e034523/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mr-wangyong/ShapeView/acbde00f6d45c6c72f9db0b401c9c3b31e034523/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mr-wangyong/ShapeView/acbde00f6d45c6c72f9db0b401c9c3b31e034523/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mr-wangyong/ShapeView/acbde00f6d45c6c72f9db0b401c9c3b31e034523/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ShapeViewCustom
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/mrwang/shapeviewcustom/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.mrwang.shapeviewcustom;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/b.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mr-wangyong/ShapeView/acbde00f6d45c6c72f9db0b401c9c3b31e034523/b.png
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext {
5 | kotlin_version = '1.4.10'
6 | }
7 | repositories {
8 | jcenter()
9 | google()
10 | }
11 |
12 | dependencies {
13 | classpath 'com.android.tools.build:gradle:4.0.2'
14 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
15 | classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.0'
16 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
17 | // NOTE: Do not place your application dependencies here; they belong
18 | // in the individual module build.gradle files
19 | }
20 | }
21 |
22 | allprojects {
23 | repositories {
24 | jcenter()
25 | google()
26 | }
27 | }
28 |
29 | task clean(type: Delete) {
30 | delete rootProject.buildDir
31 | }
32 |
--------------------------------------------------------------------------------
/buildSrc/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/buildSrc/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'groovy'
2 | dependencies {
3 | compile gradleApi()
4 | compile localGroovy()
5 | compile 'com.android.tools.build:gradle:4.0.2'
6 | compile 'org.aspectj:aspectjtools:1.8.10'
7 | compile 'org.aspectj:aspectjrt:1.8.13'
8 | }
9 | repositories {
10 | jcenter()
11 | google()
12 | }
--------------------------------------------------------------------------------
/buildSrc/src/main/groovy/com/mrwang/plugin/PluginImpl.groovy:
--------------------------------------------------------------------------------
1 | package com.mrwang.plugin
2 |
3 | import org.gradle.api.Plugin
4 | import org.gradle.api.Project
5 | import org.gradle.api.tasks.compile.JavaCompile
6 | import org.aspectj.bridge.IMessage
7 | import org.aspectj.bridge.MessageHandler
8 | import org.aspectj.tools.ajc.Main
9 | import com.android.build.gradle.AppPlugin
10 | import com.android.build.gradle.LibraryPlugin
11 |
12 | public class PluginImpl implements Plugin {
13 | void apply(Project project) {
14 | //得到当前module的插件类型,是application还是lib
15 | System.out.println("========================");
16 | System.out.println("Aspject开始编译!");
17 | System.out.println("========================");
18 | def hasApp = project.plugins.withType(AppPlugin)
19 | def hasLib = project.plugins.withType(LibraryPlugin)
20 | if (!hasApp && !hasLib) {
21 | throw new IllegalStateException("'android' or 'android-library' plugin required.")
22 | }
23 |
24 | final def log = project.logger
25 | final def variants
26 | if (hasApp) {
27 | variants = project.android.applicationVariants
28 | } else {
29 | variants = project.android.libraryVariants
30 | }
31 |
32 | project.dependencies {
33 | compile 'org.aspectj:aspectjrt:1.8.13'
34 | }
35 |
36 | variants.all {
37 | variant ->
38 |
39 | JavaCompile javaCompile = variant.javaCompile
40 | javaCompile.doLast {
41 | String[] args = ["-showWeaveInfo",
42 | "-1.5",
43 | "-inpath", javaCompile.destinationDir.toString(),
44 | "-aspectpath", javaCompile.classpath.asPath,
45 | "-d", javaCompile.destinationDir.toString(),
46 | "-classpath", javaCompile.classpath.asPath,
47 | "-bootclasspath", project.android.bootClasspath.join(File.pathSeparator)]
48 | log.debug "ajc args: " + Arrays.toString(args)
49 |
50 | MessageHandler handler = new MessageHandler(true);
51 | new Main().run(args, handler);
52 | for (IMessage message : handler.getMessages(null, true)) {
53 | switch (message.getKind()) {
54 | case IMessage.ABORT:
55 | case IMessage.ERROR:
56 | case IMessage.FAIL:
57 | log.error message.message, message.thrown
58 | break;
59 | case IMessage.WARNING:
60 | log.warn message.message, message.thrown
61 | break;
62 | case IMessage.INFO:
63 | log.info message.message, message.thrown
64 | break;
65 | case IMessage.DEBUG:
66 | log.debug message.message, message.thrown
67 | break;
68 | }
69 | }
70 | }
71 | }
72 |
73 | System.out.println("========================");
74 | System.out.println("Aspject编译结束!");
75 | System.out.println("========================");
76 | }
77 | }
--------------------------------------------------------------------------------
/buildSrc/src/main/resources/META-INF/gradle-plugins/com.mrwang.plugin.properties:
--------------------------------------------------------------------------------
1 | implementation-class=com.mrwang.plugin.PluginImpl
2 |
--------------------------------------------------------------------------------
/c.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mr-wangyong/ShapeView/acbde00f6d45c6c72f9db0b401c9c3b31e034523/c.png
--------------------------------------------------------------------------------
/d.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mr-wangyong/ShapeView/acbde00f6d45c6c72f9db0b401c9c3b31e034523/d.png
--------------------------------------------------------------------------------
/e.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mr-wangyong/ShapeView/acbde00f6d45c6c72f9db0b401c9c3b31e034523/e.png
--------------------------------------------------------------------------------
/f.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mr-wangyong/ShapeView/acbde00f6d45c6c72f9db0b401c9c3b31e034523/f.png
--------------------------------------------------------------------------------
/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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mr-wangyong/ShapeView/acbde00f6d45c6c72f9db0b401c9c3b31e034523/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Nov 09 15:01:44 CST 2020
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-6.1.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 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':buildsrc'
2 | include ':app', ':shapeview'
3 |
--------------------------------------------------------------------------------
/shapeview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/shapeview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.hujiang.android-aspectjx'
3 | apply plugin: 'com.mrwang.plugin'
4 | group='com.github.shapeView'
5 |
6 | android {
7 | compileSdkVersion 25
8 | buildToolsVersion "25.0.2"
9 |
10 | defaultConfig {
11 | minSdkVersion 15
12 | targetSdkVersion 25
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
17 |
18 | }
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | }
26 |
27 | aspectjx {
28 | //排除所有package路径中包含`android.support`的class文件及库(jar文件)
29 | exclude 'android.support'
30 | }
31 |
32 |
33 | dependencies {
34 | compile fileTree(dir: 'libs', include: ['*.jar'])
35 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
36 | exclude group: 'com.android.support', module: 'support-annotations'
37 | })
38 | compile 'com.android.support:appcompat-v7:25.3.1'
39 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
40 | testCompile 'junit:junit:4.12'
41 | compile 'org.aspectj:aspectjrt:1.8.13'
42 | }
43 |
--------------------------------------------------------------------------------
/shapeview/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/chengwangyong/Downloads/android-sdk-macosx/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/shapeview/src/androidTest/java/com/mrwang/shapeview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.mrwang.shapeview;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.mrwang.shapeview.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/shapeview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/shapeview/src/main/java/com/inject/ShapeBuilder.java:
--------------------------------------------------------------------------------
1 | package com.inject;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * 在 lib中使用
10 | *
11 | * 知乎正解 https://zhuanlan.zhihu.com/p/40008022
12 | * 核心要点 需要在两端都配置ajc
13 | * @author chengwangyong
14 | * @date 2018/10/15
15 | */
16 | @Retention(RetentionPolicy.RUNTIME)
17 | @Target({ElementType.CONSTRUCTOR,ElementType.METHOD})
18 | public @interface ShapeBuilder {
19 | }
20 |
--------------------------------------------------------------------------------
/shapeview/src/main/java/com/inject/ShapeInject.java:
--------------------------------------------------------------------------------
1 | package com.inject;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.View;
6 |
7 | import com.mrwang.ShapeViewProxy;
8 |
9 | import org.aspectj.lang.JoinPoint;
10 | import org.aspectj.lang.annotation.Aspect;
11 | import org.aspectj.lang.annotation.Before;
12 | import org.aspectj.lang.annotation.Pointcut;
13 |
14 |
15 | /**
16 | * @author chengwangyong
17 | * @date 2018/10/16
18 | */
19 | @Aspect
20 | public class ShapeInject{
21 |
22 | @Pointcut("execution(@com.inject.ShapeBuilder * *(..))")
23 | public void DebugToolMethod() {
24 | }
25 |
26 | @Before("DebugToolMethod()")
27 | public void onDebugToolMethodBefore(JoinPoint joinPoint) throws Throwable {
28 | System.out.println(" DebugToolMethod inject: ");
29 | Context context = null;
30 | AttributeSet attrs = null;
31 | View view = null;
32 | int defStyle = 0;
33 | for (Object arg : joinPoint.getArgs()) {
34 | if (arg instanceof Context) {
35 | context = (Context) arg;
36 | } else if (arg instanceof AttributeSet) {
37 | attrs = (AttributeSet) arg;
38 | } else if (arg instanceof Integer) {
39 | defStyle = (Integer) arg;
40 | }
41 | }
42 | Object aThis = joinPoint.getThis();
43 | if (aThis instanceof View) {
44 | view = (View) aThis;
45 | }
46 | if (context == null || view == null) {
47 | return;
48 | }
49 | ShapeViewProxy.proxyShapeAttributes(view, context, attrs, defStyle);
50 | }
51 | }
--------------------------------------------------------------------------------
/shapeview/src/main/java/com/mrwang/GradientDrawableBuilder.java:
--------------------------------------------------------------------------------
1 | package com.mrwang;
2 |
3 | import android.graphics.drawable.GradientDrawable;
4 | import android.support.annotation.ColorRes;
5 |
6 | /**
7 | * 未完待续
8 | * @author chengwangyong
9 | * @date 2017/12/19
10 | */
11 | public class GradientDrawableBuilder {
12 |
13 | GradientDrawable drawable;
14 |
15 |
16 | public void setShape(GradientDrawable drawable, int shape) {
17 | switch (shape) {
18 | case GradientDrawable.RECTANGLE:
19 | drawable.setShape(GradientDrawable.RECTANGLE);
20 | break;
21 | case GradientDrawable.OVAL:
22 | drawable.setShape(GradientDrawable.OVAL);
23 | break;
24 | case GradientDrawable.LINE:
25 | drawable.setShape(GradientDrawable.LINE);
26 | break;
27 | case GradientDrawable.RING:
28 | drawable.setShape(GradientDrawable.RING);
29 | break;
30 | }
31 | }
32 |
33 | private void setGradientStartColor(@ColorRes int color){
34 |
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/shapeview/src/main/java/com/mrwang/NumberTextView.java:
--------------------------------------------------------------------------------
1 | package com.mrwang;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.AppCompatTextView;
5 | import android.util.AttributeSet;
6 |
7 | /**
8 | * @author chengwangyong
9 | * @date 2018/9/23
10 | */
11 | public class NumberTextView extends AppCompatTextView {
12 | private int number;
13 |
14 | public NumberTextView(Context context) {
15 | super(context);
16 | }
17 |
18 | public NumberTextView(Context context, AttributeSet attrs) {
19 | super(context, attrs);
20 | }
21 |
22 | public NumberTextView(Context context, AttributeSet attrs, int defStyleAttr) {
23 | super(context, attrs, defStyleAttr);
24 | }
25 |
26 | public void setNumber(int number) {
27 | if (this.number != number) {
28 | setText(String.valueOf(number));
29 | }
30 | this.number = number;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/shapeview/src/main/java/com/mrwang/ShapeConstraintLayout.java:
--------------------------------------------------------------------------------
1 | package com.mrwang;
2 |
3 | import android.content.Context;
4 | import android.support.constraint.ConstraintLayout;
5 | import android.util.AttributeSet;
6 |
7 | import com.inject.ShapeBuilder;
8 |
9 | /**
10 | * @author chengwangyong
11 | * @date 2018/9/23
12 | */
13 | public class ShapeConstraintLayout extends ConstraintLayout {
14 |
15 | public ShapeConstraintLayout(Context context) {
16 | super(context);
17 | }
18 |
19 | public ShapeConstraintLayout(Context context, AttributeSet attrs) {
20 | super(context, attrs);
21 | }
22 |
23 | @ShapeBuilder
24 | public ShapeConstraintLayout(Context context, AttributeSet attrs, int defStyleAttr) {
25 | super(context, attrs, defStyleAttr);
26 | }
27 |
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/shapeview/src/main/java/com/mrwang/ShapeFrameLayout.java:
--------------------------------------------------------------------------------
1 | package com.mrwang;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.NonNull;
5 | import android.support.annotation.Nullable;
6 | import android.util.AttributeSet;
7 | import android.widget.FrameLayout;
8 |
9 | import com.inject.ShapeBuilder;
10 |
11 | /**
12 | * @author chengwangyong
13 | * @date 2018/9/23
14 | */
15 | public class ShapeFrameLayout extends FrameLayout {
16 | public ShapeFrameLayout(@NonNull Context context) {
17 | this(context, null);
18 | }
19 |
20 | public ShapeFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
21 | this(context, attrs,0);
22 | }
23 |
24 | @ShapeBuilder
25 | public ShapeFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
26 | super(context, attrs, defStyleAttr);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/shapeview/src/main/java/com/mrwang/ShapeLinearLayout.java:
--------------------------------------------------------------------------------
1 | package com.mrwang;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.Nullable;
5 | import android.util.AttributeSet;
6 | import android.widget.LinearLayout;
7 |
8 | import com.inject.ShapeBuilder;
9 |
10 | /**
11 | * @author chengwangyong
12 | * @date 2018/9/23
13 | */
14 | public class ShapeLinearLayout extends LinearLayout {
15 |
16 | @ShapeBuilder
17 | public ShapeLinearLayout(Context context) {
18 | this(context, null);
19 | }
20 |
21 | @ShapeBuilder
22 | public ShapeLinearLayout(Context context, @Nullable AttributeSet attrs) {
23 | this(context, attrs, 0);
24 | }
25 |
26 | @ShapeBuilder
27 | public ShapeLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
28 | super(context, attrs, defStyleAttr);
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/shapeview/src/main/java/com/mrwang/ShapeNumberTextView.java:
--------------------------------------------------------------------------------
1 | package com.mrwang;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import com.inject.ShapeBuilder;
6 |
7 | /**
8 | * @author chengwangyong
9 | * @date 2018/9/23
10 | */
11 | public class ShapeNumberTextView extends NumberTextView {
12 |
13 | public ShapeNumberTextView(Context context) {
14 | this(context,null);
15 | }
16 |
17 | public ShapeNumberTextView(Context context, AttributeSet attrs) {
18 | this(context, attrs,0);
19 | }
20 |
21 |
22 | public ShapeNumberTextView(Context context, AttributeSet attrs, int defStyleAttr) {
23 | super(context, attrs, defStyleAttr);
24 | init(context,attrs,defStyleAttr);
25 | }
26 |
27 | @ShapeBuilder
28 | public void init(Context context, AttributeSet attrs, int defStyleAttr) {
29 |
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/shapeview/src/main/java/com/mrwang/ShapeRelativeLayout.java:
--------------------------------------------------------------------------------
1 | package com.mrwang;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.widget.RelativeLayout;
6 |
7 | import com.inject.ShapeBuilder;
8 |
9 | /**
10 | * @author chengwangyong
11 | * @date 2018/9/23
12 | */
13 | public class ShapeRelativeLayout extends RelativeLayout {
14 | public ShapeRelativeLayout(Context context) {
15 | this(context, null);
16 | }
17 |
18 | public ShapeRelativeLayout(Context context, AttributeSet attrs) {
19 | this(context, attrs, 0);
20 | }
21 |
22 | @ShapeBuilder
23 | public ShapeRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
24 | super(context, attrs, defStyleAttr);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/shapeview/src/main/java/com/mrwang/ShapeTextView.java:
--------------------------------------------------------------------------------
1 | package com.mrwang;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.AppCompatTextView;
5 | import android.util.AttributeSet;
6 |
7 | import com.inject.ShapeBuilder;
8 |
9 | /**
10 | * @author chengwangyong
11 | * @date 2018/9/23
12 | */
13 | public class ShapeTextView extends AppCompatTextView{
14 | public ShapeTextView(Context context) {
15 | this(context,null);
16 | }
17 |
18 | public ShapeTextView(Context context, AttributeSet attrs) {
19 | this(context, attrs,0);
20 | }
21 |
22 | @ShapeBuilder
23 | public ShapeTextView(Context context, AttributeSet attrs, int defStyleAttr) {
24 | super(context, attrs, defStyleAttr);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/shapeview/src/main/java/com/mrwang/ShapeView.java:
--------------------------------------------------------------------------------
1 | package com.mrwang;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.widget.AppCompatImageView;
6 | import android.util.AttributeSet;
7 |
8 | import com.inject.ShapeBuilder;
9 |
10 |
11 | /**
12 | * User: chengwangyong(chengwangyong@blinnnk.com)
13 | * Date: 2017/8/19
14 | * Time: 下午5:07
15 | */
16 | public class ShapeView extends AppCompatImageView {
17 |
18 | public ShapeView(Context context) {
19 | this(context, null);
20 | }
21 |
22 | public ShapeView(Context context, @Nullable AttributeSet attrs) {
23 | this(context, attrs, 0);
24 | }
25 |
26 |
27 | public ShapeView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
28 | super(context, attrs, defStyleAttr);
29 | init();
30 | }
31 |
32 | @ShapeBuilder
33 | public void init() {
34 | System.out.println("inject ShapeView");
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/shapeview/src/main/java/com/mrwang/ShapeViewProxy.java:
--------------------------------------------------------------------------------
1 | package com.mrwang;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.drawable.GradientDrawable;
6 | import android.support.annotation.StyleableRes;
7 | import android.support.v4.view.ViewCompat;
8 | import android.util.AttributeSet;
9 | import android.view.View;
10 |
11 | import com.mrwang.shapeview.R;
12 |
13 |
14 | /**
15 | * User: chengwangyong(chengwangyong@blinnnk.com)
16 | * Date: 2017/8/19
17 | * Time: 下午5:07
18 | */
19 | public class ShapeViewProxy {
20 |
21 | public static void proxyShapeAttributes(View view, Context context, AttributeSet attrs, int defStyle) {
22 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ShapeView,
23 | defStyle, 0);
24 |
25 | int shape = typedArray.getInt(R.styleable.ShapeView_shape, 0);
26 |
27 | int gradientStartColor = typedArray.getColor(R.styleable.ShapeView_gradientStartColor, 0);
28 | int gradientEndColor = typedArray.getColor(R.styleable.ShapeView_gradientEndColor, 0);
29 | int gradientCenterColor = typedArray.getColor(R.styleable.ShapeView_gradientCenterColor, 0);
30 | int gradientAngle = typedArray.getInt(R.styleable.ShapeView_gradientAngle, 0);
31 |
32 | GradientDrawable drawable;
33 | if (hasValue(typedArray, R.styleable.ShapeView_gradientStartColor)
34 | && hasValue(typedArray, R.styleable.ShapeView_gradientEndColor)) {
35 | int[] colors;
36 | if (hasValue(typedArray, R.styleable.ShapeView_gradientCenterColor)) {
37 | colors = new int[]{gradientStartColor, gradientCenterColor, gradientEndColor};
38 | } else {
39 | colors = new int[]{gradientStartColor, gradientEndColor};
40 | }
41 | drawable = new GradientDrawable(getAngle(gradientAngle),
42 | colors);
43 | } else {
44 | drawable = new GradientDrawable();
45 | }
46 |
47 | float cornersRadius = typedArray.getDimension(R.styleable.ShapeView_cornersRadius, 0);
48 | float cornersTopLeftRadius =
49 | typedArray.getDimension(R.styleable.ShapeView_cornersTopLeftRadius, 0);
50 | float cornersTopRightRadius =
51 | typedArray.getDimension(R.styleable.ShapeView_cornersTopRightRadius, 0);
52 | float cornersBottomLeftRadius =
53 | typedArray.getDimension(R.styleable.ShapeView_cornersBottomLeftRadius, 0);
54 | float cornersBottomRightRadius =
55 | typedArray.getDimension(R.styleable.ShapeView_cornersBottomRightRadius, 0);
56 |
57 | float strokeWidth = typedArray.getDimension(R.styleable.ShapeView_strokeShapeWidth, 0);
58 | int strokeColor = typedArray.getColor(R.styleable.ShapeView_strokeShapeColor, 0);
59 | float strokeDashGap = typedArray.getDimension(R.styleable.ShapeView_strokeDashGap, 0);
60 | float strokeDashWidth = typedArray.getDimension(R.styleable.ShapeView_strokeDashWidth, 0);
61 |
62 | if (hasValue(strokeWidth) && hasValue(typedArray, R.styleable.ShapeView_strokeShapeColor)) {
63 | if (hasValue(strokeDashGap)
64 | || hasValue(strokeDashWidth)) {
65 | drawable.setStroke(Math.round(strokeWidth), strokeColor, strokeDashWidth, strokeDashGap);
66 | } else {
67 | drawable.setStroke(Math.round(strokeWidth), strokeColor);
68 | }
69 | }
70 |
71 | int gradientType = typedArray.getInt(R.styleable.ShapeView_gradientType, -1);
72 |
73 | float gradientCenterX = typedArray.getFloat(R.styleable.ShapeView_gradientCenterX, 0);
74 | float gradientCenterY = typedArray.getFloat(R.styleable.ShapeView_gradientCenterY, 0);
75 | float gradientRadius = typedArray.getDimension(R.styleable.ShapeView_gradientRadius, 0);
76 | boolean useLevel = typedArray.getBoolean(R.styleable.ShapeView_gradientUseLevel, false);
77 |
78 | int solidColor = typedArray.getColor(R.styleable.ShapeView_solidColor, 0);
79 |
80 | if (hasValue(typedArray, R.styleable.ShapeView_solidColor)) {
81 | drawable.setColor(solidColor);
82 | }
83 | typedArray.recycle();
84 |
85 |
86 | if (hasValue(gradientType)) {
87 | setGradientType(drawable, gradientType);
88 | if (hasValue(gradientCenterX)
89 | || hasValue(gradientCenterY)) {
90 | drawable.setGradientCenter(gradientCenterX, gradientCenterY);
91 | }
92 | if (hasValue(gradientRadius)) {
93 | drawable.setGradientRadius(gradientRadius);
94 | }
95 | drawable.setUseLevel(useLevel);
96 | }
97 |
98 | setShape(drawable, shape);
99 | if (hasValue(cornersRadius)) {
100 | drawable.setCornerRadius(cornersRadius);
101 | } else if (hasValue(cornersTopLeftRadius)
102 | || hasValue(cornersTopRightRadius)
103 | || hasValue(cornersBottomLeftRadius)
104 | || hasValue(cornersBottomRightRadius)) {
105 | drawable.setCornerRadii(new float[]{
106 | cornersTopLeftRadius, cornersTopLeftRadius,
107 | cornersTopRightRadius, cornersTopRightRadius,
108 | cornersBottomLeftRadius, cornersBottomLeftRadius,
109 | cornersBottomRightRadius, cornersBottomRightRadius});
110 | }
111 | ViewCompat.setBackground(view, drawable);
112 | }
113 |
114 |
115 | private static boolean hasValue(float value) {
116 |
117 | return value > 0;
118 | }
119 |
120 | private static boolean hasValue(TypedArray typedArray, @StyleableRes int res) {
121 | return typedArray.hasValue(res);
122 | }
123 |
124 | private static void setShape(GradientDrawable drawable, int shape) {
125 | switch (shape) {
126 | case GradientDrawable.RECTANGLE:
127 | drawable.setShape(GradientDrawable.RECTANGLE);
128 | break;
129 | case GradientDrawable.OVAL:
130 | drawable.setShape(GradientDrawable.OVAL);
131 | break;
132 | case GradientDrawable.LINE:
133 | drawable.setShape(GradientDrawable.LINE);
134 | break;
135 | case GradientDrawable.RING:
136 | drawable.setShape(GradientDrawable.RING);
137 | break;
138 | }
139 | }
140 |
141 | private static void setGradientType(GradientDrawable drawable, int gradientType) {
142 | switch (gradientType) {
143 | case GradientDrawable.LINEAR_GRADIENT:
144 | drawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
145 | break;
146 | case GradientDrawable.RADIAL_GRADIENT:
147 | drawable.setGradientType(GradientDrawable.RADIAL_GRADIENT);
148 | break;
149 | case GradientDrawable.SWEEP_GRADIENT:
150 | drawable.setGradientType(GradientDrawable.SWEEP_GRADIENT);
151 | break;
152 | }
153 | }
154 |
155 | private static GradientDrawable.Orientation getAngle(int angle) {
156 | switch (angle) {
157 | case 0:
158 | return GradientDrawable.Orientation.LEFT_RIGHT;
159 | case 45:
160 | return GradientDrawable.Orientation.BL_TR;
161 | case 90:
162 | return GradientDrawable.Orientation.BOTTOM_TOP;
163 | case 135:
164 | return GradientDrawable.Orientation.BR_TL;
165 | case 180:
166 | return GradientDrawable.Orientation.RIGHT_LEFT;
167 | case 225:
168 | return GradientDrawable.Orientation.TR_BL;
169 | case 270:
170 | return GradientDrawable.Orientation.TOP_BOTTOM;
171 | case 315:
172 | return GradientDrawable.Orientation.TL_BR;
173 | }
174 | return GradientDrawable.Orientation.TOP_BOTTOM;
175 | }
176 |
177 | }
178 |
--------------------------------------------------------------------------------
/shapeview/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/shapeview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ShapeView
3 |
4 |
--------------------------------------------------------------------------------
/shapeview/src/test/java/com/mrwang/shapeview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.mrwang.shapeview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------