├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── themes.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── values-night
│ │ │ │ └── themes.xml
│ │ │ ├── layout
│ │ │ │ └── activity_main.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── vip
│ │ │ └── input
│ │ │ └── MainActivity.kt
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── vip
│ │ │ └── input
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── vip
│ │ └── input
│ │ └── ExampleInstrumentedTest.kt
├── build.gradle
└── proguard-rules.pro
├── edit
├── .gitignore
├── consumer-rules.pro
├── build.gradle
├── src
│ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── attrs.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── vip
│ │ │ └── edit
│ │ │ └── InputBoxView.kt
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── vip
│ │ │ └── edit
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── vip
│ │ └── edit
│ │ └── ExampleInstrumentedTest.kt
└── proguard-rules.pro
├── .idea
├── .gitignore
├── compiler.xml
├── vcs.xml
├── runConfigurations.xml
├── misc.xml
├── gradle.xml
└── jarRepositories.xml
├── image
├── abner.jpg
├── input_001.jpg
├── input_002.jpg
├── input_003.jpg
├── input_004.jpg
├── input_005.jpg
├── input_006.jpg
├── input_007.jpg
└── input_008.jpg
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.md
├── gradlew
└── assembly.gradle
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/edit/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/edit/consumer-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/image/abner.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AbnerMing888/InputBoxView/HEAD/image/abner.jpg
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = "InputBoxView"
2 | include ':app'
3 | include ':edit'
4 |
--------------------------------------------------------------------------------
/image/input_001.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AbnerMing888/InputBoxView/HEAD/image/input_001.jpg
--------------------------------------------------------------------------------
/image/input_002.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AbnerMing888/InputBoxView/HEAD/image/input_002.jpg
--------------------------------------------------------------------------------
/image/input_003.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AbnerMing888/InputBoxView/HEAD/image/input_003.jpg
--------------------------------------------------------------------------------
/image/input_004.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AbnerMing888/InputBoxView/HEAD/image/input_004.jpg
--------------------------------------------------------------------------------
/image/input_005.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AbnerMing888/InputBoxView/HEAD/image/input_005.jpg
--------------------------------------------------------------------------------
/image/input_006.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AbnerMing888/InputBoxView/HEAD/image/input_006.jpg
--------------------------------------------------------------------------------
/image/input_007.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AbnerMing888/InputBoxView/HEAD/image/input_007.jpg
--------------------------------------------------------------------------------
/image/input_008.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AbnerMing888/InputBoxView/HEAD/image/input_008.jpg
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | InputBoxView
3 |
--------------------------------------------------------------------------------
/edit/build.gradle:
--------------------------------------------------------------------------------
1 | apply from: "${rootProject.rootDir}/assembly.gradle"
2 | project.ext.setAppOrLibDefaultConfig project
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AbnerMing888/InputBoxView/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AbnerMing888/InputBoxView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AbnerMing888/InputBoxView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AbnerMing888/InputBoxView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AbnerMing888/InputBoxView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AbnerMing888/InputBoxView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AbnerMing888/InputBoxView/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/AbnerMing888/InputBoxView/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/AbnerMing888/InputBoxView/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/AbnerMing888/InputBoxView/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/AbnerMing888/InputBoxView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/edit/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply from: "${rootProject.rootDir}/assembly.gradle"
2 | apply plugin: 'kotlin-kapt'
3 | project.ext.setAppDefaultConfig project
4 | dependencies {
5 | implementation "com.vip:edit:1.0.4"
6 | }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Mar 24 10:38:47 CST 2023
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/vip/input/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.vip.input
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/edit/src/test/java/com/vip/edit/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.vip.edit
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/vip/input/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.vip.input
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.vip.input", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/edit/src/androidTest/java/com/vip/edit/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.vip.edit
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.vip.edit.test", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/vip/input/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.vip.input
2 |
3 | import androidx.appcompat.app.AppCompatActivity
4 | import android.os.Bundle
5 | import android.util.Log
6 | import com.vip.edit.InputBoxView
7 |
8 | class MainActivity : AppCompatActivity() {
9 | override fun onCreate(savedInstanceState: Bundle?) {
10 | super.onCreate(savedInstanceState)
11 | setContentView(R.layout.activity_main)
12 | val ibView = findViewById(R.id.ib_view)
13 |
14 | ibView.inputChangeContent {
15 | //输入一个回调一下
16 | Log.e("输入回调======", it)
17 | }
18 | ibView.inputEndResult {
19 | //最终的结果值
20 | Log.e("最终结果======", it)
21 | }
22 |
23 | ibView.showKeyBoard {
24 | //启动自定义键盘
25 | }
26 |
27 | }
28 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/edit/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
25 |
26 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/edit/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # InputBoxView
2 | 一个非常方便的输入框,验证码、密码、车牌输入等等都可使用,非常的方便!
3 |
4 | ## 效果展示
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | ## 快速开始
16 |
17 | 1、在你的根项目下的build.gradle文件下,引入maven。
18 |
19 | ```groovy
20 | allprojects {
21 | repositories {
22 | maven { url "https://gitee.com/AbnerAndroid/almighty/raw/master" }
23 | }
24 | }
25 | ```
26 | 2、在你需要使用的Module中build.gradle文件下,引入依赖。
27 |
28 | ```groovy
29 | dependencies {
30 | implementation 'com.vip:edit:1.0.4'
31 | }
32 | ```
33 | 3、XML引入即可
34 |
35 | ```xml
36 |
50 |
51 | ```
52 |
53 | 4、属性介绍
54 |
55 | | 属性 | 类型 | 概述 |
56 | | ---- | ---- | ---- |
57 | | input_canvas_type | enum | 绘制类型,目前有三种,线(line),矩形(rect),圆角(round),圆角需要结合属性input_radius使用 |
58 | | input_canvas_style | enum | 绘制画笔类型,空心还是实心,空心(stroke),实心(fill),实心和空心(fill_and_stroke) |
59 | | input_background | color | 输入框的背景 |
60 | | input_select_background | color | 输入框的选择背景 |
61 | | input_radius | dimension | 输入框圆角度数 |
62 | | input_line_height | dimension | 输入框下划线的高度 |
63 | | input_length | integer | 输入框的长度 |
64 | | input_spacing | dimension | 输入框的间距 |
65 | | input_text_color | color | 输入框的内容颜色 |
66 | | input_text_size | dimension | 输入框的文字大小 |
67 | | input_text_type | enum | 输入框的文字类型,普通文字(text),星号(asterisk),黑圆圈(round) |
68 | | input_is_cursor | boolean | 输入框是否有光标,默认展示光标 |
69 | | input_cursor_direction | boolean | 输入框光标方向 |
70 | | input_cursor_width | dimension | 输入框光标宽度 |
71 | | input_cursor_color | color | 输入框光标颜色 |
72 | | input_cursor_spacing | color | 输入框光标间距 |
73 | | input_cursor_is_twinkle | boolean | 输入框的光标是否闪烁 |
74 | | input_is_android_keyboard | boolean | 输入框是否弹起原生的软件盘,默认弹起,可以调用自定义的键盘 |
75 | | input_cursor_margin_bottom | dimension | 横向的光标距离底部的距离 |
76 |
77 | 5、方法介绍
78 |
79 | | 方法 | 参数 | 概述 |
80 | | ---- | ---- | ---- |
81 | | clearContent | 无参 | 清空内容,全部清空 |
82 | | deleteContent | 无参 | 逐个删除内容,触发一次,删除一个 |
83 | | setContent | String | 设置内容 |
84 | | hideInputMethod | 无参 | 隐藏软键盘,使用系统软键盘时 |
85 | | showKeyBoard | 回调函数 | 需要弹起自己的软键盘时可以调用 |
86 | | inputChangeContent | 回调函数 | 获取连续的输入结果 |
87 | | inputEndResult | 回调函数 | 获取最终的输入内容,当等于你设置的length时进行回调 |
88 |
89 |
90 | ## 文章介绍
91 |
92 | [一个简单的自定义输入框](https://juejin.cn/post/7216143702125166653)
93 |
94 | ## 欢迎关注作者
95 |
96 | 微信搜索【Android干货铺】,或扫描下面二维码关注,查阅更多技术文章!
97 |
98 |
99 |
100 | ## License
101 |
102 | ```
103 | Copyright (C) AbnerMing, InputBoxView Open Source Project
104 |
105 | Licensed under the Apache License, Version 2.0 (the "License");
106 | you may not use this file except in compliance with the License.
107 | You may obtain a copy of the License at
108 |
109 | http://www.apache.org/licenses/LICENSE-2.0
110 |
111 | Unless required by applicable law or agreed to in writing, software
112 | distributed under the License is distributed on an "AS IS" BASIS,
113 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
114 | See the License for the specific language governing permissions and
115 | limitations under the License.
116 | ```
117 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/assembly.gradle:
--------------------------------------------------------------------------------
1 | project.ext {
2 | //是否允许module单独调试
3 | isModuleDebug = false
4 | isModuleName = ""//单独调试module名
5 | //基础信息配置
6 | compileSdkVersion = 30
7 | buildToolsVersion = "30.0.2"
8 | minSdkVersion = 21
9 | targetSdkVersion = 30
10 | applicationId = "com.vip.input"
11 | versionCode = 1
12 | versionName = "1.0.0"
13 |
14 | //设置app配置
15 | setAppDefaultConfig = {
16 | extension ->
17 | //指定为application
18 | extension.apply plugin: 'com.android.application'
19 | extension.description "app"
20 |
21 | //公共的apply 主要是用于三方库
22 | extension.apply plugin: 'kotlin-android'
23 | extension.apply plugin: 'kotlin-parcelize'
24 | extension.apply plugin: 'kotlin-kapt'
25 |
26 | appImplementation = "app"
27 | //设置项目的android
28 | setAppAndroidConfig extension.android
29 | //设置项目的三方库依赖
30 | setDependencies extension.dependencies
31 |
32 | }
33 |
34 | //设置application 公共的android配置
35 | setAppAndroidConfig = {
36 | extension ->
37 | extension.compileSdkVersion project.ext.compileSdkVersion
38 | extension.buildToolsVersion project.ext.buildToolsVersion
39 | extension.defaultConfig {
40 | applicationId project.ext.applicationId
41 | minSdkVersion project.ext.minSdkVersion
42 | targetSdkVersion project.ext.targetSdkVersion
43 | versionCode project.ext.versionCode
44 | versionName project.ext.versionName
45 | extension.flavorDimensions "versionCode"
46 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
47 |
48 | if (appImplementation == "app") {
49 | ndk {
50 | //设置支持的SO库架构
51 | abiFilters "armeabi-v7a"
52 | }
53 | }
54 | }
55 |
56 | extension.compileOptions {
57 | sourceCompatibility JavaVersion.VERSION_1_8
58 | targetCompatibility JavaVersion.VERSION_1_8
59 | }
60 | extension.kotlinOptions {
61 | jvmTarget = '1.8'
62 | }
63 |
64 | extension.buildFeatures.dataBinding = true
65 | }
66 |
67 | //动态改变,用于单模块调试
68 | setAppOrLibDefaultConfig = {
69 | extension ->
70 |
71 | if (project.ext.isModuleDebug && project.ext.isModuleName == project.name) {
72 | extension.apply plugin: 'com.android.application'
73 | extension.description "app"
74 | } else {
75 | extension.apply plugin: 'com.android.library'
76 | extension.description "lib"
77 |
78 | }
79 | extension.apply plugin: 'kotlin-android'
80 | extension.apply plugin: 'kotlin-parcelize'
81 | extension.apply plugin: 'kotlin-kapt'
82 |
83 | appImplementation = project.name
84 |
85 | //设置通用Android配置
86 | setAppOrLibAndroidConfig extension.android
87 | //设置通用依赖配置
88 | setDependencies extension.dependencies
89 | }
90 |
91 |
92 | //设置lib 公共的android配置
93 | setLibAndroidConfig = {
94 | extension -> //extension 相当于 android 对象
95 | extension.compileSdkVersion project.ext.compileSdkVersion
96 | extension.buildToolsVersion project.ext.buildToolsVersion
97 | extension.defaultConfig {
98 | minSdkVersion project.ext.minSdkVersion
99 | targetSdkVersion project.ext.targetSdkVersion
100 | versionCode project.ext.versionCode
101 | versionName project.ext.versionName
102 |
103 | testInstrumentationRunner "android.support.tablet_test.runner.AndroidJUnitRunner"
104 |
105 | }
106 |
107 | }
108 |
109 | //设置通用的 android配置(可作为project单独调试)
110 | setAppOrLibAndroidConfig = {
111 | extension ->
112 | extension.compileSdkVersion project.ext.compileSdkVersion
113 | extension.buildToolsVersion project.ext.buildToolsVersion
114 | extension.defaultConfig {
115 | minSdkVersion project.ext.minSdkVersion
116 | targetSdkVersion project.ext.targetSdkVersion
117 | versionCode project.ext.versionCode
118 | versionName project.ext.versionName
119 |
120 | extension.flavorDimensions "versionCode"
121 |
122 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
123 | }
124 |
125 | //使用的jdk版本
126 | extension.compileOptions {
127 | sourceCompatibility JavaVersion.VERSION_1_8
128 | targetCompatibility JavaVersion.VERSION_1_8
129 | }
130 | extension.kotlinOptions {
131 | jvmTarget = '1.8'
132 | }
133 |
134 | }
135 |
136 | //设置lib配置(只可以作为lib,不可单独调试)
137 | setLibDefaultConfig = {
138 | extension ->
139 | //library,代表只是单纯的库,不需要依赖其他模块
140 | extension.apply plugin: 'com.android.library'
141 | extension.description "lib"
142 |
143 | setLibAndroidConfig extension.android
144 | setDependencies extension.dependencies
145 | }
146 |
147 | //公用的三方库依赖,慎重引入,主要引入基础库依赖
148 | setDependencies = {
149 | extension ->
150 | extension.implementation fileTree(dir: 'libs', include: ['*.jar'])
151 | extension.implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
152 | extension.implementation 'androidx.core:core-ktx:1.3.1'
153 | extension.implementation 'androidx.appcompat:appcompat:1.3.1'
154 | extension.implementation 'com.google.android.material:material:1.4.0'
155 | extension.implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
156 | extension.testImplementation 'junit:junit:4.+'
157 | extension.androidTestImplementation 'androidx.test.ext:junit:1.1.2'
158 | extension.androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
159 |
160 | }
161 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/edit/src/main/java/com/vip/edit/InputBoxView.kt:
--------------------------------------------------------------------------------
1 | package com.vip.edit
2 |
3 | import android.animation.ValueAnimator
4 | import android.annotation.SuppressLint
5 | import android.content.Context
6 | import android.graphics.Canvas
7 | import android.graphics.Color
8 | import android.graphics.Paint
9 | import android.graphics.Rect
10 | import android.text.InputFilter
11 | import android.text.InputFilter.LengthFilter
12 | import android.text.TextUtils
13 | import android.util.AttributeSet
14 | import android.view.MotionEvent
15 | import android.view.inputmethod.InputMethodManager
16 | import androidx.appcompat.widget.AppCompatEditText
17 |
18 | /**
19 | *AUTHOR:AbnerMing
20 | *DATE:2023/3/14
21 | *INTRODUCE:输入框
22 | */
23 | class InputBoxView : AppCompatEditText {
24 |
25 | private var mInputCanvasStyle = 0//绘制画笔类型,空心还是实心
26 |
27 | private var mInputCanvasType = 0//绘制类型,默认是下滑线
28 |
29 | private var mBackGroundColor = Color.GRAY//背景颜色
30 |
31 | private var mRadius = 5f//圆角,默认为5
32 |
33 | private var mLineHeight = 2f//下划线的高度
34 |
35 | private var mLength: Int = 6//输入框的个数,默认是6个
36 |
37 | private var mIsAndroidKeyBoard = true//是否启用原生的软键盘
38 |
39 | private var mPaint: Paint? = null//画笔
40 |
41 | private var mCursorPaint: Paint? = null//光标画笔
42 |
43 | private var mRectWidth: Float = 0f//矩形的边框
44 |
45 | private var mTextType: Int = 0//输入框类型
46 |
47 | private var mSpacing: Float = 20f//间距
48 |
49 | private var mTextColor = Color.BLACK//内容颜色
50 |
51 | private var mIsCursor = true//是否有光标
52 |
53 | private var mCursorDirection = true//光标方向,默认纵向
54 |
55 | private var mCursorTwinkle = true//光标是否闪烁,默认闪烁
56 |
57 | private var mCursorColor = Color.BLACK//光标的颜色
58 |
59 | private var mCursorWidth = 2f//光标的宽度
60 |
61 | private var mCursorSpacing = 20f//光标的间距
62 |
63 | private var mTextSize = 28f//文字大小
64 |
65 | private var mIsAttachedToWindows: Boolean = false
66 |
67 | private var mSelectBackGroundColor = 0//选中的边框颜色
68 |
69 | private var mCursorMarginBottom = 10f//光标距离底部的距离
70 |
71 | //动画
72 | private val cursorAnim: ValueAnimator = ValueAnimator.ofInt(0, 2).apply {
73 | duration = 1000
74 | repeatCount = ValueAnimator.INFINITE
75 | repeatMode = ValueAnimator.RESTART
76 | }
77 |
78 | constructor(
79 | context: Context
80 | ) : super(context) {
81 | initData(context)
82 | }
83 |
84 |
85 | @SuppressLint("Recycle")
86 | constructor(
87 | context: Context,
88 | attrs: AttributeSet?
89 | ) : super(context, attrs) {
90 | context.obtainStyledAttributes(attrs, R.styleable.InputBoxView)
91 | .apply {
92 | //绘制类型,目前有三种,线,矩形,圆角
93 | mInputCanvasType = getInt(R.styleable.InputBoxView_input_canvas_type, 0)
94 | //绘制画笔类型,空心还是实心
95 | mInputCanvasStyle = getInt(R.styleable.InputBoxView_input_canvas_style, 0)
96 | //输入框的背景颜色
97 | mBackGroundColor =
98 | getColor(R.styleable.InputBoxView_input_background, mBackGroundColor)
99 | //输入框的选中背景颜色
100 | mSelectBackGroundColor =
101 | getColor(
102 | R.styleable.InputBoxView_input_select_background,
103 | mSelectBackGroundColor
104 | )
105 | //输入框的角度
106 | mRadius = getDimension(R.styleable.InputBoxView_input_radius, mRadius)
107 | //下划线的高度
108 | mLineHeight = getDimension(R.styleable.InputBoxView_input_line_height, mLineHeight)
109 | //输入框的长度
110 | mLength = getInt(R.styleable.InputBoxView_input_length, mLength)
111 | //输入框的间距
112 | mSpacing = getDimension(R.styleable.InputBoxView_input_spacing, mSpacing)
113 | //输入框的文字颜色
114 | mTextColor = getColor(R.styleable.InputBoxView_input_text_color, Color.BLACK)
115 | //文字大小
116 | mTextSize = getDimension(R.styleable.InputBoxView_input_text_size, mTextSize)
117 | //输入框类型
118 | mTextType = getInt(R.styleable.InputBoxView_input_text_type, mTextType)
119 | //输入是否有光标
120 | mIsCursor =
121 | getBoolean(R.styleable.InputBoxView_input_is_cursor, true)
122 | //光标方向
123 | mCursorDirection =
124 | getBoolean(R.styleable.InputBoxView_input_cursor_direction, true)
125 | //光标的宽度
126 | mCursorWidth =
127 | getDimension(R.styleable.InputBoxView_input_cursor_width, mCursorWidth)
128 | //光标的压颜色
129 | mCursorColor = getColor(R.styleable.InputBoxView_input_cursor_color, Color.BLACK)
130 | //光标的间距
131 | mCursorSpacing =
132 | getDimension(R.styleable.InputBoxView_input_cursor_spacing, mCursorSpacing)
133 | //输入框的光标是否闪烁
134 | mCursorTwinkle =
135 | getBoolean(R.styleable.InputBoxView_input_cursor_is_twinkle, true)
136 | //输入框是否弹起原生的软件盘
137 | mIsAndroidKeyBoard =
138 | getBoolean(R.styleable.InputBoxView_input_is_android_keyboard, true)
139 | //横向的光标距离底部的距离
140 | mCursorMarginBottom =
141 | getDimension(R.styleable.InputBoxView_input_cursor_spacing, mCursorSpacing)
142 | }
143 |
144 | initData(context)
145 | }
146 |
147 | /**
148 | * AUTHOR:AbnerMing
149 | * INTRODUCE:初始化
150 | */
151 | private fun initData(context: Context) {
152 | setBackgroundColor(Color.TRANSPARENT)//设置背景颜色为透明
153 | filters = arrayOf(LengthFilter(mLength))//设置最大输入
154 | isFocusable = false//默认情况下不获取焦点
155 | setTextColor(Color.TRANSPARENT)//设置颜色透明
156 | isCursorVisible = false//设置无光标
157 |
158 | mPaint = Paint().apply {
159 | style = Paint.Style.FILL
160 | isAntiAlias = true
161 | }
162 | //创建光标画笔
163 | mCursorPaint = Paint().apply {
164 | color = mCursorColor
165 | }
166 |
167 |
168 | }
169 |
170 |
171 | override fun onDraw(canvas: Canvas?) {
172 | super.onDraw(canvas)
173 | //每个输入框的宽度=屏幕的宽-左右的边距-输入框直接的间距/输入框的个数
174 | mRectWidth = (width - mSpacing * (mLength - 1)) / mLength
175 | //绘制输入框
176 | canvasInputBox(canvas)
177 | //绘制内容
178 | drawText(canvas)
179 | if (mIsCursor) {
180 | //绘制光标
181 | drawCursor(canvas)
182 | }
183 |
184 | }
185 |
186 | /**
187 | * AUTHOR:AbnerMing
188 | * INTRODUCE:绘制内容
189 | */
190 | private fun drawText(canvas: Canvas?) {
191 | mPaint!!.apply {
192 | style = Paint.Style.FILL
193 | color = mTextColor//设置内容颜色
194 | textSize = mTextSize
195 | }
196 |
197 | if (!TextUtils.isEmpty(text)) {
198 | for (a in text!!.indices) {
199 | val content = text!![a].toString()
200 | var endContent = content
201 |
202 | if (mTextType == 1) {
203 | endContent = "*"
204 | } else if (mTextType == 2) {
205 | endContent = "●"
206 | }
207 |
208 | val rect = Rect()
209 | mPaint!!.getTextBounds(endContent, 0, content.length, rect)
210 | val w = mPaint!!.measureText(endContent)//获取文字的宽
211 | //获取文字的X坐标
212 | val textX = ((a + 1) * mRectWidth) + a * mSpacing - mRectWidth / 2 - w / 2
213 | val h = rect.height()
214 | //获取文字的Y坐标
215 | var textY = (height + h) / 2.0f
216 | //针对星号做特殊处理
217 | if (mTextType == 1) {
218 | textY += mTextSize / 3
219 | }
220 |
221 | canvas?.drawText(endContent, textX, textY, mPaint!!)
222 | }
223 | }
224 | }
225 |
226 | /**
227 | * AUTHOR:AbnerMing
228 | * INTRODUCE:绘制光标
229 | */
230 | private fun drawCursor(canvas: Canvas?) {
231 | mCursorPaint!!.apply {
232 | strokeWidth = mCursorWidth
233 | isAntiAlias = true
234 | }
235 | //需要根据当前输入的位置,计算光标的绘制位置
236 | val len = text?.length
237 | if (len!! < mLength) {
238 | if (mCursorDirection) {
239 | //纵向光标
240 | val rectWidth = ((len + 1) * mRectWidth) + len * mSpacing - mRectWidth / 2
241 | canvas?.drawLine(
242 | rectWidth,
243 | mCursorSpacing,
244 | rectWidth,
245 | height - mCursorSpacing,
246 | mCursorPaint!!
247 | )
248 | } else {
249 | val endX = ((len + 1) * mRectWidth) + len * mSpacing
250 | val startX = endX - mRectWidth
251 | //横向光标
252 | canvas?.drawLine(
253 | startX + mCursorSpacing,
254 | height.toFloat() - mCursorMarginBottom,//减去距离底部的边距
255 | endX - mCursorSpacing,
256 | height.toFloat() - mCursorMarginBottom,
257 | mCursorPaint!!
258 | )
259 | }
260 | }
261 |
262 | }
263 |
264 | override fun onTouchEvent(event: MotionEvent?): Boolean {
265 |
266 | if (event?.action == MotionEvent.ACTION_DOWN) {
267 | //手指按下
268 | showKeyboard()
269 | text?.let { setSelection(it.length) }
270 | return false
271 | }
272 |
273 | return super.onTouchEvent(event)
274 | }
275 |
276 | /**
277 | * AUTHOR:AbnerMing
278 | * INTRODUCE:弹起软件盘
279 | */
280 | private fun showKeyboard() {
281 | if (mIsAndroidKeyBoard) {
282 | isFocusable = true
283 | isFocusableInTouchMode = true
284 | requestFocus()
285 | val im =
286 | context.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
287 | ?: return
288 | im.showSoftInput(this, InputMethodManager.SHOW_FORCED)
289 | } else {
290 | //启用自定义的软键盘
291 | if (mKeyBoard != null) {
292 | mKeyBoard?.invoke()
293 | }
294 | }
295 | }
296 |
297 |
298 | override fun onTextChanged(
299 | text: CharSequence?,
300 | start: Int,
301 | lengthBefore: Int,
302 | lengthAfter: Int
303 | ) {
304 | super.onTextChanged(text, start, lengthBefore, lengthAfter)
305 | if (!mIsAttachedToWindows) return
306 |
307 | //输入框的光标是否闪烁
308 | if (mCursorTwinkle) {
309 | if ((text?.length ?: 0) >= mLength) {
310 | cursorAnim.takeIf { it.isStarted || it.isRunning }?.end()
311 | } else if (!cursorAnim.isRunning) {
312 | cursorAnim.start()
313 | }
314 | }
315 |
316 | val endContent = text.toString()
317 | if (endContent.length == mLength) {
318 | //一样的话,进行回调
319 | mEndContentResult?.invoke(endContent)
320 | }
321 |
322 | mChangeContent?.invoke(endContent)
323 |
324 | }
325 |
326 |
327 | /**
328 | * AUTHOR:AbnerMing
329 | * INTRODUCE:获取最终的输入结果
330 | */
331 | private var mEndContentResult: ((String) -> Unit?)? = null
332 | fun inputEndResult(block: (result: String) -> Unit) {
333 | mEndContentResult = block
334 | }
335 |
336 | /**
337 | * AUTHOR:AbnerMing
338 | * INTRODUCE:获取连续的输入结果
339 | */
340 | private var mChangeContent: ((String) -> Unit?)? = null
341 | fun inputChangeContent(block: (result: String) -> Unit) {
342 | mChangeContent = block
343 | }
344 |
345 | /**
346 | * AUTHOR:AbnerMing
347 | * INTRODUCE:显示自己定义的软件盘
348 | */
349 | private var mKeyBoard: (() -> Unit?)? = null
350 | fun showKeyBoard(block: () -> Unit) {
351 | mKeyBoard = block
352 | }
353 |
354 |
355 | /**
356 | * AUTHOR:AbnerMing
357 | * INTRODUCE:绘制输入框
358 | */
359 | private fun canvasInputBox(canvas: Canvas?) {
360 | mPaint!!.apply {
361 | color = mBackGroundColor//设置背景颜色
362 | strokeCap = Paint.Cap.ROUND//圆角线
363 | }
364 |
365 |
366 | for (a in 0 until mLength) {
367 |
368 | val textLength = text.toString().length//当前输入的长度
369 |
370 | if (mSelectBackGroundColor != 0) {
371 | var paintStyle = Paint.Style.STROKE
372 | when (mInputCanvasStyle) {
373 | 0 -> {
374 | paintStyle = Paint.Style.STROKE
375 | }
376 | 1 -> {
377 | paintStyle = Paint.Style.FILL
378 | }
379 | 2 -> {
380 | paintStyle = Paint.Style.FILL_AND_STROKE
381 | }
382 | }
383 | if (a == textLength) {
384 | mPaint!!.apply {
385 | style = paintStyle
386 | color = mSelectBackGroundColor//设置选中背景颜色
387 | }
388 | } else {
389 | mPaint!!.apply {
390 | style = paintStyle
391 | color = mBackGroundColor//设置背景颜色
392 | }
393 |
394 | }
395 | }
396 |
397 | val left = a * mRectWidth + a * mSpacing
398 | val top = 0f
399 | val right = (a + 1) * mRectWidth + a * mSpacing
400 | val bottom = height.toFloat()
401 |
402 | when (mInputCanvasType) {
403 | 0 -> {
404 | //绘制下划线
405 | canvas?.drawRoundRect(
406 | left,
407 | bottom - mLineHeight,
408 | right,
409 | bottom,
410 | mRadius,
411 | mRadius,
412 | mPaint!!
413 | )
414 | }
415 | 1 -> {
416 | //绘制矩形
417 | canvas?.drawRect(left, top, right, bottom, mPaint!!)
418 | }
419 | 2 -> {
420 | //绘制圆角矩形
421 | canvas?.drawRoundRect(left, top, right, bottom, mRadius, mRadius, mPaint!!)
422 | }
423 | }
424 | }
425 | }
426 |
427 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
428 | super.onMeasure(widthMeasureSpec, heightMeasureSpec)
429 | val heightMode = MeasureSpec.getMode(heightMeasureSpec)
430 | var height = measuredHeight
431 | if (heightMode == MeasureSpec.AT_MOST) {
432 | height = 96
433 | }
434 | setMeasuredDimension(measuredWidth, height)
435 | }
436 |
437 | override fun onAttachedToWindow() {
438 | super.onAttachedToWindow()
439 | mIsAttachedToWindows = true
440 | if (mCursorTwinkle) {
441 | //不在运行,开启动画
442 | if (!cursorAnim.isRunning) {
443 | cursorAnim.start()
444 | }
445 | cursorAnim.addUpdateListener {
446 | val v = it.animatedValue as Int
447 | if (v == 0) {
448 | mCursorPaint?.color = Color.TRANSPARENT
449 | } else {
450 | mCursorPaint?.color = mCursorColor
451 | }
452 | postInvalidate()
453 | }
454 | }
455 |
456 | }
457 |
458 | override fun onDetachedFromWindow() {
459 | super.onDetachedFromWindow()
460 | mIsAttachedToWindows = false
461 | if (mCursorTwinkle) {
462 | if (cursorAnim.isRunning || cursorAnim.isStarted) {
463 | cursorAnim.end()
464 | }
465 | cursorAnim.removeAllUpdateListeners()
466 | }
467 |
468 | hideInputMethod()
469 |
470 | }
471 |
472 |
473 | /**
474 | * AUTHOR:AbnerMing
475 | * INTRODUCE:隐藏软件盘
476 | */
477 | fun hideInputMethod() {
478 | if (mIsAndroidKeyBoard) {
479 | val imm: InputMethodManager =
480 | context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
481 | imm.hideSoftInputFromWindow(windowToken, 0) //强制隐藏
482 | }
483 | }
484 |
485 |
486 | /**
487 | * AUTHOR:AbnerMing
488 | * INTRODUCE:清空内容
489 | */
490 | fun clearContent() {
491 | mEndContent = ""
492 | setText("")
493 | }
494 |
495 | /**
496 | * AUTHOR:AbnerMing
497 | * INTRODUCE:设置内容
498 | */
499 | private var mEndContent = ""
500 | fun setContent(content: String) {
501 | if (mEndContent.length < mLength) {
502 | mEndContent += content
503 | setText(mEndContent)
504 | }
505 |
506 | }
507 |
508 | /**
509 | * AUTHOR:AbnerMing
510 | * INTRODUCE:逐个删除
511 | */
512 | fun deleteContent() {
513 | if (!TextUtils.isEmpty(mEndContent)) {
514 | mEndContent = mEndContent.substring(0, mEndContent.length - 1)
515 | setText(mEndContent)
516 | }
517 | }
518 |
519 | }
--------------------------------------------------------------------------------