|
1 | | -# android-passcodeview |
| 1 | +# Android Passcode Keypad View |
| 2 | + |
| 3 | +A custom view with keyboard and character display to be used for authentication. |
| 4 | + |
| 5 | +The view has a bunch customisation options to make to look and work the way whichever needed. |
| 6 | + |
| 7 | +## Demo |
| 8 | +<img src="https://arjun-sna.github.io/raw/passcodeview_1.gif" width="250" /> |
| 9 | +<img src="https://arjun-sna.github.io/raw/passcodeview_2.gif" width="250" /> |
| 10 | + |
| 11 | +## Installation |
| 12 | +--to be updated |
| 13 | + |
| 14 | +## Usage |
| 15 | + Add the view in the layout file |
| 16 | + |
| 17 | + ```xml |
| 18 | + <in.arjsna.lib.PassCodeView |
| 19 | + android:id="@+id/pass_code_view" |
| 20 | + android:layout_width="match_parent" |
| 21 | + android:layout_height="wrap_content" |
| 22 | + app:digits="4" |
| 23 | + app:digit_size="30.0dp" |
| 24 | + app:key_text_size="30.0sp" |
| 25 | + android:padding="25.0dp" |
| 26 | + app:empty_drawable="@drawable/empty_dot" |
| 27 | + app:filled_drawable="@drawable/filled_dot"/> |
| 28 | + |
| 29 | + ``` |
| 30 | + |
| 31 | +View attributes that can be included in xml are |
| 32 | + |
| 33 | + |
| 34 | +`digits` - number of digits in passcode |
| 35 | + |
| 36 | +`filled_drawable` - drawable to be show for filled digits |
| 37 | + |
| 38 | +`empty_drawable` - drawable to be show for empty digits |
| 39 | + |
| 40 | +`key_text_size` - size of text in keyboard's key |
| 41 | + |
| 42 | +`digit_spacing` - horizontal space between each digit |
| 43 | + |
| 44 | +`digit_vertical_padding` - vertical padding of digits |
| 45 | + |
| 46 | +`divider_visible` - boolean to show or hide divider between digits and keyboard |
| 47 | + |
| 48 | + |
| 49 | +Other customisations options available are |
| 50 | + |
| 51 | +```java |
| 52 | +PassCodeView passCodeView = (PassCodeView) findViewById(R.id.pass_code_view); |
| 53 | +Typeface typeFace = Typeface.createFromAsset(getAssets(), "fonts/Font-Bold.ttf"); |
| 54 | + |
| 55 | +/** |
| 56 | + *Set TypeFace for the font in keys of keypad |
| 57 | + */ |
| 58 | +passCodeView.setTypeFace(typeFace); |
| 59 | + |
| 60 | +/** |
| 61 | + * Set color for the keypad text |
| 62 | + * @param color - Resource id of the color to be set |
| 63 | + */ |
| 64 | +passCodeView.setKeyTextColor(getResources.getColor(R.color.black)); |
| 65 | + |
| 66 | +/** |
| 67 | + * Set size of keypad text |
| 68 | + * @param size - Text size value to be set |
| 69 | + */ |
| 70 | +passCodeView.setKeyTextSize(30); |
| 71 | + |
| 72 | +/** |
| 73 | + * Reset the code to empty |
| 74 | + */ |
| 75 | +passCodeView.reset(); |
| 76 | + |
| 77 | +/** |
| 78 | + * Attach {@code TextChangeListener} to get notified on text changes |
| 79 | + * @param listener - {@Code TextChangeListener} object to be attached and notified |
| 80 | + */ |
| 81 | +passCodeView.setOnTextChangeListener(new PassCodeView.TextChangeListener() { |
| 82 | + @Override |
| 83 | + public void onTextChanged(String text) { |
| 84 | + Log.i("Passcode", "text"); |
| 85 | + } |
| 86 | + }); |
| 87 | +``` |
| 88 | + |
| 89 | +License |
| 90 | +======= |
| 91 | + |
| 92 | +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. |
| 93 | +You may obtain a copy of the License in the LICENSE file, or at: |
| 94 | + |
| 95 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 96 | + |
| 97 | +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. |
| 98 | + |
0 commit comments