|
本帖最后由 wjjs2008 于 2018-4-4 07:06 编辑
github上有一个图片验证码组件,我想引入到WEX5应该 如何做?控件的使用方法如下:
Feature
1.简单,实用,只需一两句代码即可使用
2.采用策略模式为使用者开放自定义拼图样式策略,对拼图样式(拼图形状、视觉效果)进行定制
Usage
1.在app的build.gradle添加依赖
compile 'com.luozm.captcha:captcha:1.0.5'
2.将Captcha添加至布局
<com.luozm.captcha.Captcha
android:id="@+id/captCha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:src="@mipmap/cat"/>
3.在编写Java代码
captcha = (Captcha) findViewById(R.id.captCha);
captcha.setCaptchaListener(new Captcha.CaptchaListener() {
@Override
public void onAccess(long time) {
Toast.makeText(MainActivity.this,"验证成功",Toast.LENGTH_SHORT).show();
}
@Override
public void onFailed() {
Toast.makeText(MainActivity.this,"验证失败",Toast.LENGTH_SHORT).show();
}
});
4.(可选)自定义拼图样式
1.编写策略类,继承CaptchaStrategy类,重写策略方法,具体可参考DefaultCaptchaStrategy类
public abstract class CaptchaStrategy {
protected Context mContext;
public CaptchaStrategy(Context ctx) {
this.mContext = ctx;
}
protected Context getContext() {
return mContext;
}
/**
* 定义拼图缺块的形状
*
* @param blockSize 单位dp,注意转化为px
* @return path of the shape
*/
public abstract Path getBlockShape(int blockSize);
/**
* 定义拼图缺块的位置信息
*
* @param width picture width
* @param height picture height
* @return position info of the block
*/
public abstract PictureVertifyView.PositionInfo getBlockPostionInfo(int width, int height);
/**
* 获得绘制拼图缺块阴影的Paint
*/
public abstract Paint getBlockShadowPaint();
/**
* 获得绘制拼图滑块的Paint
*/
public abstract Paint getBlockBitmapPaint();
/**
* 装饰滑块图片,在绘制图片后执行,即绘制滑块前景
* @param canvas 图片的画布
* @shape 拼图形状
*/
public void decoreateSwipeBlockBitmap(Canvas canvas,Path shape) {
}
}
2.添加Java代码
captCha.setCaptchaStrategy(new XXXCaptchaStrategy(context));
5.(可选)自定义滑块条 与Seekbar自定义样式一样
<com.luozm.captcha.Captcha
android:id="@+id/captCha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:progressDrawable="@drawable/progress"
app:thumbDrawable="@drawable/thumb"
app:src="@mipmap/cat"/>
|
|