Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "com.mcxtzhang.swipecaptcha"
minSdkVersion 14
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.mcxtzhang.captchalib.CannotTouchSeekBar;
import com.mcxtzhang.captchalib.SwipeCaptchaView;

public class MainActivity extends AppCompatActivity {
SwipeCaptchaView mSwipeCaptchaView;
SeekBar mSeekBar;
CannotTouchSeekBar mSeekBar;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSwipeCaptchaView = (SwipeCaptchaView) findViewById(R.id.swipeCaptchaView);
mSeekBar = (SeekBar) findViewById(R.id.dragBar);
mSeekBar = (CannotTouchSeekBar) findViewById(R.id.dragBar);
findViewById(R.id.btnChange).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
app:captchaHeight="30dp"
app:captchaWidth="30dp"/>

<SeekBar
<com.mcxtzhang.captchalib.CannotTouchSeekBar
android:id="@+id/dragBar"
android:layout_width="320dp"
android:layout_height="60dp"
Expand Down
2 changes: 1 addition & 1 deletion captchalib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {
buildToolsVersion "24.0.3"

defaultConfig {
minSdkVersion 14
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.mcxtzhang.captchalib;

import android.content.Context;
import android.support.v7.widget.AppCompatSeekBar;
import android.util.AttributeSet;
import android.view.MotionEvent;

public class CannotTouchSeekBar extends AppCompatSeekBar {
private static int left = 0;
private static int right = 0;

public CannotTouchSeekBar(Context context) {
this(context,null);
}

public CannotTouchSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
}


@Override
public boolean dispatchTouchEvent(MotionEvent event) {
if(left==0||right==0) {
left = getThumb().getBounds().left;
right = getThumb().getBounds().right;
}


int eventX = (int) event.getX();

if(event.getAction()==MotionEvent.ACTION_DOWN){
if(eventX<=left||eventX>=right){
return false;
}
}


return super.dispatchTouchEvent(event);
}
}