起步软件技术论坛
搜索
 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1639|回复: 1

[处理中3] 安卓自定义组件如何引用到WEX5

[复制链接]

87

主题

213

帖子

685

积分

高级会员

Rank: 4

积分
685
发表于 2018-4-3 23:05:47 | 显示全部楼层 |阅读模式
本帖最后由 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"/>

发表于 2018-4-4 16:40:00 | 显示全部楼层
你可以参考attachmentSimple 组件 的文件输出流写出文件的方式实现
自定义action  通过 response 对象将文件流写出去,验证码就是个图片的文件流
http://docs.wex5.com/wex5-server-question-list-2015/

http://docs.wex5.com/wex5-app-question-list-2092/
qq:1912779713
WeX5教程--WeX5下载
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|X3技术论坛|Justep Inc.    

GMT+8, 2025-6-22 14:43 , Processed in 0.058334 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

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