private final class CheckForTap implements Runnable { public void run() { // 进入该函数,说明已经过了ViewConfiguration.getTapTimeout()时间, // 即pre-pressed状态结束,宣告触摸进入pressed状态 mPrivateFlags &= ~PREPRESSED; mPrivateFlags |= PRESSED; refreshDrawableState(); // 刷新控件的背景Drawable // 如果长按检测没有被去使能,则发送一个检测长按事件的异步延迟消息 if ((mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) { postCheckForLongClick(ViewConfiguration.getTapTimeout()); } } } private void postCheckForLongClick(int delayOffset) { mHasPerformedLongPress = false; // 实例化CheckForLongPress对象 if (mPendingCheckForLongPress == null) { mPendingCheckForLongPress = new CheckForLongPress(); } mPendingCheckForLongPress.rememberWindowAttachCount(); // 调用PostDelayed函数发送长按事件的异步延迟消息 postDelayed(mPendingCheckForLongPress, ViewConfiguration.getLongPressTimeout() - delayOffset); }
3)CheckForLongPress类
该类定义了长按操作发生时的响应处理,同样实现了Runnable接口