I
I
Ilfar2017-08-08 18:22:28
Multitouch and gestures
Ilfar, 2017-08-08 18:22:28

Why doesn't multitouch work?

On the screen are ImageView and SeekBar elements. you need to move both elements at the same time: change the value of the seekbar and move the imageView.
a4867204e4a340fab6954bc8c3c3f621.jpg
case MotionEvent.ACTION_MOVE does not work on this code:
(if the code is moved to case MotionEvent.ACTION_DOWN, then only one touch works.)

OnTouchListener onTch = new OnTouchListener()
        {
            @Override
            public boolean onTouch(View v, MotionEvent event)
            {   // индекс касания
                int pointerIndex = event.getActionIndex();
                ClipData clipData = ClipData.newPlainText("", "");
                View.DragShadowBuilder dsb = new View.DragShadowBuilder(imV);
                // событие
                int actionMask = event.getActionMasked();
     switch (actionMask) {
                    case MotionEvent.ACTION_DOWN: // первое касание
                        //inTouch = true;
                       break;
                    case MotionEvent.ACTION_POINTER_DOWN: // последующие касания       
                      break;
                    case MotionEvent.ACTION_UP: // прерывание последнего касания
                        //inTouch = false;
                        break;
                    case MotionEvent.ACTION_POINTER_UP: // прерывания касаний
                       // upPI = pointerIndex;
                        break;
                    case MotionEvent.ACTION_MOVE: // движение
                        Log.d(TAG, "intouch1="+inTouch);
                        if(v.getId()==R.id.imageView);
                        {
                            Log.d(TAG, "v.getId="+v.getId());
                            Log.d(TAG, "R.id.imageView="+R.id.imageView);

                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                                Log.d(LOG_TAG, "startDragAndDrop1");
                                v.startDragAndDrop(clipData, dsb, v, 0);
                                Log.d(LOG_TAG, "startDragAndDrop2");
                            } else {
                                Log.d(LOG_TAG, "startDragAndDrop3");
                                v.startDrag(clipData, dsb, v, 0);
                                Log.d(LOG_TAG, "startDragAndDrop4");
                            }
                            v.setVisibility(View.INVISIBLE);
                            Log.d(LOG_TAG, "1234");
                        }
                        break;
                }
                    return false;
            }
        };

seekbar:
@Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
    {
        String val_seekBar=String.valueOf(100+seekBar.getProgress());
        mTextView.setText(val_seekBar);
    }

If you change the imageView and seekBar elements to Button, then everything works fine - you can click on both buttons at the same time:
@Override
    public boolean onTouch(View v, MotionEvent event) {
        // событие
        int actionMask = event.getActionMasked();
        // индекс касания
        int pointerIndex = event.getActionIndex();
        // число касаний
        int pointerCount = event.getPointerCount();
        switch (actionMask) {
            case MotionEvent.ACTION_DOWN: // первое касание
                inTouch = true;
            case MotionEvent.ACTION_POINTER_DOWN: // последующие касания
                downPI = pointerIndex;
                break;
            case MotionEvent.ACTION_UP: // прерывание последнего касания
                inTouch = false;
                tx1.setText("0");
                tx2.setText("0");
                tx3.setText("0");
            case MotionEvent.ACTION_POINTER_UP: // прерывания касаний
                upPI = pointerIndex;
                break;
            case MotionEvent.ACTION_MOVE: // движение
                switch (v.getId()) {
                    case R.id.button:
                        tx1.setText("Нажата кнопка Button1");
                        break;
                    case R.id.button2:
                        tx2.setText("Нажата кнопка Button2");
                        break;
                }
                break;
        }
        return true;
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question