├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── activity_test.xml
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── arron
│ │ │ └── passwordviewdemo
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── arron
│ │ │ └── passwordviewdemo
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── arron
│ │ └── passwordviewdemo
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── passwordview
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ ├── strings.xml
│ │ │ │ └── attrs.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── arron
│ │ │ └── passwordview
│ │ │ └── PasswordView.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── arron
│ │ │ └── passwordview
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── arron
│ │ └── passwordview
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── Demo_rect.png
├── Demo_underline.png
├── .idea
├── copyright
│ └── profiles_settings.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/passwordview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':passwordview'
2 |
--------------------------------------------------------------------------------
/Demo_rect.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EoniJJ/PasswordView/HEAD/Demo_rect.png
--------------------------------------------------------------------------------
/Demo_underline.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EoniJJ/PasswordView/HEAD/Demo_underline.png
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EoniJJ/PasswordView/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PasswordViewDemo
3 |
4 |
--------------------------------------------------------------------------------
/passwordview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PasswordView
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EoniJJ/PasswordView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EoniJJ/PasswordView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EoniJJ/PasswordView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EoniJJ/PasswordView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EoniJJ/PasswordView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
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-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/passwordview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_test.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/arron/passwordviewdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.arron.passwordviewdemo;
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 | }
--------------------------------------------------------------------------------
/passwordview/src/test/java/com/arron/passwordview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.arron.passwordview;
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 | }
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/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 G:\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 |
--------------------------------------------------------------------------------
/passwordview/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 G:\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/passwordview/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/arron/passwordviewdemo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.arron.passwordviewdemo;
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.arron.passwordviewdemo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/passwordview/src/androidTest/java/com/arron/passwordview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.arron.passwordview;
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.arron.passwordview.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/passwordview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.0"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
27 | exclude group: 'com.android.support', module: 'support-annotations'
28 | })
29 | compile 'com.android.support:appcompat-v7:24.0.0'
30 | testCompile 'junit:junit:4.12'
31 | }
32 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.0"
6 | defaultConfig {
7 | applicationId "com.arron.passwordviewdemo"
8 | minSdkVersion 15
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:24.0.0'
28 | testCompile 'junit:junit:4.12'
29 | compile project(':passwordview')
30 | }
31 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | PasswordView
2 | ====
3 | 下划线(方框)密码输入框
4 |
5 | ## Demo
6 |
7 |
8 |
9 |
10 | ## How to use ?
11 | ` in layout.xml `
12 | ```xml
13 |
20 | ```
21 | 详细请下载[Demo](https://codeload.github.com/EoniJJ/PasswordView/zip/master)查看
22 | ## Attribute
23 | + passwordLength (密码长度)
24 | + mode (样式切换 underline->下划线 rect->边框)
25 | + passwordPadding (每个密码框间隔)
26 | + borderColor (边框颜色)
27 | + borderWidth(边框大小)
28 | + cursorFlashTime(光标闪烁间隔时间)
29 | + isCursorEnable(是否启用光标)
30 | + cipherTextSize(‘*’号大小)
31 | + cursorColor(光标颜色)
32 | + cipherEnable(是否启用‘*’显示)
33 |
34 | ## License
35 | > The MIT license.
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
15 |
21 |
22 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/arron/passwordviewdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.arron.passwordviewdemo;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | import com.arron.passwordview.PasswordView;
10 |
11 | public class MainActivity extends AppCompatActivity implements PasswordView.PasswordListener, View.OnClickListener {
12 | private String tag = getClass().getSimpleName();
13 | private PasswordView passwordView;
14 | private Button btnChangeMode;
15 |
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 | passwordView = (PasswordView) findViewById(R.id.passwordView);
22 | btnChangeMode = (Button) findViewById(R.id.btn_change_mode);
23 | btnChangeMode.setOnClickListener(this);
24 | passwordView.setPasswordListener(this);
25 | }
26 |
27 | @Override
28 | public void passwordChange(String changeText) {
29 | Log.d(tag, "changeText = " + changeText);
30 | }
31 |
32 | @Override
33 | public void passwordComplete() {
34 | Log.d(tag, "passwordComplete");
35 | }
36 |
37 | @Override
38 | public void keyEnterPress(String password, boolean isComplete) {
39 | Log.d(tag, "password = " + password + " isComplete = " + isComplete);
40 | }
41 |
42 | @Override
43 | public void onClick(View v) {
44 | int viewId = v.getId();
45 | if (viewId == R.id.btn_change_mode) {
46 | passwordView.setMode(passwordView.getMode() == PasswordView.Mode.RECT ? PasswordView.Mode.UNDERLINE : PasswordView.Mode.RECT);
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/passwordview/src/main/java/com/arron/passwordview/PasswordView.java:
--------------------------------------------------------------------------------
1 | package com.arron.passwordview;
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.Rect;
9 | import android.os.Bundle;
10 | import android.os.Parcelable;
11 | import android.text.InputType;
12 | import android.text.TextUtils;
13 | import android.util.AttributeSet;
14 | import android.view.KeyEvent;
15 | import android.view.MotionEvent;
16 | import android.view.View;
17 | import android.view.animation.Animation;
18 | import android.view.inputmethod.EditorInfo;
19 | import android.view.inputmethod.InputConnection;
20 | import android.view.inputmethod.InputMethodManager;
21 |
22 | import java.util.Timer;
23 | import java.util.TimerTask;
24 |
25 | /**
26 | * Created by Arron on 2016/11/21 0021.
27 | * 密码输入框
28 | */
29 |
30 | public class PasswordView extends View {
31 |
32 | private Mode mode; //样式模式
33 | private int passwordLength;//密码个数
34 | private long cursorFlashTime;//光标闪动间隔时间
35 | private int passwordPadding;//每个密码间的间隔
36 | private int passwordSize = dp2px(40);//单个密码大小
37 | private int borderColor;//边框颜色
38 | private int borderWidth;//下划线粗细
39 | private int cursorPosition;//光标位置
40 | private int cursorWidth;//光标粗细
41 | private int cursorHeight;//光标长度
42 | private int cursorColor;//光标颜色
43 | private boolean isCursorShowing;//光标是否正在显示
44 | private boolean isCursorEnable;//是否开启光标
45 | private boolean isInputComplete;//是否输入完毕
46 | private int cipherTextSize;//密文符号大小
47 | private boolean cipherEnable;//是否开启密文
48 | private static String CIPHER_TEXT = "*"; //密文符号
49 | private String[] password;//密码数组
50 | private InputMethodManager inputManager;
51 | private PasswordListener passwordListener;
52 | private Paint paint;
53 | private Timer timer;
54 | private TimerTask timerTask;
55 | public PasswordView(Context context) {
56 | super(context);
57 | }
58 |
59 | public Mode getMode() {
60 | return mode;
61 | }
62 |
63 | public void setMode(Mode mode) {
64 | this.mode = mode;
65 | postInvalidate();
66 | }
67 |
68 | public enum Mode {
69 | /**
70 | * 下划线样式
71 | */
72 | UNDERLINE(0),
73 |
74 | /**
75 | * 边框样式
76 | */
77 | RECT(1);
78 | private int mode;
79 |
80 | Mode(int mode) {
81 | this.mode = mode;
82 | }
83 |
84 | public int getMode() {
85 | return this.mode;
86 | }
87 |
88 | static Mode formMode(int mode) {
89 | for (Mode m : values()) {
90 | if (mode == m.mode) {
91 | return m;
92 | }
93 | }
94 | throw new IllegalArgumentException();
95 | }
96 | }
97 |
98 | /**
99 | * 当前只支持从xml中构建该控件
100 | *
101 | * @param context
102 | * @param attrs
103 | */
104 | public PasswordView(Context context, AttributeSet attrs) {
105 | super(context, attrs);
106 | readAttribute(attrs);
107 | }
108 |
109 | private void readAttribute(AttributeSet attrs) {
110 | if (attrs != null) {
111 | TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.PasswordView);
112 | mode = Mode.formMode(typedArray.getInteger(R.styleable.PasswordView_mode, Mode.UNDERLINE.getMode()));
113 | passwordLength = typedArray.getInteger(R.styleable.PasswordView_passwordLength, 4);
114 | cursorFlashTime = typedArray.getInteger(R.styleable.PasswordView_cursorFlashTime, 500);
115 | borderWidth = typedArray.getDimensionPixelSize(R.styleable.PasswordView_borderWidth, dp2px(3));
116 | borderColor = typedArray.getColor(R.styleable.PasswordView_borderColor, Color.BLACK);
117 | cursorColor = typedArray.getColor(R.styleable.PasswordView_cursorColor, Color.GRAY);
118 | isCursorEnable = typedArray.getBoolean(R.styleable.PasswordView_isCursorEnable, true);
119 | //如果为边框样式,则padding 默认置为0
120 | if (mode == Mode.UNDERLINE) {
121 | passwordPadding = typedArray.getDimensionPixelSize(R.styleable.PasswordView_passwordPadding, dp2px(15));
122 | } else {
123 | passwordPadding = typedArray.getDimensionPixelSize(R.styleable.PasswordView_passwordPadding, 0);
124 | }
125 | cipherEnable = typedArray.getBoolean(R.styleable.PasswordView_cipherEnable, true);
126 | typedArray.recycle();
127 | }
128 | password = new String[passwordLength];
129 | init();
130 | }
131 |
132 | private void init() {
133 | setFocusableInTouchMode(true);
134 | MyKeyListener MyKeyListener = new MyKeyListener();
135 | setOnKeyListener(MyKeyListener);
136 | inputManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
137 | paint = new Paint();
138 | paint.setAntiAlias(true);
139 | timerTask = new TimerTask() {
140 | @Override
141 | public void run() {
142 | isCursorShowing = !isCursorShowing;
143 | postInvalidate();
144 | }
145 | };
146 | timer = new Timer();
147 | }
148 |
149 | @Override
150 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
151 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
152 | int width = 0;
153 | switch (widthMode) {
154 | case MeasureSpec.UNSPECIFIED:
155 | case MeasureSpec.AT_MOST:
156 | //没有指定大小,宽度 = 单个密码框大小 * 密码位数 + 密码框间距 *(密码位数 - 1)
157 | width = passwordSize * passwordLength + passwordPadding * (passwordLength - 1);
158 | break;
159 | case MeasureSpec.EXACTLY:
160 | //指定大小,宽度 = 指定的大小
161 | width = MeasureSpec.getSize(widthMeasureSpec);
162 | //密码框大小等于 (宽度 - 密码框间距 *(密码位数 - 1)) / 密码位数
163 | passwordSize = (width - (passwordPadding * (passwordLength - 1))) / passwordLength;
164 | break;
165 | }
166 | setMeasuredDimension(width, passwordSize);
167 |
168 | }
169 |
170 | @Override
171 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
172 | super.onSizeChanged(w, h, oldw, oldh);
173 | //文本大小
174 | cipherTextSize = passwordSize / 2;
175 | //光标宽度
176 | cursorWidth = dp2px(2);
177 | //光标长度
178 | cursorHeight = passwordSize / 2;
179 | }
180 |
181 | @Override
182 | protected void onDraw(Canvas canvas) {
183 | super.onDraw(canvas);
184 | if (mode == Mode.UNDERLINE) {
185 | //绘制下划线
186 | drawUnderLine(canvas, paint);
187 | } else {
188 | //绘制方框
189 | drawRect(canvas, paint);
190 | }
191 | //绘制光标
192 | drawCursor(canvas, paint);
193 | //绘制密码文本
194 | drawCipherText(canvas, paint);
195 | }
196 |
197 | class MyKeyListener implements OnKeyListener {
198 |
199 | @Override
200 | public boolean onKey(View v, int keyCode, KeyEvent event) {
201 | int action = event.getAction();
202 | if (action == KeyEvent.ACTION_DOWN) {
203 | if (keyCode == KeyEvent.KEYCODE_DEL) {
204 | /**
205 | * 删除操作
206 | */
207 | if (TextUtils.isEmpty(password[0])) {
208 | return true;
209 | }
210 | String deleteText = delete();
211 | if (passwordListener != null && !TextUtils.isEmpty(deleteText)) {
212 | passwordListener.passwordChange(deleteText);
213 | }
214 | postInvalidate();
215 | return true;
216 | }
217 | if (keyCode >= KeyEvent.KEYCODE_0 && keyCode <= KeyEvent.KEYCODE_9) {
218 | /**
219 | * 只支持数字
220 | */
221 | if (isInputComplete) {
222 | return true;
223 | }
224 | String addText = add((keyCode - 7) + "");
225 | if (passwordListener != null && !TextUtils.isEmpty(addText)) {
226 | passwordListener.passwordChange(addText);
227 | }
228 | postInvalidate();
229 | return true;
230 | }
231 | if (keyCode == KeyEvent.KEYCODE_ENTER) {
232 | /**
233 | * 确认键
234 | */
235 | if (passwordListener != null) {
236 | passwordListener.keyEnterPress(getPassword(), isInputComplete);
237 | }
238 | return true;
239 | }
240 | }
241 | return false;
242 | }
243 | }
244 |
245 | /**
246 | * 删除
247 | */
248 | private String delete() {
249 | String deleteText = null;
250 | if (cursorPosition > 0) {
251 | deleteText = password[cursorPosition - 1];
252 | password[cursorPosition - 1] = null;
253 | cursorPosition--;
254 | } else if (cursorPosition == 0) {
255 | deleteText = password[cursorPosition];
256 | password[cursorPosition] = null;
257 | }
258 | isInputComplete = false;
259 | return deleteText;
260 | }
261 |
262 | /**
263 | * 增加
264 | */
265 | private String add(String c) {
266 | String addText = null;
267 | if (cursorPosition < passwordLength) {
268 | addText = c;
269 | password[cursorPosition] = c;
270 | cursorPosition++;
271 | if (cursorPosition == passwordLength) {
272 | isInputComplete = true;
273 | if (passwordListener != null) {
274 | passwordListener.passwordComplete();
275 | }
276 | }
277 | }
278 | return addText;
279 | }
280 |
281 | /**
282 | * 获取密码
283 | */
284 | private String getPassword() {
285 | StringBuffer stringBuffer = new StringBuffer();
286 | for (String c : password) {
287 | if (TextUtils.isEmpty(c)) {
288 | continue;
289 | }
290 | stringBuffer.append(c);
291 | }
292 | return stringBuffer.toString();
293 | }
294 |
295 | /**
296 | * 绘制密码替代符号
297 | *
298 | * @param canvas
299 | * @param paint
300 | */
301 | private void drawCipherText(Canvas canvas, Paint paint) {
302 | //画笔初始化
303 | paint.setColor(Color.GRAY);
304 | paint.setTextSize(cipherTextSize);
305 | paint.setTextAlign(Paint.Align.CENTER);
306 | paint.setStyle(Paint.Style.FILL);
307 | //文字居中的处理
308 | Rect r = new Rect();
309 | canvas.getClipBounds(r);
310 | int cHeight = r.height();
311 | paint.getTextBounds(CIPHER_TEXT, 0, CIPHER_TEXT.length(), r);
312 | float y = cHeight / 2f + r.height() / 2f - r.bottom;
313 |
314 | //根据输入的密码位数,进行for循环绘制
315 | for (int i = 0; i < password.length; i++) {
316 | if (!TextUtils.isEmpty(password[i])) {
317 | // x = paddingLeft + 单个密码框大小/2 + ( 密码框大小 + 密码框间距 ) * i
318 | // y = paddingTop + 文字居中所需偏移量
319 | if (cipherEnable) {
320 | //没有开启明文显示,绘制密码密文
321 | canvas.drawText(CIPHER_TEXT,
322 | (getPaddingLeft() + passwordSize / 2) + (passwordSize + passwordPadding) * i,
323 | getPaddingTop() + y, paint);
324 | } else {
325 | //明文显示,直接绘制密码
326 | canvas.drawText(password[i],
327 | (getPaddingLeft() + passwordSize / 2) + (passwordSize + passwordPadding) * i,
328 | getPaddingTop() + y, paint);
329 | }
330 | }
331 | }
332 | }
333 |
334 | /**
335 | * 绘制光标
336 | *
337 | * @param canvas
338 | * @param paint
339 | */
340 | private void drawCursor(Canvas canvas, Paint paint) {
341 | //画笔初始化
342 | paint.setColor(cursorColor);
343 | paint.setStrokeWidth(cursorWidth);
344 | paint.setStyle(Paint.Style.FILL);
345 | //光标未显示 && 开启光标 && 输入位数未满 && 获得焦点
346 | if (!isCursorShowing && isCursorEnable && !isInputComplete && hasFocus()) {
347 | // 起始点x = paddingLeft + 单个密码框大小 / 2 + (单个密码框大小 + 密码框间距) * 光标下标
348 | // 起始点y = paddingTop + (单个密码框大小 - 光标大小) / 2
349 | // 终止点x = 起始点x
350 | // 终止点y = 起始点y + 光标高度
351 | canvas.drawLine((getPaddingLeft() + passwordSize / 2) + (passwordSize + passwordPadding) * cursorPosition,
352 | getPaddingTop() + (passwordSize - cursorHeight) / 2,
353 | (getPaddingLeft() + passwordSize / 2) + (passwordSize + passwordPadding) * cursorPosition,
354 | getPaddingTop() + (passwordSize + cursorHeight) / 2,
355 | paint);
356 | }
357 | }
358 |
359 | /**
360 | * 绘制密码框下划线
361 | *
362 | * @param canvas
363 | * @param paint
364 | */
365 | private void drawUnderLine(Canvas canvas, Paint paint) {
366 | //画笔初始化
367 | paint.setColor(borderColor);
368 | paint.setStrokeWidth(borderWidth);
369 | paint.setStyle(Paint.Style.FILL);
370 | for (int i = 0; i < passwordLength; i++) {
371 | //根据密码位数for循环绘制直线
372 | // 起始点x为paddingLeft + (单个密码框大小 + 密码框边距) * i , 起始点y为paddingTop + 单个密码框大小
373 | // 终止点x为 起始点x + 单个密码框大小 , 终止点y与起始点一样不变
374 | canvas.drawLine(getPaddingLeft() + (passwordSize + passwordPadding) * i, getPaddingTop() + passwordSize,
375 | getPaddingLeft() + (passwordSize + passwordPadding) * i + passwordSize, getPaddingTop() + passwordSize,
376 | paint);
377 | }
378 | }
379 |
380 | private void drawRect(Canvas canvas, Paint paint) {
381 | paint.setColor(borderColor);
382 | paint.setStrokeWidth(0);
383 | paint.setStyle(Paint.Style.STROKE);
384 | Rect rect;
385 | for (int i = 0; i < passwordLength; i++) {
386 | int startX = getPaddingLeft() + (passwordSize + passwordPadding) * i;
387 | int startY = getPaddingTop();
388 | int stopX = getPaddingLeft() + (passwordSize + passwordPadding) * i + passwordSize;
389 | int stopY = getPaddingTop() + passwordSize;
390 | rect = new Rect(startX, startY, stopX, stopY);
391 | canvas.drawRect(rect, paint);
392 | }
393 | }
394 |
395 | @Override
396 | public boolean onTouchEvent(MotionEvent event) {
397 | if (event.getAction() == MotionEvent.ACTION_DOWN) {
398 | /**
399 | * 弹出软键盘
400 | */
401 | requestFocus();
402 | inputManager.showSoftInput(this, InputMethodManager.SHOW_FORCED);
403 | return true;
404 | }
405 | return super.onTouchEvent(event);
406 | }
407 |
408 | @Override
409 | public void onWindowFocusChanged(boolean hasWindowFocus) {
410 | super.onWindowFocusChanged(hasWindowFocus);
411 | if (!hasWindowFocus) {
412 | inputManager.hideSoftInputFromWindow(this.getWindowToken(), 0);
413 | }
414 | }
415 |
416 | @Override
417 | protected void onAttachedToWindow() {
418 | super.onAttachedToWindow();
419 | //cursorFlashTime为光标闪动的间隔时间
420 | timer.scheduleAtFixedRate(timerTask, 0, cursorFlashTime);
421 | }
422 |
423 | @Override
424 | protected void onDetachedFromWindow() {
425 | super.onDetachedFromWindow();
426 | timer.cancel();
427 | }
428 |
429 | private int dp2px(float dp) {
430 | float scale = getContext().getResources().getDisplayMetrics().density;
431 | return (int) (dp * scale + 0.5f);
432 | }
433 |
434 | private int sp2px(float spValue) {
435 | float fontScale = getContext().getResources().getDisplayMetrics().scaledDensity;
436 | return (int) (spValue * fontScale + 0.5f);
437 | }
438 |
439 | @Override
440 | public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
441 | outAttrs.inputType = InputType.TYPE_CLASS_NUMBER; //输入类型为数字
442 | return super.onCreateInputConnection(outAttrs);
443 | }
444 |
445 | public void setPasswordListener(PasswordListener passwordListener) {
446 | this.passwordListener = passwordListener;
447 | }
448 |
449 | public void setPasswordSize(int passwordSize) {
450 | this.passwordSize = passwordSize;
451 | postInvalidate();
452 | }
453 |
454 | public void setPasswordLength(int passwordLength) {
455 | this.passwordLength = passwordLength;
456 | postInvalidate();
457 | }
458 |
459 | public void setCursorColor(int cursorColor) {
460 | this.cursorColor = cursorColor;
461 | postInvalidate();
462 | }
463 |
464 | public void setCursorEnable(boolean cursorEnable) {
465 | isCursorEnable = cursorEnable;
466 | postInvalidate();
467 | }
468 |
469 | public void setCipherEnable(boolean cipherEnable) {
470 | this.cipherEnable = cipherEnable;
471 | postInvalidate();
472 | }
473 |
474 | /**
475 | * 密码监听者
476 | */
477 | public interface PasswordListener {
478 | /**
479 | * 输入/删除监听
480 | *
481 | * @param changeText 输入/删除的字符
482 | */
483 | void passwordChange(String changeText);
484 |
485 | /**
486 | * 输入完成
487 | */
488 | void passwordComplete();
489 |
490 | /**
491 | * 确认键后的回调
492 | *
493 | * @param password 密码
494 | * @param isComplete 是否达到要求位数
495 | */
496 | void keyEnterPress(String password, boolean isComplete);
497 |
498 | }
499 |
500 | @Override
501 | protected Parcelable onSaveInstanceState() {
502 | Bundle bundle = new Bundle();
503 | bundle.putParcelable("superState", super.onSaveInstanceState());
504 | bundle.putStringArray("password", password);
505 | bundle.putInt("cursorPosition", cursorPosition);
506 | return bundle;
507 | }
508 |
509 | @Override
510 | protected void onRestoreInstanceState(Parcelable state) {
511 | if (state instanceof Bundle) {
512 | Bundle bundle = (Bundle) state;
513 | password = bundle.getStringArray("password");
514 | cursorPosition = bundle.getInt("cursorPosition");
515 | state = bundle.getParcelable("superState");
516 | }
517 | super.onRestoreInstanceState(state);
518 | }
519 | }
520 |
--------------------------------------------------------------------------------