Sure, I understand the inconvenience with using vendor specific libraries. Besides, OpenSense is ~100KB in size, which is a bit of an overkill for just fixing a small feature :)
MotionEvent.getSource() returns 0x00004002, which is SOURCE_STYLUS as of API 14 (and a constant in PenEventICS), however the stylus buttons do not affect its value.
I did have more success using MotionEvent.getMetaState(), which returns 0x00000000 when no button pressed, 0x00000001 when pen button 1 pressed and 0x00000002 when button 2 pressed. Of course, this is only valid if event source is stylus, since given values are otherwise defined as constants META_SHIFT_ON (0x01) and META_ALT_ON (0x02) of MotionEvent/KeyEvent.
Now this implies [correct me if I'm wrong] that within isPenButtonPressed(..) method, only checking for meta value is not enough, isPenEvent(..) has to be true too, since name.vbraun.view.write.HandwriterView.onTouchEvent(MotionEvent) does not check isPenEvent(MotionEvent) prior to checking isPenButtonPressed(MotionEvent), and that could mean something else changed the meta value. As I said, I'm not sure if I'm right as I did not have time to look through the entire code base yet, so the described behaviour could be prevented somewhere else in the code :)
Also, I did not have a chance to test this with some other device but HTC Flyer. If the behaviour elsewhere could be problematic with using MotionEvent.getMetaState() to get the state of pen buttons, I'd suggest moving the logic for Flyer and other HTC devices that do not support API 14 or higher to a separate class.
Regards,
Urban Soban
Does Quill check isPenButtonPressed(MotionEvent) only if isPenEvent(MotionEvent) is true? If not, isPenEvent(..) also needs to be checked even though getMetaState() returns appropriate value. [may you point me to the source location where isPenEvent() is checked, as I did not have time to look around yet]