class CheckForLongPress implements Runnable { private int mOriginalWindowAttachCount; public void run() { // 进入该函数,说明检测到了长按操作 if (isPressed() && (mParent != null) && mOriginalWindowAttachCount == mWindowAttachCount) { if (performLongClick()) { mHasPerformedLongPress = true; } } } public void rememberWindowAttachCount() { mOriginalWindowAttachCount = mWindowAttachCount; } } public boolean performLongClick() { sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED); boolean handled = false; if (mOnLongClickListener != null) { // 回调用户实现的长按操作监听函数(OnLongClickListener) handled = mOnLongClickListener.onLongClick(View.this); } if (!handled) { // 如果OnLongClickListener的onLongClick返回false // 则需要继续处理该长按事件,这里是显示上下文菜单 handled = showContextMenu(); } if (handled) { // 长按操作事件被处理了,此时应该给用户触觉上的反馈 performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); } return handled; }
Android系统中长按事件的实现机制解析(4)
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:http://www.heiqu.com/9df479337d8185755c79c70b341bcc1e.html