A clean, minimal, highly customizable pin lock view for Android

Overview

PinLockView

A clean, minimalistic, easy-to-use and highly customizable pin lock custom view for Android.

Specs

Download API License Android Arsenal

PinLockView

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.

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.

PinLockView

Download

This library is available in jCenter which is the default Maven repository used in Android Studio.

Gradle

dependencies {
    // other dependencies here
    
    implementation 'com.andrognito.pinlockview:pinlockview:2.1.0'
}

Maven

<dependency>
  <groupId>com.andrognito.pinlockview</groupId>
  <artifactId>pinlockview</artifactId>
  <version>2.1.0</version>
  <type>pom</type>
</dependency>

Usage

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.

Step 1

Place the view in your XML layout file.

    <com.andrognito.pinlockview.PinLockView
        android:id="@+id/pin_lock_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

Step 2

Reference the view in code and add a listener to it.

    mPinLockView = (PinLockView) findViewById(R.id.pin_lock_view);
    mPinLockView.setPinLockListener(mPinLockListener);

Implement the listener interface as follows,

private PinLockListener mPinLockListener = new PinLockListener() {
    @Override
    public void onComplete(String pin) {
        Log.d(TAG, "Pin complete: " + pin);
     }

    @Override
    public void onEmpty() {
        Log.d(TAG, "Pin empty");
    }

    @Override
    public void onPinChange(int pinLength, String intermediatePin) {
         Log.d(TAG, "Pin changed, new length " + pinLength + " with intermediate pin " + intermediatePin);
    }
};

And that's it! Your PinLockView is ready to rock.

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.

Customization

IndicatorDots (Addon)

PinLockView comes bundled with an addon view, IndicatorDots which can be optionally attached with the PinLockView to indicate pin changes visually to the user.

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.

Add the view to you XML layout, generally placed above your PinLockView,

 <com.andrognito.pinlockview.IndicatorDots
        android:id="@+id/indicator_dots"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

then find a reference to the view and attach it to the parent PinLockView,

mIndicatorDots = (IndicatorDots) findViewById(R.id.indicator_dots);
mPinLockView.attachIndicatorDots(mIndicatorDots);

You MUST attach it to the PinLockView, otherwise it will be simply ignored.

Theming

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.

  app:pinLength="6"                                       // Change the pin length
  app:keypadTextColor="#E6E6E6"                           // Change the color of the keypad text
  app:keypadTextSize="16dp"                               // Change the text size in the keypad
  app:keypadButtonSize="72dp"                             // Change the size of individual keys/buttons
  app:keypadVerticalSpacing="24dp"                        // Alters the vertical spacing between the keypad buttons
  app:keypadHorizontalSpacing="36dp"                      // Alters the horizontal spacing between the keypad buttons
  app:keypadButtonBackgroundDrawable="@drawable/bg"       // Set a custom background drawable for the buttons
  app:keypadDeleteButtonDrawable="@drawable/ic_back"      // Set a custom drawable for the delete button
  app:keypadDeleteButtonSize="16dp"                       // Change the size of the delete button icon in the keypad
  app:keypadShowDeleteButton="false"                      // Should show the delete button, default is true
  app:keypadDeleteButtonPressedColor="#C8C8C8"            // Change the pressed/focused state color of the delete button
  
  app:dotEmptyBackground="@drawable/empty"                // Customize the empty state of the dots
  app:dotFilledBackground"@drawable/filled"               // Customize the filled state of the dots
  app:dotDiameter="12dp"                                  // Change the diameter of the dots
  app:dotSpacing="16dp"                                   // Change the spacing between individual dots
  app:indicatorType="fillWithAnimation"                   // Choose between "fixed", "fill" and "fillWithAnimation"

Contribution

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.

About The Author

Aritra Roy

Android & Backend Developer. Blogger. Designer. Fitness Enthusiast.

License

Copyright 2017 aritraroy

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

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.
Comments
  • Can't change IndicatorDots colors

    Can't change IndicatorDots colors

    I can't change the color of empty or filled state of the IndicatorDots neither using "dotEmptyBackground" nor "dotFilledBackground"

    question 
    opened by KhalidElSayed 4
  • the number 4 is not visible.

    the number 4 is not visible.

    first of all, thank you for your library!

    the PinLockView does not visible number 4 my LG G3.Cat6 device. i think, can you solve it with little edit to PinLockAdapter.

    please see below lines(PinLockAdapter.java: 70):

    if (position == 10) {
      holder.mNumberButton.setText("0");
    } else if (position == 9) {
      holder.mNumberButton.setVisibility(View.INVISIBLE);
    } else {
      holder.mNumberButton.setText(String.valueOf((position + 1) % 10));
    }
    

    edit to:

    if (position == 10) {
      holder.mNumberButton.setText("0");
      holder.mNumberButton.setVisibility(View.VISIBLE);
    } else if (position == 9) {
      holder.mNumberButton.setVisibility(View.INVISIBLE);
    } else {
      holder.mNumberButton.setText(String.valueOf((position + 1) % 10));
      holder.mNumberButton.setVisibility(View.VISIBLE);
    }
    

    how think about it?

    opened by chulwoo-park 4
  • keypadButtonBackgroundDrawable

    keypadButtonBackgroundDrawable

    Hello Your lib is great But keypadButtonBackgroundDrawable does not apply correctly Even when I set

    app:keypadButtonBackgroundDrawable="?attr/selectableItemBackgroundBorderless"

    it's apply only to zero button

    opened by solareye 4
  • AnimatorCompatHelper Class Not Found Exception using AppCompat 27.0.0

    AnimatorCompatHelper Class Not Found Exception using AppCompat 27.0.0

    When using compat library 27.0.0 the app crash when call animatorCompatHelper

    java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/animation/AnimatorCompatHelper;
                                                           at android.support.v7.widget.DefaultItemAnimator.resetAnimation(DefaultItemAnimator.java:515)
                                                           at android.support.v7.widget.DefaultItemAnimator.animateChange(DefaultItemAnimator.java:322)
                                                           at android.support.v7.widget.SimpleItemAnimator.animateChange(SimpleItemAnimator.java:149)
                                                           at android.support.v7.widget.RecyclerView.animateChange(RecyclerView.java:3836)
    
    opened by Jaime97 3
  • FATAL EXCEPTION

    FATAL EXCEPTION

    How to fix? android.view.InflateException: Binary XML file line #9: Error inflating class android.widget.Button at android.view.LayoutInflater.createView(LayoutInflater.java:640) at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748) at android.view.LayoutInflater.rInflate(LayoutInflater.java:813) at android.view.LayoutInflater.inflate(LayoutInflater.java:511) at android.view.LayoutInflater.inflate(LayoutInflater.java:415) at com.andrognito.pinlockview.PinLockAdapter.onCreateViewHolder(PinLockAdapter.java:41)

    Error here: PinLockAdapter.class @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { RecyclerView.ViewHolder viewHolder; if (viewType == VIEW_TYPE_NUMBER) { View view = View.inflate(parent.getContext(),R.layout.layout_number_item, null); viewHolder = new NumberViewHolder(view); } else { View view = View.inflate(parent.getContext(),R.layout.layout_delete_item, null); viewHolder = new DeleteViewHolder(view); } return viewHolder; }

    Error when: ... //from service: view_pin = View.inflate(this, R.layout.activity_lock_pin, null); ... <com.andrognito.pinlockview.PinLockView android:id="@+id/pin_lock_view_Pin" android:layout_width="300dp" android:layout_height="wrap_content" />

    opened by ShifuSD 3
  • Allows dots to be initialised as they're being typed

    Allows dots to be initialised as they're being typed

    Would it be possible to have the indicator dots show up as they're being typed (for a non-fixed PIN length) instead of having the number of dots be the length of the PIN?

    enhancement 
    opened by ProfPh 3
  • Clear indicator dots

    Clear indicator dots

    Hi, thanks for your good job. I've implemented this in an application and I like to clear indicator dots when the entered pin is incorrect. how can I do so?

    opened by amirj700 2
  • LTR direction for indicator view and PinLockView

    LTR direction for indicator view and PinLockView

    Hello, I've just made a couple of changes after I noticed that in my device the PinLockView and IndicatorDots views are shown in RTL because of my native device's language is Hebrew (which is an RTL language), and so the sample app looked like this: (Don't be worry about the big numeric text sizes and everything in the screenshots, I just changed it in my sample app's view attributes) temp_screenshot2

    And after my submitted changes: temp_screenshot1

    Of course I also checked the results with an LTR based language (English) and it looked the same as in RTL based language (Hebrew).

    Thank you for a great library!

    opened by idish 2
  • how to implement ripple effect on pressed

    how to implement ripple effect on pressed

    ` <com.andrognito.pinlockview.IndicatorDots

        android:id="@+id/indicator_dots"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/profile_name"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="36dp"
        app:dotDiameter="12dp"
        app:dotSpacing="16dp" />
    
    <com.andrognito.pinlockview.PinLockView
        android:id="@+id/pin_lock_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/indicator_dots"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="16dp"
        app:dotFilledBackground="@drawable/dot_filled"
        app:keypadButtonSize="72dp"
    
        app:keypadDeleteButtonPressedColor="#C8C8C8"
        app:keypadDeleteButtonSize="16dp"
        app:keypadShowDeleteButton="true"
        app:keypadTextColor="@color/white"
        app:keypadTextSize="18dp" />`
    
    question 
    opened by altaf2892 2
  • Back button isn't being shown

    Back button isn't being shown

    No matter what I do. The back button is not being shown.

    <com.andrognito.pinlockview.PinLockView android:id="@+id/pin_lock_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/indicator_dots" app:keypadButtonSize="72dp" app:keypadTextSize="18dp" app:keypadShowDeleteButton="true" app:keypadTextColor="@color/white" android:layout_centerHorizontal="true" android:layout_marginTop="16dp" />

    opened by jd-alexander 2
  • fix inflating crash when used outside Activity (issue #16 and #9)

    fix inflating crash when used outside Activity (issue #16 and #9)

    Hello. I'm using your library and I like it. But I found a bug when PinLockView used outside Activity same as in issue #16 and #9. My little commit will fix this bug. Please accept my pull request and add this fix to new version. Thanks for your beautiful library.

    opened by shpp-vsmaga 1
  • keypadButtonBackgroundDrawable attribute is not working.

    keypadButtonBackgroundDrawable attribute is not working.

    Hi,

    I want to change keypad buttons background. There is an attribute that call keypadButtonBackgroundDrawable but it is not working. I put drawable to this attribute but it makes background as a primary color. Is there any possible solution to change background of keypad buttons?

    opened by pelsinkaplanfinagotech 0
  • Unable to change color of dots for filled/Empty

    Unable to change color of dots for filled/Empty

    Indicator dots of PinView only show white color for filled and grey color for empty. Nothing happens when used : "app:dotFilledBackground="@drawable/circle""

    opened by Sharjeel97 1
  • Can't use this library anymore with a material dependency

    Can't use this library anymore with a material dependency

    Hi, The resource attribute name attr/indicatorType is duplicated to material-component's one. The attr/indicatorType should be changed to another one. Can't use this library anymore with it.

    opened by rurimo 4
  • Duplicate Resource Error due to the lack of prefix on attributes

    Duplicate Resource Error due to the lack of prefix on attributes

    Error I got: error: duplicate value for resource 'attr/indicatorType' with config ''

    Seems like there is an attribute conflict with com.google.android.material:material:1.3.0-alpha01. Can you attach a prefix to the attribute indicatorType?

    opened by tom5079 0
  • last indicator dot is not filled when number is typed in

    last indicator dot is not filled when number is typed in

    Hi, I am not sure why but when user type in the number into the pinlockview, the last of the indicator dot is not filled even though a number is typed in :(

    opened by lionlollipop 0
Owner
Aritra Roy
Design-focused Engineer | Android Developer | Open-Source Enthusiast | Part-time Blogger
Aritra Roy
You can store all your password, bank details, card details in one place and remember only one master PIN. The application works totally offline.

Keep Password An application where you can store all your password, bank details, card details in one place and remember only one master PIN. The appl

rıdvan 4 Apr 18, 2022
A Simple and Minimal Quotes Android Application to demonstrate the Modern Android Development tools

Quotee Android ?? A Simple and Minimal Quotes Android Application to demonstrate the Modern Android Development tools. Developed with ❤️ by Aminullah

null 12 Aug 24, 2022
🎥 A Simple and Minimal Movies Android Application to demonstrate the Modern Android Development and Jetpack Compose.

ComposeMovie Android ?? A Simple and Minimal Movies Android Application to demonstrate the Modern Android Development and Jetpack Compose. Built with

null 13 Oct 1, 2022
🛒A Minimal Expense E-Commerce App built to demonstrate the use of modern android architecture components [Navigation, Room, MotionLayout, etc..] with MVVM Architecture. ✔

E-Store A Simple E-Commerce App ?? built to demonstrate the use of modern android architecture component with MVVM Architecture ?? . Made with love ❤️

Ameen Essa 14 Nov 3, 2022
Minimal Android Launcher built with Kotlin.

Minimal Android Launcher A minimal launcher displaying only core apps you really need, with a note widget to quickly add reminders on your home screen

Jolene 0 Sep 10, 2022
A simple and minimal app to track how long you've been sober from anything you want.

Sobriety A simple and minimal app to track how long you've been sober from anything you want. I mostly designed this out of spite for "I Am Sober", wh

Katherine Rose 26 Nov 21, 2022
This project shows trending github repositories using MVI (Model View Intent) using kotlin flows and multi module clean architecture

GithubTrendingMVIFlow Build Architecture: This project shows trending github repositories using MVI (Model View Intent) using kotlin flows and multi m

Zulqurnain Haider 0 Jun 2, 2022
A movies application built Using clean architecture and MVVM (Model-view-viewModel).

Movies-App This is a movies application which fecthes upcoming and popular movies from the movie Database(TMBD). It is built Using clean architecture

Felix Kariuki 4 Dec 20, 2022
This service provides first-class custom ROM integration for my Repainter app, which offers customizable dynamic theming for Android 12.

Repainter ROM integration This service provides first-class custom ROM integration for my Repainter app, which offers customizable dynamic theming for

Danny Lin 42 Jan 7, 2023
Quick photo and video camera with a flash, customizable resolution and no ads.

Simple Camera A camera with flash, zoom and no ads. The camera is usable for both photo taking and video recording. You can switch between front and r

Simple Mobile Tools 644 Dec 26, 2022
A simple calendar with events, customizable widgets and no ads.

Simple Calendar A simple calendar with events and a customizable widget. A simple calendar with optional CalDAV synchronization. You can easily create

Simple Mobile Tools 3k Jan 3, 2023
QuizApp - App for using (opentdb.com) API for making quizzes with customizable options

Quiz-App App for using (opentdb.com) API for making quizzes with customizable op

Uptech 0 Nov 22, 2021
Android app which fetches a sample movies list to display. Built using Kotlin and latest Android tech stack, with an approach to clean architecture.

movies-sample-app This is an Android app which fetches a sample movies list to display. Built using Kotlin and latest Android tech stack, with an appr

Nadeem Ahmed 1 Oct 21, 2021
Simple Android movies app using MVVM clean architecture.

Simple Android movies app using MVVM clean architecture.

Marcos Calvo García 57 Dec 30, 2022
The Rick And Morty - MVVM with a clean architecture approach using some of the best practices in Android Development.

Rick-and-Morty The Rick And Morty - App consuming a Rick and Morty API to display Characters it has been built with clean architecture principles, Rep

Akhilesh Patil 61 Jan 7, 2023
An android app built using Kotlin following Multi-Module Clean Architecture MVVM

Notflix ??️ Work In Progress ?? An android app built using Kotlin that consumes TMDB API to display current trending, upcoming and popular movies ?? a

Victor Kabata 290 Dec 30, 2022
A weather app for Android using OpenWeatherMap with MVVM + Clean Architecture

Weather App ?? Weather App for Android that shows 16 days forecast for Paris, France - Made with Hilt, Coroutines, Retrofit, ViewModel, Navigation bas

Waseef Akhtar 7 Oct 4, 2022
MVVM News Application with clean code architecture & android jetpack components.

Android - Clean Architecture - Kotlin The purpose of this repo is to follow up Clean Architecture principles by bringing them to Android. The repo con

Rafsan Ahmad 38 Aug 8, 2022
A Mars Photos app for Android using NASA APIs with MVVM + Clean Architecture

Mars Photos App ?? Mars Photos App for Android that display a list of photos taken from cameras from different rovers - Made with Hilt, Coroutines, Re

Waseef Akhtar 3 Jun 30, 2022