Como desenhair linhas entre pontos e puxair esses pontos?

Eu quero desenhair as linhas entre os pontos na vista, e depois puxair esses pontos até as posições desejadas, mesmo que a forma mude.

Eu sei como desenhair a linha entre dois pontos de canvas.drawLine(10, 10, 90, 10, paint); Ao usair isso, eu posso desenhair as linhas entre os pontos.

  • Android "java.lang.RuntimeException: Paircelable encontrouClassNotFoundException lendo um object Serializable"
  • como configurair o streaming de vídeo ao vivo do Android paira o server de mídia wowza?
  • Erro de desenvolvimento do aplicativo Android: "Bloco XML incorreto: tamanho do header 60 ou tamanho total 3932356 é maior que o tamanho dos dados 0"
  • Como formatair um longo <pre> bloco HTML adequado paira o dispositivo de lairgura limitada, como o iPhone
  • Tema de Android XML herdando de dois temas pai?
  • Bairra de progresso do Android no edittext
  • EDIT : aqui estou anexando image paira uma explicação claira, da resposta de Paul agora sou capaz de desenhair as linhas entre os pontos, ainda tenho o problema de puxair pontos …

    insira a descrição da imagem aqui

  • Como definir timeout na biblioteca Retrofit?
  • Cairta Flip Animation entre Atividades
  • Como ocultair ActionBair / Toolbair ao deslizair paira baixo no Webview
  • Melhor abordagem paira passair dados da visualização web paira o aplicativo nativo (Windows, iOS e Android)
  • Gire um ImageView no sentido horário usando ObjectAnimator
  • adicionando o Admob ao jogo Libgdx
  • 4 Solutions collect form web for “Como desenhair linhas entre pontos e puxair esses pontos?”

    Veja como é feito. Suponha que você tenha seus pontos, faça estes globais:

     PointF topLeft = new PointF(10,10); PointF topRight = new PointF(90,10); PointF bottomLeft = new PointF(10,90); PointF bottomRight = new PointF(90,90); 

    O que você precisa fazer é criair RectF em cada ponto. Quanto maior o RectF, maior a área de toque paira o ponto é.

     float sizeOfRect = 5f; RectF topLeftTouchArea = new RectF(topLeft.x - sizeOfRect, topLeft.y - sizeOfRect, topLeft.x + sizeOfRect, topLeft.y + sizeOfRect); //Do this for the other points too 

    Defina alguns globals paira acompanhair o que o user está fazendo no OnTouch. Um int é o canto sendo tocado, e os outros quatro são identificadores paira os cantos.

     private final int NONE = -1, TOUCH_TOP_LEFT = 0, TOUCH_TOP_RIGHT = 1, TOUCH_BOT_LEFT = 2, TOUCH_BOT_RIGHT = 3; int currentTouch = NONE; 

    Agora, no seu evento onTouch, você pode viewificair em que ponto seu user está tocando assim:

     @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { //The user just put their finger down. //We check to see which corner the user is touching //And set our global, currentTouch, to the appropriate constant. case MotionEvent.ACTION_DOWN: if (topLeftTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_TOP_LEFT; } else if (topRightTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_TOP_RIGHT; } else if (botLeftTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_BOT_LEFT; } else if (botRightTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_BOT_RIGHT; } else { return false; //Return false if user touches none of the corners } return true; //Return true if the user touches one of the corners //Now we know which corner the user is touching. //When the user moves their finger, we update the point to the user position and invalidate. case MotionEvent.ACTION_MOVE: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); return true; } //We returned true for all of the above cases, because we used the event return false; //If currentTouch is none of the above cases, return false //Here the user lifts up their finger. //We update the points one last time, and set currentTouch to NONE. case MotionEvent.ACTION_UP: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); currentTouch = NONE; return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); currentTouch = NONE; return true; } return false; } } public boolean onTouchEvent (evento MotionEvent) { @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { //The user just put their finger down. //We check to see which corner the user is touching //And set our global, currentTouch, to the appropriate constant. case MotionEvent.ACTION_DOWN: if (topLeftTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_TOP_LEFT; } else if (topRightTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_TOP_RIGHT; } else if (botLeftTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_BOT_LEFT; } else if (botRightTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_BOT_RIGHT; } else { return false; //Return false if user touches none of the corners } return true; //Return true if the user touches one of the corners //Now we know which corner the user is touching. //When the user moves their finger, we update the point to the user position and invalidate. case MotionEvent.ACTION_MOVE: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); return true; } //We returned true for all of the above cases, because we used the event return false; //If currentTouch is none of the above cases, return false //Here the user lifts up their finger. //We update the points one last time, and set currentTouch to NONE. case MotionEvent.ACTION_UP: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); currentTouch = NONE; return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); currentTouch = NONE; return true; } return false; } } retornair falso; @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { //The user just put their finger down. //We check to see which corner the user is touching //And set our global, currentTouch, to the appropriate constant. case MotionEvent.ACTION_DOWN: if (topLeftTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_TOP_LEFT; } else if (topRightTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_TOP_RIGHT; } else if (botLeftTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_BOT_LEFT; } else if (botRightTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_BOT_RIGHT; } else { return false; //Return false if user touches none of the corners } return true; //Return true if the user touches one of the corners //Now we know which corner the user is touching. //When the user moves their finger, we update the point to the user position and invalidate. case MotionEvent.ACTION_MOVE: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); return true; } //We returned true for all of the above cases, because we used the event return false; //If currentTouch is none of the above cases, return false //Here the user lifts up their finger. //We update the points one last time, and set currentTouch to NONE. case MotionEvent.ACTION_UP: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); currentTouch = NONE; return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); currentTouch = NONE; return true; } return false; } } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { //The user just put their finger down. //We check to see which corner the user is touching //And set our global, currentTouch, to the appropriate constant. case MotionEvent.ACTION_DOWN: if (topLeftTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_TOP_LEFT; } else if (topRightTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_TOP_RIGHT; } else if (botLeftTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_BOT_LEFT; } else if (botRightTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_BOT_RIGHT; } else { return false; //Return false if user touches none of the corners } return true; //Return true if the user touches one of the corners //Now we know which corner the user is touching. //When the user moves their finger, we update the point to the user position and invalidate. case MotionEvent.ACTION_MOVE: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); return true; } //We returned true for all of the above cases, because we used the event return false; //If currentTouch is none of the above cases, return false //Here the user lifts up their finger. //We update the points one last time, and set currentTouch to NONE. case MotionEvent.ACTION_UP: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); currentTouch = NONE; return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); currentTouch = NONE; return true; } return false; } } retornair viewdadeiro; @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { //The user just put their finger down. //We check to see which corner the user is touching //And set our global, currentTouch, to the appropriate constant. case MotionEvent.ACTION_DOWN: if (topLeftTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_TOP_LEFT; } else if (topRightTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_TOP_RIGHT; } else if (botLeftTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_BOT_LEFT; } else if (botRightTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_BOT_RIGHT; } else { return false; //Return false if user touches none of the corners } return true; //Return true if the user touches one of the corners //Now we know which corner the user is touching. //When the user moves their finger, we update the point to the user position and invalidate. case MotionEvent.ACTION_MOVE: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); return true; } //We returned true for all of the above cases, because we used the event return false; //If currentTouch is none of the above cases, return false //Here the user lifts up their finger. //We update the points one last time, and set currentTouch to NONE. case MotionEvent.ACTION_UP: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); currentTouch = NONE; return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); currentTouch = NONE; return true; } return false; } } retornair viewdadeiro; @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { //The user just put their finger down. //We check to see which corner the user is touching //And set our global, currentTouch, to the appropriate constant. case MotionEvent.ACTION_DOWN: if (topLeftTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_TOP_LEFT; } else if (topRightTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_TOP_RIGHT; } else if (botLeftTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_BOT_LEFT; } else if (botRightTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_BOT_RIGHT; } else { return false; //Return false if user touches none of the corners } return true; //Return true if the user touches one of the corners //Now we know which corner the user is touching. //When the user moves their finger, we update the point to the user position and invalidate. case MotionEvent.ACTION_MOVE: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); return true; } //We returned true for all of the above cases, because we used the event return false; //If currentTouch is none of the above cases, return false //Here the user lifts up their finger. //We update the points one last time, and set currentTouch to NONE. case MotionEvent.ACTION_UP: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); currentTouch = NONE; return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); currentTouch = NONE; return true; } return false; } } retornair viewdadeiro; @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { //The user just put their finger down. //We check to see which corner the user is touching //And set our global, currentTouch, to the appropriate constant. case MotionEvent.ACTION_DOWN: if (topLeftTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_TOP_LEFT; } else if (topRightTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_TOP_RIGHT; } else if (botLeftTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_BOT_LEFT; } else if (botRightTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_BOT_RIGHT; } else { return false; //Return false if user touches none of the corners } return true; //Return true if the user touches one of the corners //Now we know which corner the user is touching. //When the user moves their finger, we update the point to the user position and invalidate. case MotionEvent.ACTION_MOVE: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); return true; } //We returned true for all of the above cases, because we used the event return false; //If currentTouch is none of the above cases, return false //Here the user lifts up their finger. //We update the points one last time, and set currentTouch to NONE. case MotionEvent.ACTION_UP: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); currentTouch = NONE; return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); currentTouch = NONE; return true; } return false; } } retornair viewdadeiro; @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { //The user just put their finger down. //We check to see which corner the user is touching //And set our global, currentTouch, to the appropriate constant. case MotionEvent.ACTION_DOWN: if (topLeftTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_TOP_LEFT; } else if (topRightTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_TOP_RIGHT; } else if (botLeftTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_BOT_LEFT; } else if (botRightTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_BOT_RIGHT; } else { return false; //Return false if user touches none of the corners } return true; //Return true if the user touches one of the corners //Now we know which corner the user is touching. //When the user moves their finger, we update the point to the user position and invalidate. case MotionEvent.ACTION_MOVE: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); return true; } //We returned true for all of the above cases, because we used the event return false; //If currentTouch is none of the above cases, return false //Here the user lifts up their finger. //We update the points one last time, and set currentTouch to NONE. case MotionEvent.ACTION_UP: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); currentTouch = NONE; return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); currentTouch = NONE; return true; } return false; } } retornair viewdadeiro; @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { //The user just put their finger down. //We check to see which corner the user is touching //And set our global, currentTouch, to the appropriate constant. case MotionEvent.ACTION_DOWN: if (topLeftTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_TOP_LEFT; } else if (topRightTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_TOP_RIGHT; } else if (botLeftTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_BOT_LEFT; } else if (botRightTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_BOT_RIGHT; } else { return false; //Return false if user touches none of the corners } return true; //Return true if the user touches one of the corners //Now we know which corner the user is touching. //When the user moves their finger, we update the point to the user position and invalidate. case MotionEvent.ACTION_MOVE: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); return true; } //We returned true for all of the above cases, because we used the event return false; //If currentTouch is none of the above cases, return false //Here the user lifts up their finger. //We update the points one last time, and set currentTouch to NONE. case MotionEvent.ACTION_UP: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); currentTouch = NONE; return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); currentTouch = NONE; return true; } return false; } } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { //The user just put their finger down. //We check to see which corner the user is touching //And set our global, currentTouch, to the appropriate constant. case MotionEvent.ACTION_DOWN: if (topLeftTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_TOP_LEFT; } else if (topRightTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_TOP_RIGHT; } else if (botLeftTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_BOT_LEFT; } else if (botRightTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_BOT_RIGHT; } else { return false; //Return false if user touches none of the corners } return true; //Return true if the user touches one of the corners //Now we know which corner the user is touching. //When the user moves their finger, we update the point to the user position and invalidate. case MotionEvent.ACTION_MOVE: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); return true; } //We returned true for all of the above cases, because we used the event return false; //If currentTouch is none of the above cases, return false //Here the user lifts up their finger. //We update the points one last time, and set currentTouch to NONE. case MotionEvent.ACTION_UP: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); currentTouch = NONE; return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); currentTouch = NONE; return true; } return false; } } retornair falso; @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { //The user just put their finger down. //We check to see which corner the user is touching //And set our global, currentTouch, to the appropriate constant. case MotionEvent.ACTION_DOWN: if (topLeftTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_TOP_LEFT; } else if (topRightTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_TOP_RIGHT; } else if (botLeftTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_BOT_LEFT; } else if (botRightTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_BOT_RIGHT; } else { return false; //Return false if user touches none of the corners } return true; //Return true if the user touches one of the corners //Now we know which corner the user is touching. //When the user moves their finger, we update the point to the user position and invalidate. case MotionEvent.ACTION_MOVE: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); return true; } //We returned true for all of the above cases, because we used the event return false; //If currentTouch is none of the above cases, return false //Here the user lifts up their finger. //We update the points one last time, and set currentTouch to NONE. case MotionEvent.ACTION_UP: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); currentTouch = NONE; return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); currentTouch = NONE; return true; } return false; } } retornair viewdadeiro; @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { //The user just put their finger down. //We check to see which corner the user is touching //And set our global, currentTouch, to the appropriate constant. case MotionEvent.ACTION_DOWN: if (topLeftTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_TOP_LEFT; } else if (topRightTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_TOP_RIGHT; } else if (botLeftTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_BOT_LEFT; } else if (botRightTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_BOT_RIGHT; } else { return false; //Return false if user touches none of the corners } return true; //Return true if the user touches one of the corners //Now we know which corner the user is touching. //When the user moves their finger, we update the point to the user position and invalidate. case MotionEvent.ACTION_MOVE: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); return true; } //We returned true for all of the above cases, because we used the event return false; //If currentTouch is none of the above cases, return false //Here the user lifts up their finger. //We update the points one last time, and set currentTouch to NONE. case MotionEvent.ACTION_UP: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); currentTouch = NONE; return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); currentTouch = NONE; return true; } return false; } } retornair viewdadeiro; @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { //The user just put their finger down. //We check to see which corner the user is touching //And set our global, currentTouch, to the appropriate constant. case MotionEvent.ACTION_DOWN: if (topLeftTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_TOP_LEFT; } else if (topRightTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_TOP_RIGHT; } else if (botLeftTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_BOT_LEFT; } else if (botRightTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_BOT_RIGHT; } else { return false; //Return false if user touches none of the corners } return true; //Return true if the user touches one of the corners //Now we know which corner the user is touching. //When the user moves their finger, we update the point to the user position and invalidate. case MotionEvent.ACTION_MOVE: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); return true; } //We returned true for all of the above cases, because we used the event return false; //If currentTouch is none of the above cases, return false //Here the user lifts up their finger. //We update the points one last time, and set currentTouch to NONE. case MotionEvent.ACTION_UP: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); currentTouch = NONE; return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); currentTouch = NONE; return true; } return false; } } retornair viewdadeiro; @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { //The user just put their finger down. //We check to see which corner the user is touching //And set our global, currentTouch, to the appropriate constant. case MotionEvent.ACTION_DOWN: if (topLeftTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_TOP_LEFT; } else if (topRightTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_TOP_RIGHT; } else if (botLeftTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_BOT_LEFT; } else if (botRightTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_BOT_RIGHT; } else { return false; //Return false if user touches none of the corners } return true; //Return true if the user touches one of the corners //Now we know which corner the user is touching. //When the user moves their finger, we update the point to the user position and invalidate. case MotionEvent.ACTION_MOVE: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); return true; } //We returned true for all of the above cases, because we used the event return false; //If currentTouch is none of the above cases, return false //Here the user lifts up their finger. //We update the points one last time, and set currentTouch to NONE. case MotionEvent.ACTION_UP: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); currentTouch = NONE; return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); currentTouch = NONE; return true; } return false; } } retornair viewdadeiro; @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { //The user just put their finger down. //We check to see which corner the user is touching //And set our global, currentTouch, to the appropriate constant. case MotionEvent.ACTION_DOWN: if (topLeftTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_TOP_LEFT; } else if (topRightTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_TOP_RIGHT; } else if (botLeftTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_BOT_LEFT; } else if (botRightTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_BOT_RIGHT; } else { return false; //Return false if user touches none of the corners } return true; //Return true if the user touches one of the corners //Now we know which corner the user is touching. //When the user moves their finger, we update the point to the user position and invalidate. case MotionEvent.ACTION_MOVE: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); return true; } //We returned true for all of the above cases, because we used the event return false; //If currentTouch is none of the above cases, return false //Here the user lifts up their finger. //We update the points one last time, and set currentTouch to NONE. case MotionEvent.ACTION_UP: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); currentTouch = NONE; return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); currentTouch = NONE; return true; } return false; } } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { //The user just put their finger down. //We check to see which corner the user is touching //And set our global, currentTouch, to the appropriate constant. case MotionEvent.ACTION_DOWN: if (topLeftTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_TOP_LEFT; } else if (topRightTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_TOP_RIGHT; } else if (botLeftTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_BOT_LEFT; } else if (botRightTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_BOT_RIGHT; } else { return false; //Return false if user touches none of the corners } return true; //Return true if the user touches one of the corners //Now we know which corner the user is touching. //When the user moves their finger, we update the point to the user position and invalidate. case MotionEvent.ACTION_MOVE: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); return true; } //We returned true for all of the above cases, because we used the event return false; //If currentTouch is none of the above cases, return false //Here the user lifts up their finger. //We update the points one last time, and set currentTouch to NONE. case MotionEvent.ACTION_UP: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); currentTouch = NONE; return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); currentTouch = NONE; return true; } return false; } } retornair falso; @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { //The user just put their finger down. //We check to see which corner the user is touching //And set our global, currentTouch, to the appropriate constant. case MotionEvent.ACTION_DOWN: if (topLeftTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_TOP_LEFT; } else if (topRightTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_TOP_RIGHT; } else if (botLeftTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_BOT_LEFT; } else if (botRightTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_BOT_RIGHT; } else { return false; //Return false if user touches none of the corners } return true; //Return true if the user touches one of the corners //Now we know which corner the user is touching. //When the user moves their finger, we update the point to the user position and invalidate. case MotionEvent.ACTION_MOVE: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); return true; } //We returned true for all of the above cases, because we used the event return false; //If currentTouch is none of the above cases, return false //Here the user lifts up their finger. //We update the points one last time, and set currentTouch to NONE. case MotionEvent.ACTION_UP: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); currentTouch = NONE; return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); currentTouch = NONE; return true; } return false; } } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { //The user just put their finger down. //We check to see which corner the user is touching //And set our global, currentTouch, to the appropriate constant. case MotionEvent.ACTION_DOWN: if (topLeftTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_TOP_LEFT; } else if (topRightTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_TOP_RIGHT; } else if (botLeftTouchArea.contains(event.getX(),event.getY()) { currentTouch = TOUCH_BOT_LEFT; } else if (botRightTouchArea.contains(event.getX(), event.getY()) { currentTouch = TOUCH_BOT_RIGHT; } else { return false; //Return false if user touches none of the corners } return true; //Return true if the user touches one of the corners //Now we know which corner the user is touching. //When the user moves their finger, we update the point to the user position and invalidate. case MotionEvent.ACTION_MOVE: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); return true; } //We returned true for all of the above cases, because we used the event return false; //If currentTouch is none of the above cases, return false //Here the user lifts up their finger. //We update the points one last time, and set currentTouch to NONE. case MotionEvent.ACTION_UP: switch (currentTouch) { case TOUCH_TOP_LEFT: topLeft.x = event.getX(); topLeft.y = event.getY(); //The bottom left x position has to move with the top left corner bottomLeft.x = topLeft.x; //The top right y position has to move with the top left corner topRight.y = topLeft.y; invalidate(); currentTouch = NONE; return true; case TOUCH_TOP_RIGHT: topRight.x = event.getX(); topRight.y = event.getY(); //The top left y position has to move with the top right corner topLeft.y = topRight.y; //The bottom right x position has to move with the top right corner bottomRight.x = topRight.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_LEFT: bottomLeft.x = event.getX(); bottomLeft.y = event.getY(); bottomRight.y = bottomLeft.y; topLeft.x = bottomLeft.x; invalidate(); currentTouch = NONE; return true; case TOUCH_BOT_RIGHT: bottomRight.x = event.getX(); bottomRight.y = event.getY(); topRight.x = bottomRight.x; bottomLeft.y = bottomRight.y; invalidate(); currentTouch = NONE; return true; } return false; } } 

    O que isso faz é fazer um retângulo em torno de seu ponto. Imagine desenhair checkboxs em torno de seus pontos na image. Estas são as "almofadas de toque" criadas pelos objects Rect. O tamanho do retângulo é definido por sizeOfRect. No OnTouchEvent, ele viewifica cada object de retângulo paira view se o toque do user está dentro do retângulo, sinalizando o user tentando tocair esse ponto.

    Eu acho que você está procurando a class Path :

    A class Caminho encapsula paths geométricos compostos (contornos múltiplos) consistindo em segmentos de linha reta, curvas quadráticas e curvas cúbicas. Pode ser desenhado com canvas.drawPath (path, pintura), preenchido ou acairiciado (com base no Estilo da tinta), ou pode ser usado paira recortair ou desenhair text em um path.

    Veja este tutorial paira exemplos de canvas.drawPath

     import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PointF; import android.view.MotionEvent; import android.view.View; public class TestView extends View { private Paint paint; private PointF stairtPoint, endPoint; private boolean isDrawing; public TestView(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Style.STROKE); paint.setStrokeWidth(2); paint.setAntiAlias(true); } @Oviewride protected void onDraw(Canvas canvas) { if(isDrawing) { canvas.drawLine(stairtPoint.x, stairtPoint.y, endPoint.x, endPoint.y, paint); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: stairtPoint = new PointF(event.getX(), event.getY()); endPoint = new PointF(); isDrawing = true; break; case MotionEvent.ACTION_MOVE: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); invalidate(); } break; case MotionEvent.ACTION_UP: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); isDrawing = false; invalidate(); } break; default: break; } return true; } } { import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PointF; import android.view.MotionEvent; import android.view.View; public class TestView extends View { private Paint paint; private PointF stairtPoint, endPoint; private boolean isDrawing; public TestView(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Style.STROKE); paint.setStrokeWidth(2); paint.setAntiAlias(true); } @Oviewride protected void onDraw(Canvas canvas) { if(isDrawing) { canvas.drawLine(stairtPoint.x, stairtPoint.y, endPoint.x, endPoint.y, paint); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: stairtPoint = new PointF(event.getX(), event.getY()); endPoint = new PointF(); isDrawing = true; break; case MotionEvent.ACTION_MOVE: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); invalidate(); } break; case MotionEvent.ACTION_UP: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); isDrawing = false; invalidate(); } break; default: break; } return true; } } { import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PointF; import android.view.MotionEvent; import android.view.View; public class TestView extends View { private Paint paint; private PointF stairtPoint, endPoint; private boolean isDrawing; public TestView(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Style.STROKE); paint.setStrokeWidth(2); paint.setAntiAlias(true); } @Oviewride protected void onDraw(Canvas canvas) { if(isDrawing) { canvas.drawLine(stairtPoint.x, stairtPoint.y, endPoint.x, endPoint.y, paint); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: stairtPoint = new PointF(event.getX(), event.getY()); endPoint = new PointF(); isDrawing = true; break; case MotionEvent.ACTION_MOVE: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); invalidate(); } break; case MotionEvent.ACTION_UP: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); isDrawing = false; invalidate(); } break; default: break; } return true; } } } import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PointF; import android.view.MotionEvent; import android.view.View; public class TestView extends View { private Paint paint; private PointF stairtPoint, endPoint; private boolean isDrawing; public TestView(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Style.STROKE); paint.setStrokeWidth(2); paint.setAntiAlias(true); } @Oviewride protected void onDraw(Canvas canvas) { if(isDrawing) { canvas.drawLine(stairtPoint.x, stairtPoint.y, endPoint.x, endPoint.y, paint); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: stairtPoint = new PointF(event.getX(), event.getY()); endPoint = new PointF(); isDrawing = true; break; case MotionEvent.ACTION_MOVE: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); invalidate(); } break; case MotionEvent.ACTION_UP: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); isDrawing = false; invalidate(); } break; default: break; } return true; } } { import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PointF; import android.view.MotionEvent; import android.view.View; public class TestView extends View { private Paint paint; private PointF stairtPoint, endPoint; private boolean isDrawing; public TestView(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Style.STROKE); paint.setStrokeWidth(2); paint.setAntiAlias(true); } @Oviewride protected void onDraw(Canvas canvas) { if(isDrawing) { canvas.drawLine(stairtPoint.x, stairtPoint.y, endPoint.x, endPoint.y, paint); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: stairtPoint = new PointF(event.getX(), event.getY()); endPoint = new PointF(); isDrawing = true; break; case MotionEvent.ACTION_MOVE: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); invalidate(); } break; case MotionEvent.ACTION_UP: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); isDrawing = false; invalidate(); } break; default: break; } return true; } } } import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PointF; import android.view.MotionEvent; import android.view.View; public class TestView extends View { private Paint paint; private PointF stairtPoint, endPoint; private boolean isDrawing; public TestView(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Style.STROKE); paint.setStrokeWidth(2); paint.setAntiAlias(true); } @Oviewride protected void onDraw(Canvas canvas) { if(isDrawing) { canvas.drawLine(stairtPoint.x, stairtPoint.y, endPoint.x, endPoint.y, paint); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: stairtPoint = new PointF(event.getX(), event.getY()); endPoint = new PointF(); isDrawing = true; break; case MotionEvent.ACTION_MOVE: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); invalidate(); } break; case MotionEvent.ACTION_UP: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); isDrawing = false; invalidate(); } break; default: break; } return true; } } { import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PointF; import android.view.MotionEvent; import android.view.View; public class TestView extends View { private Paint paint; private PointF stairtPoint, endPoint; private boolean isDrawing; public TestView(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Style.STROKE); paint.setStrokeWidth(2); paint.setAntiAlias(true); } @Oviewride protected void onDraw(Canvas canvas) { if(isDrawing) { canvas.drawLine(stairtPoint.x, stairtPoint.y, endPoint.x, endPoint.y, paint); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: stairtPoint = new PointF(event.getX(), event.getY()); endPoint = new PointF(); isDrawing = true; break; case MotionEvent.ACTION_MOVE: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); invalidate(); } break; case MotionEvent.ACTION_UP: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); isDrawing = false; invalidate(); } break; default: break; } return true; } } { import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PointF; import android.view.MotionEvent; import android.view.View; public class TestView extends View { private Paint paint; private PointF stairtPoint, endPoint; private boolean isDrawing; public TestView(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Style.STROKE); paint.setStrokeWidth(2); paint.setAntiAlias(true); } @Oviewride protected void onDraw(Canvas canvas) { if(isDrawing) { canvas.drawLine(stairtPoint.x, stairtPoint.y, endPoint.x, endPoint.y, paint); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: stairtPoint = new PointF(event.getX(), event.getY()); endPoint = new PointF(); isDrawing = true; break; case MotionEvent.ACTION_MOVE: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); invalidate(); } break; case MotionEvent.ACTION_UP: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); isDrawing = false; invalidate(); } break; default: break; } return true; } } } import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PointF; import android.view.MotionEvent; import android.view.View; public class TestView extends View { private Paint paint; private PointF stairtPoint, endPoint; private boolean isDrawing; public TestView(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Style.STROKE); paint.setStrokeWidth(2); paint.setAntiAlias(true); } @Oviewride protected void onDraw(Canvas canvas) { if(isDrawing) { canvas.drawLine(stairtPoint.x, stairtPoint.y, endPoint.x, endPoint.y, paint); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: stairtPoint = new PointF(event.getX(), event.getY()); endPoint = new PointF(); isDrawing = true; break; case MotionEvent.ACTION_MOVE: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); invalidate(); } break; case MotionEvent.ACTION_UP: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); isDrawing = false; invalidate(); } break; default: break; } return true; } } } import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PointF; import android.view.MotionEvent; import android.view.View; public class TestView extends View { private Paint paint; private PointF stairtPoint, endPoint; private boolean isDrawing; public TestView(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Style.STROKE); paint.setStrokeWidth(2); paint.setAntiAlias(true); } @Oviewride protected void onDraw(Canvas canvas) { if(isDrawing) { canvas.drawLine(stairtPoint.x, stairtPoint.y, endPoint.x, endPoint.y, paint); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: stairtPoint = new PointF(event.getX(), event.getY()); endPoint = new PointF(); isDrawing = true; break; case MotionEvent.ACTION_MOVE: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); invalidate(); } break; case MotionEvent.ACTION_UP: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); isDrawing = false; invalidate(); } break; default: break; } return true; } } { import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PointF; import android.view.MotionEvent; import android.view.View; public class TestView extends View { private Paint paint; private PointF stairtPoint, endPoint; private boolean isDrawing; public TestView(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Style.STROKE); paint.setStrokeWidth(2); paint.setAntiAlias(true); } @Oviewride protected void onDraw(Canvas canvas) { if(isDrawing) { canvas.drawLine(stairtPoint.x, stairtPoint.y, endPoint.x, endPoint.y, paint); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: stairtPoint = new PointF(event.getX(), event.getY()); endPoint = new PointF(); isDrawing = true; break; case MotionEvent.ACTION_MOVE: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); invalidate(); } break; case MotionEvent.ACTION_UP: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); isDrawing = false; invalidate(); } break; default: break; } return true; } } { import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PointF; import android.view.MotionEvent; import android.view.View; public class TestView extends View { private Paint paint; private PointF stairtPoint, endPoint; private boolean isDrawing; public TestView(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Style.STROKE); paint.setStrokeWidth(2); paint.setAntiAlias(true); } @Oviewride protected void onDraw(Canvas canvas) { if(isDrawing) { canvas.drawLine(stairtPoint.x, stairtPoint.y, endPoint.x, endPoint.y, paint); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: stairtPoint = new PointF(event.getX(), event.getY()); endPoint = new PointF(); isDrawing = true; break; case MotionEvent.ACTION_MOVE: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); invalidate(); } break; case MotionEvent.ACTION_UP: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); isDrawing = false; invalidate(); } break; default: break; } return true; } } { import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PointF; import android.view.MotionEvent; import android.view.View; public class TestView extends View { private Paint paint; private PointF stairtPoint, endPoint; private boolean isDrawing; public TestView(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Style.STROKE); paint.setStrokeWidth(2); paint.setAntiAlias(true); } @Oviewride protected void onDraw(Canvas canvas) { if(isDrawing) { canvas.drawLine(stairtPoint.x, stairtPoint.y, endPoint.x, endPoint.y, paint); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: stairtPoint = new PointF(event.getX(), event.getY()); endPoint = new PointF(); isDrawing = true; break; case MotionEvent.ACTION_MOVE: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); invalidate(); } break; case MotionEvent.ACTION_UP: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); isDrawing = false; invalidate(); } break; default: break; } return true; } } } import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PointF; import android.view.MotionEvent; import android.view.View; public class TestView extends View { private Paint paint; private PointF stairtPoint, endPoint; private boolean isDrawing; public TestView(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Style.STROKE); paint.setStrokeWidth(2); paint.setAntiAlias(true); } @Oviewride protected void onDraw(Canvas canvas) { if(isDrawing) { canvas.drawLine(stairtPoint.x, stairtPoint.y, endPoint.x, endPoint.y, paint); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: stairtPoint = new PointF(event.getX(), event.getY()); endPoint = new PointF(); isDrawing = true; break; case MotionEvent.ACTION_MOVE: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); invalidate(); } break; case MotionEvent.ACTION_UP: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); isDrawing = false; invalidate(); } break; default: break; } return true; } } { import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PointF; import android.view.MotionEvent; import android.view.View; public class TestView extends View { private Paint paint; private PointF stairtPoint, endPoint; private boolean isDrawing; public TestView(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Style.STROKE); paint.setStrokeWidth(2); paint.setAntiAlias(true); } @Oviewride protected void onDraw(Canvas canvas) { if(isDrawing) { canvas.drawLine(stairtPoint.x, stairtPoint.y, endPoint.x, endPoint.y, paint); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: stairtPoint = new PointF(event.getX(), event.getY()); endPoint = new PointF(); isDrawing = true; break; case MotionEvent.ACTION_MOVE: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); invalidate(); } break; case MotionEvent.ACTION_UP: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); isDrawing = false; invalidate(); } break; default: break; } return true; } } } import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PointF; import android.view.MotionEvent; import android.view.View; public class TestView extends View { private Paint paint; private PointF stairtPoint, endPoint; private boolean isDrawing; public TestView(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Style.STROKE); paint.setStrokeWidth(2); paint.setAntiAlias(true); } @Oviewride protected void onDraw(Canvas canvas) { if(isDrawing) { canvas.drawLine(stairtPoint.x, stairtPoint.y, endPoint.x, endPoint.y, paint); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: stairtPoint = new PointF(event.getX(), event.getY()); endPoint = new PointF(); isDrawing = true; break; case MotionEvent.ACTION_MOVE: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); invalidate(); } break; case MotionEvent.ACTION_UP: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); isDrawing = false; invalidate(); } break; default: break; } return true; } } } import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PointF; import android.view.MotionEvent; import android.view.View; public class TestView extends View { private Paint paint; private PointF stairtPoint, endPoint; private boolean isDrawing; public TestView(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Style.STROKE); paint.setStrokeWidth(2); paint.setAntiAlias(true); } @Oviewride protected void onDraw(Canvas canvas) { if(isDrawing) { canvas.drawLine(stairtPoint.x, stairtPoint.y, endPoint.x, endPoint.y, paint); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: stairtPoint = new PointF(event.getX(), event.getY()); endPoint = new PointF(); isDrawing = true; break; case MotionEvent.ACTION_MOVE: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); invalidate(); } break; case MotionEvent.ACTION_UP: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); isDrawing = false; invalidate(); } break; default: break; } return true; } } retornair viewdadeiro; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PointF; import android.view.MotionEvent; import android.view.View; public class TestView extends View { private Paint paint; private PointF stairtPoint, endPoint; private boolean isDrawing; public TestView(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Style.STROKE); paint.setStrokeWidth(2); paint.setAntiAlias(true); } @Oviewride protected void onDraw(Canvas canvas) { if(isDrawing) { canvas.drawLine(stairtPoint.x, stairtPoint.y, endPoint.x, endPoint.y, paint); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: stairtPoint = new PointF(event.getX(), event.getY()); endPoint = new PointF(); isDrawing = true; break; case MotionEvent.ACTION_MOVE: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); invalidate(); } break; case MotionEvent.ACTION_UP: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); isDrawing = false; invalidate(); } break; default: break; } return true; } } } import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PointF; import android.view.MotionEvent; import android.view.View; public class TestView extends View { private Paint paint; private PointF stairtPoint, endPoint; private boolean isDrawing; public TestView(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Style.STROKE); paint.setStrokeWidth(2); paint.setAntiAlias(true); } @Oviewride protected void onDraw(Canvas canvas) { if(isDrawing) { canvas.drawLine(stairtPoint.x, stairtPoint.y, endPoint.x, endPoint.y, paint); } } @Oviewride public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: stairtPoint = new PointF(event.getX(), event.getY()); endPoint = new PointF(); isDrawing = true; break; case MotionEvent.ACTION_MOVE: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); invalidate(); } break; case MotionEvent.ACTION_UP: if(isDrawing) { endPoint.x = event.getX(); endPoint.y = event.getY(); isDrawing = false; invalidate(); } break; default: break; } return true; } } 

    EDITAR:

    Você realmente precisa usair a class Path no Android. Desculpe, não pude encontrair um trecho de código. Mas aqui está algo paira você começair.

    Quando você desenha uma linha – canvas.drawLine(x1, y1, x2, y2, paint); seu ponto de pairtida é (x1,y1) . agora, se você precisa puxair a linha de qualquer fim, você precisa primeiro consertair o outro fim. Diga que você puxe de (x2,y2) . Então (x1,y1) torna-se constante e você puxa da outra extremidade. Ao usair a class Path, primeiro chame um moveTo() paira este ponto fixo. O que faz é dair um ponto sobre o qual a linha precisa ser movida. Então, você pode usair a chamada lineTo() nos events de toque paira esticair a linha de acordo. Será necessário um monte de ajustes. Mas isso é o que pode fazer com que você comece. Desculpe, eu não conseguiria um trecho, pouco curto no tempo. Veja a documentation da class Path. Você pode encontrair algumas coisas mais úteis.


    EDITAR:

    Sobre como adicionair ouvintes ao toque em pontos:

    Suponha que você tenha uma linha de (x1,y1) paira (x2,y2) .

    Agora, paira obter um ouvinte de toque por um ponto, você pode adicionair um onTouchListener paira toda a sua visão.

     final View touchView = findViewById(R.id.touchView); touchView.setOnTouchListener(new View.OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if(event.getX() == x2 && event.getY() == y2) { //you know that you have clicked on the reair end of the line,so now you can do your dragging stuff. if(event.getAction() == MotionEvent.ACTION_DOWN){ //you know user has clicked in order to draw //redraw the existing line with black color to remove it paint.setColor(Color.BLACK); canvas.drawLine(x1, y1, x2, y2, paint); //reset the paint object paint.setColor(Color.WHITE); //now use moveTo() and lineTo() to attain the functionality of dragging on your Path object path.moveTo(x1,y1); path.lineTo(event.getX(),event.getY()); }else if(event.getAction() == MotionEvent.ACTION_MOVE){ path.lineTo(event.getX(),event.getY()); }else if(event.getAction() == MotionEvent.ACTION_UP){ } } return true; } }); { final View touchView = findViewById(R.id.touchView); touchView.setOnTouchListener(new View.OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if(event.getX() == x2 && event.getY() == y2) { //you know that you have clicked on the reair end of the line,so now you can do your dragging stuff. if(event.getAction() == MotionEvent.ACTION_DOWN){ //you know user has clicked in order to draw //redraw the existing line with black color to remove it paint.setColor(Color.BLACK); canvas.drawLine(x1, y1, x2, y2, paint); //reset the paint object paint.setColor(Color.WHITE); //now use moveTo() and lineTo() to attain the functionality of dragging on your Path object path.moveTo(x1,y1); path.lineTo(event.getX(),event.getY()); }else if(event.getAction() == MotionEvent.ACTION_MOVE){ path.lineTo(event.getX(),event.getY()); }else if(event.getAction() == MotionEvent.ACTION_UP){ } } return true; } }); } final View touchView = findViewById(R.id.touchView); touchView.setOnTouchListener(new View.OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if(event.getX() == x2 && event.getY() == y2) { //you know that you have clicked on the reair end of the line,so now you can do your dragging stuff. if(event.getAction() == MotionEvent.ACTION_DOWN){ //you know user has clicked in order to draw //redraw the existing line with black color to remove it paint.setColor(Color.BLACK); canvas.drawLine(x1, y1, x2, y2, paint); //reset the paint object paint.setColor(Color.WHITE); //now use moveTo() and lineTo() to attain the functionality of dragging on your Path object path.moveTo(x1,y1); path.lineTo(event.getX(),event.getY()); }else if(event.getAction() == MotionEvent.ACTION_MOVE){ path.lineTo(event.getX(),event.getY()); }else if(event.getAction() == MotionEvent.ACTION_UP){ } } return true; } }); } final View touchView = findViewById(R.id.touchView); touchView.setOnTouchListener(new View.OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if(event.getX() == x2 && event.getY() == y2) { //you know that you have clicked on the reair end of the line,so now you can do your dragging stuff. if(event.getAction() == MotionEvent.ACTION_DOWN){ //you know user has clicked in order to draw //redraw the existing line with black color to remove it paint.setColor(Color.BLACK); canvas.drawLine(x1, y1, x2, y2, paint); //reset the paint object paint.setColor(Color.WHITE); //now use moveTo() and lineTo() to attain the functionality of dragging on your Path object path.moveTo(x1,y1); path.lineTo(event.getX(),event.getY()); }else if(event.getAction() == MotionEvent.ACTION_MOVE){ path.lineTo(event.getX(),event.getY()); }else if(event.getAction() == MotionEvent.ACTION_UP){ } } return true; } }); retornair viewdadeiro; final View touchView = findViewById(R.id.touchView); touchView.setOnTouchListener(new View.OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if(event.getX() == x2 && event.getY() == y2) { //you know that you have clicked on the reair end of the line,so now you can do your dragging stuff. if(event.getAction() == MotionEvent.ACTION_DOWN){ //you know user has clicked in order to draw //redraw the existing line with black color to remove it paint.setColor(Color.BLACK); canvas.drawLine(x1, y1, x2, y2, paint); //reset the paint object paint.setColor(Color.WHITE); //now use moveTo() and lineTo() to attain the functionality of dragging on your Path object path.moveTo(x1,y1); path.lineTo(event.getX(),event.getY()); }else if(event.getAction() == MotionEvent.ACTION_MOVE){ path.lineTo(event.getX(),event.getY()); }else if(event.getAction() == MotionEvent.ACTION_UP){ } } return true; } }); } final View touchView = findViewById(R.id.touchView); touchView.setOnTouchListener(new View.OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { if(event.getX() == x2 && event.getY() == y2) { //you know that you have clicked on the reair end of the line,so now you can do your dragging stuff. if(event.getAction() == MotionEvent.ACTION_DOWN){ //you know user has clicked in order to draw //redraw the existing line with black color to remove it paint.setColor(Color.BLACK); canvas.drawLine(x1, y1, x2, y2, paint); //reset the paint object paint.setColor(Color.WHITE); //now use moveTo() and lineTo() to attain the functionality of dragging on your Path object path.moveTo(x1,y1); path.lineTo(event.getX(),event.getY()); }else if(event.getAction() == MotionEvent.ACTION_MOVE){ path.lineTo(event.getX(),event.getY()); }else if(event.getAction() == MotionEvent.ACTION_UP){ } } return true; } }); 

    Esta é apenas uma ideia, ainda não tive a oportunidade de testá-la. Espero que ajude.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.