Code example for Rect

Methods: setwidth

0
  private void update() { 
    playedBar.set(progressBar);
 
    if (totalTime > 0) {
      playedBar.right =
          playedBar.left + (int) ((progressBar.width() * (long) currentTime) / totalTime);
    } else { 
      playedBar.right = progressBar.left;
    } 
 
    if (!scrubbing) {
      scrubberLeft = playedBar.right - scrubber.getWidth() / 2;
    } 
    invalidate();
  } 
 
  /** 
   * @return the preferred height of this view, including invisible padding 
   */ 
  public int getPreferredHeight() { 
    return timeBounds.height() + vPaddingInPx + scrubberPadding;
  } 
 
  /** 
   * @return the height of the time bar, excluding invisible padding 
   */ 
  public int getBarHeight() { 
    return timeBounds.height() + vPaddingInPx;
  } 
 
  public void setTime(int currentTime, int totalTime) {
    if (this.currentTime == currentTime && this.totalTime == totalTime) {
        return; 
    } 
    this.currentTime = currentTime;
    this.totalTime = totalTime;
    update(); 
  } 
 
  public void setShowTimes(boolean showTimes) {
    this.showTimes = showTimes;
    requestLayout();
  } 
 
  public void resetTime() { 
    setTime(0, 0); 
  } 
 
  public void setShowScrubber(boolean showScrubber) {
    this.showScrubber = showScrubber;
    if (!showScrubber && scrubbing) {
      listener.onScrubbingEnd(getScrubberTime());
      scrubbing = false;
    } 
    requestLayout();
  } 
 
  private boolean inScrubber(float x, float y) {
    int scrubberRight = scrubberLeft + scrubber.getWidth();
    int scrubberBottom = scrubberTop + scrubber.getHeight();
    return scrubberLeft - scrubberPadding < x && x < scrubberRight + scrubberPadding
        && scrubberTop - scrubberPadding < y && y < scrubberBottom + scrubberPadding;
  } 
 
  private void clampScrubber() { 
    int half = scrubber.getWidth() / 2;
    int max = progressBar.right - half;
    int min = progressBar.left - half;
    scrubberLeft = Math.min(max, Math.max(min, scrubberLeft));
  } 
 
  private int getScrubberTime() { 
    return (int) ((long) (scrubberLeft + scrubber.getWidth() / 2 - progressBar.left)
        * totalTime / progressBar.width());
  } 
 
  @Override 
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int w = r - l;
    int h = b - t;
    if (!showTimes && !showScrubber) {
      progressBar.set(0, 0, w, h);
    } else { 
      int margin = scrubber.getWidth() / 3;
      if (showTimes) {
        margin += timeBounds.width();
      } 
      int progressY = (h + scrubberPadding) / 2;
      scrubberTop = progressY - scrubber.getHeight() / 2 + 1;
      progressBar.set(
          getPaddingLeft() + margin, progressY,
          w - getPaddingRight() - margin, progressY + 4);
    } 
    update(); 
  }