├── .gitignore ├── .idea ├── caches │ └── build_file_checksums.ser ├── gradle.xml └── misc.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── infideap │ │ └── blockedittextexample │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── infideap │ │ │ └── blockedittextexample │ │ │ └── MainActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.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 │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── infideap │ └── blockedittextexample │ └── ExampleUnitTest.java ├── blockedittext ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── infideap │ │ └── blockedittext │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── infideap │ │ │ └── blockedittext │ │ │ ├── BlockEditText.kt │ │ │ └── CardPrefix.kt │ └── res │ │ ├── drawable │ │ ├── ic_amex.xml │ │ ├── ic_mastercard.xml │ │ └── ic_visa.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── infideap │ └── blockedittext │ └── ExampleUnitTest.java ├── build.gradle ├── device-2018-05-29-233023.png ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/libraries 5 | /.idea/modules.xml 6 | /.idea/workspace.xml 7 | .DS_Store 8 | /build 9 | /captures 10 | .externalNativeBuild 11 | /.idea/ -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiburagi/BlockEditText/794dfe900ee4f7feaea6a2b6cd059332f440fc96/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 20 | 21 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2018 Shiburagi 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BlockEditText 2 | 3 | [ ![Download](https://api.bintray.com/packages/infideap2/Block-EditText/com.infideap.blockedittext/images/download.svg) ](https://bintray.com/infideap2/Block-EditText/com.infideap.blockedittext/_latestVersion) 4 | 5 | Block EditText is a library provide an input view present in multiple block style that common use in **TAC** or **credit card field**. 6 | 7 | ![Alt Text](https://raw.githubusercontent.com/shiburagi/BlockEditText/preview/preview2.gif) 8 | 9 | Android 14.0+ support 10 | 11 | --- 12 | 13 | Buy Me a Coffee at ko-fi.com 14 | [![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=D9JKYQL8452AL) 15 | 16 | ## Including In Your Project 17 | If you are a Maven user you can easily include the library by specifying it as 18 | a dependency: 19 | 20 | #### Gradle 21 | ```groovy 22 | repositories { 23 | maven{ 24 | maven { url 'https://jitpack.io' } 25 | } 26 | } 27 | ``` 28 | ```groovy 29 | dependencies { 30 | implementation 'com.github.shiburagi:BlockEditText:v0.2' 31 | } 32 | ``` 33 | 34 | **or**, 35 | you can include it by **download this project** and **import /blockedittext** as **module**. 36 | 37 | ## How to use 38 | **Creating the layout** 39 | ### TAC 40 | ```xml 41 | 52 | 53 | ``` 54 | 55 | ### Credit Card 56 | ```xml 57 | 67 | ``` 68 | 69 | 70 | ### Customize 71 | ```java 72 | amexEditText.setNumberOfBlock(3); 73 | amexEditText.setDefaultLength(4); 74 | amexEditText.setLengthAt(1,6); 75 | 76 | amexEditText.setHint("Amex"); 77 | amexEditText.setText("1234567890"); 78 | amexEditText.getText(); 79 | 80 | amexEditText.setTextSize(16); 81 | amexEditText.setHintTextSize(16); 82 | amexEditText.setSeparatorTextSize(16); 83 | 84 | amexEditText.setSeparatorCharacter('-'); 85 | amexEditText.setSeparatorPadding(8); 86 | 87 | amexEditText.setInputType(InputType.TYPE_CLASS_NUMBER); 88 | 89 | amexEditText.setTextAppearance(android.support.v7.appcompat.R.style.Base_TextAppearance_AppCompat_Medium); 90 | amexEditText.setHintTextAppearance(android.support.v7.appcompat.R.style.Base_TextAppearance_AppCompat_Medium); 91 | amexEditText.setSeparatorTextAppearance(android.support.v7.appcompat.R.style.Base_TextAppearance_AppCompat_Medium); 92 | 93 | amexEditText.setEdiTextBackground(ContextCompat.getDrawable(this, R.drawable.selector_edittext_round_border_line)); 94 | 95 | amexEditText.setSelection(0); 96 | amexEditText.setShiftPosition(true); 97 | 98 | amexEditText.addCardPrefix(CardPrefix.amex(this)) 99 | amexEditText.addCardPrefix(CardPrefix.amex(amexDrawable)) 100 | amexEditText.addCardPrefix(new CardPrefix(this, R.drawable.ic_amex, "34")) 101 | amexEditText.addCardPrefix(new CardPrefix(amexDrawable, "34")) 102 | 103 | ``` 104 | 105 | ### Listener 106 | 107 | ```java 108 | amexEditText.setTextChangedListener(TextWatcher watcher) 109 | amexEditText.setOnCardPrefixListener(OnCardPrefixListener listener) 110 | ``` 111 | 112 | 113 | ## Contact 114 | For any enquiries, please send an email to tr32010@gmail.com. 115 | 116 | ## License 117 | 118 | Copyright 2018 Shiburagi 119 | 120 | Licensed under the Apache License, Version 2.0 (the "License"); 121 | you may not use this file except in compliance with the License. 122 | You may obtain a copy of the License at 123 | 124 | http://www.apache.org/licenses/LICENSE-2.0 125 | 126 | Unless required by applicable law or agreed to in writing, software 127 | distributed under the License is distributed on an "AS IS" BASIS, 128 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 129 | See the License for the specific language governing permissions and 130 | limitations under the License. 131 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | 4 | android { 5 | compileSdkVersion 30 6 | defaultConfig { 7 | applicationId "com.infideap.blockedittextexample" 8 | minSdkVersion 15 9 | targetSdkVersion 30 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' 13 | } 14 | buildFeatures { 15 | dataBinding true 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | implementation fileTree(include: ['*.jar'], dir: 'libs') 28 | implementation 'androidx.appcompat:appcompat:1.2.0' 29 | implementation 'androidx.constraintlayout:constraintlayout:2.0.1' 30 | testImplementation 'junit:junit:4.12' 31 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 32 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 33 | debugImplementation project(':blockedittext') 34 | releaseImplementation 'com.infideap.blockedittext:block-edittext:0.3.1' 35 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 36 | implementation 'com.app.infideap.stylishwidget:stylish-widget:1.4.2-alpha', { 37 | exclude group: 'com.android.support', module: 'support-annotations' 38 | exclude group: 'com.android.support', module: 'support-v4' 39 | exclude group: 'com.android.support', module: 'design' 40 | exclude group: 'com.android.support', module: 'recyclerview-v7' 41 | } 42 | } 43 | repositories { 44 | mavenCentral() 45 | } 46 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/infideap/blockedittextexample/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.infideap.blockedittextexample; 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 | * Instrumented 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() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.infideap.blockedittext", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/infideap/blockedittextexample/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.infideap.blockedittextexample 2 | 3 | import android.content.res.ColorStateList 4 | import android.graphics.Color 5 | import android.graphics.Typeface 6 | import android.os.Bundle 7 | import androidx.appcompat.app.AppCompatActivity 8 | import android.text.Editable 9 | import android.text.InputType 10 | import android.text.TextWatcher 11 | import androidx.core.content.ContextCompat 12 | import androidx.databinding.DataBindingUtil 13 | import com.infideap.blockedittext.BlockEditText 14 | import com.infideap.blockedittext.CardPrefix 15 | import com.infideap.blockedittextexample.databinding.ActivityMainBinding 16 | 17 | class MainActivity : AppCompatActivity() { 18 | override fun onCreate(savedInstanceState: Bundle?) { 19 | super.onCreate(savedInstanceState) 20 | val binding: ActivityMainBinding = DataBindingUtil.setContentView( 21 | this, R.layout.activity_main) 22 | val amexEditText: BlockEditText = findViewById(R.id.blockEditText_amex) 23 | amexEditText.setNumberOfBlock(3) 24 | amexEditText.setDefaultLength(4) 25 | amexEditText.setLengthAt(1, 6) 26 | amexEditText.setLengthAt(2, 5) 27 | amexEditText.setHint("Amex") 28 | amexEditText.setSeparatorCharacter('-') 29 | amexEditText.setInputType(InputType.TYPE_CLASS_NUMBER) 30 | amexEditText.setEdiTextBackground(ContextCompat.getDrawable(this, R.drawable.selector_edittext_round_border_line)) 31 | amexEditText.setTextChangedListener(object : TextWatcher { 32 | override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {} 33 | override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { 34 | if (s.length >= amexEditText.maxLength) { 35 | amexEditText.setBackgroundColor(Color.GREEN) 36 | } else amexEditText.setBackgroundColor(Color.TRANSPARENT) 37 | } 38 | 39 | override fun afterTextChanged(s: Editable) {} 40 | }) 41 | val cardEditText: BlockEditText = findViewById(R.id.blockEditText_card) 42 | cardEditText.addCardPrefix(CardPrefix.amex(this)) 43 | val icNumberEditText: BlockEditText = findViewById(R.id.blockEditText_ic_number) 44 | // Data Binding 45 | binding.idNumber = "980201-01-1234" 46 | binding.numberOfBlockId = 3 47 | 48 | icNumberEditText.setDefaultLength(6) 49 | icNumberEditText.setLengthAt(1, 2) 50 | icNumberEditText.setLengthAt(2, 4) 51 | 52 | 53 | val customFontEditText: BlockEditText = findViewById(R.id.blockEditText_custom_font) 54 | // customFontEditText.setTypeface(Typeface.createFromAsset(resources.assets, "Quicksand-Light.ttf")) 55 | 56 | val customTextColorEditText: BlockEditText = findViewById(R.id.blockEditText_custom_text_color) 57 | // customTextColorEditText.setHintTextColor(Color.BLACK) 58 | customTextColorEditText.setInputTextColor(ColorStateList( 59 | arrayOf( 60 | intArrayOf(android.R.attr.state_focused), 61 | intArrayOf()), 62 | intArrayOf(ContextCompat.getColor(this,R.color.colorPrimary), Color.BLACK), 63 | )) 64 | 65 | 66 | } 67 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/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 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 16 | 17 | 20 | 21 | 22 | 28 | 29 | 33 | 34 | 44 | 45 | 56 | 57 | 68 | 69 | 70 | 81 | 84 | 85 | 86 | 92 | 93 | 105 | 106 | 112 | 113 | 127 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 150 | 151 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiburagi/BlockEditText/794dfe900ee4f7feaea6a2b6cd059332f440fc96/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiburagi/BlockEditText/794dfe900ee4f7feaea6a2b6cd059332f440fc96/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiburagi/BlockEditText/794dfe900ee4f7feaea6a2b6cd059332f440fc96/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiburagi/BlockEditText/794dfe900ee4f7feaea6a2b6cd059332f440fc96/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiburagi/BlockEditText/794dfe900ee4f7feaea6a2b6cd059332f440fc96/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiburagi/BlockEditText/794dfe900ee4f7feaea6a2b6cd059332f440fc96/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiburagi/BlockEditText/794dfe900ee4f7feaea6a2b6cd059332f440fc96/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiburagi/BlockEditText/794dfe900ee4f7feaea6a2b6cd059332f440fc96/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiburagi/BlockEditText/794dfe900ee4f7feaea6a2b6cd059332f440fc96/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiburagi/BlockEditText/794dfe900ee4f7feaea6a2b6cd059332f440fc96/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #9b59b6 4 | #8e44ad 5 | #e67e22 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | BlockEditText 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/test/java/com/infideap/blockedittextexample/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.infideap.blockedittextexample; 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() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /blockedittext/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /blockedittext/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-kapt' 4 | apply plugin: 'maven-publish' 5 | android { 6 | compileSdkVersion 30 7 | 8 | 9 | defaultConfig { 10 | minSdkVersion 14 11 | targetSdkVersion 30 12 | versionCode 1 13 | versionName "1.0" 14 | 15 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' 16 | 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | 25 | } 26 | afterEvaluate { 27 | def publish_groupId = 'com.infideap.blockedittext' 28 | def publish_artifactId = 'block-edittext' 29 | def publish_version = '0.3.1' 30 | publishing { 31 | publications { 32 | // Creates a Maven publication called "release". 33 | release(MavenPublication) { 34 | // Applies the component for the release build variant. 35 | from components.release 36 | 37 | // You can then customize attributes of the publication as shown below. 38 | groupId = publish_groupId 39 | artifactId = publish_artifactId 40 | version = publish_version 41 | } 42 | // Creates a Maven publication called “debug”. 43 | debug(MavenPublication) { 44 | // Applies the component for the debug build variant. 45 | from components.debug 46 | 47 | groupId = publish_groupId 48 | artifactId = publish_artifactId 49 | version = publish_version 50 | } 51 | } 52 | } 53 | } 54 | dependencies { 55 | implementation fileTree(dir: 'libs', include: ['*.jar']) 56 | implementation "androidx.core:core-ktx:1.3.2" 57 | implementation 'androidx.appcompat:appcompat:1.2.0' 58 | 59 | implementation 'com.app.infideap.stylishwidget:stylish-widget:1.3.9', { 60 | exclude group: 'com.android.support', module: 'support-annotations' 61 | exclude group: 'com.android.support', module: 'support-v4' 62 | exclude group: 'com.android.support', module: 'design' 63 | exclude group: 'com.android.support', module: 'recyclerview-v7' 64 | } 65 | testImplementation 'junit:junit:4.12' 66 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 67 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 68 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 69 | } 70 | repositories { 71 | mavenCentral() 72 | } -------------------------------------------------------------------------------- /blockedittext/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /blockedittext/src/androidTest/java/com/infideap/blockedittext/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.infideap.blockedittext; 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 | * Instrumented 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() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.infideap.blockedittext.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /blockedittext/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /blockedittext/src/main/java/com/infideap/blockedittext/BlockEditText.kt: -------------------------------------------------------------------------------- 1 | package com.infideap.blockedittext 2 | 3 | import android.content.Context 4 | import android.content.res.ColorStateList 5 | import android.graphics.Typeface 6 | import android.graphics.drawable.Drawable 7 | import android.os.Build 8 | import android.text.* 9 | import android.util.AttributeSet 10 | import android.util.Log 11 | import android.util.SparseArray 12 | import android.util.SparseIntArray 13 | import android.view.* 14 | import android.view.View.OnFocusChangeListener 15 | import android.view.View.OnKeyListener 16 | import android.widget.EditText 17 | import android.widget.FrameLayout 18 | import android.widget.ImageView 19 | import android.widget.LinearLayout 20 | import androidx.annotation.RequiresApi 21 | import androidx.core.content.ContextCompat 22 | import androidx.core.util.keyIterator 23 | import androidx.core.view.ViewCompat 24 | import com.app.infideap.stylishwidget.util.Utils 25 | import com.app.infideap.stylishwidget.view.AEditText 26 | import com.app.infideap.stylishwidget.view.ATextView 27 | import java.util.* 28 | 29 | class BlockEditText : FrameLayout { 30 | private var noOfBlock = 1 31 | private var linearLayout: LinearLayout? = null 32 | private var blockLinearLayout: LinearLayout? = null 33 | private val lengths = SparseIntArray() 34 | private var lengthUsed: SparseIntArray? = null 35 | private var defaultLength = 1 36 | private var hintTextView: ATextView? = null 37 | private var inputType = InputType.TYPE_CLASS_TEXT 38 | private var inputTextColor: ColorStateList? = null 39 | private var typeface: Typeface? = null 40 | private var watcher: TextWatcher? = null 41 | private var callback: ActionMode.Callback? = null 42 | private val editTexts = SparseArray() 43 | private var separator: Char? = null 44 | private var separatorTextAppearance = androidx.appcompat.R.style.Base_TextAppearance_AppCompat_Medium 45 | private var separatorPadding = 16 46 | private var separatorTextSize = 0f 47 | private var textSize = 0f 48 | private var hintTextSize = 0f 49 | private var textAppearance = androidx.appcompat.R.style.Base_TextAppearance_AppCompat_Medium 50 | private var hintTextAppearance = androidx.appcompat.R.style.Base_TextAppearance_AppCompat_Medium 51 | private var editTextBackground: Drawable? = null 52 | private var hint: String? = null 53 | private var hintColorDefault: ColorStateList? = null 54 | private var hintColorFocus: ColorStateList? = null 55 | private var shiftPosition = true 56 | private val cardPrefixes: MutableList = ArrayList() 57 | private var iconImageView: ImageView? = null 58 | private var cardPrefixListener: OnCardPrefixListener? = null 59 | private var cardIconSize = Utils.convertDpToPixel(48f).toInt() 60 | private var isEnabled = true 61 | private var isShowCardIcon = false 62 | private var editTextStyle = 0 63 | 64 | constructor(context: Context) : super(context) { 65 | init(context, null) 66 | } 67 | 68 | constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) { 69 | init(context, attrs) 70 | } 71 | 72 | constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { 73 | init(context, attrs) 74 | } 75 | 76 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) 77 | constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) { 78 | init(context, attrs) 79 | } 80 | 81 | private fun init(context: Context, attrs: AttributeSet?) { 82 | lengthUsed = lengths 83 | linearLayout = LinearLayout(getContext()) 84 | linearLayout!!.orientation = LinearLayout.VERTICAL 85 | linearLayout!!.layoutParams = createWidthMatchParentLayoutParams() 86 | blockLinearLayout = LinearLayout(getContext()) 87 | blockLinearLayout!!.orientation = LinearLayout.HORIZONTAL 88 | blockLinearLayout!!.layoutParams = createWidthMatchParentLayoutParams() 89 | linearLayout!!.addView(blockLinearLayout) 90 | addView(linearLayout) 91 | val a = context.obtainStyledAttributes(attrs, R.styleable.BlockEditText) 92 | editTextBackground = a.getDrawable(R.styleable.BlockEditText_editTextBackground) 93 | hint = a.getString(R.styleable.BlockEditText_hint) 94 | setHint(hint) 95 | 96 | 97 | var tempStr = a.getString(R.styleable.BlockEditText_separatorCharacter) 98 | if (!TextUtils.isEmpty(tempStr)) { 99 | separator = tempStr!![0] 100 | } 101 | noOfBlock = a.getInt( 102 | R.styleable.BlockEditText_numberOfBlock, 103 | noOfBlock 104 | ) 105 | defaultLength = a.getInt( 106 | R.styleable.BlockEditText_defaultLength, 107 | defaultLength 108 | ) 109 | textAppearance = a.getResourceId( 110 | R.styleable.BlockEditText_hintTextAppearance, 111 | textAppearance 112 | ) 113 | hintTextAppearance = a.getResourceId( 114 | R.styleable.BlockEditText_hintTextAppearance, 115 | hintTextAppearance 116 | ) 117 | separatorTextAppearance = a.getResourceId( 118 | R.styleable.BlockEditText_separatorTextAppearance, 119 | separatorTextAppearance 120 | ) 121 | textSize = a.getDimension( 122 | R.styleable.BlockEditText_textSize, 123 | textSize 124 | ) 125 | hintTextSize = a.getDimension( 126 | R.styleable.BlockEditText_hintTextSize, 127 | hintTextSize 128 | ) 129 | separatorTextSize = a.getDimension( 130 | R.styleable.BlockEditText_separatorTextSize, 131 | separatorTextSize 132 | ) 133 | cardIconSize = a.getDimensionPixelOffset( 134 | R.styleable.BlockEditText_cardIconSize, 135 | cardIconSize 136 | ) 137 | separatorPadding = a.getDimensionPixelOffset( 138 | R.styleable.BlockEditText_hintTextSize, 139 | separatorPadding 140 | ) 141 | inputType = a.getInt( 142 | R.styleable.BlockEditText_inputType, 143 | inputType 144 | ) 145 | shiftPosition = a.getBoolean( 146 | R.styleable.BlockEditText_showCardIcon, 147 | true 148 | ) 149 | isShowCardIcon = a.getBoolean( 150 | R.styleable.BlockEditText_showCardIcon, 151 | true 152 | ) 153 | editTextStyle = a.getResourceId( 154 | R.styleable.BlockEditText_style, -1 155 | ) 156 | val cardPrefix = a.getInt( 157 | R.styleable.BlockEditText_cardPrefix, 158 | 0 159 | ) 160 | if (containsFlag(cardPrefix, AMEX)) { 161 | cardPrefixes.add(CardPrefix.amex(getContext())) 162 | } 163 | if (containsFlag(cardPrefix, MASTERCARD)) { 164 | cardPrefixes.add(CardPrefix.mastercard(getContext())) 165 | } 166 | if (containsFlag(cardPrefix, VISA)) { 167 | cardPrefixes.add(CardPrefix.visa(getContext())) 168 | } 169 | setHintTextAppearance(hintTextAppearance) 170 | shiftPosition = a.getBoolean( 171 | R.styleable.BlockEditText_shiftPosition, 172 | true 173 | ) 174 | initLayout() 175 | tempStr = a.getString(R.styleable.BlockEditText_text) 176 | if (tempStr != null) text = tempStr 177 | 178 | 179 | val filename = a.getString(R.styleable.BlockEditText_typefaceFromAsset); 180 | Log.e("Filename", filename ?: "") 181 | if (filename != null) 182 | setTypefaceFromAsset(filename) 183 | 184 | val color = a.getColorStateList( 185 | R.styleable.BlockEditText_inputTextColor 186 | ) 187 | if (color != null) 188 | setInputTextColor(color) 189 | val hintTextColor = a.getColorStateList( 190 | R.styleable.BlockEditText_hintTextColor 191 | ) 192 | if (hintTextColor != null) 193 | setHintTextColor(hintTextColor.defaultColor) 194 | a.recycle() 195 | } 196 | 197 | private fun containsFlag(flagSet: Int, flag: Int): Boolean { 198 | return flagSet or flag == flagSet 199 | } 200 | 201 | private fun createWidthMatchParentLayoutParams(): ViewGroup.LayoutParams { 202 | return LinearLayout.LayoutParams( 203 | LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT 204 | ) 205 | } 206 | 207 | private fun initLayout() { 208 | blockLinearLayout!!.removeAllViews() 209 | var i = 0 210 | var text: String = text.toString() 211 | while (i < noOfBlock) { 212 | val length = getLength(i) 213 | val editText: AEditText? 214 | if (editTexts[i] == null) { 215 | editText = if (editTextStyle == -1) { 216 | AEditText(context) 217 | } else { 218 | AEditText(context, null, editTextStyle) 219 | } 220 | editText.addTextChangedListener(createTextChangeListener(editText, i)) 221 | editTexts.put(i, editText) 222 | editText.onFocusChangeListener = OnFocusChangeListener { _, hasFocus -> 223 | if (hintTextView != null) { 224 | val hintColorFocus: ColorStateList = ColorStateList.valueOf( 225 | editText.textColors.getColorForState( 226 | intArrayOf(android.R.attr.state_focused), 227 | ContextCompat.getColor(context, R.color.colorAccent) 228 | )) 229 | updateHintTextColor(hasFocus); 230 | } 231 | } 232 | editText.setSupportTextAppearance(textAppearance) 233 | setTextSize(editText, textSize) 234 | editText.setOnKeyListener(createKeyListener(editText, i)) 235 | } else { 236 | editText = editTexts[i] 237 | } 238 | editText!!.inputType = inputType 239 | editText.typeface = typeface 240 | if (inputTextColor != null) 241 | editText.setTextColor(inputTextColor); 242 | val filters = arrayOfNulls(1) 243 | filters[0] = LengthFilter(editText, i) 244 | editText.filters = filters 245 | val params = LinearLayout.LayoutParams( 246 | 0, LinearLayout.LayoutParams.WRAP_CONTENT, length.toFloat() 247 | ) 248 | editText.layoutParams = params 249 | editText.gravity = Gravity.CENTER 250 | blockLinearLayout!!.addView(editText) 251 | if (editTextBackground != null) setEdiTextBackground(editText, editTextBackground!!) 252 | if (i + 1 < noOfBlock && separator != null) { 253 | val textView = ATextView(context) 254 | textView.text = separator.toString() 255 | textView.typeface = typeface 256 | val textViewParams = LinearLayout.LayoutParams( 257 | LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT 258 | ) 259 | textViewParams.gravity = Gravity.CENTER 260 | textView.layoutParams = textViewParams 261 | textView.setPadding(separatorPadding, 0, separatorPadding, 0) 262 | textView.setSupportTextAppearance(separatorTextAppearance) 263 | if (separatorTextSize > 0) textView.textSize = separatorTextSize 264 | blockLinearLayout!!.addView(textView) 265 | } 266 | editText.text = null 267 | setEditTextEnable(editText, i) 268 | i++ 269 | } 270 | while (i < editTexts.size()) { 271 | editTexts.remove(i) 272 | } 273 | this.text = text 274 | hideOrShowCardIcon() 275 | } 276 | 277 | private fun updateHintTextColor(hasFocus: Boolean) { 278 | hintTextView!!.setHintTextColor( 279 | if (hasFocus) hintColorFocus else hintColorDefault 280 | ) 281 | } 282 | 283 | private fun setEditTextEnable(editText: AEditText?, i: Int) { 284 | if (shiftPosition && i > 0) editText!!.isEnabled = false else editText!!.isEnabled = isEnabled 285 | } 286 | 287 | fun getText(editText: EditText): Editable { 288 | return editText.text 289 | } 290 | 291 | private fun createKeyListener(editText: AEditText, i: Int): OnKeyListener { 292 | return OnKeyListener { v, keyCode, event -> 293 | if (keyCode == KeyEvent.KEYCODE_DEL) { 294 | if (editText.selectionStart == 0 && editText.selectionEnd == 0) { 295 | val prevEditText = editTexts[i - 1] 296 | if (prevEditText != null) { 297 | prevEditText.requestFocus() 298 | if (editText.length() > 0) { 299 | prevEditText.editableText.delete(getText(prevEditText).length - 1, prevEditText.text!!.length) 300 | prevEditText.setSelection(prevEditText.text!!.length - 1) 301 | } 302 | return@OnKeyListener true 303 | } 304 | } 305 | } 306 | false 307 | } 308 | } 309 | 310 | private fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { 311 | if (watcher != null) watcher!!.beforeTextChanged(s, start, count, after) 312 | } 313 | 314 | private fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { 315 | if (watcher != null) watcher!!.onTextChanged(s, start, before, count) 316 | } 317 | 318 | private fun afterTextChanged(s: Editable) { 319 | if (watcher != null) watcher!!.afterTextChanged(s) 320 | } 321 | 322 | fun setTextChangedListener(watcher: TextWatcher?) { 323 | this.watcher = watcher 324 | } 325 | 326 | fun setCustomInsertionActionModeCallback(callback: ActionMode.Callback?) { 327 | this.callback = callback 328 | for (i in 0 until editTexts.size()) { 329 | val editText = editTexts[i] 330 | setCustomInsertionActionModeCallback(editText, callback) 331 | } 332 | } 333 | 334 | private fun setCustomInsertionActionModeCallback(editText: AEditText?, callback: ActionMode.Callback?) { 335 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 336 | editText!!.customInsertionActionModeCallback = callback 337 | } else editText!!.customSelectionActionModeCallback = callback 338 | } 339 | 340 | fun setSeparatorCharacter(separator: Char?) { 341 | this.separator = separator 342 | initLayout() 343 | } 344 | 345 | var text: CharSequence? 346 | get() { 347 | val builder = StringBuilder() 348 | for (i in 0 until editTexts.size()) { 349 | val editText = editTexts[i] 350 | builder.append(editText!!.text) 351 | } 352 | return builder.toString() 353 | } 354 | set(sequence) { 355 | var i = 0 356 | while (i < editTexts.size()) { 357 | val editText = editTexts[i] 358 | editText?.text = null 359 | i++ 360 | } 361 | if (sequence != null) { 362 | val text = sequence.toString() 363 | val editText = editTexts[0] 364 | editText!!.editableText.insert(0, text) 365 | } 366 | } 367 | val maxLength: Int 368 | get() { 369 | var length = 0 370 | for (i in 0 until editTexts.size()) { 371 | length += getLength(i) 372 | } 373 | return length 374 | } 375 | 376 | private fun getLength(i: Int): Int { 377 | return lengthUsed!![i, defaultLength] 378 | } 379 | 380 | fun setTextSize(textSize: Float) { 381 | this.textSize = textSize 382 | for (i in 0 until editTexts.size()) { 383 | val editText = editTexts[i] 384 | setTextSize(editText, textSize) 385 | } 386 | } 387 | 388 | private fun setTextSize(editText: AEditText?, textSize: Float) { 389 | if (textSize > 0) editText!!.textSize = textSize 390 | } 391 | 392 | fun setTextAppearance(textAppearance: Int) { 393 | this.textAppearance = textAppearance 394 | for (i in 0 until editTexts.size()) { 395 | val editText = editTexts[i] 396 | editText!!.setSupportTextAppearance(textAppearance) 397 | } 398 | } 399 | 400 | fun setInputType(type: Int) { 401 | inputType = type 402 | for (i in 0 until editTexts.size()) { 403 | val editText = editTexts[i] 404 | editText!!.inputType = type 405 | } 406 | } 407 | 408 | 409 | fun setInputTextColor(color: ColorStateList) { 410 | inputTextColor = color 411 | 412 | hintColorFocus = ColorStateList.valueOf(color.getColorForState( 413 | intArrayOf(android.R.attr.state_focused), 414 | ContextCompat.getColor(context, R.color.colorAccent))) 415 | for (i in 0 until editTexts.size()) { 416 | val editText = editTexts[i] 417 | editText!!.setTextColor(inputTextColor); 418 | 419 | } 420 | } 421 | 422 | 423 | fun setInputTextColor(color: Int) { 424 | 425 | 426 | for (i in 0 until editTexts.size()) { 427 | val editText = editTexts[i] 428 | editText!!.setTextColor(color); 429 | inputTextColor = editText.textColors 430 | } 431 | } 432 | 433 | fun setTypefaceFromAsset(filename: String) { 434 | setTypeface(Typeface.createFromAsset(context.resources.assets, filename)); 435 | } 436 | 437 | fun setTypeface(typeface: Typeface) { 438 | Log.e("Typeface", typeface.toString()) 439 | this.typeface = typeface 440 | if (hintTextView != null) 441 | hintTextView!!.typeface = typeface 442 | 443 | for (i in 0 until editTexts.size()) { 444 | val editText = editTexts[i] 445 | editText!!.typeface = typeface 446 | } 447 | } 448 | 449 | fun setNumberOfBlock(block: Int) { 450 | noOfBlock = block 451 | initLayout() 452 | } 453 | 454 | fun setDefaultLength(defaultLength: Int) { 455 | this.defaultLength = defaultLength 456 | initLayout() 457 | } 458 | 459 | fun setEdiTextBackground(drawable: Drawable?) { 460 | for (i in 0 until editTexts.size()) { 461 | val editText = editTexts[i] 462 | setEdiTextBackground(editText, drawable) 463 | } 464 | } 465 | 466 | private fun setEdiTextBackground(editText: AEditText?, drawable: Drawable?) { 467 | ViewCompat.setBackground(editText!!, drawable?.constantState?.newDrawable()) 468 | } 469 | 470 | fun setLengthAt(index: Int, length: Int) { 471 | lengths.put(index, length) 472 | initLayout() 473 | } 474 | 475 | fun setHint(hint: String?) { 476 | if (hintTextView == null) { 477 | hintTextView = ATextView(context) 478 | hintTextView!!.typeface = typeface 479 | hintTextView!!.setPadding(16, 0, 16, 0) 480 | setHintTextAppearance(hintTextAppearance) 481 | setHintTextSize(hintTextAppearance.toFloat()) 482 | linearLayout!!.addView(hintTextView, 0) 483 | hintColorDefault = hintTextView!!.hintTextColors 484 | // hintColorFocus = ContextCompat.getColorStateList( 485 | // context, 486 | // R.color.colorAccent 487 | // ) 488 | 489 | 490 | } 491 | hintTextView!!.visibility = if (hint == null) GONE else VISIBLE 492 | hintTextView!!.hint = hint 493 | } 494 | 495 | fun setHintTextSize(textSize: Float) { 496 | hintTextSize = textSize 497 | if (hintTextView != null && textSize > 0) { 498 | hintTextView!!.textSize = textSize 499 | } 500 | } 501 | 502 | fun setHintTextAppearance(textAppearance: Int) { 503 | hintTextAppearance = textAppearance 504 | if (hintTextView != null) { 505 | hintTextView!!.setSupportTextAppearance(textAppearance) 506 | } 507 | } 508 | 509 | fun setHintTextColor(color: Int) { 510 | hintColorDefault = ColorStateList.valueOf(color) 511 | if (hintTextView != null) { 512 | var focus = false; 513 | for (i in 0 until editTexts.size()) { 514 | val editText = editTexts[i] 515 | if (editText?.isFocused == true) { 516 | focus = true 517 | break; 518 | } 519 | } 520 | updateHintTextColor(focus) 521 | } 522 | } 523 | 524 | // fun setFocusHintTextColor(color: Int) { 525 | // hintColorFocus = ColorStateList.valueOf(color) 526 | // } 527 | 528 | fun setSeparatorTextAppearance(textAppearance: Int) { 529 | separatorTextAppearance = textAppearance 530 | initLayout() 531 | } 532 | 533 | fun setSeparatorPadding(padding: Int) { 534 | separatorPadding = padding 535 | initLayout() 536 | } 537 | 538 | fun setSeparatorTextSize(textSize: Float) { 539 | separatorTextSize = textSize 540 | initLayout() 541 | } 542 | 543 | fun setSelection(selection: Int) { 544 | var selection = selection 545 | for (i in 0 until editTexts.size()) { 546 | val length = getLength(i) 547 | if (selection < length) { 548 | val editText = editTexts[i] 549 | editText!!.requestFocus() 550 | editText.setSelection(selection) 551 | break 552 | } 553 | selection -= length 554 | } 555 | } 556 | 557 | fun addCardPrefix(cardPrefix: CardPrefix) { 558 | cardPrefixes.add(cardPrefix) 559 | hideOrShowCardIcon() 560 | } 561 | 562 | fun addCardPrefix(index: Int, cardPrefix: CardPrefix) { 563 | cardPrefixes.add(index, cardPrefix) 564 | hideOrShowCardIcon() 565 | } 566 | 567 | fun removeCardPrefix(cardPrefix: CardPrefix): Boolean { 568 | val b = cardPrefixes.remove(cardPrefix) 569 | hideOrShowCardIcon() 570 | return b 571 | } 572 | 573 | fun removeCardPrefix(index: Int): CardPrefix { 574 | val cardPrefix = cardPrefixes.removeAt(index) 575 | hideOrShowCardIcon() 576 | return cardPrefix 577 | } 578 | 579 | fun setCardIconSize(size: Int) { 580 | cardIconSize = size 581 | if (iconImageView != null) { 582 | iconImageView!!.layoutParams.width = size 583 | iconImageView!!.requestLayout() 584 | } 585 | } 586 | 587 | override fun setEnabled(isEnabled: Boolean) { 588 | this.isEnabled = isEnabled 589 | for (i in 0 until editTexts.size()) { 590 | val editText = editTexts[i] 591 | editText!!.isEnabled = isEnabled 592 | } 593 | } 594 | 595 | fun setShowCardIcon(isShowCardIcon: Boolean) { 596 | this.isShowCardIcon = isShowCardIcon 597 | hideOrShowCardIcon() 598 | } 599 | 600 | fun setShiftPosition(b: Boolean) { 601 | shiftPosition = b 602 | initLayout() 603 | } 604 | 605 | override fun isEnabled(): Boolean { 606 | return isEnabled 607 | } 608 | 609 | fun isShiftPosition(): Boolean { 610 | return shiftPosition 611 | } 612 | 613 | private fun hideOrShowCardIcon() { 614 | if (isShowCardIcon && cardPrefixes.size > 0) { 615 | if (iconImageView == null) { 616 | iconImageView = ImageView(context) 617 | iconImageView!!.scaleType = ImageView.ScaleType.FIT_CENTER 618 | iconImageView!!.adjustViewBounds = true 619 | val params: ViewGroup.LayoutParams = LayoutParams( 620 | cardIconSize, 621 | ViewGroup.LayoutParams.MATCH_PARENT 622 | ) 623 | iconImageView!!.layoutParams = params 624 | blockLinearLayout!!.addView(iconImageView) 625 | updateCardIcon() 626 | } else if (iconImageView!!.parent == null) { 627 | blockLinearLayout!!.addView(iconImageView) 628 | } 629 | iconImageView!!.visibility = VISIBLE 630 | } else if (iconImageView != null) { 631 | iconImageView!!.visibility = GONE 632 | } 633 | } 634 | 635 | private fun updateCardIcon() { 636 | if (cardPrefixes.size > 0) { 637 | val text: String = text.toString() 638 | for (cardPrefix in cardPrefixes) { 639 | for (prefix in cardPrefix.prefixes) if (text.startsWith(prefix)) { 640 | iconImageView!!.setImageDrawable(cardPrefix.icon) 641 | if (cardPrefix.lengths.size() > 0) { 642 | lengthUsed = cardPrefix.lengths 643 | updateEditTextLength() 644 | } 645 | if (cardPrefixListener != null) cardPrefixListener!!.onCardUpdate(cardPrefix) 646 | return 647 | } 648 | } 649 | lengthUsed = lengths 650 | if (iconImageView != null) { 651 | iconImageView!!.setImageDrawable(null) 652 | updateEditTextLength() 653 | } 654 | if (cardPrefixListener != null) cardPrefixListener!!.onCardUpdate(null) 655 | } 656 | } 657 | 658 | private fun updateEditTextLength() { 659 | for (i in 0 until editTexts.size()) { 660 | val editText = editTexts[i] 661 | val params = editText!!.layoutParams as LinearLayout.LayoutParams 662 | params.weight = getLength(i).toFloat() 663 | editText.requestLayout() 664 | } 665 | } 666 | 667 | fun setOnCardPrefixListener(listener: OnCardPrefixListener?) { 668 | cardPrefixListener = listener 669 | } 670 | 671 | private fun createActionModeCallback(editText: AEditText): ActionMode.Callback { 672 | return object : ActionMode.Callback { 673 | override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { 674 | return true 675 | } 676 | 677 | override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean { 678 | return false 679 | } 680 | 681 | override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { 682 | return false 683 | } 684 | 685 | override fun onDestroyActionMode(mode: ActionMode) {} 686 | } 687 | } 688 | 689 | private fun createTextChangeListener(editText: AEditText, index: Int): TextWatcher { 690 | return object : TextWatcher { 691 | var sequence: CharSequence = "" 692 | var beforeSequence: CharSequence = "" 693 | var prevLength = 0 694 | var selection = 0 695 | var start = 0 696 | var before = 0 697 | override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { 698 | var start = start 699 | prevLength = s.length 700 | selection = editText.selectionStart 701 | beforeSequence = sequence 702 | for (i in 0 until index) { 703 | start += getLength(i) 704 | } 705 | this.start = start 706 | before = beforeSequence.length 707 | this@BlockEditText.beforeTextChanged(beforeSequence, this.start, before, before + (after - count)) 708 | } 709 | 710 | override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { 711 | val nextView: EditText? = editTexts[index + 1] 712 | val prevView: EditText? = editTexts[index - 1] 713 | if (s.length > prevLength && editText.isFocused && editText.selectionStart == getLength(index)) 714 | if (s.length == getLength(index) && nextView != null && nextView.text.isEmpty()) nextView.requestFocus() 715 | else if (s.isEmpty() && prevView != null) prevView.requestFocus() 716 | if (shiftPosition && s.length < getLength(index)) { 717 | if (editText.selectionStart == 0 && editText.isFocused && prevView != null) { 718 | prevView.requestFocus() 719 | prevView.setSelection(prevView.text.length) 720 | } 721 | if (nextView != null && !nextView.text.toString().isEmpty()) { 722 | var length = getLength(index) - s.length 723 | length = if (length > nextView.text.length) nextView.text.length else length 724 | var editable = nextView.text 725 | val temp = editable.toString().substring(0, length) 726 | editable = editable.delete(0, length) 727 | editText.append(temp) 728 | editText.setSelection(selection) 729 | nextView.text = editable 730 | } 731 | } 732 | sequence = text!! 733 | this@BlockEditText.onTextChanged(sequence, this.start, this.before, sequence.length) 734 | } 735 | 736 | override fun afterTextChanged(s: Editable) { 737 | val nextView: EditText? = editTexts[index + 1] 738 | if (shiftPosition && nextView != null) nextView.isEnabled = isEnabled && s.length >= getLength(index) 739 | updateCardIcon() 740 | this@BlockEditText.afterTextChanged(s) 741 | } 742 | } 743 | } 744 | 745 | inner class LengthFilter(private val editText: AEditText, private val index: Int) : InputFilter { 746 | override fun filter(source: CharSequence, start: Int, end: Int, dest: Spanned, 747 | dstart: Int, dend: Int): CharSequence? { 748 | var source = source 749 | source = if (editText.inputType == InputType.TYPE_CLASS_NUMBER) { 750 | source.toString().replace("[\\D]".toRegex(), "") 751 | } else { 752 | source.toString().replace("[\\W]".toRegex(), "") 753 | } 754 | val mMax = getLength(index) 755 | var keep = mMax - (dest.length - (dend - dstart)) 756 | val nextView: EditText? = editTexts[index + 1] 757 | if (source.isEmpty()) return null 758 | return if (keep <= 0) { 759 | if (nextView != null && text!!.length < maxLength) { 760 | val s = source.toString() 761 | var temp = editText.text.toString() 762 | val selection = editText.selectionStart 763 | temp = temp.substring(0, selection) + source + temp.substring(selection) 764 | editText.setText(temp.substring(0, mMax)) 765 | temp = temp.substring(mMax) 766 | if (selection + source.length <= mMax) editText.setSelection(selection + source.length) else { 767 | nextView.requestFocus() 768 | nextView.setSelection(0) 769 | } 770 | if (temp.isNotEmpty()) { 771 | nextView.editableText.insert(0, temp) 772 | val nextLength = getLength(index + 1) 773 | nextView.setSelection(if (temp.length < nextLength) temp.length else nextLength) 774 | } else nextView.setSelection(0) 775 | } 776 | "" 777 | } else if (keep >= end - start) { 778 | null // keep original 779 | } else { 780 | if (source.length > keep) if (nextView != null && text!!.length < maxLength) { 781 | val s = source.toString() 782 | var temp = editText.text.toString() 783 | val selection = editText.selectionStart 784 | temp = temp.substring(0, selection) + source + temp.substring(selection) 785 | editText.setText(temp.substring(0, mMax)) 786 | temp = temp.substring(mMax) 787 | if (selection + source.length <= mMax) editText.setSelection(selection + source.length) else { 788 | nextView.requestFocus() 789 | nextView.setSelection(0) 790 | } 791 | if (temp.isNotEmpty()) { 792 | nextView.editableText.insert(0, temp) 793 | val nextLength = getLength(index + 1) 794 | nextView.setSelection(if (temp.length < nextLength) temp.length else nextLength) 795 | } else nextView.setSelection(0) 796 | return "" 797 | } 798 | keep += start 799 | if (Character.isHighSurrogate(source[keep - 1])) { 800 | --keep 801 | if (keep == start) { 802 | return "" 803 | } 804 | } 805 | source.subSequence(start, keep) 806 | } 807 | } 808 | } 809 | 810 | interface OnCardPrefixListener { 811 | fun onCardUpdate(cardPrefix: CardPrefix?) 812 | } 813 | 814 | companion object { 815 | private const val AMEX = 1 816 | private const val MASTERCARD = 2 817 | private const val VISA = 3 818 | } 819 | } -------------------------------------------------------------------------------- /blockedittext/src/main/java/com/infideap/blockedittext/CardPrefix.kt: -------------------------------------------------------------------------------- 1 | package com.infideap.blockedittext 2 | 3 | import android.content.Context 4 | import android.graphics.drawable.Drawable 5 | import android.util.SparseIntArray 6 | import androidx.core.content.ContextCompat 7 | 8 | class CardPrefix(icon: Drawable?, vararg prefix: String) { 9 | val prefixes: Array = prefix 10 | val icon: Drawable? = icon 11 | val lengths = SparseIntArray() 12 | 13 | constructor(context: Context?, iconRes: Int, vararg prefix: String) : this(ContextCompat.getDrawable(context!!, iconRes), *prefix) {} 14 | 15 | fun lengthAt(index: Int, length: Int) { 16 | lengths.put(index, length) 17 | } 18 | 19 | companion object { 20 | fun visa(context: Context?): CardPrefix { 21 | val cardPrefix = visa(ContextCompat.getDrawable(context!!, R.drawable.ic_visa)) 22 | cardPrefix.lengthAt(0, 5) 23 | cardPrefix.lengthAt(1, 6) 24 | cardPrefix.lengthAt(2, 5) 25 | return cardPrefix 26 | } 27 | 28 | fun visa(drawable: Drawable?): CardPrefix { 29 | return CardPrefix(drawable, "4") 30 | } 31 | 32 | fun amex(context: Context?): CardPrefix { 33 | val cardPrefix = amex(ContextCompat.getDrawable(context!!, R.drawable.ic_amex)) 34 | cardPrefix.lengthAt(0, 4) 35 | cardPrefix.lengthAt(1, 6) 36 | cardPrefix.lengthAt(2, 5) 37 | return cardPrefix 38 | } 39 | 40 | fun amex(drawable: Drawable?): CardPrefix { 41 | return CardPrefix(drawable, "34", "37") 42 | } 43 | 44 | fun mastercard(context: Context?): CardPrefix { 45 | val cardPrefix = mastercard(ContextCompat.getDrawable(context!!, R.drawable.ic_mastercard)) 46 | cardPrefix.lengthAt(0, 5) 47 | cardPrefix.lengthAt(1, 6) 48 | cardPrefix.lengthAt(2, 5) 49 | return cardPrefix 50 | } 51 | 52 | fun mastercard(drawable: Drawable?): CardPrefix { 53 | return CardPrefix(drawable, "50", "51", "52", "53", "54", "55") 54 | } 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /blockedittext/src/main/res/drawable/ic_amex.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /blockedittext/src/main/res/drawable/ic_mastercard.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /blockedittext/src/main/res/drawable/ic_visa.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /blockedittext/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 | -------------------------------------------------------------------------------- /blockedittext/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FF4081 4 | 5 | -------------------------------------------------------------------------------- /blockedittext/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | blockedittext 3 | 4 | -------------------------------------------------------------------------------- /blockedittext/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /blockedittext/src/test/java/com/infideap/blockedittext/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.infideap.blockedittext; 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() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '1.4.10' 5 | 6 | repositories { 7 | google() 8 | jcenter() 9 | } 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:4.0.1' 12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 13 | 14 | 15 | // NOTE: Do not place your application dependencies here; they belong 16 | // in the individual module build.gradle files 17 | } 18 | } 19 | 20 | allprojects { 21 | repositories { 22 | google() 23 | jcenter() 24 | } 25 | } 26 | 27 | task clean(type: Delete) { 28 | delete rootProject.buildDir 29 | } 30 | -------------------------------------------------------------------------------- /device-2018-05-29-233023.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiburagi/BlockEditText/794dfe900ee4f7feaea6a2b6cd059332f440fc96/device-2018-05-29-233023.png -------------------------------------------------------------------------------- /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 | android.enableJetifier=true 10 | android.useAndroidX=true 11 | org.gradle.jvmargs=-Xmx1536m 12 | # When configured, Gradle will run in incubating parallel mode. 13 | # This option should only be used with decoupled projects. More details, visit 14 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 15 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiburagi/BlockEditText/794dfe900ee4f7feaea6a2b6cd059332f440fc96/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Feb 06 00:21:52 MYT 2019 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-6.1.1-all.zip 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':blockedittext' 2 | --------------------------------------------------------------------------------