Code Monkey home page Code Monkey logo

applock's Introduction

App Lock

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

AppLock Sample

Installation

repositories {
    jcenter()
}

dependencies {
    compile('com.guardanis:applock:2.0.2')
}

Usage

The goal of AppLock is to allow users to enroll and authenticate with a PIN or Fingerprint to lock the application from being used by unauthorized parties.

Activities

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, LockCreationActivity.class);
startActivityForResult(intent, LockingHelper.REQUEST_CODE_CREATE_LOCK);

To check if the user has elected to enroll in AppLock authentication, you can simply call AppLock.isEnrolled(Contect) and redirect to the UnlockActivity if the action requires authentication:

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

If you want to do both of the above in a single step (that is, check if the user is enrolled and open the unlock flow if true), you can call:

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

...

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
    if(requestCode == LockingHelper.REQUEST_CODE_ULOCK && resultCode == Activity.RESULT_OK)
        doSomethingThatRequiresLockingIfEnabled();
}
Dialogs

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

new UnlockDialogBuilder(activity)
    .onUnlocked(() -> { doSomethingThatRequiresLockingIfEnabled(); })
    .onCanceled(() -> { })
    .showIfRequiredOrSuccess(TimeUnit.MINUTES.toMillies(15));

Or, create the enrollment with a Dialog:

new LockCreationDialogBuilder(this)
    .onCanceled(() -> { showIndicatorMessage("You canceled..."); })
    .onLockCreated(() -> { showIndicatorMessage("Lock created!"); })
    .show()

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

@Override
protected void onPostResume(){
    super.onPostResume();
    
    AppLock.onActivityResumed(this);
}

or you can simply have your Activity extend the LockableCompatActivity supplied with this library.

By default, AppLock 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 applock__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 authentication present on a specific action (e.g. payments), you should use the UnlockDialogBuilder's methods posted above instead of locking the entire Activity.

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

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

Theme

All themes, styles, dimensions, strings, etc. are all customizable via overriding the resources. See applock/src/main/res/values/ for details.

TODO:

  • Allow backup authentication options

applock's People

Contributors

mattsilber avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.