PasscodeView


Source link: https://github.com/kevalpatel2106/PasscodeView

PasscodeView

PasscodeView is an Android Library to easily and securely authenticate the user with the PIN code or using the fingerprint scanner.

Why

  • Secure authentication is the key factor in many application (e.g. financial applications). Many application uses PIN-based authentication.

  • But Android System doesn't provide any easy to set the view for PIN-based authentication which can tightly integrate and take advantage of fingerprint API introduced in newer versions of android. This limitation led me to work on this project.

  • With the use of PasscodeView, you can easily integrate PIN & Fingerprint based authentication in your application.

Features:

This library provides easy and secure PIN authentication view, which

  • provides access to built-in fingerprint-based authentication. This handles all the complexities of integrating the fingerprint API with your application.
  • provide error feedback when PIN entered is wrong.
  • is highly customizable. So that you can match it with your application them. It provides you control over,
    • color and shape of each key. 👉 Guide
    • localized name of each key in pin keyboard. 👉 Guide
    • size of the each single key.
    • color and shape of pin indicators. 👉 Guide
    • Control over tactile feedback for key press and authentication success/failure events.
    • Authenticate using the pattern.

Demo:

Authentication using PIN/Fingerprint

Success Fail Fingerprint Success Fingerprint Fail

Localized Texts

English Hindi

Different Key Shape

Rectangle Circle Square

Pattern based authentication

Here is the link of the demo application. 👉 Demo

How to use this library?

  • Gradle Dependency:

    • Add below lines to app/build.gradle file of your project.
    dependencies {
    
      compile 'com.kevalpatel2106:passcodeview:1.2' 
    }
     
    • To integrate using maven visit this page.

PIN based authentication:

  • Add PinView in your layout file.

    <com.kevalpatel.passcodeview.PinView
    
    android:id="@+id/pin_view"
    
    android:layout_width="match_parent"
    
    android:layout_height="match_parent"
    
    android:layout_below="@id/imageView"
    
    app:dividerColor="@color/colorPrimaryDark"
    
    app:fingerprintDefaultText="Scan your finger to unlock application"
    
    app:fingerprintEnable="true"
    
    app:fingerprintTextColor="@color/colorAccent"
    
    app:fingerprintTextSize="@dimen/finger_print_text_size"
    
    app:titleTextColor="@android:color/white"/>
  • Set the correct pin code to authenticate the user in your activity/fragment.

    @Override protected void onCreate(Bundle savedInstanceState) {
    
    super.onCreate(savedInstanceState);
    
    //....
    //...
    
    PinView pinView = (PinView) findViewById(R.id.pin_view);
    
    pinView.setCorrectPin(new int[]{
    1, 2, 3, 4
    }
    );
    
    //... 
    }
    
  • Set the shape of the key you want to use.

    • There are three built-in key shapes. You can also generate your own key by extending Key class.
      • Round key
      • Rectangle key
      • Square key
    • Here is the example for the round keys.
      @Override
    protected void onCreate(Bundle savedInstanceState) {
    
      super.onCreate(savedInstanceState);
    
      //....
      //...
    
     PinView pinView = (PinView) findViewById(R.id.pin_view);
    
      pinView.setCorrectPin(new int[]{
    1, 2, 3, 4
    }
    );
    
      //Build the desired key shape and pass the theme parameters.
      //REQUIRED
      pinView.setKey(new RoundKey.Builder(pinView)
    
     .setKeyPadding(R.dimen.key_padding)
    
     .setKeyStrokeColorResource(R.color.colorAccent)
    
     .setKeyStrokeWidth(R.dimen.key_stroke_width)
    
     .setKeyTextColorResource(R.color.colorAccent)
    
     .setKeyTextSize(R.dimen.key_text_size)
    
     .build());
    
     //...
    
    }
    
  • Set the shape of the pin indicators you want to use.

    • There are three built in key shapes.
      • Round indicator
      • Dot indicator
      • Circle indicator
    • Here is the example for the round indicator. You can learn more about other indicators from here.
      @Override
    protected void onCreate(Bundle savedInstanceState) {
    
      super.onCreate(savedInstanceState);
    
      //....
      //...
    
     PinView pinView = (PinView) findViewById(R.id.pin_view);
    
      pinView.setCorrectPin(new int[]{
    1, 2, 3, 4
    }
    );
    
      pinView.setKey(...);
    
     //Build the desired indicator shape and pass the theme attributes.
      //REQUIRED
      pinView.setIndicator(new CircleIndicator.Builder(pinView)
    
     .setIndicatorRadius(R.dimen.indicator_radius)
    
     .setIndicatorFilledColorResource(R.color.colorAccent)
    
     .setIndicatorStrokeColorResource(R.color.colorAccent)
    
     .setIndicatorStrokeWidth(R.dimen.indicator_stroke_width)
    
     .build());
    
     //...
    
    }
    
  • Set key names.

    • Set the texts to display on different keys. This is an optional step. If you don't set the key names, by default PINView will display English locale digits.
    • If you want to learn more about key name localization visit here.
      @Override
    protected void onCreate(Bundle savedInstanceState) {
    
      super.onCreate(savedInstanceState);
    
      //....
      //...
    
     PinView pinView = (PinView) findViewById(R.id.pin_view);
    
      pinView.setCorrectPin(new int[]{
    1, 2, 3, 4
    }
    );
    
      pinView.setKey(...);
    
      pinView.setIndicator(...);
    
     //Set the name of the keys based on your locale.
      //OPTIONAL. If not passed key names will be displayed based on english locale.
      pinView.setKeyNames(new KeyNamesBuilder()
    
      .setKeyOne(this, R.string.key_1)
    
      .setKeyTwo(this, R.string.key_2)
    
      .setKeyThree(this, R.string.key_3)
    
      .setKeyFour(this, R.string.key_4)
    
      .setKeyFive(this, R.string.key_5)
    
      .setKeySix(this, R.string.key_6)
    
      .setKeySeven(this, R.string.key_7)
    
      .setKeyEight(this, R.string.key_8)
    
      .setKeyNine(this, R.string.key_9)
    
      .setKeyZero(this, R.string.key_0));
    
    //...
    
    }
    
  • Set callback listener to get callbacks when the user is authenticated or authentication fails.

      @Override
    protected void onCreate(Bundle savedInstanceState) {
    
      super.onCreate(savedInstanceState);
    
      //....
      //...
    
     PinView pinView = (PinView) findViewById(R.id.pin_view);
    
      pinView.setCorrectPin(new int[]{
    1, 2, 3, 4
    }
    );
    
      pinView.setKey(...);
    
    //REQUIRED
      pinView.setIndicator(...);
    
    //REQUIRED
      pinView.setKeyNames(...)
    
      //OPTIONAL
    
    pinView.setAuthenticationListener(new AuthenticationListener() {
    
     @Override
    
     public void onAuthenticationSuccessful() {
    
      //User authenticated successfully.
    
      //Navigate to next screens.
    
     
    }
    
      @Override
    
     public void onAuthenticationFailed() {
    
      //Calls whenever authentication is failed or user is unauthorized.
    
      //Do something if you want to handle unauthorized user.
    
     
    }
    
    }
    );
    
      //...
    
    }
    

Pattern based authentication:

  • Add PatternView in your layout file.

    <com.kevalpatel.passcodeview.PatternView
    
    android:id="@+id/pattern_view"
    
    android:layout_width="match_parent"
    
    android:layout_height="match_parent"
    
    android:layout_below="@id/imageView"
    
    app:dividerColor="@color/colorPrimaryDark"
    
    app:fingerprintDefaultText="Scan your finger to unlock application"
    
    app:fingerprintEnable="true"
    
    app:fingerprintTextColor="@color/colorAccent"
    
    app:fingerprintTextSize="@dimen/finger_print_text_size"
    
    app:giveTactileFeedback="true"
    
    app:patternLineColor="@color/colorAccent"
    
    app:titleTextColor="@android:color/white"/>
  • Set the number of rows and columns of the pattern in your activity/fragment.

    @Override protected void onCreate(Bundle savedInstanceState) {
    
    super.onCreate(savedInstanceState);
    
    //....
    //...
     PatternView patternView = (PatternView) findViewById(R.id.pattern_view);
    
     //Set number of pattern counts.
    //REQUIRED
    patternView.setNoOfColumn(3);
    
    //Number of columns
    patternView.setNoOfRows(3);
    
      //Number of rows
     //... 
    }
    
  • Set the correct pattern to authenticate the user in your activity/fragment.

    @Override protected void onCreate(Bundle savedInstanceState) {
    
    super.onCreate(savedInstanceState);
    
    //....
    //...
     PatternView patternView = (PatternView) findViewById(R.id.pattern_view);
    
     //Set number of pattern counts.
    //REQUIRED
    patternView.setNoOfColumn(3);
    
    //Number of columns
    patternView.setNoOfRows(3);
    
      //Number of rows
     //Set the correct pin code.
    //Display row and column number of the pattern point sequence.
    //REQUIRED
    patternView.setCorrectPattern(new PatternPoint[]{
    
      new PatternPoint(0, 0),
    
      new PatternPoint(1, 0),
    
      new PatternPoint(2, 0),
    
      new PatternPoint(2, 1)
    
    }
    );
    
    //... 
    }
    
  • Set the pattern cell shape.

    • There are two built in pattern cells available.
      • Circle indicator
      • Dot indicator
    @Override protected void onCreate(Bundle savedInstanceState) {
    
    super.onCreate(savedInstanceState);
    
    //....
    //...
     PatternView patternView = (PatternView) findViewById(R.id.pattern_view);
    
    patternView.setNoOfColumn(3);
    
    //Number of columns
    patternView.setNoOfRows(3);
    
      //Number of rows
    patternView.setCorrectPattern(new PatternPoint[]{
    ...
    }
    );
    
      //Build the desired indicator shape and pass the theme attributes.
    //REQUIRED
    patternView.setPatternCell(new CirclePatternCell.Builder(patternView)
    
      .setRadius(R.dimen.pattern_cell_radius)
    
      .setCellColorResource(R.color.colorAccent)
    
      .build());
    
     //... 
    }
    
  • Set callback listener to get callbacks when user is authenticated or authentication fails.

  @Override
protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  //....
  //...

PatternView patternView = (PatternView) findViewById(R.id.pattern_view);

  patternView.setNoOfColumn(3);

//Number of columns
  patternView.setNoOfRows(3);

  //Number of rows
  patternView.setCorrectPattern(new PatternPoint[]{
...
}
);

  patternView.setPatternCell(...);

patternView.setAuthenticationListener(new AuthenticationListener() {

@Override

public void onAuthenticationSuccessful() {

 //User authenticated successfully.

}

 @Override

public void onAuthenticationFailed() {

 //Calls whenever authentication is failed or user is unauthorized.

 //Do something

}

  
}
);

  //...

}

Visit our wiki page for more information.

How to contribute?

What's next?

  • Build more customisation parameters to provide granular control over the theme of the view.

Questions? 🤔

Hit me on twitter

License

Copyright 2017 Keval Patel

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.

Resources

A simple library to add indicators for your Carousel or ViewPagers.

Android AutocompleteTextView that receives and displays address suggestions from Smarty Streets.

A simple layout working as a switch on-off button.

The Universal Event Bus is an event dispatcher architecture which help you to use most common event bus implementation as Otto in a structured mode.

An events is a bus designed to separate different parts of the application, while still allowing them to communicate efficiently. The operation of the EventDispatcher is based on the publish-subscribe pattern: the bus asked a series of events that will be collected by those who joined them.

The publisher is, in this case, called Bus or RxBus and deals with post events using the Observable of RxJava. The event dispatcher contains two RxBuses: one dedicated to the UI thread, and the other for all the other events that have nothing to do with the UI (network calls, CRUD operations with the database etc.).

Change/add font of Entire Android Application at time with out wasting your time - TextViews, EditText, Buttons, Views, etc.

Small library that contains common extensions for Android. Aims:

  • Provide the shortest way to do things
  • Reduce count of "Compat" and "Utils" classes
  • Remove boilerplate code

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes