登录 立即注册
安币:

安卓巴士 - 安卓开发 - Android开发 - 安卓 - 移动互联网门户

android Material Design图案解锁库

[复制链接]
来自: BlueManlove 分类: Android精品源码 上传时间: 2017-7-7 10:25:07
Tag:

项目介绍:

一个好用且漂亮的Material Design图案解锁库
Download

This library is available in jCenter which is the default Maven repository used in Android Studio.

Gradle

dependencies {

// other dependencies here

compile 'com.andrognito.patternlockview:patternlockview:1.0.0'
// Optional, for RxJava2 adapter
compile 'com.andrognito.patternlockview:patternlockview-reactive:1.0.0'

}
Spread Some :heart:

GitHub stars GitHub followers
Twitter Follow

Usage

We recommend you to check the sample project to get a complete understanding of the library. The step-by-step implementation guide is as follows.

Step 1

Place the view in your XML layout file.

<com.andrognito.patternlockview.PatternLockView
    android:id="@+id/pattern_lock_view"
    android:layout_width="280dp"
    android:layout_height="280dp"/>

This is enough to get the view rendered in your layout. But you would certainly want to add a callback listener to listen to pattern changes.

Step 2

Reference the view in code and add a listener to it.

mPatternLockView = (PatternLockView) findViewById(R.id.pattern_lock_view);
mPatternLockView.addPatternLockListener(mPatternLockViewListener);
Implement the listener interface as follows,

private PatternLockViewListener mPatternLockViewListener = new PatternLockViewListener() {

    @Override
    public void onStarted() {
        Log.d(getClass().getName(), "Pattern drawing started");
    }

    @Override
    public void onProgress(List<PatternLockView.Dot> progressPattern) {
        Log.d(getClass().getName(), "Pattern progress: " +
                PatternLockUtils.patternToString(mPatternLockView, progressPattern));
    }

    @Override
    public void onComplete(List<PatternLockView.Dot> pattern) {
        Log.d(getClass().getName(), "Pattern complete: " +
                PatternLockUtils.patternToString(mPatternLockView, pattern));
    }

    @Override
    public void onCleared() {
        Log.d(getClass().getName(), "Pattern has been cleared");
    }
};

And that's it! Your PatternLockView is ready to rock. You might also want to remove the listeners when not needed, removePatternLockListener(mPatternLockViewListener);

Step 3 (Optional: ReactiveX Interface)

For the RxJava fanboys, this library supports RxJava 2 view bindings. You can subscribe to this view to get a stream of pattern change updates.

RxPatternLockView.patternChanges(mPatternLockView)

            .subscribe(new Consumer<PatternLockCompoundEvent>() {
                @Override
                public void accept(PatternLockCompoundEvent event) throws Exception {
                    if (event.getEventType() == PatternLockCompoundEvent.EventType.PATTERN_STARTED) {
                        Log.d(getClass().getName(), "Pattern drawing started");
                    } else if (event.getEventType() == PatternLockCompoundEvent.EventType.PATTERN_PROGRESS) {
                        Log.d(getClass().getName(), "Pattern progress: " +
                                PatternLockUtils.patternToString(mPatternLockView, event.getPattern()));
                    } else if (event.getEventType() == PatternLockCompoundEvent.EventType.PATTERN_COMPLETE) {
                        Log.d(getClass().getName(), "Pattern complete: " +
                                PatternLockUtils.patternToString(mPatternLockView, event.getPattern()));
                    } else if (event.getEventType() == PatternLockCompoundEvent.EventType.PATTERN_CLEARED) {
                        Log.d(getClass().getName(), "Pattern has been cleared");
                    }
                }
            });

If you are not interested in getting the compound event, you should subscribe to patternComplete() and/or patternProgress() for the specific updates. Have a detailed look here.

Customization

There are several customization options available which you can use to completely change the look-and-feel and functionality of this view to match your needs.

XML (Quick and Easy)

You can add various attributes to the PatternLockView from your XML layout.

app:dotCount="3" // Change the no.of dots in a row (or column)
app:dotNormalSize="12dp" // Change the size of the dots in normal state
app:dotSelectedSize="24dp" // Change the size of the dots in selected state
app:pathWidth="4dp" // Change the width of the path
app:aspectRatioEnabled="true" // Set if the view should respect custom aspect ratio
app:aspectRatio="square" // Set between "square", "width_bias", "height_bias"
app:normalStateColor="@color/white" // Set the color of the pattern view in normal state
app:correctStateColor="@color/primary" // Set the color of the pattern view in correct state
app:wrongStateColor="@color/pomegranate" // Set the color of the pattern view in error state
app:dotAnimationDuration="200" // Change the duration of the animating dots
app:pathEndAnimationDuration="100" // Change the duration of the path end animaiton
JAVA (Programatically)

You can also programatically change the properties of the view, thereby having more control over it.

mPatternLockView.setViewMode(PatternLockView.PatternViewMode.CORRECT); // Set the current viee more
mPatternLockView.setInStealthMode(true); // Set the pattern in stealth mode (pattern drawing is hidden)
mPatternLockView.setTactileFeedbackEnabled(true); // Enables vibration feedback when the pattern is drawn
mPatternLockView.setInputEnabled(false); // Disables any input from the pattern lock view completely

mPatternLockView.setDotCount(3);
mPatternLockView.setDotNormalSize((int) ResourceUtils.getDimensionInPx(this, R.dimen.pattern_lock_dot_size));
mPatternLockView.setDotSelectedSize((int) ResourceUtils.getDimensionInPx(this, R.dimen.pattern_lock_dot_selected_size));
mPatternLockView.setPathWidth((int) ResourceUtils.getDimensionInPx(this, R.dimen.pattern_lock_path_width));
mPatternLockView.setAspectRatioEnabled(true);
mPatternLockView.setAspectRatio(PatternLockView.AspectRatio.ASPECT_RATIO_HEIGHT_BIAS);
mPatternLockView.setNormalStateColor(ResourceUtils.getColor(this, R.color.white));
mPatternLockView.setCorrectStateColor(ResourceUtils.getColor(this, R.color.primary));
mPatternLockView.setWrongStateColor(ResourceUtils.getColor(this, R.color.pomegranate));
mPatternLockView.setDotAnimationDuration(150);
mPatternLockView.setPathEndAnimationDuration(100);

相关源码推荐:

我来说两句
所有评论(76)
ffg12 2017-7-7 10:31:38
安卓巴士是个不错的网站,我来顶个贴~
回复
东西南北 2017-7-7 10:32:13
感谢分享,楼主V5~
回复
柠檬lemon 2017-7-7 10:32:18
每次我都积极回帖的,想要安币~
回复
subsoil 2017-7-7 10:32:29
支持,感谢,祝巴士越来越好~
回复
仲夏炎凉。 2017-7-7 10:32:35
支持楼主,支持安卓巴士!
回复
yukong 2017-7-7 10:32:44
楼主是好人,回个帖会有安币吗?
回复
早午晚 2017-7-7 11:38:11
感谢分享,安卓巴士有你更精彩:)
回复
提取码:  下载次数:38 状态:已购或VIP 售价:10(原价:10)金钱 下载权限:限制会员 
2143 3 38
代码贡献英雄榜
用户名 下载数
联系我们
首页/微信公众账号投稿

帖子代码编辑/版权问题

QQ:435399051,769657487

如何获得代码达人称号

如何成为签约作者

联系我们
关闭
合作电话:
13802416937
Email:
435399051@qq.com
商务市场合作/投稿
问题反馈及帮助
联系我们

广告投放| 申请友链|手机版|站点统计|安卓巴士 ( 粤ICP备15117877号 )

快速回复 返回顶部 返回列表