App Lock


Source link: https://github.com/mattsilber/applock

App Lock

A simple library for locking and unlocking Activities (e.g. child lock) with a PIN code.

Installation

repositories {

  jcenter() 
}
  dependencies {

  compile('com.guardanis:applock:1.0.8') 
}

Usage

The goal of AppLock is to allow users to enter and confirm a PIN in order to temporarily lock the application from being used, until the PIN is re-entered by the user.

To open the Activity to create a PIN, you can simply open the AppLockActivity via (PS: If you want to use the dialog instead of the Activity (which looks cooler), see the dialog stuff below) Intents:

Intent intent = new Intent(activity, CreateLockActivity.class);
 startActivityForResult(intent, LockingHelper.REQUEST_CODE_CREATE_LOCK);

To check if a saved PIN exists, you can simply call LockingHelper.hasSavedPIN(Activity) and redirect to the UnlockActivity if the action requires PIN-authentication:

Intent intent = new Intent(activity, UnlockActivity.class);
 startActivityForResult(intent, LockingHelper.REQUEST_CODE_ULOCK);

 

If you want to do both of the above in a single step (that is, check if there's a saved PIN and open the unlock flow if yes), you can call:

if(!ActionLockingHelper.unlockIfRequired(Activity))
  doSomethingThatRequiresLockingIfEnabled();

@Override public void onActivityResult(int requestCode, int resultCode, Intent data){

  if(requestCode == LockingHelper.REQUEST_CODE_ULOCK)

doSomethingThatRequiresLockingIfEnabled();
 
}
 

If you want to do the above with a Dialog, instead of an Activity (which looks cooler, IMHO), you can simply call:

ActionLockingHelper.unlockIfRequired(Activity, new UnlockEventListener(){

  public void onCanceled(){
 
}
 // Dialog was closed without entry
  public void onUnlockFailed(String reason){
 
}
 // Not called with default Dialog, instead is handled internally
  public void onUnlockSuccessful(){

doSomethingThatRequiresLockingIfEnabled();

  
}
 
}
);

As of version 1.0.7, you can now create the lock PIN with a Dialog as well (why? because it looks cooler):

new CreateLockDialogBuilder(Activity,

new LockCreationListener(){

public void onLockCanceled(){
 
}
 // Dialog was closed without entry

public void onLockSuccessful(){

 doSomethingOnAppLocked();

}

  
}
)
  .show();

If you want an Activity to remain fully locked once a PIN has been entered, ensure that you override onPostResume() and call ActivityLockingHelper.onActivityResumed(Activity); e.g.

@Override protected void onPostResume(){

  super.onPostResume();

  ActivityLockingHelper.onActivityResumed(this);
 
}

or you can simply have your Activity extend one of the Lockable Activites available in the library ( LockableCompatActivity and LockableActionBarActivity)

By default, the ActivityLockingHelper considers a successful login as valid for 15 minutes, regardless of application state. You can shorten or extend that length by overriding the integer value for pin__default_activity_lock_reenable_minutes in your resources. Doing so will cause any Activity to re-open the UnlockActivity after the delay has passed. If you only want PIN-validation on a specific action (e.g. payments), you should use the ActionLockingHelper's methods posted above instead of locking the entre Activity.

To change the default length of the PIN, you can override

<integer name="pin__default_input_count">4</integer>

Theme

If you want to change the colors/themes, you can simply override the color values prefixed with pin__. For example, changing the ball/text colors from blue/white to green/yellow, respectively, could be done like so:

<color name="pin__default_item_background">#2ECC71</color> <color name="pin__default_item_text">#F1C40F</color>

(I wouldn't use that color mix, though. It's ugly. That was just for example)

All colors you can change can be found in /values/colors.xml

Resources

Easily add "New Post" popup button with the feeds (RecyclerView) of your app.

A nice breathing progress component.

Lightweight Android MVP library with easy implementation.

It's just an example of material transition.

A contextual actionbar library with many customization options.

An extended transition for android ViewPager.

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