├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ └── styles.xml
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── layout
│ │ │ ├── activity_second.xml
│ │ │ └── activity_main.xml
│ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ └── drawable
│ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── leondevlifelog
│ │ │ └── gesturelockviewsample
│ │ │ ├── SecondActivity.java
│ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── gesturelockview
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ └── values
│ │ │ ├── strings.xml
│ │ │ ├── dimen.xml
│ │ │ ├── colors.xml
│ │ │ └── attrs_gesture_lock_view.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── leondevlifelog
│ │ └── gesturelockview
│ │ └── GestureLockView.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── art
├── my.gif
└── miui.gif
├── .gitignore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .github
└── workflows
│ └── android.yml
├── gradle.properties
├── gradlew.bat
├── README.md
├── gradlew
└── License
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/gesturelockview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':gesturelockview'
2 |
--------------------------------------------------------------------------------
/art/my.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeonDevLifeLog/GestureLockView/HEAD/art/my.gif
--------------------------------------------------------------------------------
/art/miui.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeonDevLifeLog/GestureLockView/HEAD/art/miui.gif
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | .DS_Store
5 | /build
6 | /captures
7 | .externalNativeBuild
8 | /.idea/
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | GestureLockViewSample
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeonDevLifeLog/GestureLockView/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gesturelockview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | GestureLockView
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeonDevLifeLog/GestureLockView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeonDevLifeLog/GestureLockView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeonDevLifeLog/GestureLockView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeonDevLifeLog/GestureLockView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeonDevLifeLog/GestureLockView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeonDevLifeLog/GestureLockView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeonDevLifeLog/GestureLockView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeonDevLifeLog/GestureLockView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeonDevLifeLog/GestureLockView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LeonDevLifeLog/GestureLockView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gesturelockview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gesturelockview/src/main/res/values/dimen.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4dp
4 | 8dp
5 | 4dp
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Feb 13 11:55:33 CST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gesturelockview/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #AACCCCCC
4 | #FFBBBBBB
5 | #55CCCCCC
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.github/workflows/android.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 |
3 | on: [push]
4 |
5 | jobs:
6 | build:
7 |
8 | runs-on: ubuntu-latest
9 |
10 | steps:
11 | - uses: actions/checkout@v2
12 | - name: set up JDK 1.8
13 | uses: actions/setup-java@v1
14 | with:
15 | java-version: 1.8
16 | - name: Build with Gradle
17 | run: chmod +x gradlew && ./gradlew build
18 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/leondevlifelog/gesturelockviewsample/SecondActivity.java:
--------------------------------------------------------------------------------
1 | package com.github.leondevlifelog.gesturelockviewsample;
2 |
3 | import android.os.Bundle;
4 |
5 | import androidx.appcompat.app.AppCompatActivity;
6 |
7 | /**
8 | * @author liang
9 | * 日期 2017-11-02 14:06:02
10 | */
11 | public class SecondActivity extends AppCompatActivity {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_second);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/gesturelockview/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx1024m -XX:MaxPermSize=256m
9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | #Thu Nov 02 16:01:34 CST 2017
16 | android.enableJetifier=true
17 | android.useAndroidX=true
18 | org.gradle.jvmargs=-Xmx1536m
19 |
--------------------------------------------------------------------------------
/gesturelockview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 28
5 |
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 14
10 | targetSdkVersion 28
11 | versionCode 1
12 | versionName "0.0.1"
13 |
14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 |
30 | implementation 'androidx.appcompat:appcompat:1.0.0'
31 | testImplementation 'junit:junit:4.13'
32 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
33 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
34 | }
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.github.leondevlifelog.gesturelockviewsample"
7 | minSdkVersion 14
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0.0"
11 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
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 'androidx.appcompat:appcompat:1.1.0'
24 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
25 | testImplementation 'junit:junit:4.13'
26 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
27 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
28 | implementation project(path: ':gesturelockview')
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_second.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/gesturelockview/src/main/res/values/attrs_gesture_lock_view.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 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/leondevlifelog/gesturelockviewsample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.github.leondevlifelog.gesturelockviewsample;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.widget.CompoundButton;
6 | import android.widget.Switch;
7 | import android.widget.Toast;
8 |
9 | import androidx.appcompat.app.AppCompatActivity;
10 |
11 | import com.github.leondevlifelog.gesturelockview.GestureLockView;
12 |
13 | /**
14 | * @author liang
15 | * 日期 2017-11-02 14:04:52
16 | */
17 |
18 | public class MainActivity extends AppCompatActivity {
19 |
20 | private GestureLockView customGestureView;
21 | private GestureLockView defaultGestureView;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_main);
27 | customGestureView = findViewById(R.id.customGestureLockView);
28 | defaultGestureView = findViewById(R.id.defaultGestureLockView);
29 | GestureLockView.OnCheckPasswordListener onCheckPasswordListener = new GestureLockView.OnCheckPasswordListener() {
30 | @Override
31 | public boolean onCheckPassword(String passwd) {
32 | return passwd.equals("abcdef");
33 | }
34 |
35 | @Override
36 | public void onSuccess() {
37 | Toast.makeText(getApplicationContext(), "SUCCESS", Toast.LENGTH_SHORT).show();
38 | startActivity(new Intent(MainActivity.this, SecondActivity.class));
39 | }
40 |
41 | @Override
42 | public void onError() {
43 | Toast.makeText(getApplicationContext(), "ERROR", Toast.LENGTH_SHORT).show();
44 | }
45 | };
46 | customGestureView.setOnCheckPasswordListener(onCheckPasswordListener);
47 | defaultGestureView.setOnCheckPasswordListener(onCheckPasswordListener);
48 | Switch safeModel = findViewById(R.id.switch1);
49 | CompoundButton.OnCheckedChangeListener listener = new CompoundButton.OnCheckedChangeListener() {
50 | @Override
51 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
52 | customGestureView.setSecurityMode(isChecked);
53 | defaultGestureView.setSecurityMode(isChecked);
54 | }
55 | };
56 | safeModel.setOnCheckedChangeListener(listener);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
41 |
42 |
53 |
54 |
64 |
65 |
78 |
79 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # GestureLockView 九宫格手势解锁控件
3 |
4 | [](http://developer.android.com/index.html)
5 | 
6 | [](https://jitpack.io/#LeonDevLifeLog/GestureLockView)
7 | [](https://www.codacy.com/manual/LeonDevLifeLog/GestureLockView?utm_source=github.com&utm_medium=referral&utm_content=LeonDevLifeLog/GestureLockView&utm_campaign=Badge_Grade)
8 | [](https://android-arsenal.com/api?level=14)
9 | [](https://github.com/LeonDevLifeLog/GestureLockView/blob/master/LICENSE)
10 |
11 | ## Preview 预览
12 |
13 | |this projcet|MIUI OS|
14 | |--|--|
15 | |  |  |
16 |
17 | ## Notice 说明
18 |
19 |
20 | * 每个点代表一个字母,从a到z(需求超过5行5列(25)的暂时支持)
21 |
22 | * Every point is a char from a to z(so more than 5 col and 5 row is not support now)
23 |
24 | ### How to use 引入库依赖
25 |
26 | ```groovy
27 | allprojects {
28 | repositories {
29 | ...
30 | maven { url 'https://jitpack.io' }
31 | }
32 | }
33 |
34 |
35 | dependencies {
36 | implementation 'com.github.LeonDevLifeLog:GestureLockView:v0.0.1' //请手动替换最新版本
37 | }
38 |
39 | ```
40 | ## Layout sample 自定义属性
41 | ```xml
42 |
51 | app:dot_color="#121212"
52 | app:dot_color_pressed="#FF2254A6"
53 | app:dot_pressed_radius="6dp"
54 | app:dot_radius="6dp"
55 | app:layout_constraintEnd_toEndOf="parent"
56 | app:layout_constraintStart_toStartOf="parent"
57 | app:layout_constraintTop_toTopOf="parent"
58 | app:line_color="#55CCCCCC"
59 | app:line_width="12dp"
60 | app:min_length="4"
61 | app:row="4"
62 | app:security_mode="false"
63 | app:vibrate="true" />
64 | ```
65 |
66 | ## SetListener 使用方法
67 |
68 | 使用时只要给控件setOnCheckPasswordListener,实现以下接口
69 | ```java
70 | public interface OnCheckPasswordListener {
71 | /**
72 | * 手势密码输入完成时回调,验证密码
73 | *
这里只做密码校验
74 | *
75 | * @param passwd 输入完成的手势密码
76 | * @return true:输入的手势密码和存储在本地的密码一致
77 | *
反之false
78 | */
79 | boolean onCheckPassword(String passwd);
80 |
81 | /**
82 | * 当密码校验成功时的回调
83 | */
84 | void onSuccess();
85 |
86 | /**
87 | * 当密码校验失败时的回调
88 | */
89 | void onError();
90 | }
91 | ```
92 |
93 | ## Plan
94 |
95 | - [ ] 自定义密码错误或长度不够的时候的主颜色
96 | - [ ] 点可否被重复连接(增加密码强度)
97 | - [ ] 错误次数限制
98 | - [ ] 行列都超过5的情况下优化一下
99 |
100 | ## Licenses
101 |
102 | ```
103 | Copyright 2020 Leon
104 |
105 | Licensed under the Apache License, Version 2.0 (the "License");
106 | you may not use this file except in compliance with the License.
107 | You may obtain a copy of the License at
108 |
109 | http://www.apache.org/licenses/LICENSE-2.0
110 |
111 | Unless required by applicable law or agreed to in writing, software
112 | distributed under the License is distributed on an "AS IS" BASIS,
113 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
114 | See the License for the specific language governing permissions and
115 | limitations under the License.
116 | ```
117 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/License:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright 2017 Leon
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/gesturelockview/src/main/java/com/github/leondevlifelog/gesturelockview/GestureLockView.java:
--------------------------------------------------------------------------------
1 | package com.github.leondevlifelog.gesturelockview;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.graphics.Path;
9 | import android.graphics.Point;
10 | import android.graphics.Region;
11 | import android.os.Build;
12 | import android.os.VibrationEffect;
13 | import android.os.Vibrator;
14 | import android.util.AttributeSet;
15 | import android.util.Log;
16 | import android.view.MotionEvent;
17 | import android.view.View;
18 |
19 | import androidx.core.content.ContextCompat;
20 |
21 | import static android.content.Context.VIBRATOR_SERVICE;
22 |
23 | /**
24 | * 手势解锁密码控件
25 | *
26 | * @author liang
27 | * 日期 2017-11-01 01:57:58
28 | */
29 | @SuppressWarnings("unused")
30 | public class GestureLockView extends View {
31 | private static final String TAG = "GestureLockView";
32 | private final static int DEFAULT_ROW = 3;
33 |
34 | private final static int DEFAULT_COL = 3;
35 | private static final int PORTRAIT = 1;
36 | private static final int LANDSCAPE = 0;
37 | private Context mContext;
38 | private Paint dotPaint;
39 | private int paddingLeft;
40 | private int contentWidth;
41 | private int contentHeight;
42 | private int row;
43 | private int col;
44 | private int dotColor;
45 | private int dotRadius;
46 | private int dotPressedColor;
47 | private int lineColor;
48 | private int lineWidth;
49 | private int widthHeightOffset;
50 | private Region[][] dotsRegion;
51 | private Region globalRegion;
52 | private int[][] dotsStatus;
53 | private Path tmpPath;
54 | private Point[][] dotsPos;
55 | private Point currentPoint;
56 | /**
57 | * 安全模式,不显示按下的点和手指移动路径
58 | */
59 | private boolean securityMode;
60 | private Paint linePaint;
61 | private Path linePath;
62 |
63 | private Point lastPoint;
64 | private StringBuilder password;
65 | private int dotPressedRadius;
66 | private Vibrator vibrator;
67 | private boolean isTouching = false;
68 | private int minLength;
69 | private OnCheckPasswordListener onCheckPasswordListener;
70 | private int ERROR = 1;
71 | private int NORMAL = 2;
72 | private int realLineColor;
73 | private int realDotPressedColor;
74 | private Runnable action;
75 | private int STATUS = NORMAL;
76 |
77 | public GestureLockView(Context context) {
78 | super(context);
79 | this.mContext = context;
80 | init(null, 0);
81 | }
82 |
83 | public GestureLockView(Context context, AttributeSet attrs) {
84 | super(context, attrs);
85 | this.mContext = context;
86 | init(attrs, 0);
87 | }
88 |
89 | public GestureLockView(Context context, AttributeSet attrs, int defStyle) {
90 | super(context, attrs, defStyle);
91 | this.mContext = context;
92 | init(attrs, defStyle);
93 | }
94 |
95 | /**
96 | * 初始化一些属性
97 | *
98 | */
99 | private void init(AttributeSet attrs, int defStyle) {
100 | final TypedArray a = getContext().obtainStyledAttributes(
101 | attrs, R.styleable.GestureLockView, defStyle, 0);
102 | col = a.getInt(R.styleable.GestureLockView_row, DEFAULT_ROW);
103 | row = a.getInt(R.styleable.GestureLockView_col, DEFAULT_COL);
104 | dotColor = a.getColor(R.styleable.GestureLockView_dot_color,
105 | ContextCompat.getColor(mContext, R.color.default_dot_color));
106 | dotRadius = a.getDimensionPixelSize(R.styleable.GestureLockView_dot_radius,
107 | getResources().getDimensionPixelSize(R.dimen.default_dot_radius));
108 | dotPressedColor = a.getColor(R.styleable.GestureLockView_dot_color_pressed,
109 | ContextCompat.getColor(mContext, R.color.default_dot_pressed_color));
110 | lineColor = a.getColor(R.styleable.GestureLockView_line_color,
111 | ContextCompat.getColor(mContext, R.color.default_line_color));
112 | lineWidth = a.getDimensionPixelSize(R.styleable.GestureLockView_line_width,
113 | getResources().getDimensionPixelSize(R.dimen.default_line_width));
114 | securityMode = a.getBoolean(R.styleable.GestureLockView_security_mode, false);
115 | dotPressedRadius = a.getDimensionPixelSize(R.styleable.GestureLockView_dot_pressed_radius,
116 | getResources().getDimensionPixelSize(R.dimen.default_dot_pressed_radius));
117 | boolean vibrateable = a.getBoolean(R.styleable.GestureLockView_vibrate, true);
118 | minLength = a.getInt(R.styleable.GestureLockView_min_length, 4);
119 | a.recycle();
120 | if (vibrateable) {
121 | vibrator = (Vibrator) getContext().getSystemService(VIBRATOR_SERVICE);
122 | }
123 | dotPaint = new Paint();
124 | dotPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
125 | dotPaint.setAntiAlias(true);
126 | dotPaint.setStyle(Paint.Style.FILL);
127 | linePaint = new Paint();
128 | linePaint.setColor(lineColor);
129 | linePaint.setStyle(Paint.Style.STROKE);
130 | linePaint.setStrokeWidth(lineWidth);
131 | linePaint.setAntiAlias(true);
132 | linePaint.setStrokeJoin(Paint.Join.ROUND);
133 | linePaint.setStrokeCap(Paint.Cap.ROUND);
134 | dotsRegion = new Region[row][col];
135 | dotsPos = new Point[row][col];
136 | for (int i = 0; i < row; i++) {
137 | for (int j = 0; j < col; j++) {
138 | dotsRegion[i][j] = new Region();
139 | dotsPos[i][j] = new Point(0, 0);
140 | }
141 | }
142 | dotsStatus = new int[row][col];
143 | tmpPath = new Path();
144 |
145 | currentPoint = new Point();
146 | linePath = new Path();
147 | lastPoint = new Point(0, 0);
148 | password = new StringBuilder();
149 | }
150 |
151 | @Override
152 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
153 | super.onSizeChanged(w, h, oldw, oldh);
154 | paddingLeft = getPaddingLeft();
155 | int paddingTop = getPaddingTop();
156 | int paddingRight = getPaddingRight();
157 | int paddingBottom = getPaddingBottom();
158 |
159 | contentWidth = getWidth() - paddingLeft - paddingRight;
160 | contentHeight = getHeight() - paddingTop - paddingBottom;
161 | widthHeightOffset = Math.abs(contentHeight - contentWidth);
162 |
163 | globalRegion = new Region(0, 0, getWidth(), getBottom());
164 | }
165 |
166 | @Override
167 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
168 | int desiredWidth = 400;
169 | int desiredHeight = 400;
170 |
171 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
172 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
173 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
174 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
175 |
176 | int width;
177 | int height;
178 |
179 | if (widthMode == MeasureSpec.EXACTLY) {
180 | width = widthSize;
181 | } else if (widthMode == MeasureSpec.AT_MOST) {
182 | width = Math.min(desiredWidth, widthSize);
183 | } else {
184 | width = desiredWidth;
185 | }
186 |
187 | if (heightMode == MeasureSpec.EXACTLY) {
188 | height = heightSize;
189 | } else if (heightMode == MeasureSpec.AT_MOST) {
190 | height = Math.min(desiredHeight, heightSize);
191 | } else {
192 | height = desiredHeight;
193 | }
194 | setMeasuredDimension(width, height);
195 | }
196 |
197 | @Override
198 | protected void onDraw(Canvas canvas) {
199 | super.onDraw(canvas);
200 | //
201 | if ((lastPoint.x != 0 || lastPoint.y != 0) //不是初始点
202 | && !securityMode//不是安全模式
203 | && password.length() > 0) {
204 | canvas.drawLine(lastPoint.x, lastPoint.y, currentPoint.x, currentPoint.y, linePaint);
205 | }
206 | //
207 | //
208 | if (!securityMode || STATUS == ERROR) {
209 | canvas.drawPath(linePath, linePaint);
210 | }
211 | //
212 | for (int i = 1; i <= row; i++) {
213 | for (int j = 1; j <= col; j++) {
214 | //
215 | float x = getMiniViewSize() / row * i - getMiniViewSize() / row / 2f + paddingLeft;
216 | float y = getMiniViewSize() / col * j - getMiniViewSize() / col / 2f + paddingLeft;
217 | //
218 | if (getViewOrientation() == PORTRAIT) {
219 | y += widthHeightOffset / 2f;
220 | } else {
221 | x += widthHeightOffset / 2f;
222 | }
223 | //
224 | int realDotRadius;
225 | if (dotsStatus[i - 1][j - 1] == 1) {
226 | if (!securityMode || STATUS == ERROR) {
227 | dotPaint.setColor(realDotPressedColor);
228 | }
229 | realDotRadius = dotPressedRadius > getTouchAreaMimiRadius() ? getTouchAreaMimiRadius() - 16 : dotPressedRadius;
230 | } else {
231 | dotPaint.setColor(dotColor);
232 | realDotRadius = dotRadius;
233 | }
234 | canvas.drawCircle(x, y, realDotRadius, dotPaint);
235 | //
236 | //
237 | dotsPos[i - 1][j - 1].set((int) x, (int) y);
238 | //
239 | //
240 | tmpPath.reset();
241 | tmpPath.addCircle(x, y, getTouchAreaMimiRadius(), Path.Direction.CW);
242 | dotsRegion[i - 1][j - 1].setPath(tmpPath, globalRegion);
243 | //
244 | }
245 | }
246 | }
247 |
248 | /**
249 | * 获得最小触摸范围的半径
250 | *
为了防止触摸范围重叠
251 | *
252 | * @return 最小接触范围半径
253 | */
254 | private int getTouchAreaMimiRadius() {
255 | int max = Math.max(col, row);
256 | return getMiniViewSize() / max / 2;
257 | }
258 |
259 | /**
260 | * 获取长宽的最小值
261 | *
262 | * @return 获取最小值
263 | */
264 | private int getMiniViewSize() {
265 | return Math.min(contentHeight, contentWidth);
266 | }
267 |
268 | /**
269 | * 获得view形状,是竖屏形状还是横屏形状
270 | *
271 | * @return 形状
272 | */
273 | private int getViewOrientation() {
274 | if (contentWidth > contentHeight) {
275 | return LANDSCAPE;
276 | } else {
277 | return PORTRAIT;
278 | }
279 | }
280 |
281 | @Override
282 | public boolean onTouchEvent(MotionEvent event) {
283 | switch (event.getAction()) {
284 | case MotionEvent.ACTION_DOWN:
285 | dealDown(event);
286 | return true;
287 | case MotionEvent.ACTION_MOVE:
288 | dealMove(event);
289 | return true;
290 | case MotionEvent.ACTION_UP:
291 | resetStatus();
292 | return true;
293 | default:
294 | return true;
295 | }
296 | }
297 |
298 | /**
299 | * 处理Action Down事件
300 | *
301 | * @param event 事件
302 | */
303 | private void dealDown(MotionEvent event) {
304 | if (action != null) {
305 | removeCallbacks(action);
306 | }
307 | reset();
308 | setStatus(NORMAL);
309 | for (int i = 0; i < row; i++) {
310 | for (int j = 0; j < col; j++) {
311 | if (dotsRegion[i][j].contains((int) event.getX(), (int) (event.getY()))) {
312 | if (dotsStatus[i][j] == 0) {
313 | linePath.moveTo(dotsPos[i][j].x, dotsPos[i][j].y);
314 | lastPoint.set(dotsPos[i][j].x, dotsPos[i][j].y);
315 | vibrator();
316 | String posString = String.valueOf((char) (j * row + i + 1 + 96));
317 | Log.d(TAG, "dealDown: posString" + posString);
318 | if (password.indexOf(posString) == -1) {
319 | password.append(posString);
320 | }
321 | }
322 | dotsStatus[i][j] = 1;
323 | }
324 | }
325 | }
326 | }
327 |
328 | /**
329 | * 处理Action Move事件
330 | *
331 | * @param event 事件
332 | */
333 | private void dealMove(MotionEvent event) {
334 | currentPoint.set(((int) event.getX()), ((int) event.getY()));
335 | for (int i = 0; i < row; i++) {
336 | for (int j = 0; j < col; j++) {
337 | if (dotsRegion[i][j].contains((int) event.getX(), (int) (event.getY()))) {
338 | if (dotsStatus[i][j] == 0) {
339 | //只有这个点没被选中过,才能链接到这个点
340 | linePath.lineTo(dotsPos[i][j].x, dotsPos[i][j].y);
341 | lastPoint.set(dotsPos[i][j].x, dotsPos[i][j].y);
342 | vibrator();
343 | isTouching = true;
344 | String posString = String.valueOf((char) (j * row + i + 1 + 96));
345 | Log.d(TAG, "dealDown: posString" + posString);
346 | if (password.indexOf(posString) == -1) {
347 | password.append(posString);
348 | }
349 | }
350 | dotsStatus[i][j] = 1;
351 | } else {
352 | isTouching = false;
353 | }
354 | }
355 | }
356 | invalidate();
357 | }
358 |
359 | /**
360 | * 恢复状态
361 | */
362 | private void resetStatus() {
363 | currentPoint.set(lastPoint.x, lastPoint.y);
364 | if (password.toString().length() < minLength) {
365 | //密码长度小于最小长度
366 | setStatus(ERROR);
367 | if (onCheckPasswordListener != null) {
368 | onCheckPasswordListener.onError();
369 | }
370 | } else {
371 | //密码长度符合要求
372 | if (onCheckPasswordListener != null && onCheckPasswordListener.onCheckPassword(password.toString())) {
373 | if (onCheckPasswordListener != null) {
374 | onCheckPasswordListener.onSuccess();
375 | }
376 | } else {
377 | setStatus(ERROR);
378 | if (onCheckPasswordListener != null) {
379 | onCheckPasswordListener.onError();
380 | }
381 | }
382 | }
383 | password.delete(0, password.length());
384 | invalidate();
385 | //抬起手指后过一秒钟再清除输入轨迹
386 | action = new Runnable() {
387 | //抬起手指后过一秒钟再清除输入轨迹
388 | @Override
389 | public void run() {
390 | reset();
391 | invalidate();
392 | }
393 | };
394 | postDelayed(action, 1000);
395 | }
396 |
397 | /**
398 | * 重置一些状态
399 | */
400 | private void reset() {
401 | for (int i = 0; i < row; i++) {
402 | for (int j = 0; j < col; j++) {
403 | dotsStatus[i][j] = 0;
404 | }
405 | }
406 | linePath.rewind();
407 | linePath.moveTo(currentPoint.x, currentPoint.y);
408 | password.delete(0, password.length());
409 | }
410 |
411 | /**
412 | * 设置当前状态
413 | * NORMAL 正常输入状态
414 | * SUCCESS 密码正确状态
415 | * ERROR 密码输入错误状态
416 | *
417 | * @param i 状态
418 | */
419 | private void setStatus(int i) {
420 | if (ERROR == i) {
421 | realLineColor = Color.parseColor("#66FF0000");
422 | realDotPressedColor = Color.parseColor("#FF0000");
423 | } else if (NORMAL == i) {
424 | realLineColor = lineColor;
425 | realDotPressedColor = dotPressedColor;
426 | }
427 | STATUS = i;
428 | linePaint.setColor(realLineColor);
429 | }
430 |
431 | /**
432 | * 震动,只有第一次进入点的触摸范围时才震动
433 | */
434 | private void vibrator() {
435 | if (!isTouching) {
436 | if (vibrator != null) {
437 | if (Build.VERSION.SDK_INT >= 26) {
438 | vibrator.vibrate(VibrationEffect.createOneShot(30, 10));
439 | } else {
440 | vibrator.vibrate(30);
441 | }
442 | }
443 | }
444 | }
445 |
446 | public int getRow() {
447 | return row;
448 | }
449 |
450 | public void setRow(int row) {
451 | this.row = row;
452 | invalidate();
453 | }
454 |
455 | public int getCol() {
456 | return col;
457 | }
458 |
459 | public void setCol(int col) {
460 | this.col = col;
461 | invalidate();
462 | }
463 |
464 | public int getDotColor() {
465 | return dotColor;
466 | }
467 |
468 | public void setDotColor(int dotColor) {
469 | this.dotColor = dotColor;
470 | invalidate();
471 | }
472 |
473 | public int getDotRadius() {
474 | return dotRadius;
475 | }
476 |
477 | public void setDotRadius(int dotRadius) {
478 | this.dotRadius = dotRadius;
479 | invalidate();
480 | }
481 |
482 | public int getDotPressedColor() {
483 | return dotPressedColor;
484 | }
485 |
486 | public void setDotPressedColor(int dotPressedColor) {
487 | this.dotPressedColor = dotPressedColor;
488 | invalidate();
489 | }
490 |
491 | public int getLineColor() {
492 | return lineColor;
493 | }
494 |
495 | public void setLineColor(int lineColor) {
496 | this.lineColor = lineColor;
497 | invalidate();
498 | }
499 |
500 | public int getLineWidth() {
501 | return lineWidth;
502 | }
503 |
504 | public void setLineWidth(int lineWidth) {
505 | this.lineWidth = lineWidth;
506 | invalidate();
507 | }
508 |
509 | public boolean isSecurityMode() {
510 | return securityMode;
511 | }
512 |
513 | public void setSecurityMode(boolean securityMode) {
514 | this.securityMode = securityMode;
515 | invalidate();
516 | }
517 |
518 | public int getDotPressedRadius() {
519 | return dotPressedRadius;
520 | }
521 |
522 | public void setDotPressedRadius(int dotPressedRadius) {
523 | this.dotPressedRadius = dotPressedRadius;
524 | invalidate();
525 | }
526 |
527 | public int getMinLength() {
528 | return minLength;
529 | }
530 |
531 | public void setMinLength(int minLength) {
532 | this.minLength = minLength;
533 | invalidate();
534 | }
535 |
536 | public OnCheckPasswordListener getOnCheckPasswordListener() {
537 | return onCheckPasswordListener;
538 | }
539 |
540 | public void setOnCheckPasswordListener(OnCheckPasswordListener onCheckPasswordListener) {
541 | this.onCheckPasswordListener = onCheckPasswordListener;
542 | }
543 |
544 | public interface OnCheckPasswordListener {
545 | /**
546 | * 手势密码输入完成时回调,验证密码
547 | *
这里只做密码校验
548 | *
549 | * @param passwd 输入完成的手势密码
550 | * @return true:输入的手势密码和存储在本地的密码一致
551 | *
反之false
552 | */
553 | boolean onCheckPassword(String passwd);
554 |
555 | /**
556 | * 当密码校验成功时的回调
557 | */
558 | void onSuccess();
559 |
560 | /**
561 | * 当密码校验失败时的回调
562 | */
563 | void onError();
564 | }
565 |
566 | }
567 |
--------------------------------------------------------------------------------