捕获人行横道科尔多瓦webview触摸事件 [英] Capturing Crosswalk Cordova webview touch events

查看:175
本文介绍了捕获人行横道科尔多瓦webview触摸事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Crosswalk Cordova框架构建基于网络的Android应用,
我试图捕获发生在XWalk webview在我的应用程序的主要活动中的任何触摸事件,但到目前为止我试过我无法得到触发事件在调试会话期间触发。

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.

具体来说,我想捕获一个三指向下滑动到Web视图的任何位置,以便我可以显示一个设置窗格。

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... 
            }
        });
    }

    ....
}

我意识到我可能通过javascript事件抓住触摸事件,然后可以通过cordova api调用触发动作,但我更愿意在android应用程序中有这个逻辑。

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.

我还尝试在 onTouchEvent 方法中捕获触摸事件

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... 
}

此方法从未被触发。

任何帮助或想法都将非常感激。

Any help or ideas would be much appreciated.

推荐答案

我设法通过覆盖 Activity 类中定义的 dispatchTouchEvent 这是捕获触摸事件,并委托他们到我的cordova web视图,而不会触发我的 onTouchEvent

I managed to get this working by overriding the dispatchTouchEvent method defined in Activity class. This was capturing the touch event and delegating them to my cordova webview without ever firing my onTouchEvent.

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

    super.dispatchTouchEvent(ev);
}

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

I hope this may help someone facing this issue :)

这篇关于捕获人行横道科尔多瓦webview触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆