MotionEvent 多个触摸事件混合在一起并相互影响(请参阅演示视频)

发布于 2024-09-24 21:15:34 字数 1911 浏览 1 评论 0原文

应用程序的用途:

一个简单的应用程序,为屏幕上识别的每次触摸绘制一个圆圈并跟踪触摸事件。在“高压读数”getPressure (int pointIndex) 上,圆圈的颜色将发生变化,半径将增加。此外,手指触摸旁边还会显示带有 getPointerId (int pointIndex) 的触摸 ID、x 和 y 坐标以及压力。

下面是重要部分的代码片段(请原谅这不是最好的代码;)我知道)

protected void onDraw(Canvas canvas){

    //draw circle only when finger(s) is on screen and moves 
    if(iTouchAction == (MotionEvent.ACTION_MOVE)){
        int x,y;
        float pressure;

        //Draw circle for every touch
        for (int i = 0; i < touchEvent.getPointerCount(); i++){
            x = (int)touchEvent.getX(i);
            y = (int)touchEvent.getY(i);
            pressure = touchEvent.getPressure(i);

            //High pressure
            if (pressure > 0.25){
                canvas.drawCircle(x, y, z+30, pressureColor);
                canvas.drawText(""+touchEvent.getPointerId(i)+"  | "+x+"/"+y, x+90, y-80, touchColor);
                canvas.drawText(""+pressure, x+90, y-55, pressureColor);
            }else{ //normal touch event 
                canvas.drawCircle(x, y, z, touchColor);
                canvas.drawText(""+touchEvent.getPointerId(i)+" | "+x+"/"+y, x+60, y-50, touchColor);
                canvas.drawText(""+pressure, x+60, y-25, pressureColor);
            }
        }           
    }
}

问题:

运行 Android 2.1 的 HTC Desire 是测试平台。该应用程序运行良好,可以毫无问题地跟踪两根手指。但当两个接触点靠得太近时,它们似乎会相互干扰——看起来它们绕着共享的 x 轴和 y 轴“对齐”。有时他们甚至交换其他触摸事件的输入坐标。另一个问题是,即使 getPressure (int pointIndex) 引用 PointerID,两个触摸事件也具有相同的压力读数。

由于这有点抽象,请在此处查找视频:http://www.youtube.com/ watch?v=bFxjFexrclU

我的问题:

  1. 我的代码只是错误的吗?
  2. Android 2.1 是否不能很好地处理触摸事件,导致事情变得混乱?
  3. 这是硬件问题吗,与 1) 和 2) 无关?

感谢您的回答和/或重新链接到其他线程(抱歉可以找到解决此问题的线程)。

克里斯

Purpose of the app:

A simple app that draws a circle for every touch recognised on the screen and follows the touch events. On a 'high pressure reading' getPressure (int pointerIndex) the colour of the circle will change and the radius will increase. Additionally the touch ID with getPointerId (int pointerIndex), x- and y-coordinates and pressure are shown next to the finger touch.

Following a code snipplet of the important part (please forgive me it is not the nicest code ;) I know)

protected void onDraw(Canvas canvas){

    //draw circle only when finger(s) is on screen and moves 
    if(iTouchAction == (MotionEvent.ACTION_MOVE)){
        int x,y;
        float pressure;

        //Draw circle for every touch
        for (int i = 0; i < touchEvent.getPointerCount(); i++){
            x = (int)touchEvent.getX(i);
            y = (int)touchEvent.getY(i);
            pressure = touchEvent.getPressure(i);

            //High pressure
            if (pressure > 0.25){
                canvas.drawCircle(x, y, z+30, pressureColor);
                canvas.drawText(""+touchEvent.getPointerId(i)+"  | "+x+"/"+y, x+90, y-80, touchColor);
                canvas.drawText(""+pressure, x+90, y-55, pressureColor);
            }else{ //normal touch event 
                canvas.drawCircle(x, y, z, touchColor);
                canvas.drawText(""+touchEvent.getPointerId(i)+" | "+x+"/"+y, x+60, y-50, touchColor);
                canvas.drawText(""+pressure, x+60, y-25, pressureColor);
            }
        }           
    }
}

The problem:

A HTC Desire running Android 2.1 is the test platform. The app works fine and tracks two finger without a problem. But it seems that the two touch points interfere with each other when they get t0o close -- it looks like they circles 'snap'to a shared x and y axle. Sometimes they even swap the input coordinates of the other touch event. Another problem is that even though getPressure (int pointerIndex) refers to an PointerID both touch event have the same pressure reading.

As this is all a bit abstract, find a video here: http://www.youtube.com/watch?v=bFxjFexrclU

My question:

  1. Is my code just simply wrong?
  2. Does Android 2.1 not handle the touch events well enough get things mixed up?
  3. Is this a hardware problem and has nothing to do with 1) and 2)?

Thank you for answers and/or relinks to other thread (sorry could find one that address this problem).

Chris

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南薇 2024-10-01 21:15:34

我不想告诉你这一点,但这是你的硬件。

Nexus One 中使用的触摸面板(我相信与 HTC Desire 中使用的硬件相同)因这种特殊的工件而闻名。我们做了一些工作,通过删除一些可检测到的不良事件来缓解 Android 2.2 的 ACTION_POINTER_UP/DOWN 事件周围的“跳到其他手指的轴”问题,但当指针沿着一个轴靠近时,问题仍然存在。该面板还以随机反转 X 和 Y 坐标数据而闻名;两个点 (x0, y0) 和 (x1, y1) 变为 (x0, y1) 和 (x1, y0)。遗憾的是,当 Android 本身获取“真实”数据时,您能做的就只有这么多了。

这并不是唯一一个具有危险多点触控功能的面板。要在运行时判断您的屏幕是否能够进行精确的多点触控数据报告而不会出现此类问题,请使用 PackageManager 检查 FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT。如果您没有此功能,您仍然可以执行简单的操作,例如可靠地缩放手势。

I hate to tell you this, but it's your hardware.

The touch panel used in the Nexus One (which I believe is the same hardware used in the HTC Desire) is known for this particular artifact. We did some work to alleviate the "jumps to other finger's axis" problem around the ACTION_POINTER_UP/DOWN events for Android 2.2 by dropping some detectable bad events, but the problem still persists when the pointers get close along one axis. This panel is also known for randomly reversing X and Y coordinate data; two points (x0, y0) and (x1, y1) become (x0, y1) and (x1, y0). Sadly there's only so much you can do when the "real" data is gone by the time Android itself gets hold of it.

This isn't the only panel in the wild that has dodgy multitouch capabilities. To tell at runtime if you have a screen capable of precise multitouch data reporting without issues like this, use PackageManager to check for FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT. If you don't have this feature available you can still do simple things like scale gestures reliably.

情域 2024-10-01 21:15:34

有人在旧版本上尝试过针对多点触控手势的此修复以前是机器人吗?我计划针对我自己的项目评估它,因为它也处理 android 1。 x/2.x 有缺陷的多点触控。

Luke 似乎已经涵盖了此处描述的问题以及 3.x 之前的设备上的其他常见触摸输入问题。

希望它有帮助,干杯。

Anyone tried this fix for multitouch gestures on older androids before? I am planning to evaluate it for my own project, as it also deals with android 1.x/2.x buggy multitouch.

Luke seems to have covered the problem described here as well as other common touch input problems on pre-3.x devices.

Hope it helps, Cheers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文