├── 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
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── xyzlf
│ │ │ └── custom
│ │ │ └── keyboard
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── xyzlf
│ │ │ └── custom
│ │ │ └── keyboard
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── xyzlf
│ │ └── custom
│ │ └── keyboard
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── keyboardlib
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── drawable-xhdpi
│ │ │ ├── keboard_icon_delete.png
│ │ │ └── keyboard_icon_close.png
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ └── style.xml
│ │ ├── drawable
│ │ │ ├── keyboard_divider_line.xml
│ │ │ ├── keyboard_delete_selector.xml
│ │ │ └── keyboard_grid_item_bg.xml
│ │ ├── anim
│ │ │ ├── keyboard_exit.xml
│ │ │ └── keyboard_show.xml
│ │ └── layout
│ │ │ ├── keyboard_grid_item_image.xml
│ │ │ ├── keyboard_grid_item_text.xml
│ │ │ └── keyboard_dialog.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── xyzlf
│ │ └── custom
│ │ └── keyboardlib
│ │ ├── IKeyboardListener.java
│ │ ├── BaseDialog.java
│ │ ├── KeyboardGirdView.java
│ │ ├── KeyboardGridAdapter.java
│ │ ├── KeyboardDialog.java
│ │ └── PasswordView.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── keyboard.png
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/keyboardlib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':keyboardlib'
2 |
--------------------------------------------------------------------------------
/keyboard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xyzlf/NumericKeyboard/HEAD/keyboard.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xyzlf/NumericKeyboard/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | /gradle.properties
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | NumericKeyboard
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xyzlf/NumericKeyboard/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xyzlf/NumericKeyboard/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xyzlf/NumericKeyboard/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xyzlf/NumericKeyboard/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xyzlf/NumericKeyboard/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xyzlf/NumericKeyboard/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/xyzlf/NumericKeyboard/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/xyzlf/NumericKeyboard/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/xyzlf/NumericKeyboard/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/xyzlf/NumericKeyboard/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/keyboardlib/src/main/res/drawable-xhdpi/keboard_icon_delete.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xyzlf/NumericKeyboard/HEAD/keyboardlib/src/main/res/drawable-xhdpi/keboard_icon_delete.png
--------------------------------------------------------------------------------
/keyboardlib/src/main/res/drawable-xhdpi/keyboard_icon_close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xyzlf/NumericKeyboard/HEAD/keyboardlib/src/main/res/drawable-xhdpi/keyboard_icon_close.png
--------------------------------------------------------------------------------
/keyboardlib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | KeyboardLib
4 | 请输入支付密码
5 | 忘记密码?
6 |
7 |
8 |
--------------------------------------------------------------------------------
/keyboardlib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/keyboardlib/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #cccccc
4 | #ffe8ecef
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/keyboardlib/src/main/res/drawable/keyboard_divider_line.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/keyboardlib/src/main/res/anim/keyboard_exit.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
--------------------------------------------------------------------------------
/keyboardlib/src/main/res/anim/keyboard_show.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Jul 08 14:12:39 GMT+08:00 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/keyboardlib/src/main/java/com/xyzlf/custom/keyboardlib/IKeyboardListener.java:
--------------------------------------------------------------------------------
1 | package com.xyzlf.custom.keyboardlib;
2 |
3 | public interface IKeyboardListener {
4 |
5 | void onPasswordChange(String pwd);
6 |
7 | void onPasswordComplete(String pwd);
8 |
9 | void onForgetPwd();
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/keyboardlib/src/main/res/drawable/keyboard_delete_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/xyzlf/custom/keyboard/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.xyzlf.custom.keyboard;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/keyboardlib/src/main/res/layout/keyboard_grid_item_image.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/keyboardlib/src/main/res/layout/keyboard_grid_item_text.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/keyboardlib/src/main/res/drawable/keyboard_grid_item_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 | -
10 |
11 |
12 |
13 |
14 | -
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/xyzlf/custom/keyboard/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.xyzlf.custom.keyboard;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.xyzlf.custom.keyboard", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/keyboardlib/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\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "com.xyzlf.custom.keyboard"
8 | minSdkVersion 14
9 | targetSdkVersion 26
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 |
21 | lintOptions {
22 | // Or, if you prefer, you can continue to check for errors in release builds,
23 | // but continue the build even when errors are found:
24 | abortOnError false
25 | }
26 | }
27 |
28 | dependencies {
29 | compile fileTree(dir: 'libs', include: ['*.jar'])
30 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
31 | exclude group: 'com.android.support', module: 'support-annotations'
32 | })
33 | compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
34 | compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
35 | testCompile 'junit:junit:4.12'
36 |
37 | compile ('com.xyzlf.custom.keyboard:keyboard:0.0.1') {
38 | exclude group: 'com.android.support', module: 'appcompat-v7'
39 | }
40 |
41 | // compile (project(':keyboardlib'))
42 | }
43 |
--------------------------------------------------------------------------------
/keyboardlib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.novoda.bintray-release'
3 |
4 | android {
5 | compileSdkVersion 26
6 | buildToolsVersion "25.0.2"
7 |
8 | defaultConfig {
9 | minSdkVersion 14
10 | targetSdkVersion 26
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 |
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 |
22 | lintOptions {
23 | checkReleaseBuilds false
24 | // Or, if you prefer, you can continue to check for errors in release builds,
25 | // but continue the build even when errors are found:
26 | abortOnError false
27 | }
28 | }
29 |
30 | dependencies {
31 | compile fileTree(dir: 'libs', include: ['*.jar'])
32 | compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
33 | }
34 |
35 | Properties properties = new Properties()
36 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
37 |
38 | String localBintrayUser = properties.getProperty("bintray.user")
39 | String localBintrayApikey = properties.getProperty("bintray.apikey")
40 |
41 | //推送指令
42 | //gradlew clean build bintrayUpload
43 | //添加
44 | publish {
45 | bintrayUser = localBintrayUser //bintray.com用户名
46 | bintrayKey = localBintrayApikey //bintray.com apikey
47 | dryRun = false
48 | userOrg = localBintrayUser
49 | groupId = 'com.'+ localBintrayUser +'.custom.keyboard'//jcenter上的路径
50 | artifactId = 'keyboard'//项目名称
51 | publishVersion = '0.0.1'//版本号
52 | desc = '自定义随机数字密码键盘.'
53 | website = 'https://github.com/xyzlf/NumericKeyboard'
54 | }
55 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xyzlf/custom/keyboard/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.xyzlf.custom.keyboard;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.Toast;
7 |
8 | import com.xyzlf.custom.keyboardlib.IKeyboardListener;
9 | import com.xyzlf.custom.keyboardlib.KeyboardDialog;
10 |
11 | public class MainActivity extends AppCompatActivity {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_main);
17 |
18 | findViewById(R.id.show).setOnClickListener(new View.OnClickListener() {
19 | @Override
20 | public void onClick(View view) {
21 | final KeyboardDialog dialog = new KeyboardDialog(MainActivity.this);
22 | dialog.setKeyboardLintener(new IKeyboardListener() {
23 | @Override
24 | public void onPasswordChange(String pwd) {
25 | // Toast.makeText(MainActivity.this, "change:" + pwd, Toast.LENGTH_SHORT).show();
26 | }
27 |
28 | @Override
29 | public void onPasswordComplete(String pwd) {
30 | Toast.makeText(MainActivity.this, "complete:" + pwd, Toast.LENGTH_SHORT).show();
31 | dialog.dismiss();
32 | }
33 |
34 | @Override
35 | public void onForgetPwd() {
36 | Toast.makeText(MainActivity.this, "forget password", Toast.LENGTH_SHORT).show();
37 | }
38 | });
39 | dialog.show();
40 | }
41 | });
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/keyboardlib/src/main/java/com/xyzlf/custom/keyboardlib/BaseDialog.java:
--------------------------------------------------------------------------------
1 | package com.xyzlf.custom.keyboardlib;
2 |
3 | import android.app.Activity;
4 | import android.app.Dialog;
5 | import android.content.Context;
6 | import android.view.WindowManager;
7 |
8 | public class BaseDialog extends Dialog {
9 |
10 | public BaseDialog(Context context) {
11 | super(context);
12 | }
13 |
14 | public BaseDialog(Context context, int theme) {
15 | super(context, theme);
16 | }
17 |
18 | protected void setDialogSize(int width, int height) {
19 | if (this.getWindow() != null) {
20 | WindowManager.LayoutParams lp = this.getWindow().getAttributes();
21 | lp.width = width;
22 | if (height > 0) {
23 | lp.height = height;
24 | }
25 | this.getWindow().setAttributes(lp);
26 | }
27 | }
28 |
29 | @Override
30 | public void show() {
31 | try {
32 | Context context = getContext();
33 | if (context instanceof Activity) {
34 | if (((Activity) context).isFinishing()) {
35 | return;
36 | }
37 | }
38 | if (isShowing()) {
39 | return;
40 | }
41 | super.show();
42 | } catch (Throwable ignore) {
43 | }
44 | }
45 |
46 | @Override
47 | public void dismiss() {
48 | try {
49 | Context context = getContext();
50 | if (context instanceof Activity) {
51 | if (((Activity) context).isFinishing()) {
52 | return;
53 | }
54 | }
55 | if (isShowing()) {
56 | super.dismiss();
57 | }
58 | } catch (Throwable ignore) {
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/keyboardlib/src/main/res/values/style.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
10 |
11 |
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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # NumericKeyboard
2 | 随机数字键盘,仿支付宝支付密码UI。
3 |
4 | # Gradle
5 | compile ('com.xyzlf.custom.keyboard:keyboard:0.0.1') {
6 | exclude group: 'com.android.support', module: 'appcompat-v7'
7 | }
8 |
9 | # 效果图
10 |
11 |
12 | # 使用方式
13 |
14 | 1、初始化KeyboardDialg。
15 |
16 | 2、设置监听回调。
17 |
18 | final KeyboardDialog dialog = new KeyboardDialog(MainActivity.this);
19 | dialog.setKeyboardLintener(new IKeyboardListener() {
20 | @Override
21 | public void onPasswordChange(String pwd) {
22 | Toast.makeText(MainActivity.this, "change:" + pwd, Toast.LENGTH_SHORT).show();
23 | }
24 |
25 | @Override
26 | public void onPasswordComplete(String pwd) {
27 | Toast.makeText(MainActivity.this, "complete:" + pwd, Toast.LENGTH_SHORT).show();
28 | dialog.dismiss();
29 | }
30 |
31 | @Override
32 | public void onForgetPwd() {
33 | Toast.makeText(MainActivity.this, "forget password", Toast.LENGTH_SHORT).show();
34 | }
35 | });
36 | dialog.show();
37 |
38 |
39 | # 参考
40 |
41 | Android仿支付宝淘宝 - 自定义密码输入框和键盘:
42 |
43 | # 关于我
44 | 有任何使用问题,可以给我发邮件:
45 |
46 | Author:张利峰
47 |
48 | E-mail:519578280@qq.com
49 |
50 | # License
51 |
52 | Copyright(c)2017 xyzlf Open Source Project
53 |
54 | Licensed under the Apache License, Version 2.0 (the "License");
55 | you may not use this file except in compliance with the License.
56 | You may obtain a copy of the License at
57 |
58 | http://www.apache.org/licenses/LICENSE-2.0
59 |
60 | Unless required by applicable law or agreed to in writing, software
61 | distributed under the License is distributed on an "AS IS" BASIS,
62 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
63 | See the License for the specific language governing permissions and
64 | limitations under the License.k
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/keyboardlib/src/main/java/com/xyzlf/custom/keyboardlib/KeyboardGirdView.java:
--------------------------------------------------------------------------------
1 | package com.xyzlf.custom.keyboardlib;
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.util.AttributeSet;
9 | import android.view.View;
10 | import android.widget.GridView;
11 |
12 | public class KeyboardGirdView extends GridView {
13 |
14 | private Paint localPaint;
15 | private int strokeWidth = 1;
16 | private int color;
17 |
18 | public KeyboardGirdView(Context context) {
19 | this(context, null);
20 | }
21 |
22 | public KeyboardGirdView(Context context, AttributeSet attrs) {
23 | this(context, attrs, 0);
24 | }
25 |
26 | public KeyboardGirdView(Context context, AttributeSet attrs, int defStyle) {
27 | super(context, attrs, defStyle);
28 |
29 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.KeyboardGridView);
30 | strokeWidth = (int) typedArray.getDimension(R.styleable.KeyboardGridView_grid_line_size, strokeWidth);
31 | color = typedArray.getColor(R.styleable.KeyboardGridView_grid_line_color, Color.parseColor("#e6e6e6"));
32 | typedArray.recycle();
33 |
34 | init();
35 | }
36 |
37 | private void init() {
38 | localPaint = new Paint();
39 | localPaint.setStrokeWidth(strokeWidth);
40 | localPaint.setStyle(Paint.Style.STROKE);
41 | localPaint.setColor(color);
42 | }
43 |
44 | // @Override
45 | // public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
46 | // int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
47 | // MeasureSpec.AT_MOST);
48 | // super.onMeasure(widthMeasureSpec, expandSpec);
49 | // }
50 |
51 | @Override
52 | protected void dispatchDraw(Canvas canvas) {
53 | super.dispatchDraw(canvas);
54 | View localView1 = getChildAt(0);
55 | int column = getWidth() / localView1.getWidth();
56 | int childCount = getChildCount();
57 | for (int i = 0; i < childCount; i++) {
58 | View cellView = getChildAt(i);
59 | if ((i + 1) % column == 0) {
60 | canvas.drawLine(cellView.getLeft(), cellView.getBottom(), cellView.getRight(), cellView.getBottom(), localPaint);
61 | } else if ((i + 1) > (childCount - (childCount % column))) {
62 | canvas.drawLine(cellView.getRight(), cellView.getTop(), cellView.getRight(), cellView.getBottom(), localPaint);
63 | } else {
64 | canvas.drawLine(cellView.getRight(), cellView.getTop(), cellView.getRight(), cellView.getBottom(), localPaint);
65 | canvas.drawLine(cellView.getLeft(), cellView.getBottom(), cellView.getRight(), cellView.getBottom(), localPaint);
66 | }
67 | }
68 | if (childCount % column != 0) {
69 | for (int j = 0; j < (column - childCount % column); j++) {
70 | View lastView = getChildAt(childCount - 1);
71 | canvas.drawLine(lastView.getRight() + lastView.getWidth() * j, lastView.getTop(), lastView.getRight() + lastView.getWidth() * j, lastView.getBottom(), localPaint);
72 | }
73 | }
74 | }
75 |
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/keyboardlib/src/main/res/layout/keyboard_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
20 |
21 |
26 |
27 |
28 |
36 |
37 |
44 |
45 |
46 |
50 |
51 |
61 |
62 |
74 |
75 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/keyboardlib/src/main/java/com/xyzlf/custom/keyboardlib/KeyboardGridAdapter.java:
--------------------------------------------------------------------------------
1 | package com.xyzlf.custom.keyboardlib;
2 |
3 | import android.view.LayoutInflater;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.BaseAdapter;
7 | import android.widget.ImageView;
8 | import android.widget.TextView;
9 |
10 | import java.util.List;
11 |
12 | public class KeyboardGridAdapter extends BaseAdapter {
13 |
14 | private static final int TYPE_COUNT = 3;
15 |
16 | private static final int TYPE_TEXT = 0;
17 | private static final int TYPE_IMAGE = 1;
18 | private static final int TYPE_BANK = 2;
19 |
20 | public static final int TYPE_VALUE_BANK = -1;
21 | public static final int TYPE_VALUE_DELETE = -2;
22 |
23 | private List mDatas;
24 |
25 | public KeyboardGridAdapter(List datas) {
26 | mDatas = datas;
27 | }
28 |
29 | @Override
30 | public int getCount() {
31 | return mDatas.size();
32 | }
33 |
34 | @Override
35 | public Integer getItem(int position) {
36 | return mDatas.get(position);
37 | }
38 |
39 | @Override
40 | public long getItemId(int position) {
41 | return position;
42 | }
43 |
44 | @Override
45 | public int getItemViewType(int position) {
46 | int value = mDatas.get(position);
47 | if (value == TYPE_VALUE_BANK) {
48 | return TYPE_BANK;
49 | } else if (value == TYPE_VALUE_DELETE) {
50 | return TYPE_IMAGE;
51 | }
52 | return TYPE_TEXT;
53 | }
54 |
55 | @Override
56 | public int getViewTypeCount() {
57 | return TYPE_COUNT;
58 | }
59 |
60 | @Override
61 | public View getView(int position, View convertView, ViewGroup parent) {
62 | ViewHolder viewHolder;
63 | int type = getItemViewType(position);
64 | if (convertView == null) {
65 | viewHolder = new ViewHolder();
66 | switch (type) {
67 | case TYPE_TEXT:
68 | convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.keyboard_grid_item_text, parent, false);
69 | viewHolder.text = (TextView) convertView.findViewById(R.id.text);
70 | break;
71 |
72 | case TYPE_BANK:
73 | case TYPE_IMAGE:
74 | convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.keyboard_grid_item_image, parent, false);
75 | viewHolder.deleteIcon = (ImageView) convertView.findViewById(R.id.delete);
76 | break;
77 |
78 | default:
79 | convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.keyboard_grid_item_text, parent, false);
80 | viewHolder.text = (TextView) convertView.findViewById(R.id.text);
81 | break;
82 | }
83 | convertView.setTag(viewHolder);
84 | } else {
85 | viewHolder = (ViewHolder) convertView.getTag();
86 | }
87 |
88 | switch (type) {
89 | case TYPE_TEXT:
90 | int value = getItem(position);
91 | String text = String.valueOf(value);
92 | viewHolder.text.setText(text);
93 | break;
94 |
95 | case TYPE_IMAGE:
96 | viewHolder.deleteIcon.setEnabled(true);
97 | viewHolder.deleteIcon.setImageResource(R.drawable.keboard_icon_delete);
98 | break;
99 |
100 | case TYPE_BANK:
101 | viewHolder.deleteIcon.setEnabled(false);
102 | break;
103 | }
104 | return convertView;
105 | }
106 |
107 |
108 | private class ViewHolder {
109 | TextView text;
110 | ImageView deleteIcon;
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/keyboardlib/src/main/java/com/xyzlf/custom/keyboardlib/KeyboardDialog.java:
--------------------------------------------------------------------------------
1 | package com.xyzlf.custom.keyboardlib;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.AdapterView;
7 | import android.widget.GridView;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 | import java.util.Random;
12 |
13 |
14 | public class KeyboardDialog extends BaseDialog implements AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener {
15 |
16 | private PasswordView mPasswordView;
17 | private KeyboardGridAdapter mKeyboardAdapter;
18 |
19 | private IKeyboardListener mOnListener;
20 |
21 | public KeyboardDialog(Context context) {
22 | this(context, R.style.KeyboardDialog);
23 | }
24 |
25 | public KeyboardDialog(Context context, int style) {
26 | super(context, style);
27 | }
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.keyboard_dialog);
33 | setDialogSize(getContext().getResources().getDisplayMetrics().widthPixels, 0);
34 | setCanceledOnTouchOutside(false);
35 | findViewById(R.id.dialog_blank).setOnClickListener(new View.OnClickListener() {
36 | @Override
37 | public void onClick(View v) {
38 | dismiss();
39 | }
40 | });
41 | findViewById(R.id.dialog_close).setOnClickListener(new View.OnClickListener() {
42 | @Override
43 | public void onClick(View v) {
44 | dismiss();
45 | }
46 | });
47 | findViewById(R.id.dialog_forget_pwd).setOnClickListener(new View.OnClickListener() {
48 | @Override
49 | public void onClick(View v) {
50 | if (null != mOnListener) {
51 | mOnListener.onForgetPwd();
52 | }
53 | }
54 | });
55 |
56 | mPasswordView = (PasswordView) findViewById(R.id.dialog_password);
57 | mPasswordView.setOnPasswordListener(new PasswordView.OnPasswordListener() {
58 | @Override
59 | public void onPasswordChange(String pwd) {
60 | if (null != mOnListener) {
61 | mOnListener.onPasswordChange(pwd);
62 | }
63 | }
64 |
65 | @Override
66 | public void onPasswordComplete(String pwd) {
67 | if (null != mOnListener) {
68 | mOnListener.onPasswordComplete(pwd);
69 | }
70 | }
71 |
72 | });
73 | GridView keyboardGrid = (GridView) findViewById(R.id.dialog_grid);
74 |
75 | List datas = new ArrayList<>();
76 | for (int i = 0; i < 10; i++) {
77 | datas.add(i);
78 | }
79 | List randomList = randomList(datas);
80 | randomList.add(9, KeyboardGridAdapter.TYPE_VALUE_BANK);
81 | randomList.add(KeyboardGridAdapter.TYPE_VALUE_DELETE);
82 | mKeyboardAdapter = new KeyboardGridAdapter(randomList);
83 | keyboardGrid.setAdapter(mKeyboardAdapter);
84 | keyboardGrid.setOnItemClickListener(this);
85 | keyboardGrid.setOnItemLongClickListener(this);
86 | }
87 |
88 | public void setKeyboardLintener(IKeyboardListener listener) {
89 | this.mOnListener = listener;
90 | }
91 |
92 | @Override
93 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
94 | if (null == mKeyboardAdapter) {
95 | return;
96 | }
97 | if (position == (mKeyboardAdapter.getCount() - 3)) {
98 | return;
99 | }
100 | if (position == (mKeyboardAdapter.getCount() - 1)) {
101 | mPasswordView.deletePassword();
102 | } else {
103 | int value = mKeyboardAdapter.getItem(position);
104 | mPasswordView.addPassword(value);
105 | }
106 | }
107 |
108 | @Override
109 | public boolean onItemLongClick(AdapterView> parent, View view, int position, long id) {
110 | if (position == mKeyboardAdapter.getCount() - 1) {
111 | mPasswordView.clearPassword();
112 | return true;
113 | }
114 | return false;
115 | }
116 |
117 | private static List randomList(List sourceList) {
118 | if (isEmpty(sourceList)) {
119 | return sourceList;
120 | }
121 |
122 | List randomList = new ArrayList(sourceList.size());
123 | do {
124 | int randomIndex = Math.abs(new Random().nextInt(sourceList.size()));
125 | randomList.add(sourceList.remove(randomIndex));
126 | } while (sourceList.size() > 0);
127 |
128 | return randomList;
129 | }
130 |
131 | private static boolean isEmpty(List sourceList) {
132 | return (sourceList == null || sourceList.size() == 0);
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/keyboardlib/src/main/java/com/xyzlf/custom/keyboardlib/PasswordView.java:
--------------------------------------------------------------------------------
1 | package com.xyzlf.custom.keyboardlib;
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.RectF;
9 | import android.util.AttributeSet;
10 | import android.widget.EditText;
11 |
12 | public class PasswordView extends EditText {
13 |
14 | private static final int DEFAULT_BOARD_SIZE = 1; //默认边框大小
15 | private static final int DEFAULT_BOARD_RADIUS = 0; //默认边框圆角大小
16 | private static final int DEFAULT_PWD_CIRCLE_COUNT = 6; //默认密码个数
17 | private static final int DEFAULT_PWD_CIRCLE_RADIUS = 4; //默认密码半径
18 |
19 | private Paint mPaint;
20 | private RectF mRectF;
21 |
22 | private int mBgColor;
23 |
24 | private int mBoardColor;
25 | private int mBoardSize;
26 | private int mBoardCornerSize;
27 |
28 | private int mDividerColor;
29 | private int mDividerSize;
30 |
31 | private int mPwdCircleColor;
32 | private int mPwdCircleRadius;
33 |
34 | private int mPwdCircleCount;
35 | private int mPwdItemWidth;
36 |
37 | private StringBuilder mPasswordStr;
38 |
39 | public PasswordView(Context context) {
40 | this(context, null);
41 | }
42 |
43 | public PasswordView(Context context, AttributeSet attrs) {
44 | this(context, attrs, 0);
45 | }
46 |
47 | public PasswordView(Context context, AttributeSet attrs, int defStyleAttr) {
48 | super(context, attrs, defStyleAttr);
49 | initPaint();
50 | initAttributeSet(context, attrs);
51 |
52 | mPasswordStr = new StringBuilder(DEFAULT_PWD_CIRCLE_COUNT);
53 |
54 | setCursorVisible(false);
55 | setFocusable(false);
56 | }
57 |
58 | private void initPaint() {
59 | mPaint = new Paint();
60 | mPaint.setAntiAlias(true);
61 | mPaint.setDither(true);
62 | mRectF = new RectF();
63 | }
64 |
65 | private void initAttributeSet(Context context, AttributeSet attrs) {
66 | TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.PasswordView);
67 | mBgColor = array.getColor(R.styleable.PasswordView_pwd_bg_color, Color.WHITE);
68 |
69 | mBoardColor = array.getColor(R.styleable.PasswordView_pwd_board_color, Color.parseColor("#454a4d"));
70 | mBoardSize = (int) array.getDimension(R.styleable.PasswordView_pwd_board_size, DEFAULT_BOARD_SIZE);
71 | mBoardCornerSize = (int) array.getDimension(R.styleable.PasswordView_pwd_board_corner_size, DEFAULT_BOARD_RADIUS);
72 |
73 | mDividerColor = array.getColor(R.styleable.PasswordView_pwd_divider_color, Color.parseColor("#454a4d"));
74 | mDividerSize = (int) array.getDimension(R.styleable.PasswordView_pwd_divider_size, DEFAULT_BOARD_SIZE);
75 |
76 | mPwdCircleColor = array.getColor(R.styleable.PasswordView_pwd_circle_color, Color.parseColor("#454a4d"));
77 | mPwdCircleRadius = (int) array.getDimension(R.styleable.PasswordView_pwd_circle_radius, DEFAULT_PWD_CIRCLE_RADIUS);
78 |
79 | mPwdCircleCount = (int) array.getDimension(R.styleable.PasswordView_pwd_circle_count, DEFAULT_PWD_CIRCLE_COUNT);
80 |
81 | array.recycle();
82 | }
83 |
84 | @Override
85 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
86 | super.onSizeChanged(w, h, oldw, oldh);
87 |
88 | mPwdItemWidth = (w - (mPwdCircleCount - 1) * mDividerSize) / mPwdCircleCount;
89 | }
90 |
91 | @Override
92 | protected void onDraw(Canvas canvas) {
93 | drawBg(canvas);
94 |
95 | drawBoard(canvas);
96 |
97 | drawBoardDivider(canvas);
98 |
99 | drawPwd(canvas);
100 | }
101 |
102 | private void drawBg(Canvas canvas) {
103 | mPaint.setColor(mBgColor);
104 | mPaint.setStyle(Paint.Style.FILL);
105 | mRectF.set(0, 0, getWidth(), getHeight());
106 |
107 | if (mBoardCornerSize > 0) {
108 | canvas.drawRoundRect(mRectF, mBoardCornerSize, mBoardCornerSize, mPaint);
109 | } else {
110 | canvas.drawRect(mRectF, mPaint);
111 | }
112 | }
113 |
114 | private void drawBoard(Canvas canvas) {
115 | mPaint.setColor(mBoardColor);
116 | mPaint.setStrokeWidth(mBoardSize);
117 | mPaint.setStyle(Paint.Style.STROKE);
118 |
119 | mRectF.set(mBoardSize, mBoardSize, getWidth() - mBoardSize, getHeight() - mBoardSize);
120 |
121 | if (mBoardCornerSize > 0) {
122 | canvas.drawRoundRect(mRectF, mBoardCornerSize, mBoardCornerSize, mPaint);
123 | } else {
124 | canvas.drawRect(mRectF, mPaint);
125 | }
126 | }
127 |
128 | private void drawBoardDivider(Canvas canvas) {
129 | mPaint.setColor(mDividerColor);
130 | mPaint.setStrokeWidth(mDividerSize);
131 | mPaint.setStyle(Paint.Style.FILL);
132 |
133 | for (int i = 0; i < mPwdCircleCount - 1; i++) {
134 | int startX = (i + 1) * mDividerSize + (i + 1) * mPwdItemWidth + mBoardSize;
135 | canvas.drawLine(startX, mBoardSize, startX, getHeight() - mBoardSize, mPaint);
136 | }
137 | }
138 |
139 | private void drawPwd(Canvas canvas) {
140 | mPaint.setColor(mPwdCircleColor);
141 | mPaint.setStyle(Paint.Style.FILL);
142 |
143 | int pwdTextLength = getText().length();
144 | for (int i = 0; i < pwdTextLength; i++) {
145 | int cx = i * mDividerSize + i * mPwdItemWidth + mPwdItemWidth / 2 + mBoardSize;
146 | canvas.drawCircle(cx, getHeight() / 2, mPwdCircleRadius, mPaint);
147 | }
148 | }
149 |
150 | public void addPassword(int number) {
151 | if (mPasswordStr.length() >= mPwdCircleCount) {
152 | return;
153 | }
154 | mPasswordStr.append(number);
155 |
156 | String pwd = mPasswordStr.toString();
157 | setText(pwd);
158 |
159 | if (mPasswordStr.length() == mPwdCircleCount) {
160 | if (onPasswordListener != null) {
161 | onPasswordListener.onPasswordComplete(pwd);
162 | }
163 | } else {
164 | if (onPasswordListener != null) {
165 | onPasswordListener.onPasswordChange(pwd);
166 | }
167 | }
168 | }
169 |
170 | public void deletePassword() {
171 | int len = mPasswordStr.length();
172 | if (len <= 0) {
173 | return;
174 | }
175 | mPasswordStr.deleteCharAt(len - 1);
176 | String pwd = mPasswordStr.toString();
177 | setText(pwd);
178 |
179 | if (onPasswordListener != null) {
180 | onPasswordListener.onPasswordChange(pwd);
181 | }
182 | }
183 |
184 | public void clearPassword() {
185 | mPasswordStr.delete(0, mPasswordStr.length());
186 | setText("");
187 | }
188 |
189 | private OnPasswordListener onPasswordListener;
190 |
191 | public void setOnPasswordListener(OnPasswordListener onPasswordListener) {
192 | this.onPasswordListener = onPasswordListener;
193 | }
194 |
195 |
196 | public interface OnPasswordListener {
197 |
198 | void onPasswordChange(String pwd);
199 |
200 | void onPasswordComplete(String pwd);
201 | }
202 |
203 | }
204 |
--------------------------------------------------------------------------------