• Stars
    star
    691
  • Rank 63,170 (Top 2 %)
  • Language
    Java
  • Created over 9 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Material Design Pattern Lock with auth flow implementation

PatternLock

A Material Design Pattern Lock library with auth flow implementation.

Why PatterLock?

  • Battle-tested framework implementation with necessary modifications.
  • Supports XML attributes for customization.
  • Supports variable MxN pattern size.
  • Provides a drop-in implementation of the boilerplate create-and-confirm / verify flow, the same as the framework Settings app.
  • Provides a detailed example of integration in sample app source, e.g. implementing protected UI, theme switching.

Preview

Google Play

Sample APK

Design

This library aims to provide the basic but extensible building blocks for implementing pattern lock mechanism in an Android app. So the common usage will be extending the base Activity classes provided and overriding methods according to your need.

This library also aims to be elegant. Code taken from AOSP was slightly refactored and renamed to be clear, and the PatternView now utilizes the Android resource system for customization.

This library added support for variable pattern sizes, so that you can use pattern sizes other than framework's hard-coded 3x3 setup by setting app:pl_rowCount and app:pl_columnCount.

Integration

Gradle:

compile 'me.zhanghai.android.patternlock:library:2.1.2'

Usage

Here are some detailed usage documentation, and you can always refer to the sample app source for a working implementation.

Styling

First of all, you need to include the default styling in your theme, by adding:

<item name="patternViewStyle">@style/PatternView</item>
<!-- Or PatternView.Light, or your own style extending these two or not. -->

Or you can utilize the resource overriding trick by copying the layout/base_pattern_activity.xml from the library source to your application source, and modify it there (for instance PatternView attributes). Changes will override the original layout in this library.

Available PatternView attributes are, as in attrs.xml:

<declare-styleable name="PatternView">
    <!-- Defines the row count of the pattern. -->
    <attr name="pl_rowCount" format="integer" />
    <!-- Defines the column count of the pattern. -->
    <attr name="pl_columnCount" format="integer" />
    <!-- Defines the aspect to use when drawing PatternView. -->
    <attr name="pl_aspect">
        <!-- Square; the default value. -->
        <enum name="square" value="0" />
        <enum name="lock_width" value="1" />
        <enum name="lock_height" value="2" />
    </attr>
    <!-- Defines the regular pattern color. -->
    <attr name="pl_regularColor" format="color|reference" />
    <!-- Defines the error color. -->
    <attr name="pl_errorColor" format="color|reference" />
    <!-- Defines the success color. -->
    <attr name="pl_successColor" format="color|reference"/>
</declare-styleable>

And built-in styles, as in styles.xml:

<style name="Base.PatternView" parent="">
    <item name="pl_rowCount">3</item>
    <item name="pl_columnCount">3</item>
    <item name="pl_aspect">square</item>
</style>

<style name="PatternView" parent="Base.PatternView">
    <item name="pl_regularColor">?colorControlNormal</item>
    <item name="pl_errorColor">#fff4511e</item>
    <item name="pl_successColor">?colorControlActivated</item>
</style>

<style name="PatternView.Light" parent="Base.PatternView">
    <item name="pl_regularColor">?colorControlNormal</item>
    <item name="pl_errorColor">#fff4511e</item>
    <item name="pl_successColor">?colorControlActivated</item>
</style>

Implementing

As stated above, the common usage will be extending or checking result instead of giving Intent extras, because the actions to perform generally requires a Context or even a Activity, in which a simple callback can be difficult or even leaking Activity instances.

Set pattern activity example:

public class SampleSetPatternActivity extends SetPatternActivity {

    @Override
    protected void onSetPattern(List<PatternView.Cell> pattern) {
        String patternSha1 = PatternUtils.patternToSha1String(pattern);
        // TODO: Save patternSha1 in SharedPreferences.
    }
}

Confirm pattern activity example:

public class SampleConfirmPatternActivity extends ConfirmPatternActivity {

    @Override
    protected boolean isStealthModeEnabled() {
        // TODO: Return the value from SharedPreferences.
        return false;
    }

    @Override
    protected boolean isPatternCorrect(List<PatternView.Cell> pattern) {
        // TODO: Get saved pattern sha1.
        String patternSha1 = null;
        return TextUtils.equals(PatternUtils.patternToSha1String(pattern), patternSha1);
    }

    @Override
    protected void onForgotPassword() {

        startActivity(new Intent(this, YourResetPatternActivity.class));

        // Finish with RESULT_FORGOT_PASSWORD.
        super.onForgotPassword();
    }
}

Note that protected fields inherited from BasePatternActivity, such as mMessageText and mPatternView, are also there ready for your customization.

You can check out the sample app's PatternLockActivity for implementing a pattern-locked Activity.

PatternLock or LockPattern?

The original view in AOSP is named LockPatternView, however I believe it is named so because it displays the (screen lock) pattern, instead of the pattern as a lock. Since this library is to provide the pattern as a locking mechanism, I'd prefer naming it PatternLock, and for simplicity๏ผŒ the view is renamed to PatternView.

Differences with android-lockpattern

I know there is already a library named android-lockpattern, and I tried it for a whole day before I started writing this "yet another".

So here are the major differences.

  • That project is prefixing its resources using alp_42447968, while this project is prefixing its resources using pl, and I prefer simplicity to that "security".

  • That project provides a bunch of mechanisms and extras for its Activity (and with some private methods :( ), none of which I found suitable for my use case, while this project provides a bunch of methods to override to meet your need.

  • That project has a demo but it is close-sourced, while this project provides an open source sample application with a working pattern lock mechanism implementation.

Legacy version

There was a legacy version of this library with Android Design (Holo) appearance and native Activity. If you still want that version, checkout this.

License

Copyright 2015 Zhang Hai

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.

More Repositories

1

MaterialFiles

Material Design file manager for Android
Kotlin
5,193
star
2

Douya

ๅผ€ๆบ็š„ Material Design ่ฑ†็“ฃๅฎขๆˆท็ซฏ๏ผˆA Material Design app for douban.com๏ผ‰
Java
4,542
star
3

MaterialProgressBar

Material Design ProgressBar with consistent appearance
Java
2,219
star
4

MaterialRatingBar

Material Design RatingBar with better appearance
Java
1,958
star
5

MaterialColdStart

Utilize the window background during cold start time to make your app look faster.
Shell
1,226
star
6

AndroidFastScroll

Fast scroll for Android RecyclerView and more
Java
678
star
7

CustomTabsHelper

Custom tabs, made easy.
Java
386
star
8

Untracker

App to help you remove tracking information before sharing links
Kotlin
271
star
9

archexp

ๆต™ๆฑŸๅคงๅญฆ่ฎก็ฎ—ๆœบไฝ“็ณป็ป“ๆž„่ฏพ็จ‹ๅฎž้ชŒ
Verilog
157
star
10

AppIconLoader

Android app icon loader from AOSP iconloaderlib
Java
152
star
11

MaterialEditText

Material Design EditText with a delightful linear ripple in background
Java
146
star
12

zju-csse-undergraduate-design-latex-template

ๆต™ๆฑŸๅคงๅญฆ่ฎก็ฎ—ๆœบ็ง‘ๅญฆไธŽๆŠ€ๆœฏใ€่ฝฏไปถๅทฅ็จ‹ไธ“ไธšๆœฌ็ง‘ๆฏ•ไธš่ฎพ่ฎก LaTeX ๆจกๆฟ
TeX
135
star
13

SystemUiHelper

Helper for dealing with Android System UI visibility
Java
116
star
14

ComposePreference

Preference implementation for Jetpack Compose Material 3
Kotlin
108
star
15

BeeShell

Java REPL on Android with BeanShell
Kotlin
105
star
16

EffortlessPermissions

An Android permission library extending Google's EasyPermissions with convenient additions.
Java
85
star
17

TextSelectionWebSearch

Add web search to text selection toolbar on Android
Java
75
star
18

gnome-shell-extension-transparent-top-bar

GNOME Shell extension that brings back the transparent top bar when free-floating in GNOME Shell 3.32
JavaScript
73
star
19

DouyaApiKey

่ฑ†่Šฝ API Key ่ฎพ็ฝฎๅ‘ๅฏผ
Java
69
star
20

DoubanYearProgress

Year progress for Douban
JavaScript
62
star
21

AndroidUtil

Utilities to make the life of an Android developer easier
Java
59
star
22

AndroidSVGScripts

Bash scripts to automate and extend the process of using SVG as Android image asset
Shell
56
star
23

AndroidRetroFile

Backport of java.nio.file API (JSR 203) for Android
Java
47
star
24

mipsasm

MIPS assembler and IDE
Java
46
star
25

libarchive-android

libarchive as an Android library
C
45
star
26

MaterialPlayPauseDrawable

Material Design play/pause Drawable with animation
Java
37
star
27

join-screenshots.zhanghai.me

Join screenshots with HTML5
HTML
23
star
28

libselinux-android

libselinux as an Android library
C
22
star
29

opengl-c-solarsystem

Animated solar system model implemented with OpenGL and FreeGLUT in C
C
22
star
30

orgexp

Computer Organization Experiment, Shi Qingsong, Zhejiang University.
Verilog
21
star
31

pykeymacs

Emacs style keyboard macros implemented in Python
Python
20
star
32

vntools

Tools for working with visual novels
C++
17
star
33

deadbeef-gnome-mmkeys

Add GNOME multimedia keys support in DeadBeef player using DBus
C
16
star
34

collision-detection-bubbles

A collision detection and resolution experiment with Two.js
JavaScript
15
star
35

gtkmmproject

Gtkmm CLion Project
CMake
12
star
36

linenoise-android

Linenoise as an Android library
C
12
star
37

qt5project

Qt 5 CLion project
C++
10
star
38

Reflected

Java library for easy-to-use reflection
Java
9
star
39

SeekBarPreference

A Preference that shows a dialog with a SeekBar widget.
Java
9
star
40

Bytecoder

Android gradle plugin to generate bytecode for accessing any method or field
Java
9
star
41

AndroidLibraryTemplate

Android library template
8
star
42

Functional

Java library for JavaScript-like functional methods
Java
8
star
43

zhsh

A minimal interactive shell written in C.
C
8
star
44

DouyaCiBuilds

่ฑ†่Šฝ CI ๆž„ๅปบ็‰ˆๆœฌไป“ๅบ“
8
star
45

Palette

Sample application to showcase android.support.v7.graphics.Palette
Java
6
star
46

twitter-unwanted-follower-remover

Semi-automatic command line tool for removing unwanted followers on Twitter
JavaScript
5
star
47

particle-system-campfire

A particle system experiment with Two.js
HTML
5
star
48

AimAndroid

Another Instant Messager app, Android.
Java
5
star
49

ColorPicker

Android color picker from AOSP
Java
5
star
50

Promise

Java library for JavaScript-like Promise
Java
4
star
51

AimBackend

Another Instant Messager app, backend.
JavaScript
4
star
52

kiscript

ECMAScript, kept simple.
C
4
star
53

gettext-po-parser

Gettext PO file parser
4
star
54

xkeymacs

X11 KEYboard MACroS
C
4
star
55

zhclib

A C library written by me
C
3
star
56

translations.zhanghai.me

Search translations in open source projects
HTML
3
star
57

markdown-template

Zhang Hai's markdown template
JavaScript
3
star
58

gnome-shell-extension-es6-class-codemod

A jscodeshift transform that helps migrating GNOME Shell extensions to 3.32
JavaScript
3
star
59

stone.zhanghai.me

(Zhang Hai's) The story of the stone
HTML
3
star
60

SsidTester

SSID tester for identifying ZJUWLAN difficulty. Also serves as a sample application for beginners.
Java
3
star
61

ZJUWLANAutoLogin

A chrome extesion that enables auto login when redirected to login page on ZJUWLAN
JavaScript
3
star
62

course_linux_programming

Linux programming course
C
3
star
63

resume.zhanghai.me

Zhang Hai's resume
HTML
3
star
64

fpga-life-game

Conway's game of life implemented on FPGA with combinational logic
Verilog
3
star
65

zh-conf-backup

Backup script for Zhang Hai's configuration
Shell
3
star
66

Labyrinth

Labyrinth game with OpenGL
Java
3
star
67

slides.zhanghai.me

Zhang Hai's slides
HTML
2
star
68

resume-legacy

Source of Zhang Hai's resume, legacy version
CSS
2
star
69

douya.zhanghai.me

Zhang Hai's Douya
ApacheConf
2
star
70

douya-website

Source of Zhang Hai's Douya project home
JavaScript
2
star
71

api-functions-worth-calling

API - Functions worth calling
HTML
2
star
72

optical-system-mfc

Optical System with MFC
C
2
star
73

ExpressionEvaluator

Expression evaluator written in Java
Java
2
star
74

AimFrontend

Another Instant Messager app, frontend.
Vue
2
star
75

zh-minecraft-saves

My Minecraft saves.
Shell
2
star
76

FxPaint

Paint app written with JavaFx
Java
2
star
77

projects.zhanghai.me

Zhang Hai's projects
HTML
2
star
78

calc

C Topic Project - A calculator based on operator precedence
C
2
star
79

lms

C Topic Project - A simple Library Management System
C
1
star
80

SePolicyInject

Android library to inject rules into binary SELinux kernel policies
CMake
1
star
81

DataStructure

An object oriented implementation of fundamental data structures (and algorithms) using C++11
C++
1
star
82

WordList

A simple android application to display specially annotated English word lists
Java
1
star
83

optical-system-qt

Optical System with Qt
C
1
star
84

seafile-server-github-actions-build

Seafile Server built by GitHub Actions
1
star
85

reveal-md-template

Reveal.js template with reveal-md
Makefile
1
star
86

reveal-js-template

Zhang Hai's reveal.js template
Shell
1
star
87

ShowcaseView

A fork from legacy branch of https://github.com/amlcurran/ShowcaseView
Java
1
star
88

www.zhanghai.me

Zhang Hai's main site
HTML
1
star
89

blog.zhanghai.me

Zhang Hai's blog
HTML
1
star
90

sevenzipjbind

Mirrored from git://sevenzipjbind.git.sourceforge.net/gitroot/sevenzipjbind/sevenzipjbind
C++
1
star
91

translations-index.zhanghai.me

Translations index
1
star
92

abnf-kt

ABNF parser generator for Kotlin
Kotlin
1
star