0

The app is following. I have a line at the screen. I touch the screen and move finger. At the moment when my finger touches this line - I want to show a message.

The code:

        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction() ;
                case MotionEvent.ACTION_DOWN: 
                    break;
                case MotionEvent.ACTION_MOVE:
                    boolean isline = check_line(event.getX(),event.getY());
                    if(isline){
                        //SHOW MESSAGE
                    }
                    break;
                case MotionEvent.ACTION_UP:   
                    break;
                }
            return true;
        }

But the app sometimes can't catch the moment when when the finger is on the line. If I move slowly - then the message always appears. But if I move a bit faster - no messages.

The equation of the line is A*x + B*y + C = 0

check_line is a mathematical function, which just places my x and y in this equation. So when the equation is satisfied it returnes true, otherwise - false.

But I want all the cases to be catched.

What to do?

146 percent Russian
  • 2,016
  • 2
  • 14
  • 20
  • Thanks for a line equation:) instead of checking if touching point is close to line, you should check if line segments produced by sequential points, cross your line. – Alex Salauyou Mar 27 '14 at 12:56
  • here are calculations you need: http://stackoverflow.com/a/16314158/3459206 – Alex Salauyou Mar 27 '14 at 13:17
  • You should not use equation but inequality, because it is not likely during the move that touch event will be triggered on the line. It can appear before the line and after. – Tzoiker Mar 27 '14 at 14:37

0 Answers0