onKeyUp method

985 views
Skip to first unread message

Marco Bernasocchi

unread,
Nov 30, 2011, 4:04:38 PM11/30/11
to andro...@googlegroups.com
Hi all,
today I wanted edit the onKeyUp method of my QtActivity, but a big
comment says "do not edit the following code". It looks like there is a
special way to define all those methods with delegates in QtApplication.
I'm not a Java crack and could not figure out how this system works.
anybody has an hit?
thanks
MArco
--
Marco Bernasocchi
www.opengis.ch

Levi Ribeiro

unread,
Dec 1, 2011, 8:26:59 AM12/1/11
to android-qt
Well, I've edited it in order to cancel the "KEYCODE_BACK", I modify
QtActivity.java, and add moveTaskToBack(true)
when the key pressed is the back button. This will keep your task
running
then the user won't have to log in again. Take a look:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ( (keyCode == KeyEvent.KEYCODE_BACK) )
{
moveTaskToBack(true);
//return true;
}
if (QtApplication.m_delegateObject != null &&
QtApplication.onKeyDown != null)
return (Boolean)
QtApplication.invokeDelegateMethod(QtApplication.onKeyDown, keyCode,
event);
else
return super.onKeyDown(keyCode, event);

}

You can also inhibit the back button at all, by using "return true"
instead
of moveTaskToBack and also adding the same filter for onKeyUp.

Credits for Juan, who helped me with this "hack" hehe =)

Koying

unread,
Dec 2, 2011, 7:42:47 AM12/2/11
to andro...@googlegroups.com
Another solution is to actually send the back button to the Qt application.
This is what I deed:


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        int newKeyCode = keyCode;

        if ( (keyCode == KeyEvent.KEYCODE_BACK) )
        {
           newKeyCode = KeyEvent.KEYCODE_MEDIA_PREVIOUS;

        }
        if (QtApplication.m_delegateObject != null && QtApplication.onKeyDown != null)
            return (Boolean) QtApplication.invokeDelegateMethod(QtApplication.onKeyDown, newKeyCode, event);
        else
            return super.onKeyDown(newKeyCode, event);
    }
    public boolean super_onKeyDown(int keyCode, KeyEvent event)
    {
        return super.onKeyDown(keyCode, event);
    }
    //---------------------------------------------------------------------------


    @Override
    public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)
    {
        int newKeyCode = keyCode;

        if ( (keyCode == KeyEvent.KEYCODE_BACK) )
        {
            newKeyCode = KeyEvent.KEYCODE_MEDIA_PREVIOUS;
        }
        if (QtApplication.m_delegateObject != null && QtApplication.onKeyMultiple != null)
            return (Boolean) QtApplication.invokeDelegateMethod(QtApplication.onKeyMultiple ,newKeyCode, repeatCount, event);
        else
            return super.onKeyMultiple(newKeyCode, repeatCount, event);
    }
    public boolean super_onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)
    {
        return super.onKeyMultiple(keyCode, repeatCount, event);
    }
    //---------------------------------------------------------------------------

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event)
    {
        int newKeyCode = keyCode;

        if ( (keyCode == KeyEvent.KEYCODE_BACK) )
        {
            newKeyCode = KeyEvent.KEYCODE_MEDIA_PREVIOUS;

        }
        if (QtApplication.m_delegateObject != null  && QtApplication.onKeyDown != null)
            return (Boolean) QtApplication.invokeDelegateMethod(QtApplication.onKeyUp, newKeyCode, event);
        else
            return super.onKeyUp(newKeyCode, event);
    }
    public boolean super_onKeyUp(int keyCode, KeyEvent event)
    {
        return super.onKeyUp(keyCode, event);
    }

As, AFAIK, there is no Qt equivalent for back, I send KeyEvent.KEYCODE_MEDIA_PREVIOUS instead, which translates into Qt::Key_MediaPrevious

- Chris -

Reply all
Reply to author
Forward
0 new messages