获取surfaceview上的单击位置并显示对话框

时间:2014-10-27 08:52:13

标签: android pdf surfaceview

我希望从surfaceview中点击x和y,并在同一活动中显示对话框。

点击监听器不适用于surfaceview。

我使用android pdfview库来显示pdf文档,它使用surfaceview查看PDF页面。

https://github.com/JoanZapata/android-pdfview

另外,当我尝试绘制表面视图的缓存时,它会返回黑色视图。

     final AlertDialog.Builder addSing = new AlertDialog.Builder(PDFViewActivity.this);

       addSing.setTitle("Do you want to add Signature here ?");
       addSing.setCancelable(false);

       addSing.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub


            }
       });

       addSing.setNegativeButton("No", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub

           }
       });


    PDFViewActivity.this.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub



               addSing.show();



        }
    });

1 个答案:

答案 0 :(得分:0)

Ist点击Surface View:

点击表面视图实现onTouchListener和GestureDetector:

@Override
    public boolean onTouch(View v, MotionEvent event) {

        mGestureDetector.onTouchEvent(event);

        switch (event.getAction() & MotionEvent.ACTION_MASK) {

        case MotionEvent.ACTION_DOWN:
            if (mInputListener != null)
                mInputListener.onTouchDown(new Vector2(event.getX(), event
                        .getY()));
            break;

        case MotionEvent.ACTION_MOVE:
            if (mInputListener != null)
                mInputListener.onTouchMove(new Vector2(event.getX(), event
                        .getY()));
            break;

        case MotionEvent.ACTION_UP:
            if (mInputListener != null)
                mInputListener
                        .onTouchUp(new Vector2(event.getX(), event.getY()));
            break;
        }

        return true;
    }

    private class GestureListener extends
            GestureDetector.SimpleOnGestureListener {

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (mInputListener != null)
                mInputListener.onDoubleTap(new Vector2(e.getX(), e.getY()));
            return super.onDoubleTap(e);
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (mInputListener != null)
                mInputListener.onSingleTapConfirmed(new Vector2(e.getX(), e
                        .getY()));
            return super.onSingleTapConfirmed(e);
        }

        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            if (mInputListener != null)
                mInputListener.onSingleTap(new Vector2(e.getX(), e.getY()));
            return super.onSingleTapUp(e);
        }

    }

有关详细信息,请参阅this

IInd SurfaceView绘图缓存:来自this answer

IIIrd显​​示对话框:我认为您的代码可以正常显示对话框。

  

很抱歉,从本质上讲,SurfaceView不会在普通视图中绘制   层次结构更新系统,因此不会被绘制出来。