PinLock


Source link: https://github.com/manupsunny/PinLock

PinLock

An Android library which can be used for implementing PIN lock mechanism in Android applications.

Usage

First, add PinLock dependency to your build.gradle. PinLock is available in both Maven and jCenter.

compile "com.manusunny:pinlock:+" 
1. Setting PIN

Create a new class by extending SetPinActivity.java. And implement method onPinSet(),

public class SetPinActivitySample extends SetPinActivity {

  public void onPinSet(String pin){

//Save 'pin' as SharedPreference
  
}
 
}

That's it. Now you can start this activity using startActivityForResult(). And handle the results in onActivityResult(). Activity will return one of these result codes:

  1. PinListener.SUCCESS
  2. PinListener.CANCELLED
2. Confirming PIN

Create a new class by extending ConfirmPinActivity.java. And implement two methods,

public class ConfirmPinActivitySample extends SetPinActivity {

  @Override
  public boolean isPinCorrect(String pin) {

String currentPin = // get it from SharedPreferences

return pin.equals(currentPin);

  
}

@Override
  public void onForgotPin() {

// handle forgot PIN scenario
  
}
 
}

Now you can start this activity using startActivityForResult(). And handle the results in onActivityResult(). Activity will return one of these result codes:

  1. PinListener.SUCCESS
  2. PinListener.CANCELLED
  3. PinListener.FORGOT

Customizing the Plugin

1. Customizing Styles

All styles in this library are configurable. Give required styles in res/values/styles.xml

Example:

<resources>
  <style name="PinLock" >

<item name="pinLength">4</item>

<item name="backgroundColor">#FFFFFF</item>

 <item name="keypadButtonShape">@drawable/rectangle</item>

<item name="keypadTextColor">#000000</item>

<item name="keypadTextSize">20</item>

<item name="keypadWidth">200dp</item>

<item name="keypadHeight">230dp</item>

<item name="keypadVerticalSpacing">2dp</item>

<item name="keypadHorizontalSpacing">2dp</item>

<item name="keypadClickAnimationDuration">100</item>

 <item name="cancelForgotTextColor">#000000</item>

<item name="cancelForgotTextSize">14</item>

 <item name="infoTextColor">#000000</item>

<item name="infoTextSize">20</item>

 <item name="vibrateOnClick">true</item>

<item name="vibrateDuration">20</item>

 <item name="statusEmptyBackground">@drawable/dot_empty</item>

<item name="statusFilledBackground">@drawable/dot_filled</item>

<item name="statusDotDiameter">8dp</item>

<item name="statusDotSpacing">10dp</item>
  </style> </resources>
2. Customizing Labels

You can customize the messages and labels used in the library. Give new texts in res/values/strings.xml

Example:

<resources>
  <string name="message_enter_pin">Enter PIN</string>
  <string name="message_enter_new_pin">Enter new PIN</string>
  <string name="message_confirm_pin">Re enter PIN</string>
  <string name="message_invalid_pin">Invalid PIN. Try again</string>
  <string name="message_pin_mismatch">PIN mismatch. Try again</string>

<string name="button_cancel">Cancel</string>
  <string name="button_forgot_pin">Forgot PIN</string> </resources>

Supporting Multiple Languages

You can support multiple languages by providing texts in different languages. If texts are not available for the selected language, English will be used as the fallback language. Add res/values-<language_code> folder for each new language, and provide tranlated contents in strings.xml file.

Folder Structure :

|res
  |values

 // Default language (en)

|strings.xml
  |values-es
 // Spanish

|strings.xml
  |values-de
 // German

|strings.xml 

Example:

Sample file for Spanish res/values-es/strings.xml

<resources>
  <string name="message_enter_pin">Ingrese el PIN</string>
  <string name="message_enter_new_pin">Ingrese un nuevo PIN</string>
  <string name="message_confirm_pin">Confirme el PIN</string>
  <string name="message_invalid_pin">PIN inválido. Intente de nuevo</string>
  <string name="message_pin_mismatch">El PIN no coincide. Intente de nuevo</string>

<string name="button_cancel">Cancelar</string>
  <string name="button_forgot_pin">Olvidé mi PIN</string> </resources>

A list of languages which are currently supported by Android along with their codes are available here.

License

Copyright 2016 © Manu Sunny  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. 

Sample Screenshots

SetPin ConfirmPin ChangePin

Resources

A very simple continuous click listener implementation for Android.

OAuth2Library is an extension for Retrofit that simplifies the process of authenticating against an OAuth 2 provider.

TedPicker is image selector library for android.

Do not waste your time for write image select function code. You can take a picture or select image from gallery. Also you can customize color, drawable, select count, etc for your application.

An easy to use Android library with a fluent interface to integrate voice interaction into your Application.

Android Library that checks for updates on Google Play, GitHub or Amazon. This library notifies your apps' updates by showing a Material dialog, Snackbar or notification.

PaperParcel is an annotation processor that automatically generates type-safe Parcelable wrappers for Kotlin and Java.

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