# PatternLock
**Repository Path**: baijuncheng-open-source/PatternLock
## Basic Information
- **Project Name**: PatternLock
- **Description**: 一个实现 Material Design 模式的图案锁库。
- **Primary Language**: Unknown
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2021-06-07
- **Last Updated**: 2024-05-31
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# 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

## Design
This library aims to provide the basic but extensible building blocks for implementing pattern lock mechanism in an OpenHarmony hap. So the common usage will be extending the base Ability 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.
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:
```gradle
implementation 'com.gitee.baijuncheng-open-source:PatternLock:1.0.2'
```
## Usage
Here are some detailed usage documentation, and you can always refer to the sample app source for a working implementation.
### Styling
You can utilize the resource overriding trick by copying the `layout/pl_base_pattern_ability.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.
And built-in styles, as in `pattern.json`:
```json
{
"pattern": [
{
"name": "base",
"value": [
{
"name": "pl_rowCount",
"value": "3"
},
{
"name": "pl_columnCount",
"value": "3"
},
{
"name": "pl_aspect",
"value": "square"
}
]
}
]
}
```
### 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 `Ability`, in which a simple callback can be difficult or even leaking `Ability` instances.
Set pattern ability example:
```java
public class SampleSetPatternAbility extends SetPatternAbility {
@Override
protected void onSetPattern(List pattern) {
String patternSha1 = PatternUtils.patternToSha1String(pattern);
// TODO: Save patternSha1 in Preferences.
}
}
```
Confirm pattern ability example:
```java
public class SampleConfirmPatternAbility extends ConfirmPatternAbility {
@Override
protected boolean isStealthModeEnabled() {
// TODO: Return the value from Preferences.
return false;
}
@Override
protected boolean isPatternCorrect(List pattern) {
// TODO: Get saved pattern sha1.
String patternSha1 = null;
return TextTool.isEqual(PatternUtils.patternToSha1String(pattern), patternSha1);
}
@Override
protected void onForgotPassword() {
startAbility(new Intent(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.
## 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.