I had a wonderful discussion with a Miss Whitney Garrett about a killer feature that is conspicuously absent from Amazon’s Kindle software — stylus support. She mentioned how great it would be to be able to highlight text with a pen — just like she does in her physical books. I agreed.
In the current version of the Kindle app (18.104.22.168), styli are treated identically to finger input. Until Android 4.0, styli weren’t first class input devices so this was perfectly reasonable. But with the latest SDK, implementing basic stylus support is trivial. How can I say this? Well, I added it.
With my modifications, the Kindle for Android app supports using the stylus as a highlighter. OnTouchDown, the pen instantly starts selecting and OnTouchUp, it transparently adds the highlight. If you select already highlighted text, it removes the highlight. Finger events all function normally.
Unfortunately I can’t post any of the source code (as I disassembled and modified a closed source app), but I can give you a little insight into my implementation.
If the above were implemented in Java it would have taken under 10 lines of code and there would have been exactly 4 code insertion points.
Disassembling and reverse engineering is extraordinarily fun – I realize now that this is what I like about front end web development. You can’t beat looking at other people’s source code (and the code’s side effects) and figuring them out without documentation.
Smali bytecode is quite readable if you have any assembly experience. It’s just a really high-level version of assembly with support for things like Objects and virtual method invocation.
Flexibility is extremely important when it comes to reverse engineering. I attempted to add my functionality a few different ways before coming to my elegant, simple solution. If your first way of solving the problem seems to be too challenging, scrap it and attack the problem from a different angle.
I have two hopes: