'MotionEventCompat functions are deprecated
I am trying to add an onTouchEvent to a View, but I then see the deprecation support on this link: https://developer.android.com/sdk/support_api_diff/26.0.0-alpha1/changes/android.support.v4.view.MotionEventCompat.html.
It says, they are all deprecated. So what code should be used to replace the MotionEventCompat functions?
Solution 1:[1]
I know it is an old question but, I had to refactor some code and, I had to update these deprecated functions. It is easy to refactorize it, just do this:
- If you use constants like
MotionEventCompat.ACTION_MASK, then replace them forMotionEvent.ACTION_MASK - Every time you have something like
MotionEventCompat.getPointerId(ev, index);do this instead:ev.getPointerId(index);
And that is all! I will list a few more examples to be clearer:
- Replace
MotionEventCompat.ACTION_POINTER_DOWNbyMotionEvent.ACTION_POINTER_DOWN - Replace
MotionEventCompat.ACTION_POINTER_UPbyMotionEvent.ACTION_POINTER_UP - Replace
MotionEventCompat.getX(ev, pointerIndex);byev.getX(pointerIndex); - Replace
MotionEventCompat.getY(ev, pointerIndex);byev.getY(pointerIndex); - Replace
MotionEventCompat.getActionIndex(ev);byev.getActionIndex();
Also (not directly related to this question) I had to replace VelocityTrackerCompat.getXVelocity(velocityTracker, mActivePointerId); by velocityTracker.getXVelocity(mActivePointerId);
I hope this can help someone else in the future :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Daniel S. |

