By Radu Motisan Posted on July 27th, 2012 , 4468 Views (Rate 15.09)
For an application developer it is important to have total freedom in shaping the result of his work.
Even if Android OS has been designed without the mouse cursor in mind, there are plenty of situations where a developer needs a cursor on top of other applications installed.
We can draw the cursor at the framebuffer level, and while this provides optimum performance, it requires special privileges that regular apps don't have.
The second approach , and the subject of this article, is drawing a cursor using an Overlay.
What is an overlay?
The SDK defines them as: "Window type: system overlay windows, which need to be displayed on top of everything else. These windows must not take input focus, or they will interfere with the keyguard. "
So what we are about to do is have a small view created, make it show a cursor image, and move it around.
Hope this code proves useful. Looking forward to your comments, questions and feedback,
Customizing the system's pointer
It is possible to detect the system mouse coordinates and draw a custom overlay on top of the system mouse cursor. This way we can increase the pointer image size, a very useful enhancement for those that have problems seeing the tiny default cursor. Here is a demo showing a bluetooth mouse cursor and our bigger custom mouse cursor overlay.