Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

chiuki
Copy link

@chiuki chiuki commented Jan 31, 2014

No description provided.

@dsandler
Copy link
Owner

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?

@chiuki
Copy link
Author

chiuki commented Mar 17, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants