Ejemplo n.º 1
0
 @Override
 protected void zoomTo(float scale, float centerX, float centerY) {
   super.zoomTo(scale, centerX, centerY);
   for (HighlightView hv : mHighlightViews) {
     hv.mMatrix.set(getImageMatrix());
     hv.invalidate();
   }
 }
Ejemplo n.º 2
0
 @Override
 protected void zoomOut() {
   super.zoomOut();
   for (HighlightView hv : mHighlightViews) {
     hv.mMatrix.set(getImageMatrix());
     hv.invalidate();
   }
 }
Ejemplo n.º 3
0
 @Override
 protected void postTranslate(float deltaX, float deltaY) {
   super.postTranslate(deltaX, deltaY);
   for (int i = 0; i < mHighlightViews.size(); i++) {
     HighlightView hv = mHighlightViews.get(i);
     hv.mMatrix.postTranslate(deltaX, deltaY);
     hv.invalidate();
   }
 }
Ejemplo n.º 4
0
 @Override
 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
   super.onLayout(changed, left, top, right, bottom);
   if (mBitmapDisplayed.getBitmap() != null) {
     for (HighlightView hv : mHighlightViews) {
       hv.mMatrix.set(getImageMatrix());
       hv.invalidate();
       if (hv.mIsFocused) {
         centerBasedOnHighlightView(hv);
       }
     }
   }
 }
Ejemplo n.º 5
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;
  }