title: Rectangle Touching in android
body: <p>I create new Class called Rectangle , it contains below codes:</p>
  
  <pre><code>package com.example.komeil.speedcolor;
  
  /**
   * Created by Komeil on 20/11/2016.
   */
  
  public class Rectangle extends Shape {
      private int left;
      private int top;
      private int right;
      private int bottom;
  public Rectangle(String name,int color,int left,int top,int right,int bottom)
  {
      super(name,color);
      setLeft(left);
      setTop(top);
      setRight(right);
      setBottom(bottom);
  }
  
  
  public void setLeft(int left)
  {
      this.left = left;
  }
  
  public int getLeft(){
      return left;
  }
  
  public int getTop()
  {
      return top;
  }
  
  public void setTop(int top){
      this.top = top;
  }
  
  public void setRight(int right){
      this.right = right;
  }
  
  public int getRight(){
      return right;
  }
  
  public void setBottom(int bottom){
      this.bottom = bottom;
  }
  
  public int getBottom(){
      return bottom;
  }
  }
  </code></pre>
  
  <p>And i want create object from it and draw it with canvas.drawRect() like blow code:</p>
  
  <pre><code>canvas.drawRect(rectangle.getLeft(),rectangle.getTop(),rectangle.getRight(),rectangle.getBottom(),paint);
  </code></pre>
  
  <p>but when i use blow code for detect touch event on rectangle object it doesn't work:</p>
  
  <pre><code>@Override
  public boolean onTouchEvent(MotionEvent event) {
      return gameThread.doOnTouch(event);
  }
  
  
  public boolean doOnTouch(MotionEvent event){
  
      synchronized (event){
  
          int eventAction = event.getAction();
          int xEvent = (int)event.getX();
          int yEvent = (int)event.getY();
  
          switch (eventAction){
  
              case MotionEvent.ACTION_DOWN:
  
                          if(xEvent &gt;= rectangle.getLeft() &amp;&amp; xEvent &lt;= rectangle.getRight()
                                  &amp;&amp; yEvent &gt;= rectangle.getBottom() &amp;&amp; yEvent&lt;= rectangle.getTop())
                          {
                              touched = true;
                              score +=5;
                          }
                  }
                  break;
              case MotionEvent.ACTION_UP:
                  touched = false;
                  break;
          }
          return true;
      }
  }
  </code></pre>
  
  <p>So how detect rectangle touch?</p>