Use reflection to detect stylus via com.htc.pen.PenEvent
I was looking over this patch again and it occurred to me that I'd really rather not do Java reflection on every MotionEvent—that can be pretty expensive.
Things I'd want this patch to do:
- attempt to load the
PenEventclass just once, statically (if this fails we can safely return false fromisHTCPenEvent) - same with
isPenEvent()— let's keep that method around - we can also cache the test for "HTC", another way to bail out of
isHTCPenEventquickly - it would probably be faster to first find out if the
MotionEventwe get is an instanceofPenEvent, before attempting to callisPenEvent()on it
Does that all make sense?
Moved the HTC check, the Android version check, the class reflection and the method reflection to static block.
I cannot check if the MotionEvent is an instance of PenEvent though, since we are not compiling with the HTC library.
With this isHTCPenEvent() only does one reflection per MotionEvent (to invoke the cached method on the cached class), and only when we are running on an HTC device running HONEYCOMB_MR1 or HONEYCOMB_MR2.