Skip to content

Commit

Permalink
[Fix] fixing file style to prevent making many changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mzelzoghbi committed Mar 5, 2017
1 parent 33482af commit b4079b3
Showing 1 changed file with 63 additions and 99 deletions.
162 changes: 63 additions & 99 deletions androidtagview/src/main/java/co/lujun/androidtagview/TagView.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,84 +23,52 @@
*/
public class TagView extends View {

/**
* Border width
*/
/** Border width*/
private float mBorderWidth;

/**
* Border radius
*/
/** Border radius*/
private float mBorderRadius;

/**
* Text size
*/
/** Text size*/
private float mTextSize;

/**
* Horizontal padding for this view, include left & right padding(left & right padding are equal
*/
/** Horizontal padding for this view, include left & right padding(left & right padding are equal*/
private int mHorizontalPadding;

/**
* Vertical padding for this view, include top & bottom padding(top & bottom padding are equal)
*/
/** Vertical padding for this view, include top & bottom padding(top & bottom padding are equal)*/
private int mVerticalPadding;

/**
* TagView border color
*/
/** TagView border color*/
private int mBorderColor;

/**
* TagView background color
*/
/** TagView background color*/
private int mBackgroundColor;

/**
* TagView text color
*/
/** TagView text color*/
private int mTextColor;

/**
* Whether this view clickable
*/
/** Whether this view clickable*/
private boolean isViewClickable;

/**
* The max length for this tag view
*/
/** The max length for this tag view*/
private int mTagMaxLength;

/**
* OnTagClickListener for click action
*/
/** OnTagClickListener for click action*/
private OnTagClickListener mOnTagClickListener;

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

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

/**
* How long trigger long click callback(default 500ms)
*/
/** How long trigger long click callback(default 500ms)*/
private int mLongPressTime = 500;

/**
* Text direction(support:TEXT_DIRECTION_RTL & TEXT_DIRECTION_LTR, default TEXT_DIRECTION_LTR)
*/
/** Text direction(support:TEXT_DIRECTION_RTL & TEXT_DIRECTION_LTR, default TEXT_DIRECTION_LTR)*/
private int mTextDirection = View.TEXT_DIRECTION_LTR;

/**
* The distance between baseline and descent
*/
/** The distance between baseline and descent*/
private float bdDistance;

private Paint mPaint, mRipplePaint;
Expand All @@ -117,9 +85,7 @@ public class TagView extends View {

private float mTouchX, mTouchY;

/**
* The ripple effect duration(default 1000ms)
*/
/** The ripple effect duration(default 1000ms)*/
private int mRippleDuration = 1000;

private float mRippleRadius;
Expand Down Expand Up @@ -147,22 +113,22 @@ public class TagView extends View {
private Runnable mLongClickHandle = new Runnable() {
@Override
public void run() {
if (!isMoved && !isUp) {
int state = ((TagContainerLayout) getParent()).getTagViewState();
if (state == ViewDragHelper.STATE_IDLE) {
if (!isMoved && !isUp){
int state = ((TagContainerLayout)getParent()).getTagViewState();
if (state == ViewDragHelper.STATE_IDLE){
isExecLongClick = true;
mOnTagClickListener.onTagLongClick((int) getTag(), getText());
}
}
}
};

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

private void init(Context context, 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);
Expand All @@ -173,24 +139,24 @@ private void init(Context context, String text) {
mSlopThreshold = (int) dp2px(context, mSlopThreshold);
}

private void onDealText() {
if (!TextUtils.isEmpty(mOriginText)) {
private void onDealText(){
if(!TextUtils.isEmpty(mOriginText)) {
mAbstractText = mOriginText.length() <= mTagMaxLength ? mOriginText
: mOriginText.substring(0, mTagMaxLength - 3) + "...";
} else {
}else {
mAbstractText = "";
}
mPaint.setTypeface(mTypeface);
mPaint.setTextSize(mTextSize);
final Paint.FontMetrics fontMetrics = mPaint.getFontMetrics();
fontH = fontMetrics.descent - fontMetrics.ascent;
if (mTextDirection == View.TEXT_DIRECTION_RTL) {
if (mTextDirection == View.TEXT_DIRECTION_RTL){
fontW = 0;
for (char c : mAbstractText.toCharArray()) {
String sc = String.valueOf(c);
fontW += mPaint.measureText(sc);
}
} else {
}else {
fontW = mPaint.measureText(mAbstractText);
}
}
Expand Down Expand Up @@ -246,11 +212,11 @@ protected void onDraw(Canvas canvas) {

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
if (isViewClickable) {
if (isViewClickable){
int y = (int) event.getY();
int x = (int) event.getX();
int action = event.getAction();
switch (action) {
switch (action){
case MotionEvent.ACTION_DOWN:
if (getParent() != null) {
getParent().requestDisallowInterceptTouchEvent(true);
Expand All @@ -261,7 +227,7 @@ public boolean dispatchTouchEvent(MotionEvent event) {

case MotionEvent.ACTION_MOVE:
if (Math.abs(mLastY - y) > mSlopThreshold
|| Math.abs(mLastX - x) > mSlopThreshold) {
|| Math.abs(mLastX - x) > mSlopThreshold){
if (getParent() != null) {
getParent().requestDisallowInterceptTouchEvent(false);
}
Expand All @@ -283,15 +249,15 @@ public boolean onTouchEvent(MotionEvent event) {
mTouchY = event.getY();
splashRipple();
}
if (isEnableCross() && isClickCrossArea(event) && mOnTagClickListener != null) {
if (isEnableCross() && isClickCrossArea(event) && mOnTagClickListener != null){
if (action == MotionEvent.ACTION_DOWN) {
mOnTagClickListener.onTagCrossClick((int) getTag());
}
return true;
} else if (isViewClickable && mOnTagClickListener != null) {
}else if (isViewClickable && mOnTagClickListener != null){
int x = (int) event.getX();
int y = (int) event.getY();
switch (action) {
switch (action){
case MotionEvent.ACTION_DOWN:
mLastY = y;
mLastX = x;
Expand All @@ -302,10 +268,10 @@ public boolean onTouchEvent(MotionEvent event) {
break;

case MotionEvent.ACTION_MOVE:
if (isMoved) {
if (isMoved){
break;
}
if (Math.abs(mLastX - x) > mMoveSlop || Math.abs(mLastY - y) > mMoveSlop) {
if (Math.abs(mLastX - x) > mMoveSlop || Math.abs(mLastY - y) > mMoveSlop){
isMoved = true;
}
break;
Expand All @@ -322,34 +288,34 @@ public boolean onTouchEvent(MotionEvent event) {
return super.onTouchEvent(event);
}

private boolean isClickCrossArea(MotionEvent event) {
if (mTextDirection == View.TEXT_DIRECTION_RTL) {
private boolean isClickCrossArea(MotionEvent event){
if (mTextDirection == View.TEXT_DIRECTION_RTL){
return event.getX() <= mCrossAreaWidth;
}
return event.getX() >= getWidth() - mCrossAreaWidth;
}

private void drawCross(Canvas canvas) {
if (isEnableCross()) {
private void drawCross(Canvas canvas){
if (isEnableCross()){
mCrossAreaPadding = mCrossAreaPadding > getHeight() / 2 ? getHeight() / 2 :
mCrossAreaPadding;
int ltX, ltY, rbX, rbY, lbX, lbY, rtX, rtY;
ltX = mTextDirection == View.TEXT_DIRECTION_RTL ? (int) (mCrossAreaPadding) :
(int) (getWidth() - getHeight() + mCrossAreaPadding);
ltY = mTextDirection == View.TEXT_DIRECTION_RTL ? (int) (mCrossAreaPadding) :
(int) (mCrossAreaPadding);
lbX = mTextDirection == View.TEXT_DIRECTION_RTL ? (int) (mCrossAreaPadding) :
(int) (getWidth() - getHeight() + mCrossAreaPadding);
ltX = mTextDirection == View.TEXT_DIRECTION_RTL ? (int)(mCrossAreaPadding) :
(int)(getWidth() - getHeight() + mCrossAreaPadding);
ltY = mTextDirection == View.TEXT_DIRECTION_RTL ? (int)(mCrossAreaPadding) :
(int)(mCrossAreaPadding);
lbX = mTextDirection == View.TEXT_DIRECTION_RTL ? (int)(mCrossAreaPadding) :
(int)(getWidth() - getHeight() + mCrossAreaPadding);
lbY = mTextDirection == View.TEXT_DIRECTION_RTL ?
(int) (getHeight() - mCrossAreaPadding) : (int) (getHeight() - mCrossAreaPadding);
(int)(getHeight() - mCrossAreaPadding) : (int)(getHeight() - mCrossAreaPadding);
rtX = mTextDirection == View.TEXT_DIRECTION_RTL ?
(int) (getHeight() - mCrossAreaPadding) : (int) (getWidth() - mCrossAreaPadding);
rtY = mTextDirection == View.TEXT_DIRECTION_RTL ? (int) (mCrossAreaPadding) :
(int) (mCrossAreaPadding);
(int)(getHeight() - mCrossAreaPadding) : (int)(getWidth() - mCrossAreaPadding);
rtY = mTextDirection == View.TEXT_DIRECTION_RTL ? (int)(mCrossAreaPadding) :
(int)(mCrossAreaPadding);
rbX = mTextDirection == View.TEXT_DIRECTION_RTL ?
(int) (getHeight() - mCrossAreaPadding) : (int) (getWidth() - mCrossAreaPadding);
(int)(getHeight() - mCrossAreaPadding) : (int)(getWidth() - mCrossAreaPadding);
rbY = mTextDirection == View.TEXT_DIRECTION_RTL ?
(int) (getHeight() - mCrossAreaPadding) : (int) (getHeight() - mCrossAreaPadding);
(int)(getHeight() - mCrossAreaPadding) : (int)(getHeight() - mCrossAreaPadding);

mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(mCrossColor);
Expand All @@ -360,8 +326,8 @@ private void drawCross(Canvas canvas) {
}

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void drawRipple(Canvas canvas) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && canvas != null) {
private void drawRipple(Canvas canvas){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && canvas != null){
canvas.save();
mPath.reset();

Expand All @@ -375,8 +341,8 @@ private void drawRipple(Canvas canvas) {
}

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void splashRipple() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && mTouchX > 0 && mTouchY > 0) {
private void splashRipple(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && mTouchX > 0 && mTouchY > 0){
mRipplePaint.setColor(mRippleColor);
mRipplePaint.setAlpha(mRippleAlpha);
final float maxDis = Math.max(Math.max(Math.max(mTouchX, mTouchY),
Expand All @@ -395,32 +361,32 @@ public void onAnimationUpdate(ValueAnimator animation) {
}
}

public String getText() {
public String getText(){
return mOriginText;
}

public boolean getIsViewClickable() {
public boolean getIsViewClickable(){
return isViewClickable;
}

public void setTagMaxLength(int maxLength) {
public void setTagMaxLength(int maxLength){
this.mTagMaxLength = maxLength;
onDealText();
}

public void setOnTagClickListener(OnTagClickListener listener) {
public void setOnTagClickListener(OnTagClickListener listener){
this.mOnTagClickListener = listener;
}

public void setTagBackgroundColor(int color) {
public void setTagBackgroundColor(int color){
this.mBackgroundColor = color;
}

public void setTagBorderColor(int color) {
public void setTagBorderColor(int color){
this.mBorderColor = color;
}

public void setTagTextColor(int color) {
public void setTagTextColor(int color){
this.mTextColor = color;
}

Expand Down Expand Up @@ -449,11 +415,9 @@ public void setIsViewClickable(boolean clickable) {
this.isViewClickable = clickable;
}

public interface OnTagClickListener {
public interface OnTagClickListener{
void onTagClick(int position, String text);

void onTagLongClick(int position, String text);

void onTagCrossClick(int position);
}

Expand Down

0 comments on commit b4079b3

Please sign in to comment.