Stylus buttons

35 views
Skip to first unread message

Urban Soban

unread,
Jul 6, 2012, 3:13:52 PM7/6/12
to quill...@googlegroups.com
First of all, I have to say this, Quill is an outstanding application!

I've got a question, what are stylus buttons intended for? I own HTC Flyer, and the second pen button was used as eraser tool. However, in Quill, none of them worked. I fixed it myself, but OpenSense SDK had to be used, since Android API < 14 (and Flyer's max is 13 :) does not provide a method for reading stylus button state. Now I need an idea what to do with the first button, I'll be glad if you could suggest something :)

Also, where may I send the improvements, if desired, of couse?

Volker Braun

unread,
Jul 6, 2012, 4:38:40 PM7/6/12
to quill...@googlegroups.com
Thanks for looking at the Flyer, since I don't have one it has always been difficult to support it correctly.

Did you have a look at PenEventICS.java? This is apparently what the HTC sense sdk does internally. Google integrated their bitfields later into ICS, but one should be able to manually define the constants. What does MotionEvent.getSource() report when you press the button?

If possible I'd like to avoid adding vendor-dependent libraries as it is going to be troublesome to support different vendors.

Best wishes,
Volker

usoban

unread,
Jul 12, 2012, 2:23:16 PM7/12/12
to quill...@googlegroups.com
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]

Volker Braun

unread,
Jul 12, 2012, 9:56:25 PM7/12/12
to quill...@googlegroups.com
Hi Urban,

Thank you, I didn't know about the meta state. I've added the method
that you described to the repository, can you give it a try? The
relevant changes set is

http://code.google.com/p/android-quill/source/detail?r=a228e355470a63f1cf160689960a0275e8a25a2b

Can you try it out if it works for you?

I don't have anything linked to the 2nd pen button. Do you have a
suggestion? I don't have any hardware with 2 buttons...

And yes, the isPenEvent needs to be checked in isPenButtonPressed in this case.

Best,
Volker

usoban

unread,
Jul 13, 2012, 11:25:01 AM7/13/12
to quill...@googlegroups.com
Yes, I can confirm it works. However I'd switch the button functionality, as button number one (META_ALT_ON) had highlighting functionality with default notes app, and the second one (META_SHIFT_ON) was eraser :)

The remaining button could be the highlight button, if we had pdf annotation option one day. Or maybe it could switch between pen and fountain pen.


On Friday, July 13, 2012 3:56:25 AM UTC+2, Volker Braun wrote:
Hi Urban,

Thank you, I didn't know about the meta state. I've added the method
that you described to the repository, can you give it a try? The
relevant changes set is

http://code.google.com/p/android-quill/source/detail?r=a228e355470a63f1cf160689960a0275e8a25a2b

Can you try it out if it works for you?

I don't have anything linked to the 2nd pen button. Do you have a
suggestion? I don't have any hardware with 2 buttons...

And yes, the isPenEvent needs to be checked in isPenButtonPressed in this case.

Best,
Volker


usoban

unread,
Jul 13, 2012, 11:27:58 AM7/13/12
to quill...@googlegroups.com
Duh, I mixed it up. META_ALT_ON should be the eraser, and META_SHIFT_ON the currently undefined one.

Volker Braun

unread,
Jul 13, 2012, 2:13:52 PM7/13/12
to quill...@googlegroups.com
Great! I switched the buttons around, should work now!

Best,
Volker
Reply all
Reply to author
Forward
0 new messages