[ 
https://issues.apache.org/jira/browse/CB-8921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14993512#comment-14993512
 ] 

Sven Casimir commented on CB-8921:
----------------------------------

Tried several patches, the common suggestion to disable the boundKeyCodes check 
didn't do it for me, because then the backbutton behaviour would be compromised.
So I dug deeper into the code and found a way to make the menubutton work 
again. 
The boundKeyCodes check ensures, that custom behaviour is only executed when 
there actually is a custom event handler. But binding an event handler to 
"menubutton" in your app's JS code no longer triggers the menubutton key code 
to be added to the boundKeyCodes list. You can get that behaviour back by doing 
the following changes:

in platform_www/cordova.js in the bootstrap function (around line 1532) change 
this line:
{code}
cordova.addDocumentEventHandler('menubutton');
{code}
to this:
{code}
var menuButtonChannel = cordova.addDocumentEventHandler('menubutton');
menuButtonChannel.onHasSubscribersChange = function() {
  exec(null, null, APP_PLUGIN_NAME, "overrideButton", ['menubutton', 
this.numHandlers == 1]);
};
{code}

This will trigger the frameworks overrideButton method as soon as an event 
handler is added to "menubutton".
Then change the overrideButton method in 
CordovaLib/src/org/apache/cordova/CoreAndroid.java line 243 make the method 
look like this (add the last else-if clause):
{code}
    public void overrideButton(String button, boolean override) {
        LOG.i("App", "WARNING: Volume Button Default Behavior will be 
overridden.  The volume event will be fired!");
        if (button.equals("volumeup")) {
            webView.setButtonPlumbedToJs(KeyEvent.KEYCODE_VOLUME_UP, override);
        }
        else if (button.equals("volumedown")) {
            webView.setButtonPlumbedToJs(KeyEvent.KEYCODE_VOLUME_DOWN, 
override);
        }
        else if (button.equals("menubutton")) {
            webView.setButtonPlumbedToJs(KeyEvent.KEYCODE_MENU, override);
        }
    }
{code}

Finally in CordovaLib/src/org/apache/cordova/CoreAndroid.java line 357 
(setButtonPlumbedToJs) add a case statement after the KEYCODE_MENU entry like 
this:
{code}
public void setButtonPlumbedToJs(int keyCode, boolean override) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_VOLUME_DOWN:
            case KeyEvent.KEYCODE_VOLUME_UP:
            case KeyEvent.KEYCODE_BACK:
            case KeyEvent.KEYCODE_MENU:
                // TODO: Why are search and menu buttons handled separately?
                if (override) {
                    boundKeyCodes.add(keyCode);
                } else {
                    boundKeyCodes.remove(keyCode);
                }
                return;
            default:
                throw new IllegalArgumentException("Unsupported keycode: " + 
keyCode);
        }
    }
{code}

That should do it. At the moment I don't exactly know to which repository I 
should contribute, if anyone could give me a little hint to the appropriate 
github repo, I will file a pull request for this.

> menubutton event not firing
> ---------------------------
>
>                 Key: CB-8921
>                 URL: https://issues.apache.org/jira/browse/CB-8921
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android
>         Environment: Android Emulator, SDK 19
>            Reporter: Jean-Luc Desroches
>            Assignee: Joe Bowser
>            Priority: Minor
>
> After updating to latest version of cordova (5.0) menubutton event is never 
> triggered. Have tested in hello world app, as well as in my  own app, neither 
> of which register any menubutton events



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to