├── .gitattributes
├── .gitignore
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── zyyoona7
│ │ └── sample
│ │ ├── DownTimer.java
│ │ ├── LauncherActivity.java
│ │ ├── LockActivity.java
│ │ ├── LockFragment.java
│ │ ├── LockSettingActivity.java
│ │ └── MyApplication.java
│ └── res
│ ├── anim
│ ├── cycle_4.xml
│ ├── fade_ins.xml
│ ├── push_bottom_in_2.xml
│ └── shake.xml
│ ├── layout
│ ├── activity_launcher.xml
│ ├── activity_lock.xml
│ ├── activity_lock_setting.xml
│ └── fragment_lock.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gesturelockview
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── zyyoona7
│ │ └── lock
│ │ ├── ConvertUtils.java
│ │ ├── Dot.java
│ │ ├── GestureLockDisplayView.java
│ │ ├── GestureLockLayout.java
│ │ ├── ILockView.java
│ │ ├── JDLockView.java
│ │ ├── LockViewFactory.java
│ │ └── QQLockView.java
│ └── res
│ └── values
│ ├── attrs.xml
│ └── strings.xml
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── images
├── gesture1.gif
└── gesture2.gif
└── settings.gradle
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GestureLockView
2 | ### 手势解锁
3 | 修改[鸿洋的](http://blog.csdn.net/lmj623565791/article/details/36236113)手势解锁,继承RelativeLayout,可以自由定制手势点的样式的手势解锁
4 | ### 特性
5 | - 实现ILockView,自由定制样式
6 | - 支持修改/设置密码模式和验证密码模式
7 | ### 效果图
8 | 
9 | 
10 | ### 使用
11 | #### 1. 简单使用
12 | **设置/重置密码模式**
13 |
14 | 布局文件中:
15 |
16 | ```xml
17 |
22 |
23 |
24 |
29 |
30 |
37 |
38 |
39 |
44 |
45 |
46 |
47 | ```
48 |
49 | java 代码中:
50 |
51 | ```java
52 | private void initViews() {
53 | mGestureLockLayout = (GestureLockLayout) findViewById(R.id.l_gesture_view);
54 | mLockDisplayView = (GestureLockDisplayView) findViewById(R.id.l_display_view);
55 | mSettingHintText = (TextView) findViewById(R.id.tv_setting_hint);
56 | //设置提示view 每行每列点的个数
57 | mLockDisplayView.setDotCount(3);
58 | //设置提示view 选中状态的颜色
59 | mLockDisplayView.setDotSelectedColor(Color.parseColor("#01A0E5"));
60 | //设置提示view 非选中状态的颜色
61 | mLockDisplayView.setDotUnSelectedColor(Color.TRANSPARENT);
62 | //设置手势解锁view 每行每列点的个数
63 | mGestureLockLayout.setDotCount(3);
64 | //设置手势解锁view 最少连接数
65 | mGestureLockLayout.setMinCount(3);
66 | //默认解锁样式为手Q手势解锁样式
67 | //mGestureLockLayout.setLockView();
68 | //设置手势解锁view 模式为重置密码模式
69 | mGestureLockLayout.setMode(GestureLockLayout.RESET_MODE);
70 | }
71 |
72 | private void initEvents() {
73 | mGestureLockLayout.setOnLockResetListener(new GestureLockLayout.OnLockResetListener() {
74 | @Override
75 | public void onConnectCountUnmatched(int connectCount, int minCount) {
76 | //连接数小于最小连接数时调用
77 |
78 | mSettingHintText.setText("最少连接" + minCount + "个点");
79 | resetGesture();
80 | }
81 |
82 | @Override
83 | public void onFirstPasswordFinished(List answerList) {
84 | //第一次绘制手势成功时调用
85 |
86 | mSettingHintText.setText("确认解锁图案");
87 | //将答案设置给提示view
88 | mLockDisplayView.setAnswer(answerList);
89 | //重置
90 | resetGesture();
91 | }
92 |
93 | @Override
94 | public void onSetPasswordFinished(boolean isMatched, List answerList) {
95 | //第二次密码绘制成功时调用
96 |
97 | if (isMatched) {
98 | //两次答案一致,保存
99 | //do something
100 | } else {
101 | resetGesture();
102 | }
103 | }
104 | });
105 | }
106 |
107 | /**
108 | * 重置
109 | */
110 | private void resetGesture() {
111 | mHandler.postDelayed(new Runnable() {
112 | @Override
113 | public void run() {
114 | mGestureLockLayout.resetGesture();
115 | }
116 | }, 200);
117 | }
118 | ```
119 |
120 | **验证密码模式**
121 |
122 | 布局文件中:
123 |
124 | ```xml
125 |
130 |
131 |
137 |
138 |
143 |
144 |
145 |
146 | ```
147 |
148 | java 代码中:
149 |
150 | ```java
151 | private void initViews() {
152 | mGestureLockLayout = (GestureLockLayout) findViewById(R.id.l_lock_view);
153 | mHintText = (TextView) findViewById(R.id.tv_hint);
154 | //设置手势解锁模式为验证模式
155 | mGestureLockLayout.setMode(GestureLockLayout.VERIFY_MODE);
156 | //设置手势解锁每行每列点的个数
157 | mGestureLockLayout.setDotCount(3);
158 | //设置手势解锁最大尝试次数 默认 5
159 | mGestureLockLayout.setTryTimes(3);
160 | //设置手势解锁正确答案
161 | mGestureLockLayout.setAnswer(getCacheAnswer());
162 | }
163 |
164 | private void initEvents() {
165 | mGestureLockLayout.setOnLockVerifyListener(new GestureLockLayout.OnLockVerifyListener() {
166 | @Override
167 | public void onGestureSelected(int id) {
168 | //每选中一个点时调用
169 | }
170 |
171 | @Override
172 | public void onGestureFinished(boolean isMatched) {
173 | //绘制手势解锁完成时调用
174 |
175 | if (isMatched) {
176 | //密码匹配
177 | } else {
178 | //不匹配
179 | mHintText.setText("还有" + mGestureLockLayout.getTryTimes() + "次机会");
180 | resetGesture();
181 | }
182 | }
183 |
184 | @Override
185 | public void onGestureTryTimesBoundary() {
186 | //超出最大尝试次数时调用
187 |
188 | mGestureLockLayout.setTouchable(false);
189 | }
190 | });
191 | }
192 |
193 | private void resetGesture() {
194 | mHandler.postDelayed(new Runnable() {
195 | @Override
196 | public void run() {
197 | mGestureLockLayout.resetGesture();
198 | }
199 | }, 200);
200 | }
201 | ```
202 |
203 | #### 2. 自定义样式
204 |
205 | 实现 ILockView 接口:
206 |
207 | ```java
208 | public interface ILockView {
209 |
210 | //手势状态
211 | int NO_FINGER = 0;
212 | int FINGER_TOUCH = 1;
213 | int FINGER_UP_MATCHED = 2;
214 | int FINGER_UP_UN_MATCHED = 3;
215 |
216 | /**
217 | * 获取View
218 | *
219 | * @return
220 | */
221 | View getView();
222 |
223 | /**
224 | * 手指没触摸之前,初始状态
225 | */
226 | void onNoFinger();
227 |
228 | /**
229 | * 手指触摸,按下状态
230 | */
231 | void onFingerTouch();
232 |
233 | /**
234 | * 手指抬起,手势密码匹配状态
235 | */
236 | void onFingerUpMatched();
237 |
238 | /**
239 | * 手指抬起,手势密码不匹配状态
240 | */
241 | void onFingerUpUnmatched();
242 | }
243 | ```
244 |
245 | iOS 版京东金融手势解锁样式:
246 |
247 | ```java
248 | public class JDLockView extends View implements ILockView {
249 |
250 | private Paint mPaint;
251 | private int mCurrentState=NO_FINGER;
252 | private float mOuterRadius;
253 | private float mInnerRadius;
254 |
255 | public JDLockView(Context context) {
256 | this(context,null);
257 | }
258 |
259 | public JDLockView(Context context, @Nullable AttributeSet attrs) {
260 | super(context, attrs);
261 | init(context);
262 | }
263 |
264 | public void init(Context context){
265 | mPaint=new Paint();
266 | mPaint.setAntiAlias(true);
267 | }
268 |
269 | @Override
270 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
271 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
272 | int width = MeasureSpec.getSize(widthMeasureSpec);
273 | int height = MeasureSpec.getSize(heightMeasureSpec);
274 | width = width > height ? height : width;
275 | setMeasuredDimension(width, width);
276 | }
277 |
278 | @Override
279 | protected void onDraw(Canvas canvas) {
280 | super.onDraw(canvas);
281 | float space = 10;
282 | float x = getWidth() / 2;
283 | float y = getHeight() / 2;
284 | canvas.translate(x, y);
285 | mOuterRadius = x - space;
286 | mInnerRadius = (x - space) / 3;
287 | switch (mCurrentState) {
288 | case NO_FINGER:
289 | drawNoFinger(canvas);
290 | break;
291 | case FINGER_TOUCH:
292 | drawFingerTouch(canvas);
293 | break;
294 | case FINGER_UP_MATCHED:
295 | drawFingerUpMatched(canvas);
296 | break;
297 | case FINGER_UP_UN_MATCHED:
298 | drawFingerUpUnmatched(canvas);
299 | break;
300 | }
301 | }
302 |
303 | /**
304 | * 画无手指触摸状态
305 | *
306 | * @param canvas
307 | */
308 | private void drawNoFinger(Canvas canvas) {
309 | mPaint.setStyle(Paint.Style.FILL);
310 | mPaint.setColor(Color.GRAY);
311 | canvas.drawCircle(0, 0, mInnerRadius, mPaint);
312 | }
313 |
314 | /**
315 | * 画手指触摸状态
316 | *
317 | * @param canvas
318 | */
319 | private void drawFingerTouch(Canvas canvas) {
320 | mPaint.setStyle(Paint.Style.FILL);
321 | mPaint.setColor(Color.BLUE);
322 | canvas.drawCircle(0, 0, mInnerRadius, mPaint);
323 | mPaint.setStyle(Paint.Style.STROKE);
324 | mPaint.setStrokeWidth(ConvertUtils.dp2px(getContext(),1));
325 | canvas.drawCircle(0, 0, mOuterRadius, mPaint);
326 | }
327 |
328 | /**
329 | * 画手指抬起,匹配状态
330 | *
331 | * @param canvas
332 | */
333 | private void drawFingerUpMatched(Canvas canvas) {
334 | drawFingerTouch(canvas);
335 | }
336 |
337 | /**
338 | * 画手指抬起,不匹配状态
339 | *
340 | * @param canvas
341 | */
342 | private void drawFingerUpUnmatched(Canvas canvas) {
343 | mPaint.setStyle(Paint.Style.FILL);
344 | mPaint.setColor(Color.RED);
345 | canvas.drawCircle(0, 0, mInnerRadius, mPaint);
346 | mPaint.setStyle(Paint.Style.STROKE);
347 | mPaint.setStrokeWidth(ConvertUtils.dp2px(getContext(),1));
348 | canvas.drawCircle(0, 0, mOuterRadius, mPaint);
349 | }
350 |
351 | @Override
352 | public View getView() {
353 | return this;
354 | }
355 |
356 | @Override
357 | public void onNoFinger() {
358 | mCurrentState=NO_FINGER;
359 | postInvalidate();
360 | }
361 |
362 | @Override
363 | public void onFingerTouch() {
364 | mCurrentState=FINGER_TOUCH;
365 | postInvalidate();
366 | }
367 |
368 | @Override
369 | public void onFingerUpMatched() {
370 | mCurrentState=FINGER_UP_MATCHED;
371 | postInvalidate();
372 | }
373 |
374 | @Override
375 | public void onFingerUpUnmatched() {
376 | mCurrentState=FINGER_UP_UN_MATCHED;
377 | postInvalidate();
378 | }
379 | }
380 | ```
381 |
382 | 使用的时候只需多调用一下下面方法:
383 |
384 | ```java
385 | //设置手势解锁样式
386 | mGestureLockLayout.setLockView(new LockViewFactory() {
387 | @Override
388 | public ILockView newLockView() {
389 | return new JDLockView(LockSettingActivity.this);
390 | }
391 | });
392 | ```
393 |
394 | 其他用法同 1 一致。
395 | ### License
396 | ```
397 | Copyright 2017 zyyoona7
398 |
399 | Licensed under the Apache License, Version 2.0 (the "License");
400 | you may not use this file except in compliance with the License.
401 | You may obtain a copy of the License at
402 |
403 | http://www.apache.org/licenses/LICENSE-2.0
404 |
405 | Unless required by applicable law or agreed to in writing, software
406 | distributed under the License is distributed on an "AS IS" BASIS,
407 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
408 | See the License for the specific language governing permissions and
409 | limitations under the License.
410 | ```
411 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | buildToolsVersion '27.0.3'
6 |
7 | defaultConfig {
8 | applicationId "com.zyyoona7.sample"
9 | minSdkVersion 15
10 | targetSdkVersion 26
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | implementation fileTree(include: ['*.jar'], dir: 'libs')
24 | implementation project(':gesturelockview')
25 | implementation 'com.android.support.constraint:constraint-layout:1.1.2'
26 | api 'com.android.support:appcompat-v7:27.1.1'
27 | implementation 'me.yokeyword:fragmentation:1.3.5'
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/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 D:\Android\android-sdk-windows/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 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyyoona7/sample/DownTimer.java:
--------------------------------------------------------------------------------
1 | package com.zyyoona7.sample;
2 |
3 | import android.os.Handler;
4 | import android.os.Message;
5 | import android.os.SystemClock;
6 |
7 | /**
8 | * DownTimer
9 | *
10 | * @author cjj
11 | * @version 1.0
12 | * @category 倒计时工具类
13 | * @content 1.实例化后必须设置倒计时的总时间(totalTime)和每隔多久时间(intervalTime)回调
14 | * 2.有start()、 cancel()、 pause()、resume() 四个方法看方法就知道它的意思了
15 | */
16 | public class DownTimer {
17 | private long totalTime = -1;
18 | private long intervalTime = 0;
19 | private long remainTime;
20 | private long systemAddTotalTime;
21 | private static final int TIME = 1;
22 | private TimeListener listener;
23 | private long curReminTime;
24 | private boolean isPause = false;
25 |
26 | public DownTimer() {
27 | }
28 |
29 | public void setIntervalTime(long intervalTime) {
30 | this.intervalTime = intervalTime;
31 | }
32 |
33 | public void setTotalTime(long totalTime) {
34 | this.totalTime = totalTime;
35 | }
36 |
37 | public long getIntervalTime() {
38 | return intervalTime;
39 | }
40 |
41 | public long getTotalTime() {
42 | return totalTime;
43 | }
44 |
45 | public void start() {
46 | if (totalTime <= 0 && intervalTime <= 0) {
47 | throw new RuntimeException("you must set the totalTime > 0 or intervalTime >0");
48 | }
49 |
50 | systemAddTotalTime = SystemClock.elapsedRealtime() + totalTime;
51 |
52 | if (null != mHandler)
53 | mHandler.sendEmptyMessage(TIME);
54 | }
55 |
56 | public void cancel() {
57 | if (mHandler != null) {
58 | mHandler.removeMessages(TIME);
59 | mHandler = null;
60 | }
61 |
62 | }
63 |
64 | public void pause() {
65 | if (mHandler != null) {
66 | mHandler.removeMessages(TIME);
67 | isPause = true;
68 | curReminTime = remainTime;
69 | }
70 |
71 | }
72 |
73 | public void resume() {
74 | if (isPause == true) {
75 | isPause = false;
76 | totalTime = curReminTime;
77 | start();
78 | }
79 |
80 | }
81 |
82 | private Handler mHandler = new Handler() {
83 |
84 | @Override
85 | public void handleMessage(Message msg) {
86 | switch (msg.what) {
87 | case TIME:
88 | if (!isPause)
89 | soloveTime();
90 | break;
91 | case 2:
92 | isPause = true;
93 | break;
94 | default:
95 | break;
96 | }
97 | }
98 | };
99 |
100 |
101 | private void soloveTime() {
102 | remainTime = systemAddTotalTime - SystemClock.elapsedRealtime();
103 | if (remainTime <= 0) {
104 | if (listener != null) {
105 | listener.onFinish();
106 | cancel();
107 | }
108 | } else if (remainTime < intervalTime) {
109 | if (null != mHandler)
110 | mHandler.sendEmptyMessageDelayed(TIME, remainTime);
111 | } else {
112 | long curSystemTime = SystemClock.elapsedRealtime();
113 | if (listener != null) {
114 | listener.onInterval(remainTime);
115 | }
116 |
117 | long delay = curSystemTime + intervalTime - SystemClock.elapsedRealtime();
118 |
119 | while (delay < 0) delay += intervalTime;
120 |
121 | if (null != mHandler) {
122 | mHandler.sendEmptyMessageDelayed(TIME, delay);
123 | }
124 | }
125 | }
126 |
127 | public interface TimeListener {
128 | public void onFinish();
129 |
130 | public void onInterval(long remainTime);
131 | }
132 |
133 | public void setTimerLiener(TimeListener listener) {
134 | this.listener = listener;
135 | }
136 |
137 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zyyoona7/sample/LauncherActivity.java:
--------------------------------------------------------------------------------
1 | package com.zyyoona7.sample;
2 |
3 | import android.content.Intent;
4 | import android.graphics.Color;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.os.Bundle;
7 | import android.text.TextUtils;
8 | import android.view.View;
9 | import android.widget.Button;
10 | import android.widget.Toast;
11 |
12 | import com.zyyoona7.lock.GestureLockLayout;
13 | import com.zyyoona7.lock.ILockView;
14 | import com.zyyoona7.lock.JDLockView;
15 | import com.zyyoona7.lock.LockViewFactory;
16 | import com.zyyoona7.lock.QQLockView;
17 |
18 |
19 | public class LauncherActivity extends AppCompatActivity {
20 | // TODO: 2017/7/10 展示更多样式
21 |
22 | private Button mSettingBtn;
23 | private Button mQQBtn;
24 | private Button mJDBtn;
25 | private GestureLockLayout mGestureLockLayout;
26 |
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.activity_launcher);
31 | initViews();
32 | initEvents();
33 | }
34 |
35 | private void initViews(){
36 | mSettingBtn = (Button) findViewById(R.id.btn_setting);
37 | mQQBtn= (Button) findViewById(R.id.btn_qq);
38 | mJDBtn= (Button) findViewById(R.id.btn_jd);
39 | mGestureLockLayout= (GestureLockLayout) findViewById(R.id.l_gesture_lock_view);
40 | mGestureLockLayout.setDotCount(3);
41 | mGestureLockLayout.setMode(GestureLockLayout.VERIFY_MODE);
42 | mGestureLockLayout.setTryTimes(100);
43 | mGestureLockLayout.setAnswer(0,1,2);
44 |
45 | }
46 |
47 | private void initEvents(){
48 | mSettingBtn.setOnClickListener(new View.OnClickListener() {
49 | @Override
50 | public void onClick(View v) {
51 | goTo(LockSettingActivity.class);
52 | }
53 | });
54 |
55 | mQQBtn.setOnClickListener(new View.OnClickListener() {
56 | @Override
57 | public void onClick(View v) {
58 | mGestureLockLayout.setLockView(new LockViewFactory() {
59 | @Override
60 | public ILockView newLockView() {
61 | return new QQLockView(LauncherActivity.this);
62 | }
63 | });
64 | mGestureLockLayout.setPathWidth(2);
65 | mGestureLockLayout.setTouchedPathColor(Color.parseColor("#01A0E5"));
66 | mGestureLockLayout.setMatchedPathColor(Color.parseColor("#01A0E5"));
67 | mGestureLockLayout.setUnmatchedPathColor(Color.parseColor("#F7564A"));
68 | }
69 | });
70 |
71 | mJDBtn.setOnClickListener(new View.OnClickListener() {
72 | @Override
73 | public void onClick(View v) {
74 | mGestureLockLayout.setLockView(new LockViewFactory() {
75 | @Override
76 | public ILockView newLockView() {
77 | return new JDLockView(LauncherActivity.this);
78 | }
79 | });
80 | mGestureLockLayout.setPathWidth(1);
81 | mGestureLockLayout.setTouchedPathColor(Color.BLUE);
82 | mGestureLockLayout.setMatchedPathColor(Color.BLUE);
83 | mGestureLockLayout.setUnmatchedPathColor(Color.RED);
84 | }
85 | });
86 |
87 | mGestureLockLayout.setOnLockVerifyListener(new GestureLockLayout.OnLockVerifyListener() {
88 | @Override
89 | public void onGestureSelected(int id) {
90 |
91 | }
92 |
93 | @Override
94 | public void onGestureFinished(boolean isMatched) {
95 | if (isMatched) {
96 | Toast.makeText(LauncherActivity.this,"密码正确",Toast.LENGTH_SHORT).show();
97 | }else {
98 | Toast.makeText(LauncherActivity.this,"密码不正确",Toast.LENGTH_SHORT).show();
99 | }
100 | }
101 |
102 | @Override
103 | public void onGestureTryTimesBoundary() {
104 |
105 | }
106 | });
107 | }
108 |
109 | @Override
110 | protected void onResume() {
111 | super.onResume();
112 | if (!TextUtils.isEmpty(MyApplication.getInstance().answer)&& !MyApplication.getInstance().isUnlock) {
113 | goTo(LockActivity.class);
114 | }
115 | }
116 |
117 | public void goTo(Class clazz) {
118 | Intent intent = new Intent(this, clazz);
119 | startActivity(intent);
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyyoona7/sample/LockActivity.java:
--------------------------------------------------------------------------------
1 | package com.zyyoona7.sample;
2 |
3 | import android.os.Bundle;
4 | import android.os.Handler;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.widget.TextView;
7 |
8 | import com.zyyoona7.lock.GestureLockLayout;
9 |
10 | import me.yokeyword.fragmentation.SupportActivity;
11 |
12 | public class LockActivity extends SupportActivity {
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_lock);
18 |
19 | loadRootFragment(R.id.fl_fragment_container,LockFragment.newInstance());
20 | }
21 |
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyyoona7/sample/LockFragment.java:
--------------------------------------------------------------------------------
1 | package com.zyyoona7.sample;
2 |
3 | import android.os.Bundle;
4 | import android.os.Handler;
5 | import android.support.annotation.NonNull;
6 | import android.support.annotation.Nullable;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.TextView;
11 |
12 | import com.zyyoona7.lock.GestureLockLayout;
13 |
14 | import me.yokeyword.fragmentation.SupportFragment;
15 |
16 | public class LockFragment extends SupportFragment {
17 | private GestureLockLayout mGestureLockLayout;
18 | private TextView mHintText;
19 | private Handler mHandler = new Handler();
20 |
21 | public static LockFragment newInstance() {
22 |
23 | Bundle args = new Bundle();
24 |
25 | LockFragment fragment = new LockFragment();
26 | fragment.setArguments(args);
27 | return fragment;
28 | }
29 |
30 | @Nullable
31 | @Override
32 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
33 | return inflater.inflate(R.layout.fragment_lock,container,false);
34 | }
35 |
36 | @Override
37 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
38 | super.onViewCreated(view, savedInstanceState);
39 | initViews(view);
40 | initEvents();
41 | }
42 |
43 | private void initViews(View view) {
44 | mGestureLockLayout = (GestureLockLayout) view.findViewById(R.id.l_lock_view);
45 | mHintText = (TextView) view.findViewById(R.id.tv_hint);
46 | //设置手势解锁模式为验证模式
47 | mGestureLockLayout.setMode(GestureLockLayout.VERIFY_MODE);
48 | //设置手势解锁每行每列点的个数
49 | mGestureLockLayout.setDotCount(3);
50 | //设置手势解锁最大尝试次数 默认 5
51 | mGestureLockLayout.setTryTimes(3);
52 | //设置手势解锁正确答案
53 | mGestureLockLayout.setAnswer(MyApplication.getInstance().answer);
54 | }
55 |
56 | private void initEvents() {
57 | mGestureLockLayout.setOnLockVerifyListener(new GestureLockLayout.OnLockVerifyListener() {
58 | @Override
59 | public void onGestureSelected(int id) {
60 | //每选中一个点时调用
61 | }
62 |
63 | @Override
64 | public void onGestureFinished(boolean isMatched) {
65 | //绘制手势解锁完成时调用
66 |
67 | if (isMatched) {
68 | //密码匹配
69 | MyApplication.getInstance().isUnlock = true;
70 | _mActivity.finish();
71 | } else {
72 | //不匹配
73 | mHintText.setText("还有" + mGestureLockLayout.getTryTimes() + "次机会");
74 | resetGesture();
75 | }
76 | }
77 |
78 | @Override
79 | public void onGestureTryTimesBoundary() {
80 | //超出最大尝试次数时调用
81 |
82 | mGestureLockLayout.setTouchable(false);
83 | }
84 | });
85 | }
86 |
87 | private void resetGesture() {
88 | mHandler.postDelayed(new Runnable() {
89 | @Override
90 | public void run() {
91 | mGestureLockLayout.resetGesture();
92 | }
93 | }, 200);
94 | }
95 |
96 | @Override
97 | public void onDestroyView() {
98 | super.onDestroyView();
99 | if (mHandler != null) {
100 | mHandler.removeCallbacksAndMessages(null);
101 | }
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyyoona7/sample/LockSettingActivity.java:
--------------------------------------------------------------------------------
1 | package com.zyyoona7.sample;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.os.Handler;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.widget.TextView;
8 |
9 | import com.zyyoona7.lock.GestureLockDisplayView;
10 | import com.zyyoona7.lock.GestureLockLayout;
11 | import com.zyyoona7.lock.ILockView;
12 | import com.zyyoona7.lock.JDLockView;
13 | import com.zyyoona7.lock.LockViewFactory;
14 |
15 | import java.util.List;
16 |
17 | public class LockSettingActivity extends AppCompatActivity {
18 |
19 | private GestureLockLayout mGestureLockLayout;
20 | private GestureLockDisplayView mLockDisplayView;
21 | private TextView mSettingHintText;
22 | private Handler mHandler = new Handler();
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_lock_setting);
28 | initViews();
29 | initEvents();
30 | }
31 |
32 | private void initViews() {
33 | mGestureLockLayout = (GestureLockLayout) findViewById(R.id.l_gesture_view);
34 | mLockDisplayView = (GestureLockDisplayView) findViewById(R.id.l_display_view);
35 | mSettingHintText = (TextView) findViewById(R.id.tv_setting_hint);
36 | //设置提示view 每行每列点的个数
37 | mLockDisplayView.setDotCount(3);
38 | //设置提示view 选中状态的颜色
39 | mLockDisplayView.setDotSelectedColor(Color.parseColor("#01A0E5"));
40 | //设置提示view 非选中状态的颜色
41 | mLockDisplayView.setDotUnSelectedColor(Color.TRANSPARENT);
42 | //设置手势解锁view 每行每列点的个数
43 | mGestureLockLayout.setDotCount(3);
44 | //设置手势解锁view 最少连接数
45 | mGestureLockLayout.setMinCount(3);
46 | //默认解锁样式为手Q手势解锁样式
47 | mGestureLockLayout.setLockView(new LockViewFactory() {
48 | @Override
49 | public ILockView newLockView() {
50 | return new JDLockView(LockSettingActivity.this);
51 | }
52 | });
53 | //设置手势解锁view 模式为重置密码模式
54 | mGestureLockLayout.setMode(GestureLockLayout.RESET_MODE);
55 | }
56 |
57 | private void initEvents() {
58 | mGestureLockLayout.setOnLockResetListener(new GestureLockLayout.OnLockResetListener() {
59 | @Override
60 | public void onConnectCountUnmatched(int connectCount, int minCount) {
61 | //连接数小于最小连接数时调用
62 |
63 | mSettingHintText.setText("最少连接" + minCount + "个点");
64 | resetGesture();
65 | }
66 |
67 | @Override
68 | public void onFirstPasswordFinished(List answerList) {
69 | //第一次绘制手势成功时调用
70 |
71 | mSettingHintText.setText("确认解锁图案");
72 | //将答案设置给提示view
73 | mLockDisplayView.setAnswer(answerList);
74 | //重置
75 | resetGesture();
76 | }
77 |
78 | @Override
79 | public void onSetPasswordFinished(boolean isMatched, List answerList) {
80 | //第二次密码绘制成功时调用
81 |
82 | if (isMatched) {
83 | //两次答案一致,保存
84 | MyApplication.getInstance().answer = answerList.toString();
85 | MyApplication.getInstance().isUnlock = false;
86 | finish();
87 | } else {
88 | resetGesture();
89 | }
90 | }
91 | });
92 | }
93 |
94 | /**
95 | * 重置
96 | */
97 | private void resetGesture() {
98 | mHandler.postDelayed(new Runnable() {
99 | @Override
100 | public void run() {
101 | mGestureLockLayout.resetGesture();
102 | }
103 | }, 200);
104 | }
105 |
106 | @Override
107 | protected void onDestroy() {
108 | super.onDestroy();
109 | if (mHandler != null) {
110 | mHandler.removeCallbacksAndMessages(null);
111 | }
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyyoona7/sample/MyApplication.java:
--------------------------------------------------------------------------------
1 | package com.zyyoona7.sample;
2 |
3 | import android.app.Application;
4 |
5 | /**
6 | * Created by zyyoona7 on 2017/7/10.
7 | */
8 |
9 | public class MyApplication extends Application {
10 |
11 | public long currentTime=System.currentTimeMillis();
12 | public String answer="";
13 | public boolean isUnlock=false;
14 | private static MyApplication mInstance;
15 |
16 | @Override
17 | public void onCreate() {
18 | super.onCreate();
19 | mInstance=this;
20 | }
21 |
22 | public static MyApplication getInstance(){
23 | return mInstance;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/cycle_4.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/fade_ins.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/push_bottom_in_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/shake.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
17 |
18 |
25 |
26 |
32 |
33 |
34 |
35 |
42 |
43 |
49 |
50 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_lock.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_lock_setting.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
17 |
22 |
23 |
30 |
31 |
32 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_lock.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
22 |
23 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyyoona7/GestureLockView/cce079cddc0b09d43afbe692f8b874581cf1ade9/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyyoona7/GestureLockView/cce079cddc0b09d43afbe692f8b874581cf1ade9/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyyoona7/GestureLockView/cce079cddc0b09d43afbe692f8b874581cf1ade9/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyyoona7/GestureLockView/cce079cddc0b09d43afbe692f8b874581cf1ade9/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyyoona7/GestureLockView/cce079cddc0b09d43afbe692f8b874581cf1ade9/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 | GestureLockView
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 | google()
6 | maven {
7 | url 'https://maven.google.com/'
8 | name 'Google'
9 | }
10 | jcenter()
11 | }
12 | dependencies {
13 | classpath 'com.android.tools.build:gradle:3.1.4'
14 |
15 | // NOTE: Do not place your application dependencies here; they belong
16 | // in the individual module build.gradle files
17 | }
18 | }
19 |
20 | allprojects {
21 | repositories {
22 | google()
23 | maven {
24 | url 'https://maven.google.com/'
25 | name 'Google'
26 | }
27 | jcenter()
28 | }
29 | }
30 |
31 | task clean(type: Delete) {
32 | delete rootProject.buildDir
33 | }
34 |
--------------------------------------------------------------------------------
/gesturelockview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/gesturelockview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 27
5 | buildToolsVersion '27.0.3'
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 26
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:27.1.1'
24 | }
25 |
--------------------------------------------------------------------------------
/gesturelockview/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 D:\Android\android-sdk-windows/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 |
--------------------------------------------------------------------------------
/gesturelockview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/gesturelockview/src/main/java/com/zyyoona7/lock/ConvertUtils.java:
--------------------------------------------------------------------------------
1 | package com.zyyoona7.lock;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * Created by zyyoona7 on 2017/7/7.
7 | */
8 |
9 | public class ConvertUtils {
10 |
11 | /**
12 | * dp转px
13 | *
14 | * @param dpValue dp值
15 | * @return px值
16 | */
17 | public static int dp2px(Context context, final float dpValue) {
18 | final float scale = context.getResources().getDisplayMetrics().density;
19 | return (int) (dpValue * scale + 0.5f);
20 | }
21 |
22 | /**
23 | * px转dp
24 | *
25 | * @param pxValue px值
26 | * @return dp值
27 | */
28 | public static int px2dp(Context context, final float pxValue) {
29 | final float scale = context.getResources().getDisplayMetrics().density;
30 | return (int) (pxValue / scale + 0.5f);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/gesturelockview/src/main/java/com/zyyoona7/lock/Dot.java:
--------------------------------------------------------------------------------
1 | package com.zyyoona7.lock;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Created by zyyoona7 on 2017/7/10.
7 | */
8 |
9 | public class Dot implements Serializable {
10 |
11 | //圆心坐标
12 | private float x;
13 | private float y;
14 |
15 | //当前状态,是否选中
16 | private boolean isSelected;
17 |
18 | //下标
19 | private int index;
20 |
21 | public Dot(float x, float y, int index) {
22 | this.x = x;
23 | this.y = y;
24 | this.index = index;
25 | }
26 |
27 | public float getX() {
28 | return x;
29 | }
30 |
31 | public void setX(float x) {
32 | this.x = x;
33 | }
34 |
35 | public float getY() {
36 | return y;
37 | }
38 |
39 | public void setY(float y) {
40 | this.y = y;
41 | }
42 |
43 | public boolean isSelected() {
44 | return isSelected;
45 | }
46 |
47 | public void setSelected(boolean selected) {
48 | isSelected = selected;
49 | }
50 |
51 | public int getIndex() {
52 | return index;
53 | }
54 |
55 | public void setIndex(int index) {
56 | this.index = index;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/gesturelockview/src/main/java/com/zyyoona7/lock/GestureLockDisplayView.java:
--------------------------------------------------------------------------------
1 | package com.zyyoona7.lock;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.support.annotation.Nullable;
8 | import android.util.AttributeSet;
9 | import android.view.View;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | /**
15 | * Created by zyyoona7 on 2017/7/10.
16 | */
17 |
18 | public class GestureLockDisplayView extends View {
19 |
20 | private static final String TAG = "GestureLockDisplayView";
21 |
22 | private Paint mPaint;
23 |
24 | private int mDotCount = 3;
25 | // n * mCircleRadius*2 + ( n + 1 ) * mDotMargin = getWidth();
26 | private int mCircleRadius;
27 | //mCircle*0.5
28 | private int mDotMargin;
29 |
30 | //选中颜色
31 | private int mDotSelectedColor = Color.BLUE;
32 | //未选中时颜色
33 | private int mDotUnSelectedColor = Color.BLACK;
34 |
35 | private List mDotList = new ArrayList<>(1);
36 | private List mAnswerList = new ArrayList<>(1);
37 |
38 | public GestureLockDisplayView(Context context) {
39 | this(context, null);
40 | }
41 |
42 | public GestureLockDisplayView(Context context, @Nullable AttributeSet attrs) {
43 | super(context, attrs);
44 | init(context);
45 | }
46 |
47 | private void init(Context context) {
48 | mPaint = new Paint();
49 | mPaint.setAntiAlias(true);
50 | mPaint.setStyle(Paint.Style.FILL);
51 | mPaint.setColor(Color.BLACK);
52 | }
53 |
54 | @Override
55 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
56 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
57 | int width = MeasureSpec.getSize(widthMeasureSpec);
58 | int height = MeasureSpec.getSize(heightMeasureSpec);
59 | width = width > height ? height : width;
60 | setMeasuredDimension(width, width);
61 | }
62 |
63 | @Override
64 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
65 | super.onSizeChanged(w, h, oldw, oldh);
66 | mCircleRadius = (int) (getWidth() * 2 * 1.0f / (5 * mDotCount + 1));
67 | mDotMargin = (int) (0.8 * mCircleRadius);
68 | for (int i = 0; i < mDotCount * mDotCount; i++) {
69 | //计算圆心坐标
70 | float x = i % mDotCount * 2 * mCircleRadius + mCircleRadius + i % mDotCount * mDotMargin + mDotMargin;
71 | float y = i / mDotCount * 2 * mCircleRadius + mCircleRadius + i / mDotCount * mDotMargin + mDotMargin;
72 | //初始化点坐标
73 | mDotList.add(new Dot(x, y, i));
74 | }
75 | }
76 |
77 | @Override
78 | protected void onDraw(Canvas canvas) {
79 | super.onDraw(canvas);
80 | //同步dot状态
81 | syncAnswerState();
82 |
83 | for (int i = 0; i < mDotList.size(); i++) {
84 | Dot dot = mDotList.get(i);
85 | if (dot.isSelected()) {
86 | mPaint.setColor(mDotSelectedColor);
87 | } else {
88 | mPaint.setColor(mDotUnSelectedColor);
89 | }
90 | canvas.drawCircle(dot.getX(), dot.getY(), mCircleRadius, mPaint);
91 | }
92 | }
93 |
94 | private void syncAnswerState() {
95 | //先重置所有点的状态
96 | for (Dot dot : mDotList) {
97 | dot.setSelected(false);
98 | }
99 | //设置答案index的状态
100 | for (int i = 0; i < mAnswerList.size(); i++) {
101 | int index = mAnswerList.get(i);
102 | mDotList.get(index).setSelected(true);
103 | }
104 | }
105 |
106 | /**
107 | * 设置答案
108 | *
109 | * @param answer
110 | */
111 | public void setAnswer(int... answer) {
112 | for (int i = 0; i < answer.length; i++) {
113 | mAnswerList.add(answer[i]);
114 | }
115 | postInvalidate();
116 | }
117 |
118 | /**
119 | * 设置答案
120 | *
121 | * @param list
122 | */
123 | public void setAnswer(List list) {
124 | this.mAnswerList = list;
125 | postInvalidate();
126 | }
127 |
128 | /**
129 | * 设置选中颜色
130 | *
131 | * @param color
132 | */
133 | public void setDotSelectedColor(int color) {
134 | this.mDotSelectedColor = color;
135 | postInvalidate();
136 | }
137 |
138 | /**
139 | * 设置非选中颜色
140 | *
141 | * @param color
142 | */
143 | public void setDotUnSelectedColor(int color) {
144 | this.mDotUnSelectedColor = color;
145 | postInvalidate();
146 | }
147 |
148 | /**
149 | * 设置点的个数
150 | *
151 | * @param dotCount
152 | */
153 | public void setDotCount(int dotCount) {
154 | this.mDotCount = dotCount;
155 | }
156 | }
157 |
--------------------------------------------------------------------------------
/gesturelockview/src/main/java/com/zyyoona7/lock/GestureLockLayout.java:
--------------------------------------------------------------------------------
1 | package com.zyyoona7.lock;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.graphics.Path;
8 | import android.os.Parcel;
9 | import android.os.Parcelable;
10 | import android.util.AttributeSet;
11 | import android.view.MotionEvent;
12 | import android.view.View;
13 | import android.widget.RelativeLayout;
14 |
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | /**
19 | * Created by zyyoona7 on 2017/7/7.
20 | * 手势解锁
21 | */
22 |
23 | public class GestureLockLayout extends RelativeLayout {
24 |
25 | private static final String TAG = "GestureLockLayout";
26 |
27 | //模式选择,重置密码,设置密码模式
28 | public static final int RESET_MODE = 0;
29 | //验证密码模式
30 | public static final int VERIFY_MODE = 1;
31 |
32 | // 关于LockView的边长(n*n): n * mLockViewWidth + ( n + 1 ) * mLockViewMargin = mWidth
33 | private int mLockViewWidth = 0;
34 | //mLockViewWidth * 0.25
35 | private int mLockViewMargin = 0;
36 | //LockView数组
37 | private ArrayList mILockViews = new ArrayList<>(1);
38 |
39 | private LockViewFactory mLockViewFactory = null;
40 |
41 | //x*x的手势解锁
42 | private int mDotCount = 3;
43 |
44 | //画笔
45 | private Paint mPaint;
46 | //路径
47 | private Path mPath;
48 | //连接线的宽度
49 | private float mStrokeWidth = 2;
50 | //手指触摸是,path颜色
51 | private int mFingerTouchColor = Color.parseColor("#01A0E5");
52 | //手指抬起时,密码匹配path颜色
53 | private int mFingerUpMatchedColor = Color.parseColor("#01A0E5");
54 | //手指抬起时,密码不匹配path颜色
55 | private int mFingerUpUnmatchedColor = Color.parseColor("#F7564A");
56 |
57 | //path上一次moveTo到的点坐标
58 | private float mLastPathX = 0;
59 | private float mLastPathY = 0;
60 |
61 | //指引线的终点坐标
62 | private float mLineX = 0;
63 | private float mLineY = 0;
64 |
65 | //保存选中的LockView id
66 | private ArrayList mChooseList = new ArrayList<>(1);
67 | //答案list
68 | private ArrayList mAnswerList = new ArrayList<>(1);
69 |
70 | //是否可以触摸
71 | private boolean mTouchable = true;
72 |
73 | //允许的尝试次数
74 | private int mTryTimes = 5;
75 | //保存的尝试次数,因为模式切换的时候TryTimes可能不等于初始设置的值
76 | private int mSavedTryTimes = 5;
77 |
78 | private OnLockVerifyListener mOnLockVerifyListener;
79 | private OnLockResetListener mOnLockResetListener;
80 |
81 | //当前模式
82 | private int mCurrentMode = RESET_MODE;
83 | //RESET_MODE下最少连接数
84 | private int mMinCount = 3;
85 |
86 | public GestureLockLayout(Context context) {
87 | this(context, null);
88 | }
89 |
90 | public GestureLockLayout(Context context, AttributeSet attrs) {
91 | super(context, attrs);
92 | init(context);
93 | }
94 |
95 | private void init(final Context context) {
96 | if (mLockViewFactory == null) {
97 | setLockView(new LockViewFactory() {
98 | @Override
99 | public ILockView newLockView() {
100 | return new QQLockView(context);
101 | }
102 | });
103 | }
104 |
105 | mPaint = new Paint();
106 | mPaint.setAntiAlias(true);
107 | mPaint.setStyle(Paint.Style.STROKE);
108 | mPaint.setStrokeWidth(ConvertUtils.dp2px(context, mStrokeWidth));
109 | mPaint.setStrokeCap(Paint.Cap.ROUND);
110 | mPaint.setStrokeJoin(Paint.Join.ROUND);
111 |
112 | mPath = new Path();
113 | }
114 |
115 | @Override
116 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
117 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
118 | int width = MeasureSpec.getSize(widthMeasureSpec);
119 | int height = MeasureSpec.getSize(heightMeasureSpec);
120 |
121 | width = width > height ? height : width;
122 |
123 | mLockViewWidth = (int) (4 * width * 1.0f / (5 * mDotCount + 1));
124 | //计算LockView的间距
125 | mLockViewMargin = (int) (mLockViewWidth * 0.25);
126 |
127 | if (mLockViewFactory != null) {
128 | setLockViewParams(mLockViewFactory);
129 | }
130 | }
131 |
132 | /**
133 | * 设置LockView的参数并添加到布局中
134 | *
135 | * @param lockViewFactory
136 | */
137 | private void setLockViewParams(LockViewFactory lockViewFactory) {
138 | if (mILockViews.size() > 0) {
139 | return;
140 | }
141 | for (int i = 0; i < mDotCount * mDotCount; i++) {
142 | ILockView iLockView = lockViewFactory.newLockView();
143 | iLockView.getView().setId(i + 1);
144 | mILockViews.add(iLockView);
145 | RelativeLayout.LayoutParams lockerParams = new LayoutParams(mLockViewWidth, mLockViewWidth);
146 |
147 | //不是每行的第一个,则设置位置为前一个的右边
148 | if (i % mDotCount != 0) {
149 | lockerParams.addRule(RelativeLayout.RIGHT_OF, mILockViews.get(i - 1).getView().getId());
150 | }
151 | //从第二行开始,设置为上一行同一位置View的下面
152 | if (i > mDotCount - 1) {
153 | lockerParams.addRule(RelativeLayout.BELOW, mILockViews.get(i - mDotCount).getView().getId());
154 | }
155 |
156 | //设置右下左上的边距
157 | int rightMargin = mLockViewMargin;
158 | int bottomMargin = mLockViewMargin;
159 | int leftMargin = 0;
160 | int topMargin = 0;
161 |
162 | //每个View都有右外边距和底外边距 第一行的有上外边距 第一列的有左外边距
163 | if (i >= 0 && i < mDotCount) {//第一行
164 | topMargin = mLockViewMargin;
165 | }
166 |
167 | if (i % mDotCount == 0) {//第一列
168 | leftMargin = mLockViewMargin;
169 | }
170 |
171 | lockerParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
172 | mILockViews.get(i).onNoFinger();
173 | mILockViews.get(i).getView().setLayoutParams(lockerParams);
174 | addView(mILockViews.get(i).getView());
175 | }
176 | }
177 |
178 | @Override
179 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
180 | super.onSizeChanged(w, h, oldw, oldh);
181 | }
182 |
183 | @Override
184 | protected void onFinishInflate() {
185 | super.onFinishInflate();
186 | }
187 |
188 | /**
189 | * 保存状态
190 | *
191 | * @return
192 | */
193 | @Override
194 | protected Parcelable onSaveInstanceState() {
195 | Parcelable superState = super.onSaveInstanceState();
196 | SavedState ss = new SavedState(superState);
197 | ss.tryTimes = mTryTimes;
198 | return ss;
199 | }
200 |
201 | /**
202 | * 恢复状态
203 | *
204 | * @param state
205 | */
206 | @Override
207 | protected void onRestoreInstanceState(Parcelable state) {
208 | SavedState savedState = (SavedState) state;
209 | super.onRestoreInstanceState(savedState.getSuperState());
210 | mTryTimes = savedState.tryTimes;
211 | }
212 |
213 | @Override
214 | public boolean onTouchEvent(MotionEvent event) {
215 | if (mTouchable) {
216 | int action = event.getAction();
217 | int x = (int) event.getX();
218 | int y = (int) event.getY();
219 | switch (action) {
220 | case MotionEvent.ACTION_DOWN:
221 | handleDownEvent(x, y);
222 | break;
223 | case MotionEvent.ACTION_MOVE:
224 | handleMoveEvent(x, y);
225 | break;
226 | case MotionEvent.ACTION_UP:
227 | handleUpEvent();
228 | break;
229 | }
230 | invalidate();
231 | return true;
232 | } else {
233 | return false;
234 | }
235 | }
236 |
237 | /**
238 | * 处理按下事件
239 | *
240 | * @param x
241 | * @param y
242 | */
243 | private void handleDownEvent(int x, int y) {
244 | reset();
245 | handleMoveEvent(x, y);
246 | }
247 |
248 | /**
249 | * 处理移动事件
250 | *
251 | * @param x
252 | * @param y
253 | */
254 | private void handleMoveEvent(int x, int y) {
255 | mPaint.setColor(mFingerTouchColor);
256 | ILockView lockView = getLockViewByPoint(x, y);
257 | if (lockView != null) {
258 | int childId = lockView.getView().getId();
259 | if (!mChooseList.contains(childId)) {
260 | mChooseList.add(childId);
261 | lockView.onFingerTouch();
262 |
263 | //手势解锁监听
264 | if (mOnLockVerifyListener != null) {
265 | mOnLockVerifyListener.onGestureSelected(childId);
266 | }
267 |
268 | mLastPathX = lockView.getView().getLeft() / 2 + lockView.getView().getRight() / 2;
269 | mLastPathY = lockView.getView().getTop() / 2 + lockView.getView().getBottom() / 2;
270 |
271 | if (mChooseList.size() == 1) {
272 | mPath.moveTo(mLastPathX, mLastPathY);
273 | } else {
274 | mPath.lineTo(mLastPathX, mLastPathY);
275 | }
276 | }
277 | }
278 | //指引线终点坐标
279 | mLineX = x;
280 | mLineY = y;
281 | }
282 |
283 | /**
284 | * 处理抬起事件
285 | */
286 | private void handleUpEvent() {
287 | if (mCurrentMode == RESET_MODE) {
288 | handleResetMode();
289 | } else {
290 | handleVerifyMode();
291 | }
292 | //将指引线的终点坐标设置为最后一个Path的原点,即取消指引线
293 | mLineX = mLastPathX;
294 | mLineY = mLastPathY;
295 | }
296 |
297 | /**
298 | * 处理修改密码模式
299 | */
300 | private void handleResetMode() {
301 | if (mAnswerList.size() <= 0) {
302 | //如果AnswerList.size()==0则为第一次设置,验证连接数
303 | if (mChooseList.size() < mMinCount) {
304 | //连接数不符
305 | if (mOnLockResetListener != null) {
306 | mOnLockResetListener.onConnectCountUnmatched(mChooseList.size(), mMinCount);
307 | }
308 | toggleLockViewMatchedState(false);
309 | return;
310 | } else {
311 | //连接数符合,将选择的答案赋值给mAnswerList
312 | for (Integer integer : mChooseList) {
313 | //因为mAnswerList是从0开始,chooseList保存的是id从1开始,所以-1
314 | mAnswerList.add(integer - 1);
315 | }
316 | if (mOnLockResetListener != null) {
317 | mOnLockResetListener.onFirstPasswordFinished(mAnswerList);
318 | }
319 | toggleLockViewMatchedState(true);
320 | }
321 | } else {
322 | //mAnswerList已有答案,则验证密码,两次密码匹配保存密码
323 | boolean isAnswerRight = checkAnswer();
324 | if (isAnswerRight) {
325 | //两次密码正确,回调
326 | toggleLockViewMatchedState(true);
327 | if (mOnLockResetListener != null) {
328 | mOnLockResetListener.onSetPasswordFinished(true, mAnswerList);
329 | }
330 | } else {
331 | //两次没密码不正确
332 | toggleLockViewMatchedState(false);
333 | if (mOnLockResetListener != null) {
334 | mOnLockResetListener.onSetPasswordFinished(false, new ArrayList(1));
335 | }
336 | }
337 | }
338 | }
339 |
340 | /**
341 | * 处理验证密码模式
342 | */
343 | private void handleVerifyMode() {
344 | mTryTimes--;
345 | boolean isAnswerRight = checkAnswer();
346 | //手势解锁监听
347 | if (mOnLockVerifyListener != null) {
348 | mOnLockVerifyListener.onGestureFinished(isAnswerRight);
349 | if (mTryTimes <= 0) {
350 | mOnLockVerifyListener.onGestureTryTimesBoundary();
351 | }
352 | }
353 | if (!isAnswerRight) {
354 | toggleLockViewMatchedState(false);
355 | } else {
356 | toggleLockViewMatchedState(true);
357 | }
358 | }
359 |
360 | /**
361 | * 检查x,y点是否在LockView中
362 | *
363 | * @param childView
364 | * @param x
365 | * @param y
366 | * @return
367 | */
368 | private boolean checkPointInChild(View childView, int x, int y) {
369 | //设置了内边距,即x,y必须落入下GestureLockView的内部中间的小区域中,可以通过调整padding使得x,y落入范围不变大,或者不设置padding
370 | int padding = (int) (mLockViewWidth * 0.1);
371 | if (x >= childView.getLeft() + padding && x <= childView.getRight() - padding
372 | && y >= childView.getTop() + padding
373 | && y <= childView.getBottom() - padding) {
374 | return true;
375 | }
376 | return false;
377 | }
378 |
379 | /**
380 | * 同过x,y点获取LockView对象
381 | *
382 | * @param x
383 | * @param y
384 | * @return
385 | */
386 | private ILockView getLockViewByPoint(int x, int y) {
387 | for (ILockView lockView : mILockViews) {
388 | if (checkPointInChild(lockView.getView(), x, y)) {
389 | return lockView;
390 | }
391 | }
392 |
393 | return null;
394 | }
395 |
396 | /**
397 | * 重置手势解锁
398 | */
399 | private void reset() {
400 | if (mChooseList == null || mPath == null || mILockViews == null) {
401 | return;
402 | }
403 | mChooseList.clear();
404 | mPath.reset();
405 | for (ILockView iLockView : mILockViews) {
406 | iLockView.onNoFinger();
407 | }
408 | }
409 |
410 | /**
411 | * 重置手势
412 | */
413 | public void resetGesture() {
414 | reset();
415 | invalidate();
416 | }
417 |
418 | /**
419 | * 检查答案是否正确
420 | *
421 | * @return
422 | */
423 | private boolean checkAnswer() {
424 | if (mAnswerList.size() != mChooseList.size()) {
425 | return false;
426 | }
427 |
428 | for (int i = 0; i < mAnswerList.size(); i++) {
429 | if (mAnswerList.get(i) != mChooseList.get(i) - 1) {
430 | return false;
431 | }
432 | }
433 |
434 | return true;
435 | }
436 |
437 | /**
438 | * 切换LockView是否匹配状态
439 | *
440 | * @param isMatched
441 | */
442 | private void toggleLockViewMatchedState(boolean isMatched) {
443 | if (isMatched) {
444 | mPaint.setColor(mFingerUpMatchedColor);
445 | } else {
446 | mPaint.setColor(mFingerUpUnmatchedColor);
447 | }
448 | for (ILockView iLockView : mILockViews) {
449 | if (mChooseList.contains(iLockView.getView().getId())) {
450 | if (!isMatched) {
451 | iLockView.onFingerUpUnmatched();
452 | } else {
453 | iLockView.onFingerUpMatched();
454 | }
455 | }
456 | }
457 | }
458 |
459 | @Override
460 | protected void dispatchDraw(Canvas canvas) {
461 | super.dispatchDraw(canvas);
462 | //画Path
463 | canvas.drawPath(mPath, mPaint);
464 | //画指引线
465 | if (mChooseList.size() > 0) {
466 | canvas.drawLine(mLastPathX, mLastPathY, mLineX, mLineY, mPaint);
467 | }
468 | }
469 |
470 | /**
471 | * 设置LockView
472 | *
473 | * @param lockViewFactory
474 | */
475 | public void setLockView(LockViewFactory lockViewFactory) {
476 | if (lockViewFactory != null) {
477 | removeAllViewsInLayout();
478 | mILockViews.clear();
479 | mLockViewFactory = lockViewFactory;
480 | if (mLockViewWidth > 0) {
481 | setLockViewParams(mLockViewFactory);
482 | reset();
483 | }
484 | }
485 | }
486 |
487 | /**
488 | * 设置答案
489 | *
490 | * @param answer
491 | */
492 | public void setAnswer(int... answer) {
493 | mAnswerList.clear();
494 | for (int i = 0; i < answer.length; i++) {
495 | mAnswerList.add(answer[i]);
496 | }
497 | }
498 |
499 | /**
500 | * 将String类型的Answer设置到list
501 | * 必须时List的toString形式[x,x,x]
502 | *
503 | * @param answer
504 | */
505 | public void setAnswer(String answer) {
506 | if (answer.startsWith("[") && answer.endsWith("]")) {
507 | answer = answer.substring(1, answer.length() - 1);
508 | String[] answers = answer.split(",");
509 | mAnswerList.clear();
510 | for (int i = 0; i < answers.length; i++) {
511 | mAnswerList.add(Integer.parseInt(answers[i].trim()));
512 | }
513 | }
514 | }
515 |
516 | /**
517 | * 设置是否可以触摸
518 | *
519 | * @param touchable
520 | */
521 | public void setTouchable(boolean touchable) {
522 | this.mTouchable = touchable;
523 | reset();
524 | invalidate();
525 | }
526 |
527 | /**
528 | * 设置手势解锁监听器
529 | *
530 | * @param listener
531 | */
532 | public void setOnLockVerifyListener(OnLockVerifyListener listener) {
533 | this.mOnLockVerifyListener = listener;
534 | }
535 |
536 | public void setOnLockResetListener(OnLockResetListener listener) {
537 | this.mOnLockResetListener = listener;
538 | }
539 |
540 | /**
541 | * 设置路径宽度
542 | *
543 | * @param dp
544 | */
545 | public void setPathWidth(float dp) {
546 | mPaint.setStrokeWidth(ConvertUtils.dp2px(getContext(), dp));
547 | }
548 |
549 | /**
550 | * 设置每行点的个数
551 | *
552 | * @param count
553 | */
554 | public void setDotCount(int count) {
555 | this.mDotCount = count;
556 | }
557 |
558 | /**
559 | * 设置手指按下时Path颜色
560 | *
561 | * @param color
562 | */
563 | public void setTouchedPathColor(int color) {
564 | this.mFingerTouchColor = color;
565 | }
566 |
567 | /**
568 | * 设置手指抬起时,密码匹配颜色
569 | *
570 | * @param color
571 | */
572 | public void setMatchedPathColor(int color) {
573 | this.mFingerUpMatchedColor = color;
574 | }
575 |
576 | /**
577 | * 设置手指抬起时,密码不匹配的颜色
578 | *
579 | * @param color
580 | */
581 | public void setUnmatchedPathColor(int color) {
582 | this.mFingerUpUnmatchedColor = color;
583 | }
584 |
585 | /**
586 | * 设置最大尝试次数
587 | *
588 | * @param tryTimes
589 | */
590 | public void setTryTimes(int tryTimes) {
591 | this.mTryTimes = tryTimes;
592 | this.mSavedTryTimes = tryTimes;
593 | }
594 |
595 | /**
596 | * 获取最大尝试次数
597 | *
598 | * @return
599 | */
600 | public int getTryTimes() {
601 | return mTryTimes;
602 | }
603 |
604 | /**
605 | * 设置密码模式下,最小连接数
606 | *
607 | * @param minCount
608 | */
609 | public void setMinCount(int minCount) {
610 | this.mMinCount = minCount;
611 | }
612 |
613 | public void setMode(int mode) {
614 | this.mCurrentMode = mode;
615 | reset();
616 | //切换到验证模式的时候,还原最大尝试次数
617 | if (mCurrentMode == VERIFY_MODE) {
618 | mTryTimes = mSavedTryTimes;
619 | } else if (mCurrentMode == RESET_MODE) {
620 | //清除已有密码数据
621 | mAnswerList.clear();
622 | }
623 | }
624 |
625 | public interface OnLockVerifyListener {
626 |
627 | /**
628 | * 移动过程中选中的id
629 | *
630 | * @param id
631 | */
632 | void onGestureSelected(int id);
633 |
634 | /**
635 | * 手势动作完成
636 | *
637 | * @param isMatched 是否和密码匹配
638 | */
639 | void onGestureFinished(boolean isMatched);
640 |
641 | /**
642 | * 超过尝试次数上限
643 | */
644 | void onGestureTryTimesBoundary();
645 | }
646 |
647 | public interface OnLockResetListener {
648 |
649 | /**
650 | * 连接数不符
651 | *
652 | * @param connectCount
653 | * @param minCount
654 | */
655 | void onConnectCountUnmatched(int connectCount, int minCount);
656 |
657 | /**
658 | * 连接数符合,第一次密码设置成功
659 | *
660 | * @param answerList
661 | */
662 | void onFirstPasswordFinished(List answerList);
663 |
664 | /**
665 | * 设置密码成功
666 | *
667 | * @param isMatched 两次密码是否匹配
668 | * @param answerList 密码list
669 | */
670 | void onSetPasswordFinished(boolean isMatched, List answerList);
671 | }
672 |
673 | /**
674 | * 保存状态bean
675 | */
676 | static class SavedState extends BaseSavedState {
677 |
678 | int tryTimes;
679 |
680 | public SavedState(Parcelable source) {
681 | super(source);
682 | }
683 |
684 | /**
685 | * Constructor called from {@link #CREATOR}
686 | */
687 | private SavedState(Parcel in) {
688 | super(in);
689 | tryTimes = in.readInt();
690 | }
691 |
692 | @Override
693 | public void writeToParcel(Parcel out, int flags) {
694 | super.writeToParcel(out, flags);
695 | out.writeValue(tryTimes);
696 | }
697 |
698 | public static final Parcelable.Creator CREATOR
699 | = new Parcelable.Creator() {
700 | public SavedState createFromParcel(Parcel in) {
701 | return new SavedState(in);
702 | }
703 |
704 | public SavedState[] newArray(int size) {
705 | return new SavedState[size];
706 | }
707 | };
708 | }
709 | }
710 |
--------------------------------------------------------------------------------
/gesturelockview/src/main/java/com/zyyoona7/lock/ILockView.java:
--------------------------------------------------------------------------------
1 | package com.zyyoona7.lock;
2 |
3 | import android.view.View;
4 |
5 | /**
6 | * Created by zyyoona7 on 2017/7/7.
7 | * 接口,自定义手势解锁样式需实现
8 | */
9 |
10 | public interface ILockView {
11 |
12 | //手势状态
13 | int NO_FINGER = 0;
14 | int FINGER_TOUCH = 1;
15 | int FINGER_UP_MATCHED = 2;
16 | int FINGER_UP_UN_MATCHED = 3;
17 |
18 | /**
19 | * 获取View
20 | *
21 | * @return
22 | */
23 | View getView();
24 |
25 | /**
26 | * 手指没触摸之前,初始状态
27 | */
28 | void onNoFinger();
29 |
30 | /**
31 | * 手指触摸,按下状态
32 | */
33 | void onFingerTouch();
34 |
35 | /**
36 | * 手指抬起,手势密码匹配状态
37 | */
38 | void onFingerUpMatched();
39 |
40 | /**
41 | * 手指抬起,手势密码不匹配状态
42 | */
43 | void onFingerUpUnmatched();
44 | }
--------------------------------------------------------------------------------
/gesturelockview/src/main/java/com/zyyoona7/lock/JDLockView.java:
--------------------------------------------------------------------------------
1 | package com.zyyoona7.lock;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.support.annotation.Nullable;
8 | import android.util.AttributeSet;
9 | import android.view.View;
10 |
11 | /**
12 | * Created by zyyoona7 on 2017/7/7.
13 | */
14 |
15 | public class JDLockView extends View implements ILockView {
16 |
17 | private Paint mPaint;
18 | private int mCurrentState=NO_FINGER;
19 | private float mOuterRadius;
20 | private float mInnerRadius;
21 |
22 | public JDLockView(Context context) {
23 | this(context,null);
24 | }
25 |
26 | public JDLockView(Context context, @Nullable AttributeSet attrs) {
27 | super(context, attrs);
28 | init(context);
29 | }
30 |
31 | public void init(Context context){
32 | mPaint=new Paint();
33 | mPaint.setAntiAlias(true);
34 | }
35 |
36 | @Override
37 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
38 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
39 | int width = MeasureSpec.getSize(widthMeasureSpec);
40 | int height = MeasureSpec.getSize(heightMeasureSpec);
41 | width = width > height ? height : width;
42 | setMeasuredDimension(width, width);
43 | }
44 |
45 | @Override
46 | protected void onDraw(Canvas canvas) {
47 | super.onDraw(canvas);
48 | float space = 10;
49 | float x = getWidth() / 2;
50 | float y = getHeight() / 2;
51 | canvas.translate(x, y);
52 | mOuterRadius = x - space;
53 | mInnerRadius = (x - space) / 3;
54 | switch (mCurrentState) {
55 | case NO_FINGER:
56 | drawNoFinger(canvas);
57 | break;
58 | case FINGER_TOUCH:
59 | drawFingerTouch(canvas);
60 | break;
61 | case FINGER_UP_MATCHED:
62 | drawFingerUpMatched(canvas);
63 | break;
64 | case FINGER_UP_UN_MATCHED:
65 | drawFingerUpUnmatched(canvas);
66 | break;
67 | }
68 | }
69 |
70 | /**
71 | * 画无手指触摸状态
72 | *
73 | * @param canvas
74 | */
75 | private void drawNoFinger(Canvas canvas) {
76 | mPaint.setStyle(Paint.Style.FILL);
77 | mPaint.setColor(Color.GRAY);
78 | canvas.drawCircle(0, 0, mInnerRadius, mPaint);
79 | }
80 |
81 | /**
82 | * 画手指触摸状态
83 | *
84 | * @param canvas
85 | */
86 | private void drawFingerTouch(Canvas canvas) {
87 | mPaint.setStyle(Paint.Style.FILL);
88 | mPaint.setColor(Color.BLUE);
89 | canvas.drawCircle(0, 0, mInnerRadius, mPaint);
90 | mPaint.setStyle(Paint.Style.STROKE);
91 | mPaint.setStrokeWidth(ConvertUtils.dp2px(getContext(),1));
92 | canvas.drawCircle(0, 0, mOuterRadius, mPaint);
93 | }
94 |
95 | /**
96 | * 画手指抬起,匹配状态
97 | *
98 | * @param canvas
99 | */
100 | private void drawFingerUpMatched(Canvas canvas) {
101 | drawFingerTouch(canvas);
102 | }
103 |
104 | /**
105 | * 画手指抬起,不匹配状态
106 | *
107 | * @param canvas
108 | */
109 | private void drawFingerUpUnmatched(Canvas canvas) {
110 | mPaint.setStyle(Paint.Style.FILL);
111 | mPaint.setColor(Color.RED);
112 | canvas.drawCircle(0, 0, mInnerRadius, mPaint);
113 | mPaint.setStyle(Paint.Style.STROKE);
114 | mPaint.setStrokeWidth(ConvertUtils.dp2px(getContext(),1));
115 | canvas.drawCircle(0, 0, mOuterRadius, mPaint);
116 | }
117 |
118 | @Override
119 | public View getView() {
120 | return this;
121 | }
122 |
123 | @Override
124 | public void onNoFinger() {
125 | mCurrentState=NO_FINGER;
126 | postInvalidate();
127 | }
128 |
129 | @Override
130 | public void onFingerTouch() {
131 | mCurrentState=FINGER_TOUCH;
132 | postInvalidate();
133 | }
134 |
135 | @Override
136 | public void onFingerUpMatched() {
137 | mCurrentState=FINGER_UP_MATCHED;
138 | postInvalidate();
139 | }
140 |
141 | @Override
142 | public void onFingerUpUnmatched() {
143 | mCurrentState=FINGER_UP_UN_MATCHED;
144 | postInvalidate();
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/gesturelockview/src/main/java/com/zyyoona7/lock/LockViewFactory.java:
--------------------------------------------------------------------------------
1 | package com.zyyoona7.lock;
2 |
3 | /**
4 | * LockViewFactory 启发自 ThreadPoolExecutor 中的 ThreadFactory
5 | */
6 | public interface LockViewFactory {
7 |
8 | /**
9 | * 创建 LockView,必须是 newInstance 不能复用一个对象
10 | * @return
11 | */
12 | ILockView newLockView();
13 | }
14 |
--------------------------------------------------------------------------------
/gesturelockview/src/main/java/com/zyyoona7/lock/QQLockView.java:
--------------------------------------------------------------------------------
1 | package com.zyyoona7.lock;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.support.annotation.Nullable;
8 | import android.util.AttributeSet;
9 | import android.view.View;
10 |
11 | /**
12 | * Created by zyyoona7 on 2017/7/7.
13 | * QQ手势解锁样式
14 | */
15 |
16 | public class QQLockView extends View implements ILockView {
17 |
18 | private Paint mPaint;
19 | private int mCurrentState = NO_FINGER;
20 | private float mOuterRadius;
21 | private float mInnerRadius;
22 |
23 | public QQLockView(Context context) {
24 | this(context, null);
25 | }
26 |
27 | public QQLockView(Context context, @Nullable AttributeSet attrs) {
28 | super(context, attrs);
29 | init(context);
30 | }
31 |
32 | private void init(Context context) {
33 | mPaint = new Paint();
34 | mPaint.setAntiAlias(true);
35 | }
36 |
37 | @Override
38 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
39 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
40 | int width = MeasureSpec.getSize(widthMeasureSpec);
41 | int height = MeasureSpec.getSize(heightMeasureSpec);
42 | width = width > height ? height : width;
43 | setMeasuredDimension(width, width);
44 | }
45 |
46 | @Override
47 | protected void onDraw(Canvas canvas) {
48 | super.onDraw(canvas);
49 | float space = 10;
50 | float x = getWidth() / 2;
51 | float y = getHeight() / 2;
52 | canvas.translate(x, y);
53 | mOuterRadius = x - space;
54 | mInnerRadius = (x - space) / 3;
55 | switch (mCurrentState) {
56 | case NO_FINGER:
57 | drawNoFinger(canvas);
58 | break;
59 | case FINGER_TOUCH:
60 | drawFingerTouch(canvas);
61 | break;
62 | case FINGER_UP_MATCHED:
63 | drawFingerUpMatched(canvas);
64 | break;
65 | case FINGER_UP_UN_MATCHED:
66 | drawFingerUpUnmatched(canvas);
67 | break;
68 | }
69 | }
70 |
71 | /**
72 | * 画无手指触摸状态
73 | *
74 | * @param canvas
75 | */
76 | private void drawNoFinger(Canvas canvas) {
77 | mPaint.setStyle(Paint.Style.STROKE);
78 | mPaint.setColor(Color.parseColor("#838383"));
79 | mPaint.setStrokeWidth(ConvertUtils.dp2px(getContext(),2));
80 | canvas.drawCircle(0, 0, mOuterRadius, mPaint);
81 | }
82 |
83 | /**
84 | * 画手指触摸状态
85 | *
86 | * @param canvas
87 | */
88 | private void drawFingerTouch(Canvas canvas) {
89 | mPaint.setStyle(Paint.Style.FILL);
90 | mPaint.setColor(Color.parseColor("#ADD5E6"));
91 | canvas.drawCircle(0, 0, mOuterRadius, mPaint);
92 | mPaint.setColor(Color.parseColor("#01A0E5"));
93 | canvas.drawCircle(0, 0, mInnerRadius, mPaint);
94 | mPaint.setStyle(Paint.Style.STROKE);
95 | mPaint.setColor(Color.parseColor("#01A0E5"));
96 | mPaint.setStrokeWidth(ConvertUtils.dp2px(getContext(),1));
97 | canvas.drawCircle(0, 0, mOuterRadius, mPaint);
98 | }
99 |
100 | /**
101 | * 画手指抬起,匹配状态
102 | *
103 | * @param canvas
104 | */
105 | private void drawFingerUpMatched(Canvas canvas) {
106 | mPaint.setStyle(Paint.Style.FILL);
107 | mPaint.setColor(Color.parseColor("#ADD5E6"));
108 | canvas.drawCircle(0, 0, mOuterRadius, mPaint);
109 | mPaint.setColor(Color.parseColor("#01A0E5"));
110 | canvas.drawCircle(0, 0, mInnerRadius, mPaint);
111 | mPaint.setStyle(Paint.Style.STROKE);
112 | mPaint.setColor(Color.parseColor("#838383"));
113 | mPaint.setStrokeWidth(ConvertUtils.dp2px(getContext(),2));
114 | canvas.drawCircle(0, 0, mOuterRadius, mPaint);
115 | }
116 |
117 | /**
118 | * 画手指抬起,不匹配状态
119 | *
120 | * @param canvas
121 | */
122 | private void drawFingerUpUnmatched(Canvas canvas) {
123 | mPaint.setStyle(Paint.Style.FILL);
124 | mPaint.setColor(Color.parseColor("#EDACA7"));
125 | canvas.drawCircle(0, 0, mOuterRadius, mPaint);
126 | mPaint.setColor(Color.parseColor("#F7564A"));
127 | canvas.drawCircle(0, 0, mInnerRadius, mPaint);
128 | mPaint.setStyle(Paint.Style.STROKE);
129 | mPaint.setColor(Color.parseColor("#F7564A"));
130 | mPaint.setStrokeWidth(ConvertUtils.dp2px(getContext(),1));
131 | canvas.drawCircle(0, 0, mOuterRadius, mPaint);
132 | }
133 |
134 | @Override
135 | public View getView() {
136 | return this;
137 | }
138 |
139 | @Override
140 | public void onNoFinger() {
141 | mCurrentState = NO_FINGER;
142 | postInvalidate();
143 | }
144 |
145 | @Override
146 | public void onFingerTouch() {
147 | mCurrentState = FINGER_TOUCH;
148 | postInvalidate();
149 | }
150 |
151 | @Override
152 | public void onFingerUpMatched() {
153 | mCurrentState = FINGER_UP_MATCHED;
154 | postInvalidate();
155 | }
156 |
157 | @Override
158 | public void onFingerUpUnmatched() {
159 | mCurrentState = FINGER_UP_UN_MATCHED;
160 | postInvalidate();
161 | }
162 |
163 | public void setCurrentState(int state) {
164 | this.mCurrentState = state;
165 | postInvalidate();
166 | }
167 |
168 | }
169 |
--------------------------------------------------------------------------------
/gesturelockview/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 |
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 |
--------------------------------------------------------------------------------
/gesturelockview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | GestureLockView
3 |
4 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyyoona7/GestureLockView/cce079cddc0b09d43afbe692f8b874581cf1ade9/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 25 10:05:49 CST 2018
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-4.4-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 |
--------------------------------------------------------------------------------
/images/gesture1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyyoona7/GestureLockView/cce079cddc0b09d43afbe692f8b874581cf1ade9/images/gesture1.gif
--------------------------------------------------------------------------------
/images/gesture2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zyyoona7/GestureLockView/cce079cddc0b09d43afbe692f8b874581cf1ade9/images/gesture2.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':gesturelockview'
2 |
--------------------------------------------------------------------------------