{"id":18425647,"url":"https://github.com/zhanghai/patternlock","last_synced_at":"2025-04-05T00:07:35.802Z","repository":{"id":26951422,"uuid":"30414367","full_name":"zhanghai/PatternLock","owner":"zhanghai","description":"Material Design Pattern Lock with auth flow implementation","archived":false,"fork":false,"pushed_at":"2019-05-16T04:14:07.000Z","size":1416,"stargazers_count":687,"open_issues_count":2,"forks_count":151,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-03-28T23:05:51.308Z","etag":null,"topics":["android","android-library","material-design","pattern-lock"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zhanghai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-06T13:53:12.000Z","updated_at":"2025-02-26T09:59:38.000Z","dependencies_parsed_at":"2022-08-31T14:00:23.327Z","dependency_job_id":null,"html_url":"https://github.com/zhanghai/PatternLock","commit_stats":null,"previous_names":["dreamingincodezh/patternlock"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanghai%2FPatternLock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanghai%2FPatternLock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanghai%2FPatternLock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanghai%2FPatternLock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhanghai","download_url":"https://codeload.github.com/zhanghai/PatternLock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247266563,"owners_count":20910836,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-library","material-design","pattern-lock"],"created_at":"2024-11-06T05:04:43.923Z","updated_at":"2025-04-05T00:07:35.772Z","avatar_url":"https://github.com/zhanghai.png","language":"Java","readme":"# PatternLock\n\nA Material Design Pattern Lock library with auth flow implementation.\n\n## Why PatterLock?\n\n- Battle-tested framework implementation with necessary modifications.\n- Supports XML attributes for customization.\n- Supports variable MxN pattern size.\n- Provides a drop-in implementation of the boilerplate create-and-confirm / verify flow, the same as the framework Settings app.\n- Provides a detailed example of integration in sample app source, e.g. implementing protected UI, theme switching.\n\n## Preview\n\n\u003ca href=\"https://play.google.com/store/apps/details?id=me.zhanghai.android.patternlock.sample2\" target=\"_blank\"\u003e\u003cimg alt=\"Google Play\" height=\"90\" src=\"https://play.google.com/intl/en_US/badges/images/generic/en_badge_web_generic.png\"/\u003e\u003c/a\u003e\n\n[Sample APK](https://github.com/zhanghai/PatternLock/releases/download/v2.1.2/sample-release.apk)\n\n\u003cp\u003e\n\u003cimg src=\"screenshot/sample-1.png\" width=\"49%\"\u003e\n\u003cimg src=\"screenshot/sample-2.png\" width=\"49%\"\u003e\n\u003c/p\u003e\n\n## Design\n\nThis 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.\n\nThis 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.\n\nThis 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`.\n\n## Integration\n\nGradle:\n\n```gradle\ncompile 'me.zhanghai.android.patternlock:library:2.1.2'\n```\n\n## Usage\n\nHere are some detailed usage documentation, and you can always refer to the sample app source for a working implementation.\n\n### Styling\n\nFirst of all, you need to include the default styling in your theme, by adding:\n\n```xml\n\u003citem name=\"patternViewStyle\"\u003e@style/PatternView\u003c/item\u003e\n\u003c!-- Or PatternView.Light, or your own style extending these two or not. --\u003e\n```\n\nOr 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.\n\nAvailable `PatternView` attributes are, as in `attrs.xml`:\n\n```xml\n\u003cdeclare-styleable name=\"PatternView\"\u003e\n    \u003c!-- Defines the row count of the pattern. --\u003e\n    \u003cattr name=\"pl_rowCount\" format=\"integer\" /\u003e\n    \u003c!-- Defines the column count of the pattern. --\u003e\n    \u003cattr name=\"pl_columnCount\" format=\"integer\" /\u003e\n    \u003c!-- Defines the aspect to use when drawing PatternView. --\u003e\n    \u003cattr name=\"pl_aspect\"\u003e\n        \u003c!-- Square; the default value. --\u003e\n        \u003cenum name=\"square\" value=\"0\" /\u003e\n        \u003cenum name=\"lock_width\" value=\"1\" /\u003e\n        \u003cenum name=\"lock_height\" value=\"2\" /\u003e\n    \u003c/attr\u003e\n    \u003c!-- Defines the regular pattern color. --\u003e\n    \u003cattr name=\"pl_regularColor\" format=\"color|reference\" /\u003e\n    \u003c!-- Defines the error color. --\u003e\n    \u003cattr name=\"pl_errorColor\" format=\"color|reference\" /\u003e\n    \u003c!-- Defines the success color. --\u003e\n    \u003cattr name=\"pl_successColor\" format=\"color|reference\"/\u003e\n\u003c/declare-styleable\u003e\n```\n\nAnd built-in styles, as in `styles.xml`:\n\n```xml\n\u003cstyle name=\"Base.PatternView\" parent=\"\"\u003e\n    \u003citem name=\"pl_rowCount\"\u003e3\u003c/item\u003e\n    \u003citem name=\"pl_columnCount\"\u003e3\u003c/item\u003e\n    \u003citem name=\"pl_aspect\"\u003esquare\u003c/item\u003e\n\u003c/style\u003e\n\n\u003cstyle name=\"PatternView\" parent=\"Base.PatternView\"\u003e\n    \u003citem name=\"pl_regularColor\"\u003e?colorControlNormal\u003c/item\u003e\n    \u003citem name=\"pl_errorColor\"\u003e#fff4511e\u003c/item\u003e\n    \u003citem name=\"pl_successColor\"\u003e?colorControlActivated\u003c/item\u003e\n\u003c/style\u003e\n\n\u003cstyle name=\"PatternView.Light\" parent=\"Base.PatternView\"\u003e\n    \u003citem name=\"pl_regularColor\"\u003e?colorControlNormal\u003c/item\u003e\n    \u003citem name=\"pl_errorColor\"\u003e#fff4511e\u003c/item\u003e\n    \u003citem name=\"pl_successColor\"\u003e?colorControlActivated\u003c/item\u003e\n\u003c/style\u003e\n```\n\n### Implementing\n\nAs 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.\n\nSet pattern activity example:\n\n```java\npublic class SampleSetPatternActivity extends SetPatternActivity {\n\n    @Override\n    protected void onSetPattern(List\u003cPatternView.Cell\u003e pattern) {\n        String patternSha1 = PatternUtils.patternToSha1String(pattern);\n        // TODO: Save patternSha1 in SharedPreferences.\n    }\n}\n```\n\nConfirm pattern activity example:\n\n```java\npublic class SampleConfirmPatternActivity extends ConfirmPatternActivity {\n\n    @Override\n    protected boolean isStealthModeEnabled() {\n        // TODO: Return the value from SharedPreferences.\n        return false;\n    }\n\n    @Override\n    protected boolean isPatternCorrect(List\u003cPatternView.Cell\u003e pattern) {\n        // TODO: Get saved pattern sha1.\n        String patternSha1 = null;\n        return TextUtils.equals(PatternUtils.patternToSha1String(pattern), patternSha1);\n    }\n\n    @Override\n    protected void onForgotPassword() {\n\n        startActivity(new Intent(this, YourResetPatternActivity.class));\n\n        // Finish with RESULT_FORGOT_PASSWORD.\n        super.onForgotPassword();\n    }\n}\n```\n\nNote that protected fields inherited from `BasePatternActivity`, such as `mMessageText` and `mPatternView`, are also there ready for your customization.\n\nYou can check out the sample app's [`PatternLockActivity`](sample/src/main/java/me/zhanghai/android/patternlock/sample/app/PatternLockActivity.java) for implementing a pattern-locked `Activity`.\n\n## PatternLock or LockPattern?\n\nThe 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`.\n\n## Differences with android-lockpattern\n\nI know there is already a library named [android-lockpattern](https://code.google.com/p/android-lockpattern/), and I tried it for a whole day before I started writing this \"yet another\".\n\n So here are the major differences.\n\n* 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\".\n\n* 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.\n\n* 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.\n\n## Legacy version\n\nThere was a legacy version of this library with Android Design (Holo) appearance and native Activity. If you still want that version, checkout [this](//github.com/zhanghai/PatternLock/tree/0d82d0a1b5a01b7dcf206363012c339969c7a63d).\n\n## License\n\n    Copyright 2015 Zhang Hai\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhanghai%2Fpatternlock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhanghai%2Fpatternlock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhanghai%2Fpatternlock/lists"}