├── .gitignore
├── .idea
├── checkstyle-idea.xml
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── qaplug_profiles.xml
├── runConfigurations.xml
└── vcs.xml
├── Javadoc
├── README-ch.md
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── kingja
│ │ └── sample
│ │ └── magicmirror
│ │ └── MainActivity.java
│ └── res
│ ├── drawable
│ ├── apple.png
│ ├── beauty.png
│ ├── fav.png
│ ├── heart.png
│ ├── lemon.png
│ ├── singlestar.png
│ ├── svg_category.xml
│ ├── svg_home.xml
│ └── tag.png
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ ├── apple.png
│ ├── ic_launcher.png
│ ├── jared_leto.png
│ ├── kumamon.jpg
│ ├── megan.jpg
│ ├── sea.png
│ └── taylor.jpg
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── magicmirror
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── kingja
│ │ └── magicmirror
│ │ ├── MagicMirrorView.java
│ │ ├── MirrorFactory.java
│ │ ├── Util.java
│ │ ├── filter
│ │ └── FilterHelper.java
│ │ └── mirror
│ │ ├── AnyMirror.java
│ │ ├── CircleMirror.java
│ │ ├── Mirror.java
│ │ ├── OvalMirror.java
│ │ ├── PolygonMirror.java
│ │ ├── RectMirror.java
│ │ └── RoundRectMirror.java
│ └── res
│ └── values
│ ├── attr.xml
│ └── strings.xml
├── readme
├── TODO.MD
├── any.png
├── apple.png
├── beauty.png
├── bg_apple.png
├── bg_beauty.png
├── bg_heart.png
├── bg_lemon.png
├── bg_tag.png
├── circle.png
├── gray.png
├── heart.png
├── item.png
├── lemon.png
├── logo_magicmirror.png
├── old_picture.png
├── original.png
├── oval.png
├── polygon.png
├── preview.png
├── rect.png
├── round_rect.png
├── saturation.png
└── tag.png
└── settings.gradle
/.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/checkstyle-idea.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.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 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | 1.8
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/qaplug_profiles.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 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Javadoc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/Javadoc
--------------------------------------------------------------------------------
/README-ch.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | 中文 | [English](README.md)
4 |
5 | 提供多种常用形状,基于蒙版图的任意形状及常用滤镜的自定义ImageView。如果对您有用,请点STAR。
6 |
7 | ## Features
8 | * 基本形状
9 | * rect
10 | * circle
11 | * roundRect
12 | * oval
13 | * polygon
14 | * 蒙版形状
15 | * 滤镜
16 | * gray
17 | * oldPicture
18 | * saturation
19 |
20 |
21 | ## Preview
22 |
23 | | **基本形状**|||||
24 | |:---:|:----:|:----:|:----:|:----:|
25 | | |||||
26 | |rect|circle|roundRect|oval|polygon|
27 |
28 | | **蒙版形状**|||||
29 | |:---:|:----:|:----:|:----:|:----:|
30 | | |||||
31 | | |||||
32 | |heart.png|apple.png|tag.png|lemon.png|beauty.png|
33 |
34 | | **滤镜**|||||
35 | |:---:|:----:|:----:|:----:|:----:|
36 | | |||||
37 | |original |gray|oldPicture|saturation||
38 |
39 | ## 自定义属性
40 | | attribute | format | belong |ps |
41 | | :------------- |:-------------| :-----|:-----|
42 | | mirrorSharp | enum | ALL |rect circle roundRect oval polygon any|
43 | | mirrorSides | int | polygon|边数大于2|
44 | | mirrorCorner | dimension | roundRect ||
45 | | mirrorBorderWidth | dimension | !any ||
46 | | mirrorBorderColor | color/reference | !any ||
47 | | mirrorMaskRes | reference | polygon |蒙版图片须放在drawable文件夹下|
48 | | mirrorFilter | enum | ALL |oldPicture gray saturation|
49 |
50 |
51 | ## Gradle
52 | ```gradle
53 | compile 'com.kingja.magicmirror:magicmirror:1.2.0'
54 | ```
55 |
56 | ## Usage
57 | * 基本形状
58 | ```xml
59 |
67 | ```
68 | * 蒙版形状 (蒙版图片须放在drawable文件夹下)
69 | ```xml
70 |
76 | ```
77 | * 滤镜
78 | ```xml
79 |
84 | ```
85 | * 自定义形状
86 |
87 | 你可以通过继承 Mirror类复写getMirrorPath()方法来定制自己的形状。
88 |
89 | ## Changelog
90 |
91 | **v1.2.0**
92 | * add filter
93 |
94 | **v1.1.1**
95 | * Initial release
96 |
97 | ## Contact me
98 | Any questions:Welcome to contact me.
99 | * Email:kingjavip@gmail.com
100 |
101 | ## License
102 |
103 | Copyright 2017 KingJA
104 |
105 | Licensed under the Apache License, Version 2.0 (the "License");
106 | you may not use this file except in compliance with the License.
107 | You may obtain a copy of the License at
108 |
109 | http://www.apache.org/licenses/LICENSE-2.0
110 |
111 | Unless required by applicable law or agreed to in writing, software
112 | distributed under the License is distributed on an "AS IS" BASIS,
113 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
114 | See the License for the specific language governing permissions and
115 | limitations under the License.
116 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | English | [中文](README-ch.md)
4 |
5 | It's a little bit different from other image shape library,
6 | it supports multiple shapes for ImageView,and also some most common filter. CLICK THE ***STAR*** if it's useful to you.
7 |
8 | ## Features
9 | * Basic Shape : some most common shapes.
10 | * rect
11 | * circle
12 | * roundRect
13 | * oval
14 | * polygon
15 | * Mask Shape : any shapes based on mask picture.
16 | * Filter : some most common filters.
17 | * gray
18 | * oldPicture
19 | * saturation
20 |
21 |
22 | ## Preview
23 |
24 | | **Basic Shape**|||||
25 | |:---:|:----:|:----:|:----:|:----:|
26 | | |||||
27 | |rect|circle|roundRect|oval|polygon|
28 |
29 | | **Mask Shape**|||||
30 | |:---:|:----:|:----:|:----:|:----:|
31 | | |||||
32 | | |||||
33 | |heart.png|apple.png|tag.png|lemon.png|beauty.png|
34 |
35 | | **Filter**|||||
36 | |:---:|:----:|:----:|:----:|:----:|
37 | | |||||
38 | |original |gray|oldPicture|saturation||
39 |
40 | ## Custom attribute
41 | | attribute | format | belong |ps |
42 | | :------------- |:-------------| :-----|:-----|
43 | | mirrorSharp | enum | ALL |rect circle roundRect oval polygon any|
44 | | mirrorSides | int | polygon|>2|
45 | | mirrorCorner | dimension | roundRect ||
46 | | mirrorBorderWidth | dimension | !any ||
47 | | mirrorBorderColor | color/reference | !any ||
48 | | mirrorMaskRes | reference | polygon |res must be put in drawable folder|
49 | | mirrorFilter | enum | ALL |oldPicture gray saturation|
50 |
51 |
52 | ## Gradle
53 | ```gradle
54 | compile 'com.kingja.magicmirror:magicmirror:1.2.0'
55 | ```
56 |
57 | ## Usage
58 | * Basic Sharp
59 | ```xml
60 |
68 | ```
69 |
70 | * Mask Sharp (the res of mirrorMaskRes must be put in res/drawable)
71 | ```xml
72 |
78 | ```
79 | * Filter
80 | ```xml
81 |
86 | ```
87 | * Custom Shape
88 |
89 | You also can customize your shape by extending the Mirror and overriding the method `getMirrorPath()`.
90 |
91 | ## Changelog
92 |
93 | **v1.2.0**
94 | * add filter
95 |
96 | **v1.1.1**
97 | * Initial release
98 |
99 |
100 | ## Contact me
101 | Any questions:Welcome to contact me.
102 | * Email:kingjavip@gmail.com
103 |
104 | ## License
105 |
106 | Copyright 2017 KingJA
107 |
108 | Licensed under the Apache License, Version 2.0 (the "License");
109 | you may not use this file except in compliance with the License.
110 | You may obtain a copy of the License at
111 |
112 | http://www.apache.org/licenses/LICENSE-2.0
113 |
114 | Unless required by applicable law or agreed to in writing, software
115 | distributed under the License is distributed on an "AS IS" BASIS,
116 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
117 | See the License for the specific language governing permissions and
118 | limitations under the License.
119 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "kingja.sample.magicmirror"
8 | minSdkVersion 14
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | compile 'com.android.support:appcompat-v7:25.2.0'
25 | compile project(':magicmirror')
26 | }
27 |
--------------------------------------------------------------------------------
/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 E:\wxy\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 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/kingja/sample/magicmirror/MainActivity.java:
--------------------------------------------------------------------------------
1 | package kingja.sample.magicmirror;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
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/res/drawable/apple.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/app/src/main/res/drawable/apple.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/beauty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/app/src/main/res/drawable/beauty.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/fav.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/app/src/main/res/drawable/fav.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/heart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/app/src/main/res/drawable/heart.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/lemon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/app/src/main/res/drawable/lemon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/singlestar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/app/src/main/res/drawable/singlestar.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/svg_category.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/svg_home.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tag.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/app/src/main/res/drawable/tag.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
24 |
25 |
31 |
32 |
37 |
38 |
39 |
40 |
45 |
46 |
54 |
55 |
63 |
64 |
71 |
72 |
73 |
78 |
79 |
87 |
88 |
96 |
97 |
105 |
106 |
107 |
108 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/apple.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/app/src/main/res/mipmap-xxhdpi/apple.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/jared_leto.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/app/src/main/res/mipmap-xxhdpi/jared_leto.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/kumamon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/app/src/main/res/mipmap-xxhdpi/kumamon.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/megan.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/app/src/main/res/mipmap-xxhdpi/megan.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/sea.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/app/src/main/res/mipmap-xxhdpi/sea.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/taylor.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/app/src/main/res/mipmap-xxhdpi/taylor.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MagicMirror
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.1'
9 | }
10 | }
11 |
12 | allprojects {
13 | repositories {
14 | jcenter()
15 | }
16 | }
17 |
18 | task clean(type: Delete) {
19 | delete rootProject.buildDir
20 | }
21 |
--------------------------------------------------------------------------------
/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/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Apr 14 13:36:43 CST 2017
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-3.3-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 |
--------------------------------------------------------------------------------
/magicmirror/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/magicmirror/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 | compile 'com.android.support:appcompat-v7:25.2.0'
27 | }
28 |
29 |
30 |
--------------------------------------------------------------------------------
/magicmirror/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:\wxy\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 |
--------------------------------------------------------------------------------
/magicmirror/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/magicmirror/src/main/java/com/kingja/magicmirror/MagicMirrorView.java:
--------------------------------------------------------------------------------
1 | package com.kingja.magicmirror;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.support.v7.widget.AppCompatImageView;
8 | import android.util.AttributeSet;
9 |
10 | import com.kingja.magicmirror.mirror.Mirror;
11 |
12 | /**
13 | * Description:MagicMirrorView
14 | * Create Time:2017/3/1421:30
15 | * Author:KingJA
16 | * Email:kingjavip@gmail.com
17 | */
18 | public class MagicMirrorView extends AppCompatImageView {
19 |
20 | private static final int DEFAULT_SIDES = 5;
21 | private Mirror mirror;
22 |
23 | public MagicMirrorView(Context context) {
24 | this(context, null);
25 | }
26 |
27 | public MagicMirrorView(Context context, AttributeSet attrs) {
28 | this(context, attrs, 0);
29 | }
30 |
31 | public MagicMirrorView(Context context, AttributeSet attrs, int defStyleAttr) {
32 | super(context, attrs, defStyleAttr);
33 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MagicMirrorView);
34 | int sharpCode = typedArray.getInteger(R.styleable.MagicMirrorView_mirrorShape, 0);
35 | int corner = Util.dp2px(context, typedArray.getDimension(R.styleable.MagicMirrorView_mirrorCorner, 0));
36 | int borderWidth = Util.dp2px(context, typedArray.getDimension(R.styleable.MagicMirrorView_mirrorBorderWidth,
37 | 0));
38 | int borderColor = typedArray.getColor(R.styleable.MagicMirrorView_mirrorBorderColor, Color.TRANSPARENT);
39 | int maskRes = typedArray.getResourceId(R.styleable.MagicMirrorView_mirrorMaskRes, 0);
40 | int filter = typedArray.getInteger(R.styleable.MagicMirrorView_mirrorFilter, 0);
41 | int sides = typedArray.getInteger(R.styleable.MagicMirrorView_mirrorSides, DEFAULT_SIDES);
42 | mirror = MirrorFactory.createMirror(sharpCode)
43 | .setContext(this)
44 | .setMaskRes(maskRes)
45 | .setFilter(filter)
46 | .setCorner(corner)
47 | .setBorderWidth(borderWidth)
48 | .setBorderColor(borderColor)
49 | .setSides(sides);
50 | typedArray.recycle();
51 | //ScaleType.CENTER_CROP for default
52 | setScaleType(ScaleType.CENTER_CROP);
53 | }
54 |
55 | @Override
56 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
57 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
58 | setMeasuredDimension(mirror.getMeasuredMirrorWidth(), mirror.getMeasuredMirrorHeight());
59 | }
60 |
61 | @Override
62 | protected void onDraw(Canvas canvas) {
63 | mirror.drawMirror(canvas);
64 | }
65 |
66 | public void setCorner(int conrner) {
67 | mirror.setCorner(conrner);
68 | invalidate();
69 | }
70 |
71 | public void setBorderWidth(int borderWidth) {
72 | mirror.setBorderWidth(borderWidth);
73 | invalidate();
74 | }
75 |
76 | public void setBorderColor(int borderColor) {
77 | mirror.setBorderColor(borderColor);
78 | invalidate();
79 | }
80 |
81 | public void setSides(int sides) {
82 | mirror.setSides(sides);
83 | invalidate();
84 | }
85 |
86 | public void setFilter(int filter) {
87 | mirror.setFilter(filter);
88 | invalidate();
89 | }
90 |
91 | public void setMaskRes(int maskRes) {
92 | mirror.setMaskRes(maskRes);
93 | invalidate();
94 | }
95 |
96 | @Override
97 | public void setScaleType(ScaleType scaleType) {
98 | if (ScaleType.FIT_XY == scaleType) {
99 | scaleType = ScaleType.CENTER_CROP;
100 | }
101 | super.setScaleType(scaleType);
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/magicmirror/src/main/java/com/kingja/magicmirror/MirrorFactory.java:
--------------------------------------------------------------------------------
1 | package com.kingja.magicmirror;
2 |
3 | import com.kingja.magicmirror.mirror.AnyMirror;
4 | import com.kingja.magicmirror.mirror.CircleMirror;
5 | import com.kingja.magicmirror.mirror.Mirror;
6 | import com.kingja.magicmirror.mirror.OvalMirror;
7 | import com.kingja.magicmirror.mirror.PolygonMirror;
8 | import com.kingja.magicmirror.mirror.RectMirror;
9 | import com.kingja.magicmirror.mirror.RoundRectMirror;
10 |
11 | /**
12 | * Description:Factory patten to get the expectant mirror.
13 | * Create Time:2017/3/22 21:23
14 | * Author:KingJA
15 | * Email:kingjavip@gmail.com
16 | */
17 | public class MirrorFactory {
18 | private static final int RECT = 0;
19 | private static final int CIRCLE = 1;
20 | private static final int ROUND_RECT = 2;
21 | private static final int OVAL = 3;
22 | private static final int POLYGON = 4;
23 | private static final int ANY = 5;
24 |
25 | public static Mirror createMirror(int sharp) {
26 | Mirror mirror;
27 | switch (sharp) {
28 | case CIRCLE:
29 | mirror = new CircleMirror();
30 | break;
31 | case ROUND_RECT:
32 | mirror = new RoundRectMirror();
33 | break;
34 | case OVAL:
35 | mirror = new OvalMirror();
36 | break;
37 | case RECT:
38 | mirror = new RectMirror();
39 | break;
40 | case POLYGON:
41 | mirror = new PolygonMirror();
42 | break;
43 | case ANY:
44 | mirror = new AnyMirror();
45 | break;
46 | default:
47 | mirror = new RectMirror();
48 | break;
49 | }
50 | return mirror;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/magicmirror/src/main/java/com/kingja/magicmirror/Util.java:
--------------------------------------------------------------------------------
1 | package com.kingja.magicmirror;
2 |
3 | import android.content.Context;
4 | import android.util.TypedValue;
5 |
6 | /**
7 | * Description:Util
8 | * Create Time:2017/4/14 14:05
9 | * Author:KingJA
10 | * Email:kingjavip@gmail.com
11 | */
12 | public class Util {
13 | public static int dp2px(Context context, float dp) {
14 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources()
15 | .getDisplayMetrics());
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/magicmirror/src/main/java/com/kingja/magicmirror/filter/FilterHelper.java:
--------------------------------------------------------------------------------
1 | package com.kingja.magicmirror.filter;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Canvas;
5 | import android.graphics.ColorMatrix;
6 | import android.graphics.ColorMatrixColorFilter;
7 | import android.graphics.Paint;
8 |
9 | /**
10 | * Description:FilterHelper used for supporting the filter effect.
11 | * Create Time:2017/3/28 22:05
12 | * Author:KingJA
13 | * Email:kingjavip@gmail.com
14 | */
15 | public class FilterHelper {
16 | private static final float[] CLEAR = {
17 | 1F, 0F, 0F, 0F, 0F,
18 | 0F, 1F, 0F, 0F, 0F,
19 | 0F, 0F, 1F, 0F, 0F,
20 | 0F, 0F, 0F, 1F, 0F};
21 | private static final float[] OLDPICTURE = {
22 | 0.393F, 0.769F, 0.189F, 0, 0,
23 | 0.349F, 0.686F, 0.168F, 0, 0,
24 | 0.272F, 0.534F, 0.131F, 0, 0,
25 | 0, 0, 0, 1, 0};
26 |
27 | private static final float[] GRAY = {
28 | 0.33F, 0.59F, 0.11F, 0F, 0F,
29 | 0.33F, 0.59F, 0.11F, 0F, 0F,
30 | 0.33F, 0.59F, 0.11F, 0F, 0F,
31 | 0F, 0F, 0F, 1F, 0F};
32 |
33 | private static final float[] SATURATION = {
34 | 1.438F, -0.122F, -0.016F, 0F, -0.03F,
35 | -0.062F, 1.378F, -0.016F, 0F, 0.05F,
36 | -0.062F, -0.122F, 1.483F, 0F, -0.02F,
37 | 0F, 0F, 0F, 1F, 0F};
38 |
39 |
40 | public static Bitmap getFilterBitmap(Bitmap bitmap, int filter) {
41 | Bitmap bmp = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
42 | Canvas canvas = new Canvas(bmp);
43 | Paint paint = new Paint();
44 | ColorMatrix colorMatrix = new ColorMatrix();
45 | colorMatrix.set(getFilter(filter));
46 | paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
47 | canvas.drawBitmap(bitmap, 0, 0, paint);
48 | return bmp;
49 | }
50 |
51 | private static float[] getFilter(int filter) {
52 | float[] filterArr ;
53 | switch (filter) {
54 | case 1:
55 | filterArr = OLDPICTURE;
56 | break;
57 | case 2:
58 | filterArr = GRAY;
59 | break;
60 | case 3:
61 | filterArr = SATURATION;
62 | break;
63 | default:
64 | filterArr = CLEAR;
65 | break;
66 | }
67 | return filterArr;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/magicmirror/src/main/java/com/kingja/magicmirror/mirror/AnyMirror.java:
--------------------------------------------------------------------------------
1 | package com.kingja.magicmirror.mirror;
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.Matrix;
8 | import android.graphics.Paint;
9 | import android.graphics.Path;
10 |
11 | /**
12 | * Description:Any shape
13 | * Create Time:2017/3/22 21:31
14 | * Author:KingJA
15 | * Email:kingjavip@gmail.com
16 | */
17 | public class AnyMirror extends Mirror {
18 |
19 | @Override
20 | public Path getMirrorPath() {
21 | if (getMaskRes() == 0) {
22 | throw new IllegalArgumentException("attr 'mirrorAnySharp' can't be empty");
23 | }
24 | Bitmap bitmap = getBitmapFromRes(getMagicMirror().getResources(), getMaskRes(), getWidth(), getHeight());
25 | Path path = getPixelsPath(bitmap);
26 | bitmap.recycle();
27 | float scaleX = getWidth() * 1.0f / bitmap.getWidth();
28 | float scaleY = getHeight() * 1.0f / bitmap.getHeight();
29 | Matrix matrix = new Matrix();
30 | matrix.setScale(scaleX, scaleY);
31 | path.transform(matrix);
32 | return path;
33 | }
34 |
35 | @Override
36 | protected void setPersonalPaint(Paint bitmapPaint) {
37 | super.setPersonalPaint(bitmapPaint);
38 | bitmapPaint.setStyle(Paint.Style.STROKE);
39 | }
40 |
41 | private Path getPixelsPath(Bitmap bitmap) {
42 | Path path = new Path();
43 | int[] origin = new int[bitmap.getWidth()];
44 | int lastA;
45 | for (int i = 0; i < bitmap.getHeight(); i++) {
46 | bitmap.getPixels(origin, 0, bitmap.getWidth(), 0, i, bitmap.getWidth(), 1);
47 | lastA = 0;
48 | for (int j = 0; j < bitmap.getWidth(); j++) {
49 | int a = Color.alpha(origin[j]);
50 | if (a != 0 && lastA == 0) {
51 | path.moveTo(j, i);
52 | } else if (a == 0 && lastA != 0) {
53 | path.lineTo(j - 1, i);
54 | } else if (a != 0 && j == bitmap.getWidth() - 1) {
55 | path.lineTo(j, i);
56 | }
57 | lastA = a;
58 | }
59 | }
60 | return path;
61 | }
62 |
63 | private Bitmap getBitmapFromRes(Resources resources, int resId, int width, int height) {
64 | BitmapFactory.Options options = new BitmapFactory.Options();
65 | options.inJustDecodeBounds = true;
66 | BitmapFactory.decodeResource(resources, resId, options);
67 | int widthRatio = (int) (options.outWidth * 1.0f / width);
68 | int heightRatio = (int) (options.outHeight * 1.0f / height);
69 | options.inSampleSize = Math.max(widthRatio, heightRatio);
70 | options.inJustDecodeBounds = false;
71 | return BitmapFactory.decodeResource(resources, resId, options);
72 | }
73 |
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/magicmirror/src/main/java/com/kingja/magicmirror/mirror/CircleMirror.java:
--------------------------------------------------------------------------------
1 | package com.kingja.magicmirror.mirror;
2 |
3 | import android.graphics.Path;
4 |
5 | /**
6 | * Description:Circle
7 | * Create Time:2017/3/22 21:30
8 | * Author:KingJA
9 | * Email:kingjavip@gmail.com
10 | */
11 | public class CircleMirror extends Mirror {
12 |
13 | @Override
14 | public Path getMirrorPath() {
15 | Path path = new Path();
16 | path.addCircle(getRectF().centerX(), getRectF().centerY(), getMeasuredMirrorWidth() * 0.5f - getBorderWidth() * 0.5f, Path
17 | .Direction.CW);
18 | return path;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/magicmirror/src/main/java/com/kingja/magicmirror/mirror/Mirror.java:
--------------------------------------------------------------------------------
1 | package com.kingja.magicmirror.mirror;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapShader;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.graphics.Path;
8 | import android.graphics.RectF;
9 | import android.graphics.Shader;
10 | import android.graphics.drawable.BitmapDrawable;
11 | import android.graphics.drawable.ColorDrawable;
12 | import android.graphics.drawable.Drawable;
13 | import android.support.annotation.IdRes;
14 | import android.support.annotation.NonNull;
15 |
16 | import com.kingja.magicmirror.MagicMirrorView;
17 | import com.kingja.magicmirror.filter.FilterHelper;
18 |
19 | /**
20 | * Description:Mirror
21 | * Create Time:2017/3/22 21:01
22 | * Author:KingJA
23 | * Email:kingjavip@gmail.com
24 | */
25 | public abstract class Mirror {
26 | private int corner;
27 | private int borderWidth;
28 | private int borderColor;
29 | private int width;
30 | private int height;
31 | private int sides;
32 | private int filter;
33 | private int maskRes;
34 | private MagicMirrorView magicMirrorView;
35 |
36 |
37 | public Mirror setContext(@NonNull MagicMirrorView magicMirrorView) {
38 | this.magicMirrorView = magicMirrorView;
39 | return this;
40 | }
41 |
42 | protected MagicMirrorView getMagicMirror() {
43 | return magicMirrorView;
44 | }
45 |
46 | public Mirror setMaskRes(@IdRes int sharpResourceId) {
47 | this.maskRes = sharpResourceId;
48 | return this;
49 | }
50 |
51 | protected int getMaskRes() {
52 | return maskRes;
53 | }
54 |
55 | public Mirror setFilter(int filter) {
56 | this.filter = filter;
57 | return this;
58 | }
59 |
60 | public Mirror setCorner(int corner) {
61 | this.corner = corner;
62 | return this;
63 | }
64 |
65 | protected int getCorner() {
66 | return corner;
67 | }
68 |
69 | public Mirror setBorderWidth(int borderWidth) {
70 | this.borderWidth = borderWidth;
71 | return this;
72 | }
73 |
74 | protected int getBorderWidth() {
75 | return borderWidth;
76 | }
77 |
78 | public Mirror setSides(int sides) {
79 | this.sides = sides;
80 | return this;
81 | }
82 |
83 | protected int getSides() {
84 | if (sides < 3) {
85 | throw new IllegalArgumentException("sides can't be smaller than 3");
86 | }
87 | return sides;
88 | }
89 |
90 | public Mirror setBorderColor(int borderColor) {
91 | this.borderColor = borderColor;
92 | return this;
93 | }
94 |
95 | protected int getWidth() {
96 | return width;
97 | }
98 |
99 | public int getHeight() {
100 | return height;
101 | }
102 |
103 | protected void setWidth(int width) {
104 | this.width = width;
105 | }
106 |
107 | public void setHeight(int height) {
108 | this.height = height;
109 | }
110 |
111 | protected final Paint getStrokePaint() {
112 | Paint strokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
113 | strokePaint.setStyle(Paint.Style.STROKE);
114 | strokePaint.setColor(borderColor);
115 | strokePaint.setStrokeWidth(borderWidth);
116 | return strokePaint;
117 | }
118 |
119 |
120 | protected final RectF getRectF() {
121 | int borderOffset = (int) (borderWidth * 0.5f);
122 | RectF rectF = new RectF();
123 | rectF.set(borderOffset, borderOffset, width - borderOffset, height - borderOffset);
124 | return rectF;
125 | }
126 |
127 | protected final Paint getShaderPaint() {
128 | Bitmap mBitmap = drawableToBitmap(magicMirrorView.getDrawable());
129 | mBitmap = FilterHelper.getFilterBitmap(mBitmap, filter);
130 | BitmapShader mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
131 | Paint mBitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
132 | setPersonalPaint(mBitmapPaint);
133 | mBitmapShader.setLocalMatrix(magicMirrorView.getImageMatrix());
134 | mBitmapPaint.setShader(mBitmapShader);
135 | return mBitmapPaint;
136 | }
137 |
138 | private Bitmap drawableToBitmap(Drawable drawable) {
139 | if (drawable instanceof BitmapDrawable) {
140 | return ((BitmapDrawable) drawable).getBitmap();
141 | }
142 | Bitmap bitmap;
143 | try {
144 | if (drawable instanceof ColorDrawable) {
145 | bitmap = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888);
146 | } else {
147 | int width = drawable.getIntrinsicWidth();
148 | int height = drawable.getIntrinsicHeight();
149 | bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
150 | }
151 | Canvas canvas = new Canvas(bitmap);
152 | drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
153 | drawable.draw(canvas);
154 | } catch (Exception e) {
155 | e.printStackTrace();
156 | bitmap = null;
157 | }
158 | return bitmap;
159 | }
160 |
161 | public final void drawMirror(Canvas canvas) {
162 | canvas.drawPath(getMirrorPath(), getShaderPaint());
163 | if (borderWidth > 0) {
164 | canvas.drawPath(getMirrorPath(), getStrokePaint());
165 | }
166 | }
167 |
168 | protected void setPersonalPaint(Paint bitmapPaint) {
169 | }
170 |
171 | public int getMeasuredMirrorWidth() {
172 | width = Math.min(magicMirrorView.getMeasuredWidth(), magicMirrorView.getMeasuredHeight());
173 | return Math.min(magicMirrorView.getMeasuredWidth(), magicMirrorView.getMeasuredHeight());
174 | }
175 |
176 | public int getMeasuredMirrorHeight() {
177 | height = Math.min(magicMirrorView.getMeasuredWidth(), magicMirrorView.getMeasuredHeight());
178 | return Math.min(magicMirrorView.getMeasuredWidth(), magicMirrorView.getMeasuredHeight());
179 | }
180 |
181 | public abstract Path getMirrorPath();
182 |
183 | }
184 |
--------------------------------------------------------------------------------
/magicmirror/src/main/java/com/kingja/magicmirror/mirror/OvalMirror.java:
--------------------------------------------------------------------------------
1 | package com.kingja.magicmirror.mirror;
2 |
3 | import android.graphics.Path;
4 |
5 | /**
6 | * Description:Oval
7 | * Create Time:2017/3/22 21:31
8 | * Author:KingJA
9 | * Email:kingjavip@gmail.com
10 | */
11 | public class OvalMirror extends Mirror {
12 |
13 | @Override
14 | public int getMeasuredMirrorWidth() {
15 | setWidth(getMagicMirror().getMeasuredWidth());
16 | return getMagicMirror().getMeasuredWidth();
17 | }
18 |
19 | @Override
20 | public int getMeasuredMirrorHeight() {
21 | setHeight(getMagicMirror().getMeasuredHeight());
22 | return getMagicMirror().getMeasuredHeight();
23 | }
24 |
25 | @Override
26 | public Path getMirrorPath() {
27 | Path path = new Path();
28 | path.addOval(getRectF(), Path.Direction.CW);
29 | return path;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/magicmirror/src/main/java/com/kingja/magicmirror/mirror/PolygonMirror.java:
--------------------------------------------------------------------------------
1 | package com.kingja.magicmirror.mirror;
2 |
3 | import android.graphics.Matrix;
4 | import android.graphics.Path;
5 |
6 | /**
7 | * Description:Polygo
8 | * Create Time:2017/3/22 21:30
9 | * Author:KingJA
10 | * Email:kingjavip@gmail.com
11 | */
12 | public class PolygonMirror extends Mirror {
13 |
14 | @Override
15 | public Path getMirrorPath() {
16 | Path path = new Path();
17 | float radius, centerX, centerY;
18 | radius = centerX = centerY = Math.min(getWidth(), getHeight()) * 0.5f;
19 | radius -= getBorderWidth() * 0.5f;
20 | float offsetAngle = 0;
21 | offsetAngle = (float) (Math.PI * offsetAngle / 180);
22 | for (int i = 0; i < getSides(); i++) {
23 | float x = (float) (centerX + radius * Math.cos(offsetAngle));
24 | float y = (float) (centerY + radius * Math.sin(offsetAngle));
25 | offsetAngle += 2 * Math.PI / getSides();
26 | if (i == 0) {
27 | path.moveTo(x, y);
28 | } else {
29 | path.lineTo(x, y);
30 | }
31 | }
32 | path.close();
33 | if (getSides() % 2 != 0) {
34 | Matrix mMatrix = new Matrix();
35 | mMatrix.postRotate(-90, centerX, centerY);
36 | path.transform(mMatrix);
37 | }
38 | return path;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/magicmirror/src/main/java/com/kingja/magicmirror/mirror/RectMirror.java:
--------------------------------------------------------------------------------
1 | package com.kingja.magicmirror.mirror;
2 |
3 | import android.graphics.Path;
4 |
5 | /**
6 | * Description:Rect
7 | * Create Time:2017/3/22 21:31
8 | * Author:KingJA
9 | * Email:kingjavip@gmail.com
10 | */
11 | public class RectMirror extends Mirror {
12 |
13 | @Override
14 | public Path getMirrorPath() {
15 | Path path = new Path();
16 | path.addRect(getRectF(), Path.Direction.CW);
17 | return path;
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/magicmirror/src/main/java/com/kingja/magicmirror/mirror/RoundRectMirror.java:
--------------------------------------------------------------------------------
1 | package com.kingja.magicmirror.mirror;
2 |
3 | import android.graphics.Path;
4 |
5 | /**
6 | * Description:RoundRect
7 | * Create Time:2017/3/22 21:31
8 | * Author:KingJA
9 | * Email:kingjavip@gmail.com
10 | */
11 | public class RoundRectMirror extends Mirror {
12 |
13 | @Override
14 | public Path getMirrorPath() {
15 | Path path = new Path();
16 | path.addRoundRect(getRectF(), getCorner(), getCorner(), Path.Direction.CW);
17 | return path;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/magicmirror/src/main/res/values/attr.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 |
--------------------------------------------------------------------------------
/magicmirror/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MagicMirror
3 |
4 |
--------------------------------------------------------------------------------
/readme/TODO.MD:
--------------------------------------------------------------------------------
1 | * 状态保存
2 | * 图片滤镜
3 | * 研究https://github.com/siyamed/android-shape-imageview
4 | * 研究吧svg画布转成自定义形状的ImageView
5 | * http://blog.csdn.net/u013015161/article/details/50993199
6 | * 缩放模式
7 | * svg失真
8 | * 遮罩图片的像素要大于scr图片像素
9 | * 上传bintray
10 | * 初步完成
--------------------------------------------------------------------------------
/readme/any.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/any.png
--------------------------------------------------------------------------------
/readme/apple.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/apple.png
--------------------------------------------------------------------------------
/readme/beauty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/beauty.png
--------------------------------------------------------------------------------
/readme/bg_apple.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/bg_apple.png
--------------------------------------------------------------------------------
/readme/bg_beauty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/bg_beauty.png
--------------------------------------------------------------------------------
/readme/bg_heart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/bg_heart.png
--------------------------------------------------------------------------------
/readme/bg_lemon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/bg_lemon.png
--------------------------------------------------------------------------------
/readme/bg_tag.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/bg_tag.png
--------------------------------------------------------------------------------
/readme/circle.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/circle.png
--------------------------------------------------------------------------------
/readme/gray.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/gray.png
--------------------------------------------------------------------------------
/readme/heart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/heart.png
--------------------------------------------------------------------------------
/readme/item.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/item.png
--------------------------------------------------------------------------------
/readme/lemon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/lemon.png
--------------------------------------------------------------------------------
/readme/logo_magicmirror.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/logo_magicmirror.png
--------------------------------------------------------------------------------
/readme/old_picture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/old_picture.png
--------------------------------------------------------------------------------
/readme/original.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/original.png
--------------------------------------------------------------------------------
/readme/oval.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/oval.png
--------------------------------------------------------------------------------
/readme/polygon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/polygon.png
--------------------------------------------------------------------------------
/readme/preview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/preview.png
--------------------------------------------------------------------------------
/readme/rect.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/rect.png
--------------------------------------------------------------------------------
/readme/round_rect.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/round_rect.png
--------------------------------------------------------------------------------
/readme/saturation.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/saturation.png
--------------------------------------------------------------------------------
/readme/tag.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingJA/MagicMirror/2a61e2d992b5e51d845b241da73928bc4b3401cd/readme/tag.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':magicmirror'
2 |
--------------------------------------------------------------------------------