这个GestureListenerImpl对象负责检测参数event描写叙述的Touch事件是否产生滑动手势操作。这是通过调用它的成员函数OnTouchEvent实现的。
GestureProvider类的成员变量scale_gesture_listener_指向的是一个ScaleGestureListenerImpl对象。
这个ScaleGestureListenerImpl对象负责检测参数event描写叙述的Touch事件是否产生捏合手势操作。
这是通过调用它的成员函数OnTouchEvent实现的。
接下来,我们就分别分析GestureListenerImpl类和ScaleGestureListenerImpl类的成员函数OnTouchEvent的实现,以便了解滑动和捏合手势操作的检测过程。
GestureListenerImpl类的成员函数OnTouchEvent的实现例如以下所看到的:
class GestureProvider::GestureListenerImpl
: public GestureDetector::GestureListener,
public GestureDetector::DoubleTapListener {
public:
......
bool OnTouchEvent(const MotionEvent& e,
bool is_scale_gesture_detection_in_progress) {
......
return gesture_detector_.OnTouchEvent(e);
}
private:
......
GestureDetector gesture_detector_;
......
}; 这个函数定义在文件external/chromium_org/ui/events/gesture_detection/gesture_provider.cc中。
GestureListenerImpl类的成员函数OnTouchEvent通过调用成员变量gesture_detector_描写叙述的一个GestureDetector对象的成员函数OnTouchEvent检测测参数e描写叙述的Touch事件是否产生了滑动手势操作。
GestureDetector类的成员函数OnTouchEvent的实现例如以下所看到的:

bool GestureDetector::OnTouchEvent(const MotionEvent& ev) {
const MotionEvent::Action action = ev.GetAction();
......
const bool pointer_up = action == MotionEvent::ACTION_POINTER_UP;
const int skip_index = pointer_up ? ev.GetActionIndex() : -1;
// Determine focal point.
float sum_x = 0, sum_y = 0;
const int count = static_cast<int>(ev.GetPointerCount());
for (int i = 0; i < count; i++) {
if (skip_index == i)
continue;
sum_x += ev.GetX(i);
sum_y += ev.GetY(i);
}
const int div = pointer_up ? count - 1 : count;
const float focus_x = sum_x / div;
const float focus_y = sum_y / div;
bool handled = false;
switch (action) {
......
case MotionEvent::ACTION_MOVE:
{
const float scroll_x = last_focus_x_ - focus_x;
const float scroll_y = last_focus_y_ - focus_y;
if (is_double_tapping_) {
// Give the move events of the double-tap.
DCHECK(double_tap_listener_);
handled |= double_tap_listener_->OnDoubleTapEvent(ev);
} else if (always_in_tap_region_) {
const float delta_x = focus_x - down_focus_x_;
const float delta_y = focus_y - down_focus_y_;
const float distance_square = delta_x * delta_x + delta_y * delta_y;
if (distance_square > touch_slop_square_) {
handled = listener_->OnScroll(
*current_down_event_, ev, scroll_x, scroll_y);
last_focus_x_ = focus_x;
last_focus_y_ = focus_y;
always_in_tap_region_ = false;
......
}
......
} else if (std::abs(scroll_x) > kScrollEpsilon ||
std::abs(scroll_y) > kScrollEpsilon) {
handled =
listener_->OnScroll(*current_down_event_, ev, scroll_x, scroll_y);
last_focus_x_ = focus_x;
last_focus_y_ = focus_y;
}
......
break;
......
}
return handled;
}
这个函数定义在文件external/chromium_org/ui/events/gesture_detection/gesture_detector.cc中。
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-81019-9.html
巴菲特呢