Skip to content

Commit 7e4567e

Browse files
committed
FIX : dispatch accessibility events only if needed, cleaned up code a bit
1 parent c03ecfb commit 7e4567e

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

library/src/main/java/com/matpag/clickdrawabletextview/CsDrawableViewManager.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ private void setViewOnTouchListener(){
291291
switch (e.getAction()) {
292292
case MotionEvent.ACTION_DOWN: {
293293
//if the user clicked on one of the drawables, save some datas about it
294-
if (isOneOfDrawablesTouched(e)) {
294+
if (isOneDrawableTouched(e)) {
295295
pressedX = e.getX();
296296
pressedY = e.getY();
297297
stayedWithinClickDistance = true;
@@ -304,30 +304,27 @@ private void setViewOnTouchListener(){
304304
case MotionEvent.ACTION_MOVE: {
305305
//if the user moved the finger to much far from the initial tap point,
306306
//we cancel the touch on the drawable
307-
if (stayedWithinClickDistance && distance(pressedX, pressedY, e.getX(),
308-
e.getY()) > MAX_CLICK_DISTANCE) {
307+
if (stayedWithinClickDistance &&
308+
distance(pressedX, pressedY, e.getX(), e.getY()) > MAX_CLICK_DISTANCE) {
309309
stayedWithinClickDistance = false;
310310
}
311311
break;
312312
}
313313
case MotionEvent.ACTION_UP: {
314-
// dispatch accessibility events even if the touch didn't hit the drawable
315-
// (the lint checker is still complaining about this and the suppress warning
316-
// is ignored).
317-
// if enableTouchOnText is false should we call this?
318-
view.performClick();
319314
// proceed with the drawable touch logic
320315
long eventDuration = e.getEventTime() - e.getDownTime();
321-
if (mTouchedPosition != null){
316+
if (isOneDrawableTouching()){
322317
if ((eventDuration < MAX_CLICK_DURATION) && stayedWithinClickDistance) {
318+
//dispatch accessibility events
319+
view.performClick();
323320
dispatchDrawableClickEvent();
324321
}
325322
resetTouchedDrawable();
326323
return true;
327324
}
328325
}
329326
}
330-
return false;
327+
return view.onTouchEvent(e);
331328
});
332329
}
333330

@@ -336,7 +333,7 @@ private void setViewOnTouchListener(){
336333
* the bounds of one of the showing drawables, if true set {@link #mTouchedPosition}
337334
* with one of correct values of {@link DrawablePosition}
338335
*/
339-
private boolean isOneOfDrawablesTouched(MotionEvent event){
336+
private boolean isOneDrawableTouched(MotionEvent event){
340337
CsDrawableTouchUtils cdu = new CsDrawableTouchUtils(event, view, isLayoutRTL());
341338
if (mEndDrawable != null && mEndDrawable.isVisible()
342339
&& cdu.isEndDrawableTouched(mEndDrawable)){
@@ -367,6 +364,10 @@ private void resetTouchedDrawable(){
367364
mTouchedPosition = null;
368365
}
369366

367+
private boolean isOneDrawableTouching(){
368+
return mTouchedPosition != null;
369+
}
370+
370371

371372
@Override
372373
public void setOnDrawableClickListener(OnDrawableClickListener listener){

0 commit comments

Comments
 (0)