├── LICENSE ├── README.md ├── app ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── andrognito │ │ └── pinlockviewapp │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── andrognito │ │ │ └── pinlockviewapp │ │ │ └── SampleActivity.java │ └── res │ │ ├── drawable │ │ ├── ic_launcher.png │ │ └── img_no_avatar.png │ │ ├── layout │ │ └── activity_sample.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── andrognito │ └── pinlockviewapp │ └── ExampleUnitTest.java ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── pinlockview ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── andrognito │ │ └── pinlockview │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── andrognito │ │ │ └── pinlockview │ │ │ ├── CustomizationOptionsBundle.java │ │ │ ├── IndicatorDots.java │ │ │ ├── ItemSpaceDecoration.java │ │ │ ├── LTRGridLayoutManager.java │ │ │ ├── PinLockAdapter.java │ │ │ ├── PinLockListener.java │ │ │ ├── PinLockView.java │ │ │ ├── ResourceUtils.java │ │ │ └── ShuffleArrayUtils.java │ └── res │ │ ├── drawable │ │ ├── dot_empty.xml │ │ ├── dot_filled.xml │ │ └── ic_backspace.png │ │ ├── layout-v21 │ │ └── layout_number_item.xml │ │ ├── layout │ │ ├── layout_delete_item.xml │ │ └── layout_number_item.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ ├── dimen.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── andrognito │ └── pinlockview │ └── ExampleUnitTest.java ├── screens ├── logo.png └── promo.png └── settings.gradle /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 {yyyy} {name of copyright owner} 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 | # PinLockView 2 | A clean, minimalistic, easy-to-use and highly customizable pin lock custom view for Android. 3 | 4 | ### Specs 5 | [ ![Download](https://api.bintray.com/packages/aritraroy/maven/pin-lock-view/images/download.svg) ](https://bintray.com/aritraroy/maven/pin-lock-view/_latestVersion) [![API](https://img.shields.io/badge/API-11%2B-orange.svg?style=flat)](https://android-arsenal.com/api?level=11) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-PinLockView-green.svg?style=true)](https://android-arsenal.com/details/1/3706) 6 | 7 | ![PinLockView](https://github.com/aritraroy/PinLockView/blob/master/screens/logo.png) 8 | 9 | This library allows you to implement a pin lock mechanism in your app **easily and quickly**. There are **plenty of customization options** available to change the look-and-feel of this view to match your app's theme. 10 | 11 | You can also use it as a dial pad to dial numbers. There are several other use cases of this library and is not restricted to only pin locking. 12 | 13 | ![PinLockView](https://github.com/aritraroy/PinLockView/blob/master/screens/promo.png) 14 | 15 | # Download 16 | 17 | This library is available in **jCenter** which is the default Maven repository used in Android Studio. 18 | 19 | ## Gradle 20 | ```gradle 21 | dependencies { 22 | // other dependencies here 23 | 24 | implementation 'com.andrognito.pinlockview:pinlockview:2.1.0' 25 | } 26 | ``` 27 | 28 | ## Maven 29 | 30 | ```xml 31 | 32 | com.andrognito.pinlockview 33 | pinlockview 34 | 2.1.0 35 | pom 36 | 37 | ``` 38 | 39 | # Usage 40 | We recommend you to **check the sample app** to get a complete understanding of the library. The step-by-step implementation guide is as follows. 41 | 42 | ### Step 1 43 | 44 | Place the view in your XML layout file. 45 | 46 | ```xml 47 | 51 | ``` 52 | 53 | ### Step 2 54 | 55 | Reference the view in code and add a listener to it. 56 | 57 | ```java 58 | mPinLockView = (PinLockView) findViewById(R.id.pin_lock_view); 59 | mPinLockView.setPinLockListener(mPinLockListener); 60 | ``` 61 | 62 | Implement the listener interface as follows, 63 | 64 | ```java 65 | private PinLockListener mPinLockListener = new PinLockListener() { 66 | @Override 67 | public void onComplete(String pin) { 68 | Log.d(TAG, "Pin complete: " + pin); 69 | } 70 | 71 | @Override 72 | public void onEmpty() { 73 | Log.d(TAG, "Pin empty"); 74 | } 75 | 76 | @Override 77 | public void onPinChange(int pinLength, String intermediatePin) { 78 | Log.d(TAG, "Pin changed, new length " + pinLength + " with intermediate pin " + intermediatePin); 79 | } 80 | }; 81 | ``` 82 | 83 | And that's it! Your PinLockView is ready to rock. 84 | 85 | But the good thing is that the ```PinLockView``` comes with a whole lot of customization options which you can use to customize the view in any way you want. 86 | 87 | # Customization 88 | 89 | ## IndicatorDots (Addon) 90 | PinLockView comes bundled with an addon view, ```IndicatorDots``` which can be optionally attached with the PinLockView to indicate pin changes visually to the user. 91 | 92 | This **view has been decoupled from the PinLockView** so that you can optionally add it, if necessary. Suppose you are implementing a dial pad, then you will certainly not need this IndicatorView. 93 | 94 | Add the view to you XML layout, generally placed above your PinLockView, 95 | 96 | ```xml 97 | 101 | ``` 102 | then find a reference to the view and attach it to the parent PinLockView, 103 | 104 | ```java 105 | mIndicatorDots = (IndicatorDots) findViewById(R.id.indicator_dots); 106 | mPinLockView.attachIndicatorDots(mIndicatorDots); 107 | ``` 108 | 109 | You **MUST** attach it to the PinLockView, otherwise it will be simply ignored. 110 | 111 | ## Theming 112 | 113 | There are several theming options available through XML attributes which you can use to completely change the look-and-feel of this view to match the theme of your app. 114 | 115 | ```xml 116 | app:pinLength="6" // Change the pin length 117 | app:keypadTextColor="#E6E6E6" // Change the color of the keypad text 118 | app:keypadTextSize="16dp" // Change the text size in the keypad 119 | app:keypadButtonSize="72dp" // Change the size of individual keys/buttons 120 | app:keypadVerticalSpacing="24dp" // Alters the vertical spacing between the keypad buttons 121 | app:keypadHorizontalSpacing="36dp" // Alters the horizontal spacing between the keypad buttons 122 | app:keypadButtonBackgroundDrawable="@drawable/bg" // Set a custom background drawable for the buttons 123 | app:keypadDeleteButtonDrawable="@drawable/ic_back" // Set a custom drawable for the delete button 124 | app:keypadDeleteButtonSize="16dp" // Change the size of the delete button icon in the keypad 125 | app:keypadShowDeleteButton="false" // Should show the delete button, default is true 126 | app:keypadDeleteButtonPressedColor="#C8C8C8" // Change the pressed/focused state color of the delete button 127 | 128 | app:dotEmptyBackground="@drawable/empty" // Customize the empty state of the dots 129 | app:dotFilledBackground"@drawable/filled" // Customize the filled state of the dots 130 | app:dotDiameter="12dp" // Change the diameter of the dots 131 | app:dotSpacing="16dp" // Change the spacing between individual dots 132 | app:indicatorType="fillWithAnimation" // Choose between "fixed", "fill" and "fillWithAnimation" 133 | ``` 134 | 135 | # Contribution 136 | 137 | This library is quite exhaustive and offers a lot of customization options. If you find a bug or would like to improve any aspect of it, feel free to contribute with pull requests. 138 | 139 | # About The Author 140 | 141 | ### Aritra Roy 142 | 143 | Android & Backend Developer. Blogger. Designer. Fitness Enthusiast. 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | # License 152 | 153 | ``` 154 | Copyright 2017 aritraroy 155 | 156 | Licensed under the Apache License, Version 2.0 (the "License"); 157 | you may not use this file except in compliance with the License. 158 | You may obtain a copy of the License at 159 | 160 | http://www.apache.org/licenses/LICENSE-2.0 161 | 162 | Unless required by applicable law or agreed to in writing, software 163 | distributed under the License is distributed on an "AS IS" BASIS, 164 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 165 | See the License for the specific language governing permissions and 166 | limitations under the License. 167 | ``` 168 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.3" 6 | 7 | defaultConfig { 8 | applicationId "com.andrognito.pinlockviewapp" 9 | minSdkVersion 11 10 | targetSdkVersion 25 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:25.3.1' 26 | compile project(':pinlockview') 27 | } 28 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/aritraroy/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/andrognito/pinlockviewapp/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.andrognito.pinlockviewapp; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/andrognito/pinlockviewapp/SampleActivity.java: -------------------------------------------------------------------------------- 1 | package com.andrognito.pinlockviewapp; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.content.ContextCompat; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.util.Log; 7 | import android.view.Window; 8 | import android.view.WindowManager; 9 | 10 | import com.andrognito.pinlockview.IndicatorDots; 11 | import com.andrognito.pinlockview.PinLockListener; 12 | import com.andrognito.pinlockview.PinLockView; 13 | 14 | public class SampleActivity extends AppCompatActivity { 15 | 16 | public static final String TAG = "PinLockView"; 17 | 18 | private PinLockView mPinLockView; 19 | private IndicatorDots mIndicatorDots; 20 | 21 | private PinLockListener mPinLockListener = new PinLockListener() { 22 | @Override 23 | public void onComplete(String pin) { 24 | Log.d(TAG, "Pin complete: " + pin); 25 | } 26 | 27 | @Override 28 | public void onEmpty() { 29 | Log.d(TAG, "Pin empty"); 30 | } 31 | 32 | @Override 33 | public void onPinChange(int pinLength, String intermediatePin) { 34 | Log.d(TAG, "Pin changed, new length " + pinLength + " with intermediate pin " + intermediatePin); 35 | } 36 | }; 37 | 38 | @Override 39 | protected void onCreate(Bundle savedInstanceState) { 40 | super.onCreate(savedInstanceState); 41 | requestWindowFeature(Window.FEATURE_NO_TITLE); 42 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 43 | WindowManager.LayoutParams.FLAG_FULLSCREEN); 44 | setContentView(R.layout.activity_sample); 45 | 46 | mPinLockView = (PinLockView) findViewById(R.id.pin_lock_view); 47 | mIndicatorDots = (IndicatorDots) findViewById(R.id.indicator_dots); 48 | 49 | mPinLockView.attachIndicatorDots(mIndicatorDots); 50 | mPinLockView.setPinLockListener(mPinLockListener); 51 | //mPinLockView.setCustomKeySet(new int[]{2, 3, 1, 5, 9, 6, 7, 0, 8, 4}); 52 | //mPinLockView.enableLayoutShuffling(); 53 | 54 | mPinLockView.setPinLength(4); 55 | mPinLockView.setTextColor(ContextCompat.getColor(this, R.color.white)); 56 | 57 | mIndicatorDots.setIndicatorType(IndicatorDots.IndicatorType.FILL_WITH_ANIMATION); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aritraroy/PinLockView/5079b412c75c2a01dcd105b47cdff86a4d4e8f5c/app/src/main/res/drawable/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/img_no_avatar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aritraroy/PinLockView/5079b412c75c2a01dcd105b47cdff86a4d4e8f5c/app/src/main/res/drawable/img_no_avatar.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_sample.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 17 | 18 | 31 | 32 | 39 | 40 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aritraroy/PinLockView/5079b412c75c2a01dcd105b47cdff86a4d4e8f5c/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aritraroy/PinLockView/5079b412c75c2a01dcd105b47cdff86a4d4e8f5c/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aritraroy/PinLockView/5079b412c75c2a01dcd105b47cdff86a4d4e8f5c/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aritraroy/PinLockView/5079b412c75c2a01dcd105b47cdff86a4d4e8f5c/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aritraroy/PinLockView/5079b412c75c2a01dcd105b47cdff86a4d4e8f5c/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | PinLockViewDemo 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/andrognito/pinlockviewapp/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.andrognito.pinlockviewapp; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.3' 9 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4' 10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | jcenter() 19 | } 20 | } 21 | 22 | task clean(type: Delete) { 23 | delete rootProject.buildDir 24 | } 25 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aritraroy/PinLockView/5079b412c75c2a01dcd105b47cdff86a4d4e8f5c/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Mar 10 00:08:20 IST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /pinlockview/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | ext { 4 | bintrayRepo = 'maven' 5 | bintrayName = 'pin-lock-view' 6 | 7 | publishedGroupId = 'com.andrognito.pinlockview' 8 | libraryName = 'pinlockview' 9 | artifact = 'pinlockview' 10 | 11 | libraryDescription = 'A clean, minimalistic, easy-to-use and highly customizable pin lock custom view' 12 | 13 | siteUrl = 'https://github.com/aritraroy/PinLockView' 14 | gitUrl = 'https://github.com/aritraroy/PinLockView.git' 15 | 16 | libraryVersion = '2.1.0' 17 | 18 | developerId = 'aritraroy' 19 | developerName = 'Aritra Roy' 20 | developerEmail = 'aritra.roy.in@gmail.com' 21 | 22 | licenseName = 'The Apache Software License, Version 2.0' 23 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 24 | allLicenses = ["Apache-2.0"] 25 | } 26 | 27 | 28 | android { 29 | compileSdkVersion 25 30 | buildToolsVersion "25.0.3" 31 | 32 | defaultConfig { 33 | minSdkVersion 11 34 | targetSdkVersion 25 35 | versionCode 5 36 | versionName "2.1.0" 37 | } 38 | buildTypes { 39 | release { 40 | minifyEnabled false 41 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 42 | } 43 | } 44 | } 45 | 46 | dependencies { 47 | compile fileTree(dir: 'libs', include: ['*.jar']) 48 | testCompile 'junit:junit:4.12' 49 | compile 'com.android.support:appcompat-v7:25.3.1' 50 | compile 'com.android.support:recyclerview-v7:25.3.1' 51 | } 52 | 53 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle' 54 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle' -------------------------------------------------------------------------------- /pinlockview/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/aritraroy/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /pinlockview/src/androidTest/java/com/andrognito/pinlockview/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.andrognito.pinlockview; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /pinlockview/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /pinlockview/src/main/java/com/andrognito/pinlockview/CustomizationOptionsBundle.java: -------------------------------------------------------------------------------- 1 | package com.andrognito.pinlockview; 2 | 3 | import android.graphics.drawable.Drawable; 4 | 5 | /** 6 | * The customization options for the buttons in {@link PinLockView} 7 | * passed to the {@link PinLockAdapter} to decorate the individual views 8 | * 9 | * Created by aritraroy on 01/06/16. 10 | */ 11 | public class CustomizationOptionsBundle { 12 | 13 | private int textColor; 14 | private int textSize; 15 | private int buttonSize; 16 | private Drawable buttonBackgroundDrawable; 17 | private Drawable deleteButtonDrawable; 18 | private int deleteButtonSize; 19 | private boolean showDeleteButton; 20 | private int deleteButtonPressesColor; 21 | 22 | public CustomizationOptionsBundle() { 23 | } 24 | 25 | public int getTextColor() { 26 | return textColor; 27 | } 28 | 29 | public void setTextColor(int textColor) { 30 | this.textColor = textColor; 31 | } 32 | 33 | public int getTextSize() { 34 | return textSize; 35 | } 36 | 37 | public void setTextSize(int textSize) { 38 | this.textSize = textSize; 39 | } 40 | 41 | public int getButtonSize() { 42 | return buttonSize; 43 | } 44 | 45 | public void setButtonSize(int buttonSize) { 46 | this.buttonSize = buttonSize; 47 | } 48 | 49 | public Drawable getButtonBackgroundDrawable() { 50 | return buttonBackgroundDrawable; 51 | } 52 | 53 | public void setButtonBackgroundDrawable(Drawable buttonBackgroundDrawable) { 54 | this.buttonBackgroundDrawable = buttonBackgroundDrawable; 55 | } 56 | 57 | public Drawable getDeleteButtonDrawable() { 58 | return deleteButtonDrawable; 59 | } 60 | 61 | public void setDeleteButtonDrawable(Drawable deleteButtonDrawable) { 62 | this.deleteButtonDrawable = deleteButtonDrawable; 63 | } 64 | 65 | public int getDeleteButtonSize() { 66 | return deleteButtonSize; 67 | } 68 | 69 | public void setDeleteButtonSize(int deleteButtonSize) { 70 | this.deleteButtonSize = deleteButtonSize; 71 | } 72 | 73 | public boolean isShowDeleteButton() { 74 | return showDeleteButton; 75 | } 76 | 77 | public void setShowDeleteButton(boolean showDeleteButton) { 78 | this.showDeleteButton = showDeleteButton; 79 | } 80 | 81 | public int getDeleteButtonPressesColor() { 82 | return deleteButtonPressesColor; 83 | } 84 | 85 | public void setDeleteButtonPressesColor(int deleteButtonPressesColor) { 86 | this.deleteButtonPressesColor = deleteButtonPressesColor; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /pinlockview/src/main/java/com/andrognito/pinlockview/IndicatorDots.java: -------------------------------------------------------------------------------- 1 | package com.andrognito.pinlockview; 2 | 3 | import android.animation.LayoutTransition; 4 | import android.content.Context; 5 | import android.content.res.TypedArray; 6 | import android.support.annotation.IntDef; 7 | import android.support.v4.view.ViewCompat; 8 | import android.util.AttributeSet; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.LinearLayout; 12 | 13 | import java.lang.annotation.Retention; 14 | import java.lang.annotation.RetentionPolicy; 15 | 16 | /** 17 | * It represents a set of indicator dots which when attached with {@link PinLockView} 18 | * can be used to indicate the current length of the input 19 | *

20 | * Created by aritraroy on 01/06/16. 21 | */ 22 | public class IndicatorDots extends LinearLayout { 23 | 24 | @IntDef({IndicatorType.FIXED, IndicatorType.FILL, IndicatorType.FILL_WITH_ANIMATION}) 25 | @Retention(RetentionPolicy.SOURCE) 26 | public @interface IndicatorType { 27 | int FIXED = 0; 28 | int FILL = 1; 29 | int FILL_WITH_ANIMATION = 2; 30 | } 31 | 32 | private static final int DEFAULT_PIN_LENGTH = 4; 33 | 34 | private int mDotDiameter; 35 | private int mDotSpacing; 36 | private int mFillDrawable; 37 | private int mEmptyDrawable; 38 | private int mPinLength; 39 | private int mIndicatorType; 40 | 41 | private int mPreviousLength; 42 | 43 | public IndicatorDots(Context context) { 44 | this(context, null); 45 | } 46 | 47 | public IndicatorDots(Context context, AttributeSet attrs) { 48 | this(context, attrs, 0); 49 | } 50 | 51 | public IndicatorDots(Context context, AttributeSet attrs, int defStyleAttr) { 52 | super(context, attrs, defStyleAttr); 53 | 54 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.PinLockView); 55 | 56 | try { 57 | mDotDiameter = (int) typedArray.getDimension(R.styleable.PinLockView_dotDiameter, ResourceUtils.getDimensionInPx(getContext(), R.dimen.default_dot_diameter)); 58 | mDotSpacing = (int) typedArray.getDimension(R.styleable.PinLockView_dotSpacing, ResourceUtils.getDimensionInPx(getContext(), R.dimen.default_dot_spacing)); 59 | mFillDrawable = typedArray.getResourceId(R.styleable.PinLockView_dotFilledBackground, 60 | R.drawable.dot_filled); 61 | mEmptyDrawable = typedArray.getResourceId(R.styleable.PinLockView_dotEmptyBackground, 62 | R.drawable.dot_empty); 63 | mPinLength = typedArray.getInt(R.styleable.PinLockView_pinLength, DEFAULT_PIN_LENGTH); 64 | mIndicatorType = typedArray.getInt(R.styleable.PinLockView_indicatorType, 65 | IndicatorType.FIXED); 66 | } finally { 67 | typedArray.recycle(); 68 | } 69 | 70 | initView(context); 71 | } 72 | 73 | private void initView(Context context) { 74 | ViewCompat.setLayoutDirection(this, ViewCompat.LAYOUT_DIRECTION_LTR); 75 | if (mIndicatorType == 0) { 76 | for (int i = 0; i < mPinLength; i++) { 77 | View dot = new View(context); 78 | emptyDot(dot); 79 | 80 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(mDotDiameter, 81 | mDotDiameter); 82 | params.setMargins(mDotSpacing, 0, mDotSpacing, 0); 83 | dot.setLayoutParams(params); 84 | 85 | addView(dot); 86 | } 87 | } else if (mIndicatorType == 2) { 88 | setLayoutTransition(new LayoutTransition()); 89 | } 90 | } 91 | 92 | @Override 93 | protected void onAttachedToWindow() { 94 | super.onAttachedToWindow(); 95 | // If the indicator type is not fixed 96 | if (mIndicatorType != 0) { 97 | ViewGroup.LayoutParams params = this.getLayoutParams(); 98 | params.height = mDotDiameter; 99 | requestLayout(); 100 | } 101 | } 102 | 103 | void updateDot(int length) { 104 | if (mIndicatorType == 0) { 105 | if (length > 0) { 106 | if (length > mPreviousLength) { 107 | fillDot(getChildAt(length - 1)); 108 | } else { 109 | emptyDot(getChildAt(length)); 110 | } 111 | mPreviousLength = length; 112 | } else { 113 | // When {@code mPinLength} is 0, we need to reset all the views back to empty 114 | for (int i = 0; i < getChildCount(); i++) { 115 | View v = getChildAt(i); 116 | emptyDot(v); 117 | } 118 | mPreviousLength = 0; 119 | } 120 | } else { 121 | if (length > 0) { 122 | if (length > mPreviousLength) { 123 | View dot = new View(getContext()); 124 | fillDot(dot); 125 | 126 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(mDotDiameter, 127 | mDotDiameter); 128 | params.setMargins(mDotSpacing, 0, mDotSpacing, 0); 129 | dot.setLayoutParams(params); 130 | 131 | addView(dot, length - 1); 132 | } else { 133 | removeViewAt(length); 134 | } 135 | mPreviousLength = length; 136 | } else { 137 | removeAllViews(); 138 | mPreviousLength = 0; 139 | } 140 | } 141 | } 142 | 143 | private void emptyDot(View dot) { 144 | dot.setBackgroundResource(mEmptyDrawable); 145 | } 146 | 147 | private void fillDot(View dot) { 148 | dot.setBackgroundResource(mFillDrawable); 149 | } 150 | 151 | public int getPinLength() { 152 | return mPinLength; 153 | } 154 | 155 | public void setPinLength(int pinLength) { 156 | this.mPinLength = pinLength; 157 | removeAllViews(); 158 | initView(getContext()); 159 | } 160 | 161 | public 162 | @IndicatorType 163 | int getIndicatorType() { 164 | return mIndicatorType; 165 | } 166 | 167 | public void setIndicatorType(@IndicatorType int type) { 168 | this.mIndicatorType = type; 169 | removeAllViews(); 170 | initView(getContext()); 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /pinlockview/src/main/java/com/andrognito/pinlockview/ItemSpaceDecoration.java: -------------------------------------------------------------------------------- 1 | package com.andrognito.pinlockview; 2 | 3 | import android.graphics.Rect; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.View; 6 | 7 | /** 8 | * Created by aritraroy on 31/05/16. 9 | */ 10 | public class ItemSpaceDecoration extends RecyclerView.ItemDecoration { 11 | 12 | private final int mHorizontalSpaceWidth; 13 | private final int mVerticalSpaceHeight; 14 | private final int mSpanCount; 15 | private final boolean mIncludeEdge; 16 | 17 | public ItemSpaceDecoration(int horizontalSpaceWidth, int verticalSpaceHeight, int spanCount, boolean includeEdge) { 18 | this.mHorizontalSpaceWidth = horizontalSpaceWidth; 19 | this.mVerticalSpaceHeight = verticalSpaceHeight; 20 | this.mSpanCount = spanCount; 21 | this.mIncludeEdge = includeEdge; 22 | } 23 | 24 | @Override 25 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 26 | 27 | int position = parent.getChildAdapterPosition(view); 28 | int column = position % mSpanCount; 29 | 30 | if (mIncludeEdge) { 31 | outRect.left = mHorizontalSpaceWidth - column * mHorizontalSpaceWidth / mSpanCount; 32 | outRect.right = (column + 1) * mHorizontalSpaceWidth / mSpanCount; 33 | 34 | if (position < mSpanCount) { 35 | outRect.top = mVerticalSpaceHeight; 36 | } 37 | outRect.bottom = mVerticalSpaceHeight; 38 | } else { 39 | outRect.left = column * mHorizontalSpaceWidth / mSpanCount; 40 | outRect.right = mHorizontalSpaceWidth - (column + 1) * mHorizontalSpaceWidth / mSpanCount; 41 | if (position >= mSpanCount) { 42 | outRect.top = mVerticalSpaceHeight; 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /pinlockview/src/main/java/com/andrognito/pinlockview/LTRGridLayoutManager.java: -------------------------------------------------------------------------------- 1 | package com.andrognito.pinlockview; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.GridLayoutManager; 5 | import android.util.AttributeSet; 6 | 7 | /** 8 | * Used to always maintain an LTR layout no matter what is the real device's layout direction 9 | * to avoid an unwanted reversed direction in RTL devices 10 | * Created by Idan on 7/6/2017. 11 | */ 12 | 13 | public class LTRGridLayoutManager extends GridLayoutManager { 14 | 15 | public LTRGridLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 16 | super(context, attrs, defStyleAttr, defStyleRes); 17 | } 18 | 19 | public LTRGridLayoutManager(Context context, int spanCount) { 20 | super(context, spanCount); 21 | } 22 | 23 | public LTRGridLayoutManager(Context context, int spanCount, int orientation, boolean reverseLayout) { 24 | super(context, spanCount, orientation, reverseLayout); 25 | } 26 | 27 | @Override 28 | protected boolean isLayoutRTL(){ 29 | return false; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /pinlockview/src/main/java/com/andrognito/pinlockview/PinLockAdapter.java: -------------------------------------------------------------------------------- 1 | package com.andrognito.pinlockview; 2 | 3 | import android.content.Context; 4 | import android.graphics.PorterDuff; 5 | import android.graphics.Rect; 6 | import android.os.Build; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.util.TypedValue; 9 | import android.view.LayoutInflater; 10 | import android.view.MotionEvent; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.widget.Button; 14 | import android.widget.ImageView; 15 | import android.widget.LinearLayout; 16 | 17 | /** 18 | * Created by aritraroy on 31/05/16. 19 | */ 20 | public class PinLockAdapter extends RecyclerView.Adapter { 21 | 22 | private static final int VIEW_TYPE_NUMBER = 0; 23 | private static final int VIEW_TYPE_DELETE = 1; 24 | 25 | private Context mContext; 26 | private CustomizationOptionsBundle mCustomizationOptionsBundle; 27 | private OnNumberClickListener mOnNumberClickListener; 28 | private OnDeleteClickListener mOnDeleteClickListener; 29 | private int mPinLength; 30 | 31 | private int[] mKeyValues; 32 | 33 | public PinLockAdapter(Context context) { 34 | this.mContext = context; 35 | this.mKeyValues = getAdjustKeyValues(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}); 36 | } 37 | 38 | @Override 39 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 40 | RecyclerView.ViewHolder viewHolder; 41 | LayoutInflater inflater = LayoutInflater.from(parent.getContext()); 42 | 43 | if (viewType == VIEW_TYPE_NUMBER) { 44 | View view = inflater.inflate(R.layout.layout_number_item, parent, false); 45 | viewHolder = new NumberViewHolder(view); 46 | } else { 47 | View view = inflater.inflate(R.layout.layout_delete_item, parent, false); 48 | viewHolder = new DeleteViewHolder(view); 49 | } 50 | return viewHolder; 51 | } 52 | 53 | @Override 54 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 55 | if (holder.getItemViewType() == VIEW_TYPE_NUMBER) { 56 | NumberViewHolder vh1 = (NumberViewHolder) holder; 57 | configureNumberButtonHolder(vh1, position); 58 | } else if (holder.getItemViewType() == VIEW_TYPE_DELETE) { 59 | DeleteViewHolder vh2 = (DeleteViewHolder) holder; 60 | configureDeleteButtonHolder(vh2); 61 | } 62 | } 63 | 64 | private void configureNumberButtonHolder(NumberViewHolder holder, int position) { 65 | if (holder != null) { 66 | if (position == 9) { 67 | holder.mNumberButton.setVisibility(View.GONE); 68 | } else { 69 | holder.mNumberButton.setText(String.valueOf(mKeyValues[position])); 70 | holder.mNumberButton.setVisibility(View.VISIBLE); 71 | holder.mNumberButton.setTag(mKeyValues[position]); 72 | } 73 | 74 | if (mCustomizationOptionsBundle != null) { 75 | holder.mNumberButton.setTextColor(mCustomizationOptionsBundle.getTextColor()); 76 | if (mCustomizationOptionsBundle.getButtonBackgroundDrawable() != null) { 77 | if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { 78 | holder.mNumberButton.setBackgroundDrawable( 79 | mCustomizationOptionsBundle.getButtonBackgroundDrawable()); 80 | } else { 81 | holder.mNumberButton.setBackground( 82 | mCustomizationOptionsBundle.getButtonBackgroundDrawable()); 83 | } 84 | } 85 | holder.mNumberButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, 86 | mCustomizationOptionsBundle.getTextSize()); 87 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( 88 | mCustomizationOptionsBundle.getButtonSize(), 89 | mCustomizationOptionsBundle.getButtonSize()); 90 | holder.mNumberButton.setLayoutParams(params); 91 | } 92 | } 93 | } 94 | 95 | private void configureDeleteButtonHolder(DeleteViewHolder holder) { 96 | if (holder != null) { 97 | if (mCustomizationOptionsBundle.isShowDeleteButton() && mPinLength > 0) { 98 | holder.mButtonImage.setVisibility(View.VISIBLE); 99 | if (mCustomizationOptionsBundle.getDeleteButtonDrawable() != null) { 100 | holder.mButtonImage.setImageDrawable(mCustomizationOptionsBundle.getDeleteButtonDrawable()); 101 | } 102 | holder.mButtonImage.setColorFilter(mCustomizationOptionsBundle.getTextColor(), 103 | PorterDuff.Mode.SRC_ATOP); 104 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( 105 | mCustomizationOptionsBundle.getDeleteButtonSize(), 106 | mCustomizationOptionsBundle.getDeleteButtonSize()); 107 | holder.mButtonImage.setLayoutParams(params); 108 | } else { 109 | holder.mButtonImage.setVisibility(View.GONE); 110 | } 111 | } 112 | } 113 | 114 | @Override 115 | public int getItemCount() { 116 | return 12; 117 | } 118 | 119 | @Override 120 | public int getItemViewType(int position) { 121 | if (position == getItemCount() - 1) { 122 | return VIEW_TYPE_DELETE; 123 | } 124 | return VIEW_TYPE_NUMBER; 125 | } 126 | 127 | public int getPinLength() { 128 | return mPinLength; 129 | } 130 | 131 | public void setPinLength(int pinLength) { 132 | this.mPinLength = pinLength; 133 | } 134 | 135 | public int[] getKeyValues() { 136 | return mKeyValues; 137 | } 138 | 139 | public void setKeyValues(int[] keyValues) { 140 | this.mKeyValues = getAdjustKeyValues(keyValues); 141 | notifyDataSetChanged(); 142 | } 143 | 144 | private int[] getAdjustKeyValues(int[] keyValues) { 145 | int[] adjustedKeyValues = new int[keyValues.length + 1]; 146 | for (int i = 0; i < keyValues.length; i++) { 147 | if (i < 9) { 148 | adjustedKeyValues[i] = keyValues[i]; 149 | } else { 150 | adjustedKeyValues[i] = -1; 151 | adjustedKeyValues[i + 1] = keyValues[i]; 152 | } 153 | } 154 | return adjustedKeyValues; 155 | } 156 | 157 | public OnNumberClickListener getOnItemClickListener() { 158 | return mOnNumberClickListener; 159 | } 160 | 161 | public void setOnItemClickListener(OnNumberClickListener onNumberClickListener) { 162 | this.mOnNumberClickListener = onNumberClickListener; 163 | } 164 | 165 | public OnDeleteClickListener getOnDeleteClickListener() { 166 | return mOnDeleteClickListener; 167 | } 168 | 169 | public void setOnDeleteClickListener(OnDeleteClickListener onDeleteClickListener) { 170 | this.mOnDeleteClickListener = onDeleteClickListener; 171 | } 172 | 173 | public CustomizationOptionsBundle getCustomizationOptions() { 174 | return mCustomizationOptionsBundle; 175 | } 176 | 177 | public void setCustomizationOptions(CustomizationOptionsBundle customizationOptionsBundle) { 178 | this.mCustomizationOptionsBundle = customizationOptionsBundle; 179 | } 180 | 181 | public class NumberViewHolder extends RecyclerView.ViewHolder { 182 | Button mNumberButton; 183 | 184 | public NumberViewHolder(final View itemView) { 185 | super(itemView); 186 | mNumberButton = (Button) itemView.findViewById(R.id.button); 187 | mNumberButton.setOnClickListener(new View.OnClickListener() { 188 | @Override 189 | public void onClick(View v) { 190 | if (mOnNumberClickListener != null) { 191 | mOnNumberClickListener.onNumberClicked((Integer) v.getTag()); 192 | } 193 | } 194 | }); 195 | } 196 | } 197 | 198 | public class DeleteViewHolder extends RecyclerView.ViewHolder { 199 | LinearLayout mDeleteButton; 200 | ImageView mButtonImage; 201 | 202 | public DeleteViewHolder(final View itemView) { 203 | super(itemView); 204 | mDeleteButton = (LinearLayout) itemView.findViewById(R.id.button); 205 | mButtonImage = (ImageView) itemView.findViewById(R.id.buttonImage); 206 | 207 | if (mCustomizationOptionsBundle.isShowDeleteButton() && mPinLength > 0) { 208 | mDeleteButton.setOnClickListener(new View.OnClickListener() { 209 | @Override 210 | public void onClick(View v) { 211 | if (mOnDeleteClickListener != null) { 212 | mOnDeleteClickListener.onDeleteClicked(); 213 | } 214 | } 215 | }); 216 | 217 | mDeleteButton.setOnLongClickListener(new View.OnLongClickListener() { 218 | @Override 219 | public boolean onLongClick(View v) { 220 | if (mOnDeleteClickListener != null) { 221 | mOnDeleteClickListener.onDeleteLongClicked(); 222 | } 223 | return true; 224 | } 225 | }); 226 | 227 | mDeleteButton.setOnTouchListener(new View.OnTouchListener() { 228 | private Rect rect; 229 | 230 | @Override 231 | public boolean onTouch(View v, MotionEvent event) { 232 | if (event.getAction() == MotionEvent.ACTION_DOWN) { 233 | mButtonImage.setColorFilter(mCustomizationOptionsBundle 234 | .getDeleteButtonPressesColor()); 235 | rect = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()); 236 | } 237 | if (event.getAction() == MotionEvent.ACTION_UP) { 238 | mButtonImage.clearColorFilter(); 239 | } 240 | if (event.getAction() == MotionEvent.ACTION_MOVE) { 241 | if (!rect.contains(v.getLeft() + (int) event.getX(), 242 | v.getTop() + (int) event.getY())) { 243 | mButtonImage.clearColorFilter(); 244 | } 245 | } 246 | return false; 247 | } 248 | }); 249 | } 250 | } 251 | } 252 | 253 | public interface OnNumberClickListener { 254 | void onNumberClicked(int keyValue); 255 | } 256 | 257 | public interface OnDeleteClickListener { 258 | void onDeleteClicked(); 259 | 260 | void onDeleteLongClicked(); 261 | } 262 | } 263 | -------------------------------------------------------------------------------- /pinlockview/src/main/java/com/andrognito/pinlockview/PinLockListener.java: -------------------------------------------------------------------------------- 1 | package com.andrognito.pinlockview; 2 | 3 | /** 4 | * The listener that triggers callbacks for various events 5 | * in the {@link PinLockView} 6 | * 7 | * Created by aritraroy on 31/05/16. 8 | */ 9 | public interface PinLockListener { 10 | 11 | /** 12 | * Triggers when the complete pin is entered, 13 | * depends on the pin length set by the user 14 | * 15 | * @param pin the complete pin 16 | */ 17 | void onComplete(String pin); 18 | 19 | 20 | /** 21 | * Triggers when the pin is empty after manual deletion 22 | */ 23 | void onEmpty(); 24 | 25 | /** 26 | * Triggers on a key press on the {@link PinLockView} 27 | * 28 | * @param pinLength the current pin length 29 | * @param intermediatePin the intermediate pin 30 | */ 31 | void onPinChange(int pinLength, String intermediatePin); 32 | } 33 | -------------------------------------------------------------------------------- /pinlockview/src/main/java/com/andrognito/pinlockview/PinLockView.java: -------------------------------------------------------------------------------- 1 | package com.andrognito.pinlockview; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.drawable.Drawable; 6 | import android.support.annotation.Nullable; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.util.AttributeSet; 9 | 10 | /** 11 | * Represents a numeric lock view which can used to taken numbers as input. 12 | * The length of the input can be customized using {@link PinLockView#setPinLength(int)}, the default value being 4 13 | *

14 | * It can also be used as dial pad for taking number inputs. 15 | * Optionally, {@link IndicatorDots} can be attached to this view to indicate the length of the input taken 16 | * Created by aritraroy on 31/05/16. 17 | */ 18 | public class PinLockView extends RecyclerView { 19 | 20 | private static final int DEFAULT_PIN_LENGTH = 4; 21 | private static final int[] DEFAULT_KEY_SET = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; 22 | 23 | private String mPin = ""; 24 | private int mPinLength; 25 | private int mHorizontalSpacing, mVerticalSpacing; 26 | private int mTextColor, mDeleteButtonPressedColor; 27 | private int mTextSize, mButtonSize, mDeleteButtonSize; 28 | private Drawable mButtonBackgroundDrawable; 29 | private Drawable mDeleteButtonDrawable; 30 | private boolean mShowDeleteButton; 31 | 32 | private IndicatorDots mIndicatorDots; 33 | private PinLockAdapter mAdapter; 34 | private PinLockListener mPinLockListener; 35 | private CustomizationOptionsBundle mCustomizationOptionsBundle; 36 | private int[] mCustomKeySet; 37 | 38 | private PinLockAdapter.OnNumberClickListener mOnNumberClickListener 39 | = new PinLockAdapter.OnNumberClickListener() { 40 | @Override 41 | public void onNumberClicked(int keyValue) { 42 | if (mPin.length() < getPinLength()) { 43 | mPin = mPin.concat(String.valueOf(keyValue)); 44 | 45 | if (isIndicatorDotsAttached()) { 46 | mIndicatorDots.updateDot(mPin.length()); 47 | } 48 | 49 | if (mPin.length() == 1) { 50 | mAdapter.setPinLength(mPin.length()); 51 | mAdapter.notifyItemChanged(mAdapter.getItemCount() - 1); 52 | } 53 | 54 | if (mPinLockListener != null) { 55 | if (mPin.length() == mPinLength) { 56 | mPinLockListener.onComplete(mPin); 57 | } else { 58 | mPinLockListener.onPinChange(mPin.length(), mPin); 59 | } 60 | } 61 | } else { 62 | if (!isShowDeleteButton()) { 63 | resetPinLockView(); 64 | mPin = mPin.concat(String.valueOf(keyValue)); 65 | 66 | if (isIndicatorDotsAttached()) { 67 | mIndicatorDots.updateDot(mPin.length()); 68 | } 69 | 70 | if (mPinLockListener != null) { 71 | mPinLockListener.onPinChange(mPin.length(), mPin); 72 | } 73 | 74 | } else { 75 | if (mPinLockListener != null) { 76 | mPinLockListener.onComplete(mPin); 77 | } 78 | } 79 | } 80 | } 81 | }; 82 | 83 | private PinLockAdapter.OnDeleteClickListener mOnDeleteClickListener 84 | = new PinLockAdapter.OnDeleteClickListener() { 85 | @Override 86 | public void onDeleteClicked() { 87 | if (mPin.length() > 0) { 88 | mPin = mPin.substring(0, mPin.length() - 1); 89 | 90 | if (isIndicatorDotsAttached()) { 91 | mIndicatorDots.updateDot(mPin.length()); 92 | } 93 | 94 | if (mPin.length() == 0) { 95 | mAdapter.setPinLength(mPin.length()); 96 | mAdapter.notifyItemChanged(mAdapter.getItemCount() - 1); 97 | } 98 | 99 | if (mPinLockListener != null) { 100 | if (mPin.length() == 0) { 101 | mPinLockListener.onEmpty(); 102 | clearInternalPin(); 103 | } else { 104 | mPinLockListener.onPinChange(mPin.length(), mPin); 105 | } 106 | } 107 | } else { 108 | if (mPinLockListener != null) { 109 | mPinLockListener.onEmpty(); 110 | } 111 | } 112 | } 113 | 114 | @Override 115 | public void onDeleteLongClicked() { 116 | resetPinLockView(); 117 | if (mPinLockListener != null) { 118 | mPinLockListener.onEmpty(); 119 | } 120 | } 121 | }; 122 | 123 | public PinLockView(Context context) { 124 | super(context); 125 | init(null, 0); 126 | } 127 | 128 | public PinLockView(Context context, @Nullable AttributeSet attrs) { 129 | super(context, attrs); 130 | init(attrs, 0); 131 | } 132 | 133 | public PinLockView(Context context, @Nullable AttributeSet attrs, int defStyle) { 134 | super(context, attrs, defStyle); 135 | init(attrs, defStyle); 136 | } 137 | 138 | private void init(AttributeSet attributeSet, int defStyle) { 139 | 140 | TypedArray typedArray = getContext().obtainStyledAttributes(attributeSet, R.styleable.PinLockView); 141 | 142 | try { 143 | mPinLength = typedArray.getInt(R.styleable.PinLockView_pinLength, DEFAULT_PIN_LENGTH); 144 | mHorizontalSpacing = (int) typedArray.getDimension(R.styleable.PinLockView_keypadHorizontalSpacing, ResourceUtils.getDimensionInPx(getContext(), R.dimen.default_horizontal_spacing)); 145 | mVerticalSpacing = (int) typedArray.getDimension(R.styleable.PinLockView_keypadVerticalSpacing, ResourceUtils.getDimensionInPx(getContext(), R.dimen.default_vertical_spacing)); 146 | mTextColor = typedArray.getColor(R.styleable.PinLockView_keypadTextColor, ResourceUtils.getColor(getContext(), R.color.white)); 147 | mTextSize = (int) typedArray.getDimension(R.styleable.PinLockView_keypadTextSize, ResourceUtils.getDimensionInPx(getContext(), R.dimen.default_text_size)); 148 | mButtonSize = (int) typedArray.getDimension(R.styleable.PinLockView_keypadButtonSize, ResourceUtils.getDimensionInPx(getContext(), R.dimen.default_button_size)); 149 | mDeleteButtonSize = (int) typedArray.getDimension(R.styleable.PinLockView_keypadDeleteButtonSize, ResourceUtils.getDimensionInPx(getContext(), R.dimen.default_delete_button_size)); 150 | mButtonBackgroundDrawable = typedArray.getDrawable(R.styleable.PinLockView_keypadButtonBackgroundDrawable); 151 | mDeleteButtonDrawable = typedArray.getDrawable(R.styleable.PinLockView_keypadDeleteButtonDrawable); 152 | mShowDeleteButton = typedArray.getBoolean(R.styleable.PinLockView_keypadShowDeleteButton, true); 153 | mDeleteButtonPressedColor = typedArray.getColor(R.styleable.PinLockView_keypadDeleteButtonPressedColor, ResourceUtils.getColor(getContext(), R.color.greyish)); 154 | } finally { 155 | typedArray.recycle(); 156 | } 157 | 158 | mCustomizationOptionsBundle = new CustomizationOptionsBundle(); 159 | mCustomizationOptionsBundle.setTextColor(mTextColor); 160 | mCustomizationOptionsBundle.setTextSize(mTextSize); 161 | mCustomizationOptionsBundle.setButtonSize(mButtonSize); 162 | mCustomizationOptionsBundle.setButtonBackgroundDrawable(mButtonBackgroundDrawable); 163 | mCustomizationOptionsBundle.setDeleteButtonDrawable(mDeleteButtonDrawable); 164 | mCustomizationOptionsBundle.setDeleteButtonSize(mDeleteButtonSize); 165 | mCustomizationOptionsBundle.setShowDeleteButton(mShowDeleteButton); 166 | mCustomizationOptionsBundle.setDeleteButtonPressesColor(mDeleteButtonPressedColor); 167 | 168 | initView(); 169 | } 170 | 171 | private void initView() { 172 | setLayoutManager(new LTRGridLayoutManager(getContext(), 3)); 173 | 174 | mAdapter = new PinLockAdapter(getContext()); 175 | mAdapter.setOnItemClickListener(mOnNumberClickListener); 176 | mAdapter.setOnDeleteClickListener(mOnDeleteClickListener); 177 | mAdapter.setCustomizationOptions(mCustomizationOptionsBundle); 178 | setAdapter(mAdapter); 179 | 180 | addItemDecoration(new ItemSpaceDecoration(mHorizontalSpacing, mVerticalSpacing, 3, false)); 181 | setOverScrollMode(OVER_SCROLL_NEVER); 182 | } 183 | 184 | /** 185 | * Sets a {@link PinLockListener} to the to listen to pin update events 186 | * 187 | * @param pinLockListener the listener 188 | */ 189 | public void setPinLockListener(PinLockListener pinLockListener) { 190 | this.mPinLockListener = pinLockListener; 191 | } 192 | 193 | /** 194 | * Get the length of the current pin length 195 | * 196 | * @return the length of the pin 197 | */ 198 | public int getPinLength() { 199 | return mPinLength; 200 | } 201 | 202 | /** 203 | * Sets the pin length dynamically 204 | * 205 | * @param pinLength the pin length 206 | */ 207 | public void setPinLength(int pinLength) { 208 | this.mPinLength = pinLength; 209 | 210 | if (isIndicatorDotsAttached()) { 211 | mIndicatorDots.setPinLength(pinLength); 212 | } 213 | } 214 | 215 | /** 216 | * Get the text color in the buttons 217 | * 218 | * @return the text color 219 | */ 220 | public int getTextColor() { 221 | return mTextColor; 222 | } 223 | 224 | /** 225 | * Set the text color of the buttons dynamically 226 | * 227 | * @param textColor the text color 228 | */ 229 | public void setTextColor(int textColor) { 230 | this.mTextColor = textColor; 231 | mCustomizationOptionsBundle.setTextColor(textColor); 232 | mAdapter.notifyDataSetChanged(); 233 | } 234 | 235 | /** 236 | * Get the size of the text in the buttons 237 | * 238 | * @return the size of the text in pixels 239 | */ 240 | public int getTextSize() { 241 | return mTextSize; 242 | } 243 | 244 | /** 245 | * Set the size of text in pixels 246 | * 247 | * @param textSize the text size in pixels 248 | */ 249 | public void setTextSize(int textSize) { 250 | this.mTextSize = textSize; 251 | mCustomizationOptionsBundle.setTextSize(textSize); 252 | mAdapter.notifyDataSetChanged(); 253 | } 254 | 255 | /** 256 | * Get the size of the pin buttons 257 | * 258 | * @return the size of the button in pixels 259 | */ 260 | public int getButtonSize() { 261 | return mButtonSize; 262 | } 263 | 264 | /** 265 | * Set the size of the pin buttons dynamically 266 | * 267 | * @param buttonSize the button size 268 | */ 269 | public void setButtonSize(int buttonSize) { 270 | this.mButtonSize = buttonSize; 271 | mCustomizationOptionsBundle.setButtonSize(buttonSize); 272 | mAdapter.notifyDataSetChanged(); 273 | } 274 | 275 | /** 276 | * Get the current background drawable of the buttons, can be null 277 | * 278 | * @return the background drawable 279 | */ 280 | public Drawable getButtonBackgroundDrawable() { 281 | return mButtonBackgroundDrawable; 282 | } 283 | 284 | /** 285 | * Set the background drawable of the buttons dynamically 286 | * 287 | * @param buttonBackgroundDrawable the background drawable 288 | */ 289 | public void setButtonBackgroundDrawable(Drawable buttonBackgroundDrawable) { 290 | this.mButtonBackgroundDrawable = buttonBackgroundDrawable; 291 | mCustomizationOptionsBundle.setButtonBackgroundDrawable(buttonBackgroundDrawable); 292 | mAdapter.notifyDataSetChanged(); 293 | } 294 | 295 | /** 296 | * Get the drawable of the delete button 297 | * 298 | * @return the delete button drawable 299 | */ 300 | public Drawable getDeleteButtonDrawable() { 301 | return mDeleteButtonDrawable; 302 | } 303 | 304 | /** 305 | * Set the drawable of the delete button dynamically 306 | * 307 | * @param deleteBackgroundDrawable the delete button drawable 308 | */ 309 | public void setDeleteButtonDrawable(Drawable deleteBackgroundDrawable) { 310 | this.mDeleteButtonDrawable = deleteBackgroundDrawable; 311 | mCustomizationOptionsBundle.setDeleteButtonDrawable(deleteBackgroundDrawable); 312 | mAdapter.notifyDataSetChanged(); 313 | } 314 | 315 | /** 316 | * Get the delete button size in pixels 317 | * 318 | * @return size in pixels 319 | */ 320 | public int getDeleteButtonSize() { 321 | return mDeleteButtonSize; 322 | } 323 | 324 | /** 325 | * Set the size of the delete button in pixels 326 | * 327 | * @param deleteButtonSize size in pixels 328 | */ 329 | public void setDeleteButtonSize(int deleteButtonSize) { 330 | this.mDeleteButtonSize = deleteButtonSize; 331 | mCustomizationOptionsBundle.setDeleteButtonSize(deleteButtonSize); 332 | mAdapter.notifyDataSetChanged(); 333 | } 334 | 335 | /** 336 | * Is the delete button shown 337 | * 338 | * @return returns true if shown, false otherwise 339 | */ 340 | public boolean isShowDeleteButton() { 341 | return mShowDeleteButton; 342 | } 343 | 344 | /** 345 | * Dynamically set if the delete button should be shown 346 | * 347 | * @param showDeleteButton true if the delete button should be shown, false otherwise 348 | */ 349 | public void setShowDeleteButton(boolean showDeleteButton) { 350 | this.mShowDeleteButton = showDeleteButton; 351 | mCustomizationOptionsBundle.setShowDeleteButton(showDeleteButton); 352 | mAdapter.notifyDataSetChanged(); 353 | } 354 | 355 | /** 356 | * Get the delete button pressed/focused state color 357 | * 358 | * @return color of the button 359 | */ 360 | public int getDeleteButtonPressedColor() { 361 | return mDeleteButtonPressedColor; 362 | } 363 | 364 | /** 365 | * Set the pressed/focused state color of the delete button 366 | * 367 | * @param deleteButtonPressedColor the color of the delete button 368 | */ 369 | public void setDeleteButtonPressedColor(int deleteButtonPressedColor) { 370 | this.mDeleteButtonPressedColor = deleteButtonPressedColor; 371 | mCustomizationOptionsBundle.setDeleteButtonPressesColor(deleteButtonPressedColor); 372 | mAdapter.notifyDataSetChanged(); 373 | } 374 | 375 | public int[] getCustomKeySet() { 376 | return mCustomKeySet; 377 | } 378 | 379 | public void setCustomKeySet(int[] customKeySet) { 380 | this.mCustomKeySet = customKeySet; 381 | 382 | if (mAdapter != null) { 383 | mAdapter.setKeyValues(customKeySet); 384 | } 385 | } 386 | 387 | public void enableLayoutShuffling() { 388 | this.mCustomKeySet = ShuffleArrayUtils.shuffle(DEFAULT_KEY_SET); 389 | 390 | if (mAdapter != null) { 391 | mAdapter.setKeyValues(mCustomKeySet); 392 | } 393 | } 394 | 395 | private void clearInternalPin() { 396 | mPin = ""; 397 | } 398 | 399 | /** 400 | * Resets the {@link PinLockView}, clearing the entered pin 401 | * and resetting the {@link IndicatorDots} if attached 402 | */ 403 | public void resetPinLockView() { 404 | 405 | clearInternalPin(); 406 | 407 | mAdapter.setPinLength(mPin.length()); 408 | mAdapter.notifyItemChanged(mAdapter.getItemCount() - 1); 409 | 410 | if (mIndicatorDots != null) { 411 | mIndicatorDots.updateDot(mPin.length()); 412 | } 413 | } 414 | 415 | /** 416 | * Returns true if {@link IndicatorDots} are attached to {@link PinLockView} 417 | * 418 | * @return true if attached, false otherwise 419 | */ 420 | public boolean isIndicatorDotsAttached() { 421 | return mIndicatorDots != null; 422 | } 423 | 424 | /** 425 | * Attaches {@link IndicatorDots} to {@link PinLockView} 426 | * 427 | * @param mIndicatorDots the view to attach 428 | */ 429 | public void attachIndicatorDots(IndicatorDots mIndicatorDots) { 430 | this.mIndicatorDots = mIndicatorDots; 431 | } 432 | } 433 | -------------------------------------------------------------------------------- /pinlockview/src/main/java/com/andrognito/pinlockview/ResourceUtils.java: -------------------------------------------------------------------------------- 1 | package com.andrognito.pinlockview; 2 | 3 | import android.content.Context; 4 | import android.graphics.drawable.Drawable; 5 | import android.support.annotation.ColorRes; 6 | import android.support.annotation.DimenRes; 7 | import android.support.annotation.DrawableRes; 8 | import android.support.v4.content.ContextCompat; 9 | 10 | /** 11 | * Created by aritraroy on 10/06/16. 12 | */ 13 | public class ResourceUtils { 14 | 15 | private ResourceUtils() { 16 | throw new AssertionError(); 17 | } 18 | 19 | public static int getColor(Context context, @ColorRes int id) { 20 | return ContextCompat.getColor(context, id); 21 | } 22 | 23 | public static float getDimensionInPx(Context context, @DimenRes int id) { 24 | return context.getResources().getDimension(id); 25 | } 26 | 27 | public static Drawable getDrawable(Context context, @DrawableRes int id) { 28 | return ContextCompat.getDrawable(context, id); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /pinlockview/src/main/java/com/andrognito/pinlockview/ShuffleArrayUtils.java: -------------------------------------------------------------------------------- 1 | package com.andrognito.pinlockview; 2 | 3 | import java.util.Random; 4 | 5 | /** 6 | * Created by aritraroy on 10/03/17. 7 | */ 8 | 9 | public class ShuffleArrayUtils { 10 | 11 | /** 12 | * Shuffle an array 13 | * 14 | * @param array 15 | */ 16 | static int[] shuffle(int[] array) { 17 | int length = array.length; 18 | Random random = new Random(); 19 | random.nextInt(); 20 | 21 | for (int i = 0; i < length; i++) { 22 | int change = i + random.nextInt(length - i); 23 | swap(array, i, change); 24 | } 25 | return array; 26 | } 27 | 28 | private static void swap(int[] array, int index, int change) { 29 | int temp = array[index]; 30 | array[index] = array[change]; 31 | array[change] = temp; 32 | } 33 | } -------------------------------------------------------------------------------- /pinlockview/src/main/res/drawable/dot_empty.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /pinlockview/src/main/res/drawable/dot_filled.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /pinlockview/src/main/res/drawable/ic_backspace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aritraroy/PinLockView/5079b412c75c2a01dcd105b47cdff86a4d4e8f5c/pinlockview/src/main/res/drawable/ic_backspace.png -------------------------------------------------------------------------------- /pinlockview/src/main/res/layout-v21/layout_number_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 |