3

I'm building a web based Android app using the Crosswalk Cordova framework, and I'm trying to capture any touch events that occur on the XWalk webview within the main activity of my app, but so far everything I've tried I can't get the touch events to be triggered during debugging sessions.

Specifically I'm trying to capture a three finger swipe down anywhere on the web view so I can display a settings pane.

Here is what I've got so far in my main activity:

public class MyActivity extends CordovaActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.init();
        super.loadUrl(Config.getStartUrl());

        // appView is the main xwalk webview setup in parent
        appView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int action = event.getAction();
                // Check for three finger swipe... 
            }
        });
    }

    ....
}

I realise I could probably catch the touch event through javascript events that could then trigger the action through a cordova api call, but I'd much rather have this logic within the android app.

I've also tried capturing touch events in onTouchEvent method

public boolean onTouchEvent(View view, MotionEvent event) {
    int action = event.getAction();
    // Check for three finger swipe... 
}

But again this method is never triggered.

Any help or ideas would be much appreciated.

4

1 回答 1

3

我设法通过覆盖类中dispatchTouchEvent定义的方法来完成这项工作Activity。这是捕获触摸事件并将它们委托给我的cordova webview,而无需触发我的onTouchEvent.

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    int action = ev.getAction();
    // handle three finger swipe

    super.dispatchTouchEvent(ev);
}

我希望这可以帮助面临这个问题的人:)

于 2015-02-09T00:01:24.303 回答