code: public final void moveInside(Rect bounds) {
  	// check the right edge
  	int distanceOffRightSide = (x + w) - (bounds.x + bounds.w);
  	if (distanceOffRightSide > 0) {
  	    x -= distanceOffRightSide;
  	}
  	// check the left edge (we prefer this to fit)
  	int distanceOffLeftSide = bounds.x - x;
  	if (distanceOffLeftSide > 0) {
  	    x += distanceOffLeftSide;
  	}
  
  	// check the bottom edge
  	int distanceOffBottom = (y + h) - (bounds.y + bounds.h);
  	if (distanceOffBottom > 0) {
  	    y -= distanceOffBottom;
  	}
  	// check the top edge (we prefer this to fit)
  	int distanceOffTop = bounds.y - y;
  	if (distanceOffTop > 0) {
  	    y += distanceOffTop;
  	}	
      }
docs: Note, this actually changes this Rect (if that wasn't obvious)