Search code examples
javaandroidxbmctouchpadkodi

kodi remote application touchpad


I made a Kodi(android version) remote app(for android users) and I want to implement a touchpad control in it. I don't really know how to do that,so I need an advice on how to start and some steps that I need to follow, from someone more advanced or someone who had already did something like that. If someone need more details I will give them with pleasure.


Solution

  • I made it by myself and I want to show how I done it.

    First I made an ImageView:

     <ImageView
        android:src="@drawable/white_with_frame"
        android:orientation="vertical"
        android:layout_gravity="center_vertical"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:id="@+id/touchPad" />
    

    Then I made the functionality

    imageViewPad.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent event) {
    
                // deactivate the moving of the parent element when the touchpad is touch
                imageViewPad.getParent().requestDisallowInterceptTouchEvent(true);
    
                switch (event.getAction())
                {
                    case MotionEvent.ACTION_DOWN:
                    {
                        touchpadOnActionDown(event);
                        break;
                    }
    
                    case MotionEvent.ACTION_MOVE:
                    {
                        touchpadOnActionMove(event);
                        break;
                    }
    
                    case MotionEvent.ACTION_UP:
                    {
                        touchpadOnActionUp(event);
                        break;
                    }
    
                    default:
                        break;
                }
                return true;
            }
        });
    

    I have also the method private void touchpadOnActionMove(MotionEvent event) where I determinate the direction and when I know it I call a specific function from Kodi.