File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
library/src/main/java/com/hjq/window Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -33,14 +33,30 @@ protected LayoutParams generateDefaultLayoutParams() {
3333 return new LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT );
3434 }
3535
36+ private boolean mDownEventFlag ;
37+
3638 @ Override
3739 public boolean dispatchTouchEvent (MotionEvent ev ) {
3840 // 为什么要那么写?有人反馈给子 View 设置 OnClickListener 后,父 View 的 OnTouchListener 收不到事件
3941 // 经过排查发现:父 View 在 dispatchTouchEvent 方法中直接将触摸事件派发给了子 View 的 onTouchEvent 方法
4042 // 从而导致父 View.OnTouchListener 收不到该事件,解决方案是重写 View 的触摸规则,让父 View 的触摸监听优于子 View 的点击事件
4143 if (mOnTouchListener != null && mOnTouchListener .onTouch (this , ev )) {
44+ // 处理悬浮窗移动后仍然会触发 View 长按事件的问题,本质上是 View 在 Down 触摸事件的时候延迟发送了 LongClick 事件的 Runnable
45+ // 假设没有其他事件触发取消 LongClick 事件的 Runnable,则 LongClick 事件的 Runnable 就会执行
46+ // 这里的解决方案是模拟发送一个 Cancel 触摸事件,这样就触发取消 LongClick 事件的 Runnable 的执行
47+ // Github 地址:https://github.com/getActivity/EasyWindow/issues/71
48+ if (mDownEventFlag ) {
49+ MotionEvent newMotionEvent = MotionEvent .obtain (ev );
50+ newMotionEvent .setAction (MotionEvent .ACTION_CANCEL );
51+ super .dispatchTouchEvent (newMotionEvent );
52+ mDownEventFlag = false ;
53+ }
4254 return true ;
4355 }
56+
57+ if (ev .getAction () == MotionEvent .ACTION_DOWN ) {
58+ mDownEventFlag = true ;
59+ }
4460 return super .dispatchTouchEvent (ev );
4561 }
4662
You can’t perform that action at this time.
0 commit comments