Path.op在Android中冻结GUI?

时间:2014-12-28 10:12:28

标签: android user-interface

在我的应用程序中,用户可以用手指在Canvas上绘图。在onTouch事件期间,我想调用Path.op来检查交叉点。

结果:GUI冻结,App不会对进一步的交互做出反应。没有错误或Logcat消息。

可能导致此问题的原因以及如何防止冻结GUI?

修改 我在onTouchEvent()中的源代码和使用过的方法:

 private void touch_move(float x, float y) {
    if (activeListener && !copy){
    broadcastData(pathToByteArray(x/getScreenWidth(),y/getScreenHeight(),(byte)'M'));
    }
    else if (activeListener && copy){
        path.add(new PaintPath(x,y));
    }
    float dx = Math.abs(x - mX);
    float dy = Math.abs(y - mY);
    if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
        //totalPath = mPath;
        totalPath = new Path(mPath);
         mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2);
         lastPath = new Path(mPath);
        mX = x;
        mY = y;
        circlePath.reset();
        circlePath.addCircle(mX, mY, 30, Path.Direction.CW);
        // This causes the error
        lastPath.op(totalPath,Path.Op.DIFFERENCE);
        if (lastPath.op(totalPath, Path.Op.INTERSECT)){
            Log.e("Intersection","Intersection");
        }    
        // End of the problem
    }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
    float x = event.getX();
    float y = event.getY();

    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            if (activeListener){
            touch_start(x, y);
            invalidate();
            }
            break;
        case MotionEvent.ACTION_MOVE:
            if (activeListener){
            touch_move(x, y);
            invalidate();
            }
            break;
            ...

0 个答案:

没有答案