Created
January 18, 2017 18:29
-
-
Save Popalay/09a0381054cba5a4eef6bb0eed3b33c3 to your computer and use it in GitHub Desktop.
EndDrawableOnTouchListener
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class EndDrawableOnTouchListener implements View.OnTouchListener { | |
private static final int DRAWABLE_START = 0; | |
private static final int DRAWABLE_TOP = 1; | |
private static final int DRAWABLE_END = 2; | |
private static final int DRAWABLE_BOTTOM = 3; | |
@Override | |
public boolean onTouch(View view, MotionEvent event) { | |
if (event.getAction() == MotionEvent.ACTION_DOWN) { | |
if (!(view instanceof TextView)) { | |
throw new IllegalArgumentException("View mast inherit TextView"); | |
} | |
final int offset = (view.getRight() - ((TextView) view).getCompoundDrawables()[DRAWABLE_END] | |
.getBounds().width()); | |
if (event.getRawX() >= offset) { | |
return onDrawableTouch(event); | |
} | |
} | |
return false; | |
} | |
public abstract boolean onDrawableTouch(final MotionEvent event); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment