diff --git a/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/AbstractTouchEventHandler.java b/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/AbstractTouchEventHandler.java index 8df6728..aaf9ec6 100644 --- a/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/AbstractTouchEventHandler.java +++ b/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/AbstractTouchEventHandler.java @@ -9,7 +9,7 @@ import java.util.List; /** - * Created by 张宇(G7428) on 2017/9/19. + * Created by 张宇 on 2017/9/19. * E-mail: zhangyu4@yy.com * YY: 909017428 *

diff --git a/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/AttachToViewTouchEventHandler.java b/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/AttachToViewTouchEventHandler.java index 7ba64a8..b2ec70b 100644 --- a/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/AttachToViewTouchEventHandler.java +++ b/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/AttachToViewTouchEventHandler.java @@ -5,7 +5,7 @@ import android.view.View; /** - * Created by 张宇(G7428) on 2017/9/6. + * Created by 张宇 on 2017/9/6. * E-mail: zhangyu4@yy.com * YY: 909017428 *

diff --git a/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/InterceptClickHandler.java b/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/InterceptClickHandler.java index 61caf24..3feff54 100644 --- a/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/InterceptClickHandler.java +++ b/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/InterceptClickHandler.java @@ -7,7 +7,7 @@ import android.view.ViewGroup; /** - * Created by 张宇(G7428) on 2017/9/6. + * Created by 张宇 on 2017/9/6. * E-mail: zhangyu4@yy.com * YY: 909017428 *

diff --git a/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/TouchEventBus.java b/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/TouchEventBus.java index c714ab8..6b50cbe 100644 --- a/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/TouchEventBus.java +++ b/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/TouchEventBus.java @@ -14,7 +14,7 @@ import java.util.List; /** - * Created by 张宇(G7428) on 2017/9/1. + * Created by 张宇 on 2017/9/1. * E-mail: zhangyu4@yy.com * YY: 909017428 *

@@ -39,17 +39,18 @@ private static TouchEventBus instance() { * 分发触摸事件的起点。 * 一般在Activity的dispatchEvent开始分发。一个Activity上只能有一个起点。 * - * @param e 触摸事件 + * @param event 触摸事件 * @param parentView 起点接收触摸事件的view。用于对触摸事件的发生坐标进行调整。 */ @UiThread - public static boolean dispatchTouchEvent(MotionEvent e, @Nullable View parentView) { + public static boolean dispatchTouchEvent(MotionEvent event, @Nullable View parentView) { if (parentView == null) { throw new IllegalArgumentException("parent view can't be null"); } - if (e == null) { + if (event == null) { return false; } + MotionEvent e = MotionEvent.obtain(event); //开始一串触摸事件 if (e.getAction() == MotionEvent.ACTION_DOWN) { //获取ViewTree的顺序列表 orderList = new ArrayList<>(instance().mContainer.getOrderTouchEventHandler()); @@ -66,22 +67,26 @@ public static boolean dispatchTouchEvent(MotionEvent e, @Nullable View parentVie //如果确实担心这种情况,就需要在ViewHolder每次遍历时再copy一次 //如果完全不担心上层Handler修改MotionEvent,可以把下面这句obtain也去掉进一步提高性能 MotionEvent copyEvent = MotionEvent.obtain(e); - if (!intercepted || handler.forceMonitor()) { - //上层没拦截 或者 自己死活都要触摸事件 - intercepted = dispatchInner(handler, intercepted, copyEvent); - } else { - //已经被拦截,发一个Cancel事件,而且不再参与接下来同一串的触摸事件 - copyEvent.setAction(MotionEvent.ACTION_CANCEL); - dispatchInner(handler, true, copyEvent); - itr.remove(); + try { + if (!intercepted || handler.forceMonitor()) { + //上层没拦截 或者 自己死活都要触摸事件 + intercepted = dispatchInner(handler, intercepted, copyEvent); + } else { + //已经被拦截,发一个Cancel事件,而且不再参与接下来同一串的触摸事件 + copyEvent.setAction(MotionEvent.ACTION_CANCEL); + dispatchInner(handler, true, copyEvent); + itr.remove(); + } + } finally { + copyEvent.recycle(); } - copyEvent.recycle(); } //结束触摸后,清掉orderList防止内存泄漏 if (e.getAction() == MotionEvent.ACTION_UP || e.getAction() == MotionEvent.ACTION_CANCEL) { orderList = Collections.emptyList(); } + e.recycle(); return intercepted; } @@ -89,8 +94,8 @@ public static boolean dispatchTouchEvent(MotionEvent e, @Nullable View parentVie * @see #dispatchTouchEvent(MotionEvent, View) */ @UiThread - public static boolean dispatchTouchEvent(MotionEvent e, Activity entry) { - return dispatchTouchEvent(e, entry.getWindow().getDecorView() + public static boolean dispatchTouchEvent(MotionEvent event, Activity entry) { + return dispatchTouchEvent(event, entry.getWindow().getDecorView() .findViewById(android.R.id.content)); } @@ -98,16 +103,16 @@ public static boolean dispatchTouchEvent(MotionEvent e, Activity entry) { * @see #dispatchTouchEvent(MotionEvent, View) */ @UiThread - public static boolean dispatchTouchEvent(MotionEvent e, Fragment entry) { - return dispatchTouchEvent(e, entry.getView()); + public static boolean dispatchTouchEvent(MotionEvent event, Fragment entry) { + return dispatchTouchEvent(event, entry.getView()); } /** * @see #dispatchTouchEvent(MotionEvent, View) */ @UiThread - public static boolean dispatchTouchEvent(MotionEvent e, android.app.Fragment entry) { - return dispatchTouchEvent(e, entry.getView()); + public static boolean dispatchTouchEvent(MotionEvent event, android.app.Fragment entry) { + return dispatchTouchEvent(event, entry.getView()); } @SuppressWarnings("unchecked") diff --git a/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/TouchEventHandler.java b/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/TouchEventHandler.java index 8ad0c2f..e382837 100644 --- a/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/TouchEventHandler.java +++ b/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/TouchEventHandler.java @@ -7,7 +7,7 @@ import java.util.List; /** - * Created by 张宇(G7428) on 2017/9/4. + * Created by 张宇 on 2017/9/4. * E-mail: zhangyu4@yy.com * YY: 909017428 * diff --git a/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/TouchEventHandlerContainer.java b/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/TouchEventHandlerContainer.java index e225002..e951121 100644 --- a/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/TouchEventHandlerContainer.java +++ b/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/TouchEventHandlerContainer.java @@ -10,7 +10,7 @@ import java.util.Map; /** - * Created by 张宇(G7428) on 2017/9/5. + * Created by 张宇 on 2017/9/5. * E-mail: zhangyu4@yy.com * YY: 909017428 *

diff --git a/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/TouchEventHandlerUtil.java b/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/TouchEventHandlerUtil.java index 8c9d4d6..f8f0818 100644 --- a/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/TouchEventHandlerUtil.java +++ b/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/TouchEventHandlerUtil.java @@ -22,7 +22,7 @@ import static android.view.MotionEvent.ACTION_UP; /** - * Created by 张宇(G7428) on 2017/9/6. + * Created by 张宇 on 2017/9/6. * E-mail: zhangyu4@yy.com * YY: 909017428 */ diff --git a/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/TouchViewHolder.java b/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/TouchViewHolder.java index 906cfdf..250582e 100644 --- a/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/TouchViewHolder.java +++ b/toucheventbus/src/main/java/mobile/yy/com/toucheventbus/TouchViewHolder.java @@ -6,7 +6,7 @@ import java.util.Set; /** - * Created by 张宇(G7428) on 2017/9/8. + * Created by 张宇 on 2017/9/8. * E-mail: zhangyu4@yy.com * YY: 909017428 */