Example #1
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    CropImageActivity cropImage = (CropImageActivity) mContext;
    if (cropImage.mSaving) {
      return false;
    }

    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        for (int i = 0; i < mHighlightViews.size(); i++) {
          HighlightView hv = mHighlightViews.get(i);
          int edge = hv.getHit(event.getX(), event.getY());
          Log.e(TAG, "edge:" + edge);
          if (edge != HighlightView.GROW_NONE) {
            mMotionEdge = edge;
            mMotionHighlightView = hv;
            mLastX = event.getX();
            mLastY = event.getY();
            // shark  此处是区别移动和缩放,还原代码即可打开缩放功能
            /*mMotionHighlightView
            .setMode((edge == HighlightView.MOVE) ? HighlightView.ModifyMode.Move
                    : HighlightView.ModifyMode.Grow);*/

            mMotionHighlightView.setMode(HighlightView.ModifyMode.Move);
            break;
          }
        }
        break;
      case MotionEvent.ACTION_UP:
        if (mMotionHighlightView != null) {
          centerBasedOnHighlightView(mMotionHighlightView);
          mMotionHighlightView.setMode(HighlightView.ModifyMode.None);
        }
        mMotionHighlightView = null;
        break;
      case MotionEvent.ACTION_MOVE:
        if (mMotionHighlightView != null) {
          mMotionHighlightView.handleMotion(
              mMotionEdge, event.getX() - mLastX, event.getY() - mLastY);
          mLastX = event.getX();
          mLastY = event.getY();

          if (true) {
            // This section of code is optional. It has some user
            // benefit in that moving the crop rectangle against
            // the edge of the screen causes scrolling but it means
            // that the crop rectangle is no longer fixed under
            // the user's finger.
            ensureVisible(mMotionHighlightView);
          }
        }
        break;
    }

    switch (event.getAction()) {
      case MotionEvent.ACTION_UP:
        center(true, true);
        break;
      case MotionEvent.ACTION_MOVE:
        // if we're not zoomed then there's no point in even allowing
        // the user to move the image around. This call to center puts
        // it back to the normalized location (with false meaning don't
        // animate).
        if (getScale() == 1F) {
          center(true, true);
        }
        break;
    }

    return true;
  }