markers icon indicating copy to clipboard operation
markers copied to clipboard

Use reflection to detect stylus via com.htc.pen.PenEvent

Open chiuki opened this issue 11 years ago • 2 comments

chiuki avatar Jan 31 '14 19:01 chiuki

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 PenEvent class just once, statically (if this fails we can safely return false from isHTCPenEvent)
  • same with isPenEvent() — let's keep that method around
  • we can also cache the test for "HTC", another way to bail out of isHTCPenEvent quickly
  • it would probably be faster to first find out if the MotionEvent we get is an instanceof PenEvent, before attempting to call isPenEvent() on it

Does that all make sense?

dsandler avatar Feb 21 '14 05:02 dsandler

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.

chiuki avatar Mar 17 '14 18:03 chiuki