Skip to content

Commit

Permalink
Fix: issue #35
Browse files Browse the repository at this point in the history
  • Loading branch information
whilu committed Dec 7, 2016
1 parent 87de387 commit f8ce588
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
Expand Up @@ -18,6 +18,9 @@
import java.util.Arrays;
import java.util.List;

import static co.lujun.androidtagview.Utils.dp2px;
import static co.lujun.androidtagview.Utils.sp2px;

/**
* Author: lujun(http://blog.lujun.co)
* Date: 2015-12-30 17:14
Expand Down Expand Up @@ -1185,14 +1188,4 @@ public float getCrossLineWidth() {
public void setCrossLineWidth(float mCrossLineWidth) {
this.mCrossLineWidth = mCrossLineWidth;
}

public float dp2px(Context context, float dp) {
final float scale = context.getResources().getDisplayMetrics().density;
return dp * scale + 0.5f;
}

public float sp2px(Context context, float sp) {
final float scale = context.getResources().getDisplayMetrics().scaledDensity;
return sp * scale;
}
}
23 changes: 16 additions & 7 deletions androidtagview/src/main/java/co/lujun/androidtagview/TagView.java
Expand Up @@ -15,6 +15,9 @@
import android.view.MotionEvent;
import android.view.View;

import static co.lujun.androidtagview.Utils.dp2px;
import static co.lujun.androidtagview.Utils.sp2px;

/**
* Author: lujun(http://blog.lujun.co)
* Date: 2015-12-31 11:47
Expand Down Expand Up @@ -54,10 +57,10 @@ public class TagView extends View {
/** OnTagClickListener for click action*/
private OnTagClickListener mOnTagClickListener;

/** Move slop(default 20px)*/
private int mMoveSlop = 20;
/** Move slop(default 5dp)*/
private int mMoveSlop = 5;

/** Scroll slop threshold*/
/** Scroll slop threshold 4dp*/
private int mSlopThreshold = 4;

/** How long trigger long click callback(default 500ms)*/
Expand Down Expand Up @@ -123,16 +126,18 @@ public void run() {

public TagView(Context context, String text){
super(context);
init(text);
init(context, text);
}

private void init(String text){
private void init(Context context, String text){
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mRipplePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mRipplePaint.setStyle(Paint.Style.FILL);
mRectF = new RectF();
mPath = new Path();
mOriginText = text == null ? "" : text;
mMoveSlop = (int) dp2px(context, mMoveSlop);
mSlopThreshold = (int) dp2px(context, mSlopThreshold);
}

private void onDealText(){
Expand Down Expand Up @@ -217,15 +222,19 @@ public boolean dispatchTouchEvent(MotionEvent event) {
int action = event.getAction();
switch (action){
case MotionEvent.ACTION_DOWN:
getParent().requestDisallowInterceptTouchEvent(true);
if (getParent() != null) {
getParent().requestDisallowInterceptTouchEvent(true);
}
mLastY = y;
mLastX = x;
break;

case MotionEvent.ACTION_MOVE:
if (Math.abs(mLastY - y) > mSlopThreshold
|| Math.abs(mLastX - x) > mSlopThreshold){
getParent().requestDisallowInterceptTouchEvent(false);
if (getParent() != null) {
getParent().requestDisallowInterceptTouchEvent(false);
}
isMoved = true;
return false;
}
Expand Down
21 changes: 21 additions & 0 deletions androidtagview/src/main/java/co/lujun/androidtagview/Utils.java
@@ -0,0 +1,21 @@
package co.lujun.androidtagview;

import android.content.Context;

/**
* Author: lujun(http://blog.lujun.co)
* Date: 2016-12-7 21:53
*/

public class Utils {

public static float dp2px(Context context, float dp) {
final float scale = context.getResources().getDisplayMetrics().density;
return dp * scale + 0.5f;
}

public static float sp2px(Context context, float sp) {
final float scale = context.getResources().getDisplayMetrics().scaledDensity;
return sp * scale;
}
}

0 comments on commit f8ce588

Please sign in to comment.