Anand
Anand

Reputation: 7764

Stylus only input-mode on Android

How can I turn on the "pen-only" mode programatically on the Lenovo Thinkpad Tablet running ICS 4.0.3?

Upvotes: 0

Views: 2006

Answers (3)

Unbroken
Unbroken

Reputation: 1

I know this is old, but I found nothing else on this problem and I eventually come out with this solution: you need to extend your view and override onTouchEvent:

@Override
public boolean onTouchEvent(MotionEvent event) {
    // Disable multitouch
    if (event.getPointerCount() != 1)
        return false;

    // If not stylus return  
    MotionEvent.PointerProperties pp = new MotionEvent.PointerProperties();
    event.getPointerProperties(0, pp);
    if (pp.toolType != MotionEvent.TOOL_TYPE_STYLUS)
        return false;

    // Dispatch event to the original view 
    return super.onTouchEvent(event);
}

Upvotes: 0

Aaron Gillion
Aaron Gillion

Reputation: 2265

If you are developing an app, you can actually implement this. If your stylus can "hover" on your screen before it touches, you can add an OnHoverListener on the highest View in your activity to set a global variable isPen to true. Then override dispatchTouchEvent() in your activity and check the variable before passing on the event in your app.

rootView.setOnHoverListener(new View.OnHoverListener() {
    @Override
    public boolean onHover(View view,MotionEvent event) {
        isPen = true;
        return true;
    }
});

And

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    if(isPen) {
        return super.dispatchTouchEvent(event);
    } else {
        return true;
    }
}

Upvotes: 1

Teifu
Teifu

Reputation: 33

I'm very sorry that I can't answer your question, though I think WebnetMobile might be right - there doesn't seem to be an API method for pen-only mode. However if you go to this article http://knowledge.lapasa.net/?p=490 it states that you should focus on the diameter of the input device (the touch diameter of a finger is much greater than that of a pen stylus).

As for WebnetMobile saying it is pointless to use a tablet in pen-only mode, I'd say that it is a longed for feature of any artist or note taker to be able to rest your hand on the surface upon which you're drawing/writing.

Upvotes: 2

Related Questions