dsandler / markers

Sample app demonstrating use of Android touch APIs for pressure-sensitive drawing.
Apache License 2.0
242 stars 69 forks source link

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

Open chiuki opened 10 years ago

dsandler commented 10 years ago

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:

Does that all make sense?

chiuki commented 10 years ago

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.