Skip to content

Instantly share code, notes, and snippets.

@Popalay
Created January 18, 2017 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Popalay/09a0381054cba5a4eef6bb0eed3b33c3 to your computer and use it in GitHub Desktop.
Save Popalay/09a0381054cba5a4eef6bb0eed3b33c3 to your computer and use it in GitHub Desktop.
EndDrawableOnTouchListener
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