MCPcopy Create free account
hub / github.com/android/ndk-samples / CookEvent_Motion

Function CookEvent_Motion

endless-tunnel/app/src/main/cpp/input_util.cpp:204–259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

202}
203
204static bool CookEvent_Motion(AInputEvent* event, CookedEventCallback callback) {
205 int src = AInputEvent_getSource(event);
206 int action = AMotionEvent_getAction(event);
207 int actionMasked = action & AMOTION_EVENT_ACTION_MASK;
208 int ptrIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >>
209 AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
210
211 struct CookedEvent ev;
212 memset(&ev, 0, sizeof(ev));
213
214 if (actionMasked == AMOTION_EVENT_ACTION_DOWN ||
215 actionMasked == AMOTION_EVENT_ACTION_POINTER_DOWN) {
216 ev.type = COOKED_EVENT_TYPE_POINTER_DOWN;
217 } else if (actionMasked == AMOTION_EVENT_ACTION_UP ||
218 actionMasked == AMOTION_EVENT_ACTION_POINTER_UP) {
219 ev.type = COOKED_EVENT_TYPE_POINTER_UP;
220 } else {
221 ev.type = COOKED_EVENT_TYPE_POINTER_MOVE;
222 }
223
224 ev.motionPointerId = AMotionEvent_getPointerId(event, ptrIndex);
225 ev.motionIsOnScreen = (src & AINPUT_SOURCE_TOUCHSCREEN) != 0;
226 ev.motionX = AMotionEvent_getX(event, ptrIndex);
227 ev.motionY = AMotionEvent_getY(event, ptrIndex);
228
229 if (ev.motionIsOnScreen) {
230 // use screen size as the motion range
231 ev.motionMinX = 0.0f;
232 ev.motionMaxX = SceneManager::GetInstance()->GetScreenWidth();
233 ev.motionMinY = 0.0f;
234 ev.motionMaxY = SceneManager::GetInstance()->GetScreenHeight();
235 } else {
236 // look up motion range for this device
237 _look_up_motion_range((int)AInputEvent_getDeviceId(event),
238 (int)AInputEvent_getSource(event), &ev.motionMinX,
239 &ev.motionMaxX, &ev.motionMinY, &ev.motionMaxY);
240 }
241
242 // deliver event
243 callback(&ev);
244
245 // deliver motion info about other pointers (for multi-touch)
246 int ptrCount = AMotionEvent_getPointerCount(event);
247 for (int i = 0; i < ptrCount; i++) {
248 ev.type = COOKED_EVENT_TYPE_POINTER_MOVE;
249 ev.motionX = AMotionEvent_getX(event, i);
250 ev.motionY = AMotionEvent_getY(event, i);
251 ev.motionPointerId = AMotionEvent_getPointerId(event, i);
252 callback(&ev);
253 }
254
255 // If this is a touch-nav event, return false to indicate that we haven't
256 // handled it. This will trigger translation of swipes to DPAD keys, which is
257 // what we want. Otherwise, we say that we've handled it.
258 return (src != SOURCE_TOUCH_NAVIGATION);
259}
260
261bool CookEvent(AInputEvent* event, CookedEventCallback callback) {

Callers 1

CookEventFunction · 0.85

Calls 3

_look_up_motion_rangeFunction · 0.85
GetScreenWidthMethod · 0.45
GetScreenHeightMethod · 0.45

Tested by

no test coverage detected