在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):zhanghai/PatternLock开源软件地址(OpenSource Url):https://github.com/zhanghai/PatternLock开源编程语言(OpenSource Language):Java 100.0%开源软件介绍(OpenSource Introduction):PatternLockA Material Design Pattern Lock library with auth flow implementation. Why PatterLock?
PreviewDesignThis 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 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 IntegrationGradle: compile 'me.zhanghai.android.patternlock:library:2.1.2' UsageHere are some detailed usage documentation, and you can always refer to the sample app source for a working implementation. StylingFirst 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 Available <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 <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> ImplementingAs stated above, the common usage will be extending or checking result instead of giving 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 You can check out the sample app's PatternLock or LockPattern?The original view in AOSP is named Differences with android-lockpatternI 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.
Legacy versionThere was a legacy version of this library with Android Design (Holo) appearance and native Activity. If you still want that version, checkout this. License
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论