├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── libraries
│ ├── animated_vector_drawable_24_2_1.xml
│ ├── appcompat_v7_24_2_1.xml
│ ├── glide_3_7_0.xml
│ ├── support_annotations_24_2_1.xml
│ ├── support_compat_24_2_1.xml
│ ├── support_core_ui_24_2_1.xml
│ ├── support_core_utils_24_2_1.xml
│ ├── support_fragment_24_2_1.xml
│ ├── support_media_compat_24_2_1.xml
│ ├── support_v4_24_2_1.xml
│ └── support_vector_drawable_24_2_1.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── mcxtzhang
│ │ └── swipecaptcha
│ │ ├── CstView.java
│ │ ├── MainActivity.java
│ │ ├── TestSinView.java
│ │ └── TestThridBerserView.java
│ └── res
│ ├── drawable-xxhdpi
│ ├── pic11.jpg
│ ├── pic8.jpg
│ └── yjx.jpg
│ ├── drawable-xxxhdpi
│ ├── thumb_normal.png
│ └── thumb_press.png
│ ├── drawable
│ ├── dragbg.xml
│ └── thumb_bg.xml
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── captchalib
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── mcxtzhang
│ │ └── captchalib
│ │ ├── DrawHelperUtils.java
│ │ └── SwipeCaptchaView.java
│ └── res
│ └── values
│ ├── attrs.xml
│ └── strings.xml
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 |
39 | # Keystore files
40 | *.jks
41 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/libraries/animated_vector_drawable_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/libraries/appcompat_v7_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/libraries/glide_3_7_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/support_annotations_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/libraries/support_compat_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/libraries/support_core_ui_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/libraries/support_core_utils_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.idea/libraries/support_fragment_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/libraries/support_media_compat_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/libraries/support_v4_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/libraries/support_vector_drawable_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # -SwipeCaptcha
2 | Swipe captcha of Android platform。
3 | Android 平台的滑动验证码。
4 |
5 | **在 Android端app上,自定义View,仿一个斗鱼web端滑动验证码**。
6 | 博文:http://blog.csdn.net/zxt0601/article/details/53315975
7 |
8 | 
9 |
10 | # Usage 用法:
11 | Step 1. Add the JitPack repository to your build file
12 | 在项目根build.gradle文件中增加JitPack仓库依赖。
13 | ```
14 | allprojects {
15 | repositories {
16 | ...
17 | maven { url "https://jitpack.io" }
18 | }
19 | }
20 | ```
21 | Step 2. Add the dependency
22 | ```
23 | dependencies {
24 | compile 'com.github.mcxtzhang:SwipeCaptcha:V1.0.0'
25 | }
26 | ```
27 |
28 |
29 | Step 3.
30 | ```
31 |
40 |
41 |
50 | ```
51 |
52 |
53 |
54 |
55 | 那么本控件包含不仅包含以下功能:
56 | * 随机区域**起点(左上角x,y)**生成一个验证码阴影。
57 | * 验证码拼图 **凹凸图形**会随机变换。
58 | * 验证码区域**宽高**可自定义。
59 | * **抠图**验证码区域,绘制一个用于联动滑动的验证码滑块。
60 | * 验证失败,会闪烁几下然后回到原点。
61 | * 验证成功,会有白光扫过的动画。
62 |
63 | 分解一下验证码核心实现思路:
64 | * 控件继承自ImageView。理由:
65 | 1 如果放在项目中用,验证码图片希望可以是接口返回。ImageView以及其子类支持花式加载图片。
66 | 2 继承自ImageView,绘制图片本身不用我们干预,也不用我们操心scaleType,节省很多工作。
67 | * 在`onSizeChanged()`方法中生成 和 控件宽高相关的属性值:
68 | 1 初始化时随机生成验证码区域起点
69 | 2 生成验证码区域Path
70 | 3 生成滑块Bitmap
71 | * `onDraw()`时,依次绘制:
72 | 1 验证码阴影
73 | 2 滑块
74 |
75 | # to do list,待完善
76 | * abstract dragbar(seekbar) interface
77 | * SwipeCaptcha inside to hold the interface to do something
78 |
79 | * 抽象拖动条接口
80 | * SwipeCaptcha内部要持有这个接口 做一些事情
81 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.3"
6 | defaultConfig {
7 | applicationId "com.mcxtzhang.swipecaptcha"
8 | minSdkVersion 14
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(include: ['*.jar'], dir: 'libs')
23 | compile 'com.android.support:appcompat-v7:24.2.1'
24 | compile project(':captchalib')
25 | compile 'com.github.bumptech.glide:glide:3.7.0'
26 | }
27 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\admin\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mcxtzhang/swipecaptcha/CstView.java:
--------------------------------------------------------------------------------
1 | package com.mcxtzhang.swipecaptcha;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.Path;
9 | import android.util.AttributeSet;
10 | import android.util.Log;
11 | import android.view.View;
12 |
13 |
14 | /**
15 | * 介绍:
16 | * 作者:zhangxutong
17 | * 邮箱:mcxtzhang@163.com
18 | * 主页:http://blog.csdn.net/zxt0601
19 | * 时间: 2016/11/15.
20 | */
21 |
22 | public class CstView extends View {
23 | private static final String TAG = "zxt";
24 | ;
25 |
26 | public CstView(Context context) {
27 | super(context);
28 | }
29 |
30 | public CstView(Context context, AttributeSet attrs) {
31 | super(context, attrs);
32 | }
33 |
34 | public CstView(Context context, AttributeSet attrs, int defStyleAttr) {
35 | super(context, attrs, defStyleAttr);
36 | }
37 |
38 | @Override
39 | protected void onDraw(Canvas canvas) {
40 | canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), (R.drawable.pic11)), 0, 0, new Paint());
41 | Path path = new Path();
42 | path.moveTo(100, 100);
43 | path.lineTo(200, 100);
44 | path.lineTo(200, 200);
45 | path.lineTo(200, 300);
46 | path.close();
47 | Bitmap rightBitmap = getMaskBitmap(BitmapFactory.decodeResource(getResources(), (R.drawable.pic11)), path);
48 | canvas.drawBitmap(rightBitmap, -100, -100, new Paint());
49 |
50 | }
51 |
52 | //生成右边的背景
53 | private Bitmap getMaskBitmap(Bitmap mBitmap, Path mask) {
54 | Bitmap bgBitmap = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), Bitmap.Config.ARGB_8888);
55 | Log.e(TAG, " getRightBitmap: " + bgBitmap.getWidth());
56 | //把创建的位图作为画板
57 | Canvas mCanvas = new Canvas(bgBitmap);
58 | Paint mPaint = new Paint();
59 | mPaint.setAntiAlias(true);
60 | //mCanvas.save();
61 | //先将canvas保存
62 | //把canvas修剪成指定的路径区域
63 | //mCanvas.translate(100, 100);
64 |
65 | mCanvas.clipPath(mask);
66 | mCanvas.drawBitmap(mBitmap, 0, 0, mPaint);
67 |
68 | Log.e(TAG, "getRightBitmap: " + bgBitmap.getWidth());
69 | return bgBitmap;
70 | }
71 |
72 | private Bitmap leftBitmap;
73 |
74 | /* //生成左边的滑块的背景
75 | private void getLeftBitmap(Bitmap mBitmap) {
76 | Bitmap bgBitmap = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), Bitmap.Config.ARGB_8888);
77 | //把创建的位图作为画板
78 | Canvas mCanvas = new Canvas(bgBitmap);
79 | Paint mPaint = new Paint();
80 | mPaint.setAntiAlias(true);
81 | mCanvas.save();
82 | mCanvas.translate(point.x, point.y);
83 | mCanvas.clipPath(path);
84 | mCanvas.drawColor(Color.WHITE);
85 | mCanvas.restore();
86 | mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
87 |
88 | //先将canvas保存
89 | //把canvas修剪成指定的路径区域
90 | mCanvas.drawBitmap(mBitmap, 0, 0, mPaint);
91 | leftBitmap = Bitmap.createBitmap(bgBitmap, point.x, point.y, w, w);
92 | }*/
93 | }
94 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mcxtzhang/swipecaptcha/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.mcxtzhang.swipecaptcha;
2 |
3 | import android.graphics.Bitmap;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.util.Log;
7 | import android.view.View;
8 | import android.widget.SeekBar;
9 | import android.widget.Toast;
10 |
11 | import com.bumptech.glide.Glide;
12 | import com.bumptech.glide.request.animation.GlideAnimation;
13 | import com.bumptech.glide.request.target.SimpleTarget;
14 | import com.mcxtzhang.captchalib.SwipeCaptchaView;
15 |
16 | public class MainActivity extends AppCompatActivity {
17 | SwipeCaptchaView mSwipeCaptchaView;
18 | SeekBar mSeekBar;
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_main);
24 | mSwipeCaptchaView = (SwipeCaptchaView) findViewById(R.id.swipeCaptchaView);
25 | mSeekBar = (SeekBar) findViewById(R.id.dragBar);
26 | findViewById(R.id.btnChange).setOnClickListener(new View.OnClickListener() {
27 | @Override
28 | public void onClick(View v) {
29 | mSwipeCaptchaView.createCaptcha();
30 | mSeekBar.setEnabled(true);
31 | mSeekBar.setProgress(0);
32 | }
33 | });
34 | mSwipeCaptchaView.setOnCaptchaMatchCallback(new SwipeCaptchaView.OnCaptchaMatchCallback() {
35 | @Override
36 | public void matchSuccess(SwipeCaptchaView swipeCaptchaView) {
37 | Toast.makeText(MainActivity.this, "恭喜你啊 验证成功 可以搞事情了", Toast.LENGTH_SHORT).show();
38 | //swipeCaptcha.createCaptcha();
39 | mSeekBar.setEnabled(false);
40 | }
41 |
42 | @Override
43 | public void matchFailed(SwipeCaptchaView swipeCaptchaView) {
44 | Log.d("zxt", "matchFailed() called with: swipeCaptchaView = [" + swipeCaptchaView + "]");
45 | Toast.makeText(MainActivity.this, "你有80%的可能是机器人,现在走还来得及", Toast.LENGTH_SHORT).show();
46 | swipeCaptchaView.resetCaptcha();
47 | mSeekBar.setProgress(0);
48 | }
49 | });
50 | mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
51 |
52 | @Override
53 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
54 | mSwipeCaptchaView.setCurrentSwipeValue(progress);
55 | }
56 |
57 | @Override
58 | public void onStartTrackingTouch(SeekBar seekBar) {
59 | //随便放这里是因为控件
60 | mSeekBar.setMax(mSwipeCaptchaView.getMaxSwipeValue());
61 | }
62 |
63 | @Override
64 | public void onStopTrackingTouch(SeekBar seekBar) {
65 | Log.d("zxt", "onStopTrackingTouch() called with: seekBar = [" + seekBar + "]");
66 | mSwipeCaptchaView.matchCaptcha();
67 | }
68 | });
69 |
70 | //测试从网络加载图片是否ok
71 | Glide.with(this)
72 | .load("http://www.investide.cn/data/edata/image/20151201/20151201180507_281.jpg")
73 | .asBitmap()
74 | .into(new SimpleTarget() {
75 | @Override
76 | public void onResourceReady(Bitmap resource, GlideAnimation super Bitmap> glideAnimation) {
77 | mSwipeCaptchaView.setImageBitmap(resource);
78 | mSwipeCaptchaView.createCaptcha();
79 | }
80 | });
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mcxtzhang/swipecaptcha/TestSinView.java:
--------------------------------------------------------------------------------
1 | package com.mcxtzhang.swipecaptcha;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.graphics.Path;
8 | import android.util.AttributeSet;
9 | import android.view.View;
10 |
11 | /**
12 | * 介绍:
13 | * 作者:zhangxutong
14 | * 邮箱:mcxtzhang@163.com
15 | * 主页:http://blog.csdn.net/zxt0601
16 | * 时间: 2016/11/16.
17 | */
18 |
19 | public class TestSinView extends View {
20 | public TestSinView(Context context) {
21 | super(context);
22 | }
23 |
24 | public TestSinView(Context context, AttributeSet attrs) {
25 | super(context, attrs);
26 | }
27 |
28 | //验证码 阴影、抠图的Path
29 | private Path mCaptchaPath = new Path();
30 | //验证码的左上角(起点)的x y
31 | private int mCaptchaX = 200;
32 | private int mCaptchaY = 200;
33 | //验证码的宽高
34 | private int mCaptchaWidth = 300;
35 | private int mCaptchaHeight = 300;
36 |
37 | @Override
38 | protected void onDraw(Canvas canvas) {
39 |
40 |
41 | mCaptchaPath.reset();
42 | //从左上角开始 绘制一个不规则的阴影
43 | mCaptchaPath.moveTo(mCaptchaX, mCaptchaY);
44 |
45 |
46 | /* mCaptchaPath.lineTo(mCaptchaX + gap, mCaptchaY);
47 | //画出凹凸 由于是多段Path 无法闭合,简直阿西吧
48 | int r = mCaptchaWidth / 2 - gap;
49 | RectF oval = new RectF(mCaptchaX + gap, mCaptchaY - (r), mCaptchaX + gap + r * 2, mCaptchaY + (r));
50 | mCaptchaPath.arcTo(oval, 180, 180);*/
51 |
52 | int gap = mCaptchaWidth / 3;
53 | mCaptchaPath.lineTo(mCaptchaX + gap, mCaptchaY);
54 | //利用正弦曲线方程 Y = A sin(wx+FAI)+k,将计算后的坐标传入Path.quadTo()方法(绘制贝塞尔曲线)中,构建波浪曲线。
55 |
56 | W = (float) (Math.PI / (mCaptchaWidth - 2 * gap));
57 | FAI = (float) (-W * (mCaptchaX + gap) + Math.PI);
58 |
59 | for (int x = mCaptchaX + gap; x < mCaptchaX + mCaptchaWidth - gap; x++) {
60 | float y = (float) (A * Math.sin(W * x + FAI) + K + mCaptchaY);
61 | /* if (x == mCaptchaX + gap) {
62 | mCaptchaPath.moveTo(x, y);
63 | }*/
64 | mCaptchaPath.quadTo(x, y, x + 1, y);
65 | }
66 |
67 |
68 | mCaptchaPath.lineTo(mCaptchaX + mCaptchaWidth, mCaptchaY);//节点
69 |
70 | mCaptchaPath.lineTo(mCaptchaX + mCaptchaWidth, mCaptchaY + gap);
71 |
72 | W = (float) (Math.PI / (mCaptchaHeight - 2 * gap));
73 | FAI = (float) (-W * (mCaptchaY + gap) + Math.PI);
74 |
75 | for (int x = mCaptchaY + gap; x < mCaptchaY + mCaptchaHeight - gap; x++) {
76 | float y = (float) (A * Math.sin(W * x + FAI) + K + mCaptchaX + mCaptchaWidth);
77 | /* if (x == mCaptchaX + gap) {
78 | mCaptchaPath.moveTo(x, y);
79 | }*/
80 | mCaptchaPath.quadTo(y, x, y + 1, x);
81 | }
82 |
83 |
84 |
85 |
86 | Paint paint = new Paint();
87 | paint.setColor(Color.BLACK);
88 | paint.setStyle(Paint.Style.STROKE);
89 | canvas.drawPath(mCaptchaPath, paint);
90 | }
91 |
92 |
93 | /**
94 | * 波浪圆X轴偏移
95 | */
96 | private float FAI = 0;
97 | /**
98 | * 波浪圆振幅
99 | */
100 | private float A = 50;
101 | /**
102 | * 波浪圆的周期
103 | */
104 | private float W;
105 | /**
106 | * 波浪圆Y轴偏移
107 | */
108 | private float K = 0;
109 |
110 |
111 | /**
112 | * 角度转换成弧度
113 | *
114 | * @param degree
115 | * @return
116 | */
117 | private double degreeToRad(double degree) {
118 | return degree * Math.PI / 180;
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mcxtzhang/swipecaptcha/TestThridBerserView.java:
--------------------------------------------------------------------------------
1 | package com.mcxtzhang.swipecaptcha;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.graphics.Path;
8 | import android.graphics.PointF;
9 | import android.util.AttributeSet;
10 | import android.view.View;
11 |
12 | /**
13 | * 介绍:
14 | * 作者:zhangxutong
15 | * 邮箱:mcxtzhang@163.com
16 | * 主页:http://blog.csdn.net/zxt0601
17 | * 时间: 2016/11/16.
18 | */
19 |
20 | public class TestThridBerserView extends View {
21 | public TestThridBerserView(Context context) {
22 | super(context);
23 | }
24 |
25 | public TestThridBerserView(Context context, AttributeSet attrs) {
26 | super(context, attrs);
27 | }
28 |
29 | //验证码 阴影、抠图的Path
30 | private Path mCaptchaPath = new Path();
31 | //验证码的左上角(起点)的x y
32 | private int mCaptchaX = 200;
33 | private int mCaptchaY = 200;
34 | //验证码的宽高
35 | private int mCaptchaWidth = 300;
36 | private int mCaptchaHeight = 300;
37 |
38 | @Override
39 | protected void onDraw(Canvas canvas) {
40 | mCaptchaPath.reset();
41 | mCaptchaPath.moveTo(mCaptchaX, mCaptchaY);
42 |
43 | int gap = mCaptchaWidth / 3;
44 | mCaptchaPath.lineTo(mCaptchaX + gap, mCaptchaY);
45 | int left = mCaptchaX + gap;
46 | int right = mCaptchaX + gap * 2;
47 | PointF start = new PointF(left, mCaptchaY);
48 | PointF end = new PointF(right, mCaptchaY);
49 | drawPartCircle(start, end, mCaptchaPath, false);
50 |
51 |
52 | mCaptchaPath.lineTo(mCaptchaX + mCaptchaWidth, mCaptchaY);//节点
53 | mCaptchaPath.lineTo(mCaptchaX + mCaptchaWidth, mCaptchaY + gap);
54 |
55 | drawPartCircle(new PointF(mCaptchaX + mCaptchaWidth, mCaptchaY + gap),
56 | new PointF(mCaptchaX + mCaptchaWidth, mCaptchaY + gap * 2),
57 | mCaptchaPath, false);
58 |
59 | mCaptchaPath.lineTo(mCaptchaX + mCaptchaWidth, mCaptchaY + mCaptchaHeight);//节点
60 | mCaptchaPath.lineTo(mCaptchaX + mCaptchaWidth - gap, mCaptchaY + mCaptchaHeight);
61 |
62 | drawPartCircle(new PointF(mCaptchaX + mCaptchaWidth - gap, mCaptchaY + mCaptchaHeight),
63 | new PointF(mCaptchaX + mCaptchaWidth - gap - gap, mCaptchaY + mCaptchaHeight),
64 | mCaptchaPath, false);
65 |
66 | mCaptchaPath.lineTo(mCaptchaX, mCaptchaY + mCaptchaHeight);//节点
67 | mCaptchaPath.lineTo(mCaptchaX, mCaptchaY + mCaptchaHeight - gap);
68 |
69 | drawPartCircle(new PointF(mCaptchaX, mCaptchaY + mCaptchaHeight - gap),
70 | new PointF(mCaptchaX, mCaptchaY + mCaptchaHeight - gap * 2),
71 | mCaptchaPath, false);
72 |
73 |
74 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
75 | paint.setColor(Color.BLACK);
76 | paint.setStyle(Paint.Style.FILL);
77 | canvas.drawPath(mCaptchaPath, paint);
78 | }
79 |
80 |
81 | /**
82 | * 传入起点、终点 坐标、凹凸和Path。
83 | * 会自动绘制凹凸的半圆弧
84 | *
85 | * @param start 起点坐标
86 | * @param end 终点坐标
87 | * @param path 半圆会绘制在这个path上
88 | * @param outer 是否凸半圆
89 | */
90 | private void drawPartCircle(PointF start, PointF end, Path path, boolean outer) {
91 | float c = 0.551915024494f;
92 | //中点
93 | PointF middle = new PointF(start.x + (end.x - start.x) / 2, start.y + (end.y - start.y) / 2);
94 | //半径
95 | float r1 = (float) Math.sqrt(Math.pow((middle.x - start.x), 2) + Math.pow((middle.y - start.y), 2));
96 | //gap值
97 | float gap1 = r1 * c;
98 |
99 | if (start.x == end.x) {
100 | //绘制竖直方向的
101 |
102 | //是否是从上到下
103 | boolean topToBottom = end.y - start.y > 0 ? true : false;
104 | //以下是我写出了所有的计算公式后推的,不要问我过程,只可意会。
105 | int flag;//旋转系数
106 | if (topToBottom) {
107 | flag = 1;
108 | } else {
109 | flag = -1;
110 | }
111 | if (outer) {
112 | //凸的 两个半圆
113 | path.cubicTo(start.x + gap1 * flag, start.y,
114 | middle.x + r1 * flag, middle.y - gap1 * flag,
115 | middle.x + r1 * flag, middle.y);
116 | path.cubicTo(middle.x + r1 * flag, middle.y + gap1 * flag,
117 | end.x + gap1 * flag, end.y,
118 | end.x, end.y);
119 | } else {
120 | //凹的 两个半圆
121 | path.cubicTo(start.x - gap1 * flag, start.y,
122 | middle.x - r1 * flag, middle.y - gap1 * flag,
123 | middle.x - r1 * flag, middle.y);
124 | path.cubicTo(middle.x - r1 * flag, middle.y + gap1 * flag,
125 | end.x - gap1 * flag, end.y,
126 | end.x, end.y);
127 | }
128 | } else {
129 | //绘制水平方向的
130 |
131 | //是否是从左到右
132 | boolean leftToRight = end.x - start.x > 0 ? true : false;
133 | //以下是我写出了所有的计算公式后推的,不要问我过程,只可意会。
134 | int flag;//旋转系数
135 | if (leftToRight) {
136 | flag = 1;
137 | } else {
138 | flag = -1;
139 | }
140 | if (outer) {
141 | //凸 两个半圆
142 | path.cubicTo(start.x, start.y - gap1 * flag,
143 | middle.x - gap1 * flag, middle.y - r1 * flag,
144 | middle.x, middle.y - r1 * flag);
145 | path.cubicTo(middle.x + gap1 * flag, middle.y - r1 * flag,
146 | end.x, end.y - gap1 * flag,
147 | end.x, end.y);
148 | } else {
149 | //凹 两个半圆
150 | path.cubicTo(start.x, start.y + gap1 * flag,
151 | middle.x - gap1 * flag, middle.y + r1 * flag,
152 | middle.x, middle.y + r1 * flag);
153 | path.cubicTo(middle.x + gap1 * flag, middle.y + r1 * flag,
154 | end.x, end.y + gap1 * flag,
155 | end.x, end.y);
156 | }
157 |
158 |
159 | /*
160 | 没推导之前的公式在这里
161 | if (start.x < end.x) {
162 | if (outer) {
163 | //上左半圆 顺时针
164 | path.cubicTo(start.x, start.y - gap1,
165 | middle.x - gap1, middle.y - r1,
166 | middle.x, middle.y - r1);
167 |
168 | //上右半圆:顺时针
169 | path.cubicTo(middle.x + gap1, middle.y - r1,
170 | end.x, end.y - gap1,
171 | end.x, end.y);
172 | } else {
173 | //下左半圆 逆时针
174 | path.cubicTo(start.x, start.y + gap1,
175 | middle.x - gap1, middle.y + r1,
176 | middle.x, middle.y + r1);
177 |
178 | //下右半圆 逆时针
179 | path.cubicTo(middle.x + gap1, middle.y + r1,
180 | end.x, end.y + gap1,
181 | end.x, end.y);
182 | }
183 | } else {
184 | if (outer) {
185 | //下右半圆 顺时针
186 | path.cubicTo(start.x, start.y + gap1,
187 | middle.x + gap1, middle.y + r1,
188 | middle.x, middle.y + r1);
189 | //下左半圆 顺时针
190 | path.cubicTo(middle.x - gap1, middle.y + r1,
191 | end.x, end.y + gap1,
192 | end.x, end.y);
193 | }
194 | }*/
195 | }
196 | }
197 | }
198 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/pic11.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mcxtzhang/SwipeCaptcha/fc77cbe097c25fe1dd66f071233840d7c22e07a5/app/src/main/res/drawable-xxhdpi/pic11.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/pic8.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mcxtzhang/SwipeCaptcha/fc77cbe097c25fe1dd66f071233840d7c22e07a5/app/src/main/res/drawable-xxhdpi/pic8.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/yjx.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mcxtzhang/SwipeCaptcha/fc77cbe097c25fe1dd66f071233840d7c22e07a5/app/src/main/res/drawable-xxhdpi/yjx.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/thumb_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mcxtzhang/SwipeCaptcha/fc77cbe097c25fe1dd66f071233840d7c22e07a5/app/src/main/res/drawable-xxxhdpi/thumb_normal.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/thumb_press.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mcxtzhang/SwipeCaptcha/fc77cbe097c25fe1dd66f071233840d7c22e07a5/app/src/main/res/drawable-xxxhdpi/thumb_press.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/dragbg.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/thumb_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
24 |
25 |
34 |
35 |
41 |
42 |
46 |
47 |
51 |
52 |
56 |
57 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mcxtzhang/SwipeCaptcha/fc77cbe097c25fe1dd66f071233840d7c22e07a5/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SwipeCaptcha
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.2'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/captchalib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/captchalib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.3"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | compile 'com.android.support:appcompat-v7:24.2.1'
24 | }
25 |
--------------------------------------------------------------------------------
/captchalib/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\admin\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/captchalib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/captchalib/src/main/java/com/mcxtzhang/captchalib/DrawHelperUtils.java:
--------------------------------------------------------------------------------
1 | package com.mcxtzhang.captchalib;
2 |
3 | import android.graphics.Path;
4 | import android.graphics.PointF;
5 |
6 | /**
7 | * 介绍:帮助绘图的工具类
8 | * 作者:zhangxutong
9 | * 邮箱:mcxtzhang@163.com
10 | * 主页:http://blog.csdn.net/zxt0601
11 | * 时间: 2016/11/16.
12 | */
13 |
14 | public class DrawHelperUtils {
15 | /**
16 | * 传入起点、终点 坐标、凹凸和Path。
17 | * 会自动绘制凹凸的半圆弧
18 | *
19 | * @param start 起点坐标
20 | * @param end 终点坐标
21 | * @param path 半圆会绘制在这个path上
22 | * @param outer 是否凸半圆
23 | */
24 | public static void drawPartCircle(PointF start, PointF end, Path path, boolean outer) {
25 | float c = 0.551915024494f;
26 | //中点
27 | PointF middle = new PointF(start.x + (end.x - start.x) / 2, start.y + (end.y - start.y) / 2);
28 | //半径
29 | float r1 = (float) Math.sqrt(Math.pow((middle.x - start.x), 2) + Math.pow((middle.y - start.y), 2));
30 | //gap值
31 | float gap1 = r1 * c;
32 |
33 | if (start.x == end.x) {
34 | //绘制竖直方向的
35 |
36 | //是否是从上到下
37 | boolean topToBottom = end.y - start.y > 0 ? true : false;
38 | //以下是我写出了所有的计算公式后推的,不要问我过程,只可意会。
39 | int flag;//旋转系数
40 | if (topToBottom) {
41 | flag = 1;
42 | } else {
43 | flag = -1;
44 | }
45 | if (outer) {
46 | //凸的 两个半圆
47 | path.cubicTo(start.x + gap1 * flag, start.y,
48 | middle.x + r1 * flag, middle.y - gap1 * flag,
49 | middle.x + r1 * flag, middle.y);
50 | path.cubicTo(middle.x + r1 * flag, middle.y + gap1 * flag,
51 | end.x + gap1 * flag, end.y,
52 | end.x, end.y);
53 | } else {
54 | //凹的 两个半圆
55 | path.cubicTo(start.x - gap1 * flag, start.y,
56 | middle.x - r1 * flag, middle.y - gap1 * flag,
57 | middle.x - r1 * flag, middle.y);
58 | path.cubicTo(middle.x - r1 * flag, middle.y + gap1 * flag,
59 | end.x - gap1 * flag, end.y,
60 | end.x, end.y);
61 | }
62 | } else {
63 | //绘制水平方向的
64 |
65 | //是否是从左到右
66 | boolean leftToRight = end.x - start.x > 0 ? true : false;
67 | //以下是我写出了所有的计算公式后推的,不要问我过程,只可意会。
68 | int flag;//旋转系数
69 | if (leftToRight) {
70 | flag = 1;
71 | } else {
72 | flag = -1;
73 | }
74 | if (outer) {
75 | //凸 两个半圆
76 | path.cubicTo(start.x, start.y - gap1 * flag,
77 | middle.x - gap1 * flag, middle.y - r1 * flag,
78 | middle.x, middle.y - r1 * flag);
79 | path.cubicTo(middle.x + gap1 * flag, middle.y - r1 * flag,
80 | end.x, end.y - gap1 * flag,
81 | end.x, end.y);
82 | } else {
83 | //凹 两个半圆
84 | path.cubicTo(start.x, start.y + gap1 * flag,
85 | middle.x - gap1 * flag, middle.y + r1 * flag,
86 | middle.x, middle.y + r1 * flag);
87 | path.cubicTo(middle.x + gap1 * flag, middle.y + r1 * flag,
88 | end.x, end.y + gap1 * flag,
89 | end.x, end.y);
90 | }
91 |
92 |
93 | /*
94 | 没推导之前的公式在这里
95 | if (start.x < end.x) {
96 | if (outer) {
97 | //上左半圆 顺时针
98 | path.cubicTo(start.x, start.y - gap1,
99 | middle.x - gap1, middle.y - r1,
100 | middle.x, middle.y - r1);
101 |
102 | //上右半圆:顺时针
103 | path.cubicTo(middle.x + gap1, middle.y - r1,
104 | end.x, end.y - gap1,
105 | end.x, end.y);
106 | } else {
107 | //下左半圆 逆时针
108 | path.cubicTo(start.x, start.y + gap1,
109 | middle.x - gap1, middle.y + r1,
110 | middle.x, middle.y + r1);
111 |
112 | //下右半圆 逆时针
113 | path.cubicTo(middle.x + gap1, middle.y + r1,
114 | end.x, end.y + gap1,
115 | end.x, end.y);
116 | }
117 | } else {
118 | if (outer) {
119 | //下右半圆 顺时针
120 | path.cubicTo(start.x, start.y + gap1,
121 | middle.x + gap1, middle.y + r1,
122 | middle.x, middle.y + r1);
123 | //下左半圆 顺时针
124 | path.cubicTo(middle.x - gap1, middle.y + r1,
125 | end.x, end.y + gap1,
126 | end.x, end.y);
127 | }
128 | }*/
129 | }
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/captchalib/src/main/java/com/mcxtzhang/captchalib/SwipeCaptchaView.java:
--------------------------------------------------------------------------------
1 | package com.mcxtzhang.captchalib;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.ValueAnimator;
6 | import android.content.Context;
7 | import android.content.res.TypedArray;
8 | import android.graphics.Bitmap;
9 | import android.graphics.BlurMaskFilter;
10 | import android.graphics.Canvas;
11 | import android.graphics.Color;
12 | import android.graphics.LinearGradient;
13 | import android.graphics.Paint;
14 | import android.graphics.PaintFlagsDrawFilter;
15 | import android.graphics.Path;
16 | import android.graphics.PointF;
17 | import android.graphics.PorterDuff;
18 | import android.graphics.PorterDuffXfermode;
19 | import android.graphics.Shader;
20 | import android.graphics.drawable.BitmapDrawable;
21 | import android.support.v4.view.animation.FastOutLinearInInterpolator;
22 | import android.util.AttributeSet;
23 | import android.util.Log;
24 | import android.util.TypedValue;
25 | import android.widget.ImageView;
26 |
27 | import java.util.Random;
28 |
29 | import static com.mcxtzhang.captchalib.DrawHelperUtils.drawPartCircle;
30 |
31 | /**
32 | * 介绍:仿斗鱼滑动验证码的View
33 | * 作者:zhangxutong
34 | * 邮箱:mcxtzhang@163.com
35 | * 主页:http://blog.csdn.net/zxt0601
36 | * 时间: 2016/11/14.
37 | */
38 |
39 | public class SwipeCaptchaView extends ImageView {
40 | private static final String TAG = "zxt/" + SwipeCaptchaView.class.getName();
41 | //控件的宽高
42 | protected int mWidth;
43 | protected int mHeight;
44 |
45 | //验证码滑块的宽高
46 | private int mCaptchaWidth;
47 | private int mCaptchaHeight;
48 | //验证码的左上角(起点)的x y
49 | private int mCaptchaX;
50 | private int mCaptchaY;
51 | private Random mRandom;
52 | private Paint mPaint;
53 | //验证码 阴影、抠图的Path
54 | private Path mCaptchaPath;
55 | private PorterDuffXfermode mPorterDuffXfermode;
56 |
57 |
58 | //是否绘制滑块(验证失败闪烁动画用)
59 | private boolean isDrawMask;
60 | //滑块Bitmap
61 | private Bitmap mMaskBitmap;
62 | private Paint mMaskPaint;
63 | //用于绘制阴影的Paint
64 | private Paint mMaskShadowPaint;
65 | private Bitmap mMaskShadowBitmap;
66 | //滑块的位移
67 | private int mDragerOffset;
68 |
69 | //是否处于验证模式,在验证成功后 为false,其余情况为true
70 | private boolean isMatchMode;
71 | //验证的误差允许值
72 | private float mMatchDeviation;
73 | //验证失败的闪烁动画
74 | private ValueAnimator mFailAnim;
75 | //验证成功的白光一闪动画
76 | private boolean isShowSuccessAnim;
77 | private ValueAnimator mSuccessAnim;
78 | private Paint mSuccessPaint;//画笔
79 | private int mSuccessAnimOffset;//动画的offset
80 | private Path mSuccessPath;//成功动画 平行四边形Path
81 |
82 |
83 | public SwipeCaptchaView(Context context) {
84 | this(context, null);
85 | }
86 |
87 | public SwipeCaptchaView(Context context, AttributeSet attrs) {
88 | this(context, attrs, 0);
89 | }
90 |
91 | public SwipeCaptchaView(Context context, AttributeSet attrs, int defStyleAttr) {
92 | super(context, attrs, defStyleAttr);
93 | init(context, attrs, defStyleAttr);
94 | }
95 |
96 | private void init(Context context, AttributeSet attrs, int defStyleAttr) {
97 | int defaultSize = (int) TypedValue.applyDimension(
98 | TypedValue.COMPLEX_UNIT_SP, 16, getResources().getDisplayMetrics());
99 | mCaptchaHeight = defaultSize;
100 | mCaptchaWidth = defaultSize;
101 | mMatchDeviation = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3, getResources().getDisplayMetrics());
102 | TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.SwipeCaptchaView, defStyleAttr, 0);
103 | int n = ta.getIndexCount();
104 | for (int i = 0; i < n; i++) {
105 | int attr = ta.getIndex(i);
106 | if (attr == R.styleable.SwipeCaptchaView_captchaHeight) {
107 | mCaptchaHeight = (int) ta.getDimension(attr, defaultSize);
108 | } else if (attr == R.styleable.SwipeCaptchaView_captchaWidth) {
109 | mCaptchaWidth = (int) ta.getDimension(attr, defaultSize);
110 | } else if (attr == R.styleable.SwipeCaptchaView_matchDeviation) {
111 | mMatchDeviation = ta.getDimension(attr, mMatchDeviation);
112 | }
113 | }
114 | ta.recycle();
115 |
116 |
117 | mRandom = new Random(System.nanoTime());
118 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
119 | mPaint.setColor(0x77000000);
120 | //mPaint.setStyle(Paint.Style.STROKE);
121 | // 设置画笔遮罩滤镜
122 | mPaint.setMaskFilter(new BlurMaskFilter(20, BlurMaskFilter.Blur.SOLID));
123 |
124 | //滑块区域
125 | mPorterDuffXfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
126 | mMaskPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
127 |
128 | // 实例化阴影画笔
129 | mMaskShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
130 | mMaskShadowPaint.setColor(Color.BLACK);
131 | /* mMaskShadowPaint.setStrokeWidth(50);
132 | mMaskShadowPaint.setTextSize(50);
133 | mMaskShadowPaint.setStyle(Paint.Style.FILL_AND_STROKE);*/
134 | mMaskShadowPaint.setMaskFilter(new BlurMaskFilter(10, BlurMaskFilter.Blur.SOLID));
135 |
136 | mCaptchaPath = new Path();
137 |
138 |
139 | }
140 |
141 | @Override
142 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
143 | super.onSizeChanged(w, h, oldw, oldh);
144 | mWidth = w;
145 | mHeight = h;
146 | //动画区域 会用到宽高
147 | createMatchAnim();
148 |
149 | post(new Runnable() {
150 | @Override
151 | public void run() {
152 | createCaptcha();
153 | }
154 | });
155 | }
156 |
157 | //验证动画初始化区域
158 | private void createMatchAnim() {
159 | mFailAnim = ValueAnimator.ofFloat(0, 1);
160 | mFailAnim.setDuration(100)
161 | .setRepeatCount(4);
162 | mFailAnim.setRepeatMode(ValueAnimator.REVERSE);
163 | //失败的时候先闪一闪动画 斗鱼是 隐藏-显示 -隐藏 -显示
164 | mFailAnim.addListener(new AnimatorListenerAdapter() {
165 | @Override
166 | public void onAnimationEnd(Animator animation) {
167 | onCaptchaMatchCallback.matchFailed(SwipeCaptchaView.this);
168 | }
169 | });
170 | mFailAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
171 | @Override
172 | public void onAnimationUpdate(ValueAnimator animation) {
173 | float animatedValue = (float) animation.getAnimatedValue();
174 | Log.d(TAG, "onAnimationUpdate: " + animatedValue);
175 | if (animatedValue < 0.5f) {
176 | isDrawMask = false;
177 | } else {
178 | isDrawMask = true;
179 | }
180 | invalidate();
181 | }
182 | });
183 |
184 | int width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, getResources().getDisplayMetrics());
185 | mSuccessAnim = ValueAnimator.ofInt(mWidth + width, 0);
186 | mSuccessAnim.setDuration(500);
187 | mSuccessAnim.setInterpolator(new FastOutLinearInInterpolator());
188 | mSuccessAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
189 | @Override
190 | public void onAnimationUpdate(ValueAnimator animation) {
191 | mSuccessAnimOffset = (int) animation.getAnimatedValue();
192 | invalidate();
193 | }
194 | });
195 | mSuccessAnim.addListener(new AnimatorListenerAdapter() {
196 | @Override
197 | public void onAnimationStart(Animator animation) {
198 | isShowSuccessAnim = true;
199 | }
200 |
201 | @Override
202 | public void onAnimationEnd(Animator animation) {
203 | onCaptchaMatchCallback.matchSuccess(SwipeCaptchaView.this);
204 | isShowSuccessAnim = false;
205 | isMatchMode = false;
206 | }
207 | });
208 | mSuccessPaint = new Paint();
209 | mSuccessPaint.setShader(new LinearGradient(0, 0, width/2*3, mHeight, new int[]{
210 | 0x00ffffff, 0x88ffffff}, new float[]{0,0.5f},
211 | Shader.TileMode.MIRROR));
212 | //模仿斗鱼 是一个平行四边形滚动过去
213 | mSuccessPath = new Path();
214 | mSuccessPath.moveTo(0, 0);
215 | mSuccessPath.rLineTo(width, 0);
216 | mSuccessPath.rLineTo(width / 2, mHeight);
217 | mSuccessPath.rLineTo(-width, 0);
218 | mSuccessPath.close();
219 | }
220 |
221 | //生成验证码区域
222 | public void createCaptcha() {
223 | if (getDrawable() != null) {
224 | resetFlags();
225 | createCaptchaPath();
226 | craeteMask();
227 | invalidate();
228 | }
229 | }
230 |
231 | //重置一些flasg, 开启验证模式
232 | private void resetFlags() {
233 | isMatchMode = true;
234 | }
235 |
236 | //生成验证码Path
237 | private void createCaptchaPath() {
238 | //原本打算随机生成gap,后来发现 宽度/3 效果比较好,
239 | int gap = mRandom.nextInt(mCaptchaWidth / 2);
240 | gap = mCaptchaWidth / 3;
241 |
242 | //随机生成验证码阴影左上角 x y 点,
243 | mCaptchaX = mRandom.nextInt(mWidth - mCaptchaWidth - gap);
244 | mCaptchaY = mRandom.nextInt(mHeight - mCaptchaHeight - gap);
245 | Log.d(TAG, "createCaptchaPath() called mWidth:" + mWidth + ", mHeight:" + mHeight + ", mCaptchaX:" + mCaptchaX + ", mCaptchaY:" + mCaptchaY);
246 |
247 | mCaptchaPath.reset();
248 | mCaptchaPath.lineTo(0, 0);
249 |
250 |
251 | //从左上角开始 绘制一个不规则的阴影
252 | mCaptchaPath.moveTo(mCaptchaX, mCaptchaY);//左上角
253 |
254 |
255 | /* mCaptchaPath.lineTo(mCaptchaX + gap, mCaptchaY);
256 | //画出凹凸 由于是多段Path 无法闭合,简直阿西吧
257 | int r = mCaptchaWidth / 2 - gap;
258 | RectF oval = new RectF(mCaptchaX + gap, mCaptchaY - (r), mCaptchaX + gap + r * 2, mCaptchaY + (r));
259 | mCaptchaPath.arcTo(oval, 180, 180);*/
260 |
261 | mCaptchaPath.lineTo(mCaptchaX + gap, mCaptchaY);
262 | //draw一个随机凹凸的圆
263 | drawPartCircle(new PointF(mCaptchaX + gap, mCaptchaY),
264 | new PointF(mCaptchaX + gap * 2, mCaptchaY),
265 | mCaptchaPath, mRandom.nextBoolean());
266 |
267 |
268 | mCaptchaPath.lineTo(mCaptchaX + mCaptchaWidth, mCaptchaY);//右上角
269 | mCaptchaPath.lineTo(mCaptchaX + mCaptchaWidth, mCaptchaY + gap);
270 | //draw一个随机凹凸的圆
271 | drawPartCircle(new PointF(mCaptchaX + mCaptchaWidth, mCaptchaY + gap),
272 | new PointF(mCaptchaX + mCaptchaWidth, mCaptchaY + gap * 2),
273 | mCaptchaPath, mRandom.nextBoolean());
274 |
275 |
276 | mCaptchaPath.lineTo(mCaptchaX + mCaptchaWidth, mCaptchaY + mCaptchaHeight);//右下角
277 | mCaptchaPath.lineTo(mCaptchaX + mCaptchaWidth - gap, mCaptchaY + mCaptchaHeight);
278 | //draw一个随机凹凸的圆
279 | drawPartCircle(new PointF(mCaptchaX + mCaptchaWidth - gap, mCaptchaY + mCaptchaHeight),
280 | new PointF(mCaptchaX + mCaptchaWidth - gap * 2, mCaptchaY + mCaptchaHeight),
281 | mCaptchaPath, mRandom.nextBoolean());
282 |
283 |
284 | mCaptchaPath.lineTo(mCaptchaX, mCaptchaY + mCaptchaHeight);//左下角
285 | mCaptchaPath.lineTo(mCaptchaX, mCaptchaY + mCaptchaHeight - gap);
286 | //draw一个随机凹凸的圆
287 | drawPartCircle(new PointF(mCaptchaX, mCaptchaY + mCaptchaHeight - gap),
288 | new PointF(mCaptchaX, mCaptchaY + mCaptchaHeight - gap * 2),
289 | mCaptchaPath, mRandom.nextBoolean());
290 |
291 |
292 | mCaptchaPath.close();
293 |
294 | /* RectF oval = new RectF(mCaptchaX + gap, mCaptchaY - (r), mCaptchaX + gap + r * 2, mCaptchaY + (r));
295 | mCaptchaPath.addArc(oval, 180,180);
296 | mCaptchaPath.lineTo(mCaptchaX + mCaptchaWidth, mCaptchaY);
297 | //凹的话,麻烦一点,要利用多次move
298 | mCaptchaPath.lineTo(mCaptchaX + mCaptchaWidth, mCaptchaY + gap);
299 | oval = new RectF(mCaptchaX + mCaptchaWidth - r, mCaptchaY + gap, mCaptchaX + mCaptchaWidth + r, mCaptchaY + gap + r * 2);
300 | mCaptchaPath.addArc(oval, 90, 180);
301 | mCaptchaPath.moveTo(mCaptchaX + mCaptchaWidth, mCaptchaY + gap + r * 2);*//*
302 | mCaptchaPath.lineTo(mCaptchaX + mCaptchaWidth, mCaptchaY + mCaptchaHeight);
303 | mCaptchaPath.lineTo(mCaptchaX, mCaptchaY + mCaptchaHeight);
304 | mCaptchaPath.close();*/
305 | }
306 |
307 | //生成滑块
308 | private void craeteMask() {
309 | mMaskBitmap = getMaskBitmap(((BitmapDrawable) getDrawable()).getBitmap(), mCaptchaPath);
310 | //滑块阴影
311 | mMaskShadowBitmap = mMaskBitmap.extractAlpha();
312 | //拖动的位移重置
313 | mDragerOffset = 0;
314 | //isDrawMask 绘制失败闪烁动画用
315 | isDrawMask = true;
316 | }
317 |
318 | //抠图
319 | private Bitmap getMaskBitmap(Bitmap mBitmap, Path mask) {
320 | //以控件宽高 create一块bitmap
321 | Bitmap tempBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
322 | Log.e(TAG, " getMaskBitmap: width:" + mBitmap.getWidth() + ", height:" + mBitmap.getHeight());
323 | Log.e(TAG, " View: width:" + mWidth + ", height:" + mHeight);
324 | //把创建的bitmap作为画板
325 | Canvas mCanvas = new Canvas(tempBitmap);
326 | //有锯齿 且无法解决,所以换成XFermode的方法做
327 | //mCanvas.clipPath(mask);
328 | // 抗锯齿
329 | mCanvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
330 | //绘制用于遮罩的圆形
331 | mCanvas.drawPath(mask, mMaskPaint);
332 | //设置遮罩模式(图像混合模式)
333 | mMaskPaint.setXfermode(mPorterDuffXfermode);
334 | //★考虑到scaleType等因素,要用Matrix对Bitmap进行缩放
335 | mCanvas.drawBitmap(mBitmap, getImageMatrix(), mMaskPaint);
336 | mMaskPaint.setXfermode(null);
337 | return tempBitmap;
338 | }
339 |
340 |
341 | @Override
342 | protected void onDraw(Canvas canvas) {
343 | super.onDraw(canvas);
344 | //继承自ImageView,所以Bitmap,ImageView已经帮我们draw好了。
345 | //我只在上面绘制和验证码相关的部分,
346 |
347 | //是否处于验证模式,在验证成功后 为false,其余情况为true
348 | if (isMatchMode) {
349 | //首先绘制验证码阴影
350 | if (mCaptchaPath != null) {
351 | canvas.drawPath(mCaptchaPath, mPaint);
352 | }
353 | //绘制滑块
354 | // isDrawMask 绘制失败闪烁动画用
355 | if (null != mMaskBitmap && null != mMaskShadowBitmap && isDrawMask) {
356 | // 先绘制阴影
357 | canvas.drawBitmap(mMaskShadowBitmap, -mCaptchaX + mDragerOffset, 0, mMaskShadowPaint);
358 | canvas.drawBitmap(mMaskBitmap, -mCaptchaX + mDragerOffset, 0, null);
359 | }
360 | //验证成功,白光扫过的动画,这一块动画感觉不完美,有提高空间
361 | if (isShowSuccessAnim) {
362 | canvas.translate(mSuccessAnimOffset, 0);
363 | canvas.drawPath(mSuccessPath, mSuccessPaint);
364 | }
365 | }
366 | }
367 |
368 |
369 | /**
370 | * 校验
371 | */
372 | public void matchCaptcha() {
373 | if (null != onCaptchaMatchCallback && isMatchMode) {
374 | //这里验证逻辑,是通过比较,拖拽的距离 和 验证码起点x坐标。 默认3dp以内算是验证成功。
375 | if (Math.abs(mDragerOffset - mCaptchaX) < mMatchDeviation) {
376 | Log.d(TAG, "matchCaptcha() true: mDragerOffset:" + mDragerOffset + ", mCaptchaX:" + mCaptchaX);
377 | //matchSuccess();
378 | //成功的动画
379 | mSuccessAnim.start();
380 |
381 |
382 | } else {
383 | Log.e(TAG, "matchCaptcha() false: mDragerOffset:" + mDragerOffset + ", mCaptchaX:" + mCaptchaX);
384 |
385 | mFailAnim.start();
386 | //matchFailed();
387 | }
388 | }
389 |
390 | }
391 |
392 | /**
393 | * 重置验证码滑动距离,(一般用于验证失败)
394 | */
395 | public void resetCaptcha() {
396 | mDragerOffset = 0;
397 | invalidate();
398 | }
399 |
400 | /**
401 | * 最大可滑动值
402 | * @return
403 | */
404 | public int getMaxSwipeValue() {
405 | //return ((BitmapDrawable) getDrawable()).getBitmap().getWidth() - mCaptchaWidth;
406 | //返回控件宽度
407 | return mWidth - mCaptchaWidth;
408 | }
409 |
410 | /**
411 | * 设置当前滑动值
412 | * @param value
413 | */
414 | public void setCurrentSwipeValue(int value) {
415 | mDragerOffset = value;
416 | invalidate();
417 | }
418 |
419 | public interface OnCaptchaMatchCallback {
420 | void matchSuccess(SwipeCaptchaView swipeCaptchaView);
421 |
422 | void matchFailed(SwipeCaptchaView swipeCaptchaView);
423 | }
424 |
425 | /**
426 | * 验证码验证的回调
427 | */
428 | private OnCaptchaMatchCallback onCaptchaMatchCallback;
429 |
430 | public OnCaptchaMatchCallback getOnCaptchaMatchCallback() {
431 | return onCaptchaMatchCallback;
432 | }
433 |
434 | /**
435 | * 设置验证码验证回调
436 | *
437 | * @param onCaptchaMatchCallback
438 | * @return
439 | */
440 | public SwipeCaptchaView setOnCaptchaMatchCallback(OnCaptchaMatchCallback onCaptchaMatchCallback) {
441 | this.onCaptchaMatchCallback = onCaptchaMatchCallback;
442 | return this;
443 | }
444 | }
445 |
--------------------------------------------------------------------------------
/captchalib/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/captchalib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | captchalib
3 |
4 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mcxtzhang/SwipeCaptcha/fc77cbe097c25fe1dd66f071233840d7c22e07a5/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':captchalib'
2 |
--------------------------------------------------------------------------------