[ 
https://issues.apache.org/jira/browse/CB-7307?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Keith Wong updated CB-7307:
---------------------------

    Description: 
I have the same problem in with Cordova 3.5.0 on Android 4.4.2 emulator and 
Galaxy S3 4.1.2.  After investigation, the problem should be in the program 
CordovaWebView.java.

{code:title=CordovaWebView.java|borderStyle=solid}
    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event)
    {
        ...

        // Legacy
        else if (keyCode == KeyEvent.KEYCODE_MENU) {
            if (this.lastMenuEventTime < event.getEventTime()) {
                
this.loadUrl("javascript:cordova.fireDocumentEvent('menubutton');");
            }
            this.lastMenuEventTime = event.getEventTime();
            return super.onKeyUp(keyCode, event);  // <== Problem Line
        }
        // If search key
        else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
            
this.loadUrl("javascript:cordova.fireDocumentEvent('searchbutton');");
            return true;
        }
        ...
{code}

When it is changed as follows, it works fine.

{code:title=CordovaWebView.java|borderStyle=solid}
        // Legacy
        else if (keyCode == KeyEvent.KEYCODE_MENU) {
            if (this.lastMenuEventTime < event.getEventTime()) {
                
this.loadUrl("javascript:cordova.fireDocumentEvent('menubutton');");
            }
            this.lastMenuEventTime = event.getEventTime();
            return true;  // <== Changed as
        }
{code}

I think the problem is calling the super.onKeyUp() method and it throws a 
RuntimeException actually.  But at this point, the event is "handled", there is 
no reason to delegate the control to the parent class.  Referring to a similar 
case below for the search button, it just returns true when the javascript 
event handler is executed.

  was:
I want to implement a custom menu in my phonegap app. I have added an 
eventlistener for the menubutton event.
When I press the menubutton the first time, it opens the menu. When I press it 
again, I close the menu.
Every time after that that I want to open the menu, I have to press the 
menubutton twice (and to close, I have to press it also twice).

When I check logcat:
first press:  
W/InputMethodManagerService(  315): Window already focused, ignoring focus gain 
of: com.android.internal.view.IInputMethodClient$Stub$Proxy@421c95b8 
attribute=null

second press: 
D/DroidGap(19858): 
onMessage(onPrepareOptionsMenu,com.android.internal.view.menu.MenuBuilder@41db3150)
D/CordovaWebView(19858): >>> loadUrlNow()
D/CordovaLog(19858): MENUBUTTON PRESSED
D/CordovaLog(19858): file:///android_asset/www/app.js: Line 2393 : MENUBUTTON 
PRESSED
I/Web Console(19858): MENUBUTTON PRESSED at 
file:///android_asset/www/app.js:2393


> On Android 4.1 events are only sent on every second menu button press (Cloned)
> ------------------------------------------------------------------------------
>
>                 Key: CB-7307
>                 URL: https://issues.apache.org/jira/browse/CB-7307
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 3.5.0
>            Reporter: Keith Wong
>            Assignee: Joe Bowser
>            Priority: Minor
>
> I have the same problem in with Cordova 3.5.0 on Android 4.4.2 emulator and 
> Galaxy S3 4.1.2.  After investigation, the problem should be in the program 
> CordovaWebView.java.
> {code:title=CordovaWebView.java|borderStyle=solid}
>     @Override
>     public boolean onKeyUp(int keyCode, KeyEvent event)
>     {
>         ...
>         // Legacy
>         else if (keyCode == KeyEvent.KEYCODE_MENU) {
>             if (this.lastMenuEventTime < event.getEventTime()) {
>                 
> this.loadUrl("javascript:cordova.fireDocumentEvent('menubutton');");
>             }
>             this.lastMenuEventTime = event.getEventTime();
>             return super.onKeyUp(keyCode, event);  // <== Problem Line
>         }
>         // If search key
>         else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
>             
> this.loadUrl("javascript:cordova.fireDocumentEvent('searchbutton');");
>             return true;
>         }
>         ...
> {code}
> When it is changed as follows, it works fine.
> {code:title=CordovaWebView.java|borderStyle=solid}
>         // Legacy
>         else if (keyCode == KeyEvent.KEYCODE_MENU) {
>             if (this.lastMenuEventTime < event.getEventTime()) {
>                 
> this.loadUrl("javascript:cordova.fireDocumentEvent('menubutton');");
>             }
>             this.lastMenuEventTime = event.getEventTime();
>             return true;  // <== Changed as
>         }
> {code}
> I think the problem is calling the super.onKeyUp() method and it throws a 
> RuntimeException actually.  But at this point, the event is "handled", there 
> is no reason to delegate the control to the parent class.  Referring to a 
> similar case below for the search button, it just returns true when the 
> javascript event handler is executed.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to