コード例 #1
0
 private boolean isDeletingExistingShape(int x, int y) {
   for (ShapeDrawable shape : shapes) {
     Rect bounds = shape.getBounds();
     if (bounds.contains(x, y)) {
       shapes.remove(shape);
       return (true);
     }
   }
   return (false);
 }
コード例 #2
0
ファイル: VolumeView.java プロジェクト: lylyhs/Wifly_Light
 public void setVolume(int volume) {
   mVolume = Math.max(0, Math.min(mVolumeMax, volume));
   final Rect r = mBar.getBounds();
   if (mVertical) {
     mCover.setBounds(
         r.left + mVolume * (r.right - r.left) / mVolumeMax, r.top, r.right, r.bottom);
   } else {
     mCover.setBounds(r.left, r.top, r.right, r.top + mVolume * (r.bottom - r.top) / mVolumeMax);
   }
   this.invalidate();
 }
コード例 #3
0
ファイル: VolumeView.java プロジェクト: lylyhs/Wifly_Light
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    final Rect r = mBar.getBounds();
    final int newX = (int) event.getX();
    final int newY = (int) event.getY();
    final int coverBottom = Math.min(r.bottom, Math.max(r.top, newY));
    final int coverRight = Math.min(r.right, Math.max(r.left, newX));
    final int action = event.getAction();

    // begin of touch event, check if touch was in range
    if (MotionEvent.ACTION_DOWN == action) {
      mEmbraceTouch = (r.left <= newX && newX <= r.right);
    }

    // we can ignore all further touch events
    if (!mEmbraceTouch) {
      return false;
    }

    // check for end of touch gesture
    if (MotionEvent.ACTION_UP == action) {
      mEmbraceTouch = false;
      if (null != mOnVolumeChangedListener) {
        if (mVertical) {
          mVolume = mVolumeMax * (coverRight - r.left) / (r.right - r.left);
          mOnVolumeChangedListener.onVolumeChanged(mVolume);
        } else {
          mVolume = mVolumeMax - mVolumeMax * (coverBottom - r.top) / (r.bottom - r.top);
          mOnVolumeChangedListener.onVolumeChanged(mVolume);
        }
      }
    }

    // we moved the selection -> repaint
    if (mVertical) {
      mCover.setBounds(coverRight, r.top, r.right, r.bottom);
    } else {
      mCover.setBounds(r.left, r.top, r.right, coverBottom);
    }
    this.invalidate();
    return true;
  }