Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 8 additions & 29 deletions SplitEditTextView/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 29
buildToolsVersion "29.0.3"

compileSdk = rootProject.ext.compileSdk
namespace = "com.al.open"
defaultConfig {
minSdkVersion 21
targetSdkVersion 29
minSdk = rootProject.ext.minSdk
targetSdk = rootProject.ext.targetSdk
versionCode 1
versionName "1.0"

Expand All @@ -24,28 +23,8 @@ android {

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.appcompat:appcompat:1.7.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
}

apply plugin: 'com.novoda.bintray-release'

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.novoda:bintray-release:0.9.1'
}
}

publish {
userOrg = 'keeplearn'
groupId = 'com.open.keeplearn'
artifactId = 'SplitEditTextView'
publishVersion = '1.2.3'
desc = 'A Library Of Android UI.'
website = 'https://github.com/Chen-keeplearn/SplitEditTextView'
}
6 changes: 1 addition & 5 deletions SplitEditTextView/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.al.open">

/
</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
34 changes: 31 additions & 3 deletions SplitEditTextView/src/main/java/com/al/open/SplitEditTextView.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.InputFilter;
import android.util.AttributeSet;
Expand All @@ -18,7 +22,7 @@

import java.lang.reflect.Field;

public class SplitEditTextView extends AppCompatEditText{
public class SplitEditTextView extends AppCompatEditText {
//密码显示模式:隐藏密码,显示圆形
public static final int CONTENT_SHOW_MODE_PASSWORD = 1;
//密码显示模式:显示密码
Expand All @@ -36,6 +40,7 @@ public class SplitEditTextView extends AppCompatEditText{
private Paint mPaintContent;
private Paint mPaintBorder;
private Paint mPaintUnderline;
private Paint inputBackgroundPaint;
//边框大小
private Float mBorderSize;
//边框颜色
Expand All @@ -56,6 +61,8 @@ public class SplitEditTextView extends AppCompatEditText{
private float mSpaceSize;
//输入框样式
private int mInputBoxStyle;
private Drawable mInputBoxBackground;
private Drawable[] mInputBoxBackgroundDrawables;
//字体大小
private float mTextSize;
//字体颜色
Expand All @@ -74,6 +81,7 @@ public class SplitEditTextView extends AppCompatEditText{
private int mUnderlineFocusColor;//下划线输入样式下,输入框获取焦点时下划线颜色
private int mUnderlineNormalColor;//下划线输入样式下,下划线颜色


public SplitEditTextView(Context context) {
this(context, null);
}
Expand Down Expand Up @@ -103,6 +111,7 @@ private void initAttrs(Context c, AttributeSet attrs) {
mContentNumber = array.getInt(R.styleable.SplitEditTextView_contentNumber, 6);
mContentShowMode = array.getInteger(R.styleable.SplitEditTextView_contentShowMode, CONTENT_SHOW_MODE_PASSWORD);
mInputBoxStyle = array.getInteger(R.styleable.SplitEditTextView_inputBoxStyle, INPUT_BOX_STYLE_CONNECT);
mInputBoxBackground = array.getDrawable(R.styleable.SplitEditTextView_inputBoxBackground);
mSpaceSize = array.getDimension(R.styleable.SplitEditTextView_spaceSize, dp2px(10f));
mTextSize = array.getDimension(R.styleable.SplitEditTextView_android_textSize, sp2px(16f));
mTextColor = array.getColor(R.styleable.SplitEditTextView_android_textColor, Color.BLACK);
Expand Down Expand Up @@ -139,6 +148,12 @@ private void init() {
mPaintUnderline.setStrokeWidth(mBorderSize);
mPaintUnderline.setColor(mUnderlineNormalColor);

if (mInputBoxBackground != null && mInputBoxBackground.getConstantState() != null) {
mInputBoxBackgroundDrawables = new Drawable[mContentNumber];
for (int i = 0; i < mContentNumber; i++) {
mInputBoxBackgroundDrawables[i] = mInputBoxBackground.getConstantState().newDrawable().mutate();
}
}

//避免onDraw里面重复创建RectF对象,先初始化RectF对象,在绘制时调用set()方法
//单个输入框样式的RectF
Expand Down Expand Up @@ -365,12 +380,25 @@ private void drawUnderlineStyle(Canvas canvas) {
* 所以算上边框 +(i+1)*2*mBorderSize
*/
private void drawSingleStyle(Canvas canvas) {
float contentItemWidth = getContentItemWidth();
for (int i = 0; i < mContentNumber; i++) {
mRectFSingleBox.setEmpty();
float left = i * getContentItemWidth() + i * mSpaceSize + i * mBorderSize * 2 + mBorderSize / 2;
float right = i * mSpaceSize + (i + 1) * getContentItemWidth() + (i + 1) * 2 * mBorderSize - mBorderSize / 2;
float left = i * contentItemWidth + i * mSpaceSize + i * mBorderSize * 2 + mBorderSize / 2;
float right = left + contentItemWidth;
//为避免在onDraw里面创建RectF对象,这里使用rectF.set()方法
mRectFSingleBox.set(left, mBorderSize / 2, right, getHeight() - mBorderSize / 2);
if (mInputBoxBackgroundDrawables != null
&& mInputBoxBackgroundDrawables.length == mContentNumber
&& mInputBoxBackgroundDrawables[i] != null) {
// draw background image
// Draw the rounded rectangle with the background image
mInputBoxBackgroundDrawables[i].setBounds(
(int) mRectFSingleBox.left,
(int) mRectFSingleBox.top,
(int) mRectFSingleBox.right,
(int) mRectFSingleBox.bottom);
mInputBoxBackgroundDrawables[i].draw(canvas);
}
canvas.drawRoundRect(mRectFSingleBox, mCornerSize, mCornerSize, mPaintBorder);
}
}
Expand Down
1 change: 1 addition & 0 deletions SplitEditTextView/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<!--下划线样式-->
<enum name="underline" value="3" />
</attr>
<attr name="inputBoxBackground" format="reference" />
<!--密码字体颜色-->
<attr name="android:textColor" />
<!--密码字体大小-->
Expand Down
11 changes: 7 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = "1.3.72"
ext.kotlin_version = '2.0.0'
ext.compileSdk = 35
ext.minSdk = 21
ext.targetSdk = 34
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:8.7.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -18,7 +21,7 @@ buildscript {
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand Down
35 changes: 20 additions & 15 deletions demo/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 29
buildToolsVersion "29.0.3"

compileSdk = rootProject.ext.compileSdk
namespace = "com.al.split_edit_text_view"
defaultConfig {
minSdk = rootProject.ext.minSdk
targetSdk = rootProject.ext.targetSdk
applicationId "com.al.split_edit_text_view"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"

Expand All @@ -22,19 +20,26 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//implementation project(path: ':SplitEditTextView')
implementation 'com.open.keeplearn:SplitEditTextView:1.2.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.core:core-ktx:1.15.0'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.2.1'
implementation project(path: ':SplitEditTextView')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
implementation 'com.google.android.material:material:1.12.0'

}
6 changes: 3 additions & 3 deletions demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.al.split_edit_text_view">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
Expand All @@ -9,7 +8,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Loading