Skip to content

Commit

Permalink
Merge pull request ArthurHub#407 from hendrysetiadi89/master
Browse files Browse the repository at this point in the history
add cropmove and windowchange listener, add getCropWindowRect()
  • Loading branch information
ArthurHub authored Oct 3, 2017
2 parents 3ec8576 + 3672fcc commit b8eaedc
Showing 1 changed file with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ public class CropImageView extends FrameLayout {
*/
private OnSetCropOverlayReleasedListener mOnCropOverlayReleasedListener;

/**
* callback to be invoked when crop overlay is moved.
*/
private OnSetCropOverlayMovedListener mOnSetCropOverlayMovedListener;

/**
* callback to be invoked when crop window is changed.
*/
private OnSetCropWindowChangeListener mOnSetCropWindowChangeListener;

/**
* callback to be invoked when image async loading is complete.
*/
Expand Down Expand Up @@ -312,6 +322,10 @@ public void onCropWindowChanged(boolean inProgress) {
if (listener != null && !inProgress) {
listener.onCropOverlayReleased(getCropRect());
}
OnSetCropOverlayMovedListener movedListener = mOnSetCropOverlayMovedListener;
if (movedListener != null && inProgress) {
movedListener.onCropOverlayMoved(getCropRect());
}
}
});
mCropOverlayView.setInitialAttributeValues(options);
Expand Down Expand Up @@ -657,6 +671,18 @@ public Rect getCropRect() {
mCropOverlayView.isFixAspectRatio(), mCropOverlayView.getAspectRatioX(), mCropOverlayView.getAspectRatioY());
}

/**
* Gets the crop window's position relative to the parent's view at screen.
*
* @return a Rect instance containing cropped area boundaries of the source Bitmap
*/
public RectF getCropWindowRect() {
if (mCropOverlayView == null) {
return null;
}
return mCropOverlayView.getCropWindowRect();
}

/**
* Gets the 4 points of crop window's position relative to the source Bitmap (not the image
* displayed in the CropImageView) using the original image rotation.<br>
Expand Down Expand Up @@ -870,6 +896,20 @@ public void setOnSetCropOverlayReleasedListener(OnSetCropOverlayReleasedListener
mOnCropOverlayReleasedListener = listener;
}

/**
* Set the callback when the cropping is moved
*/
public void setOnSetCropOverlayMovedListener(OnSetCropOverlayMovedListener listener) {
mOnSetCropOverlayMovedListener = listener;
}

/**
* Set the callback when the crop window is changed
*/
public void setOnCropWindowChangedListener(OnSetCropWindowChangeListener listener) {
mOnSetCropWindowChangeListener = listener;
}

/**
* Set the callback to be invoked when image async loading ({@link #setImageUriAsync(Uri)})
* is complete (successful or failed).
Expand Down Expand Up @@ -1455,6 +1495,9 @@ private void handleCropWindowChanged(boolean inProgress, boolean animate) {
applyImageMatrix(width, height, true, animate);
}
}
if (mOnSetCropWindowChangeListener != null && !inProgress){
mOnSetCropWindowChangeListener.onCropWindowChanged();
}
}
}

Expand Down Expand Up @@ -1745,6 +1788,31 @@ public interface OnSetCropOverlayReleasedListener {
void onCropOverlayReleased(Rect rect);
}


/**
* Interface definition for a callback to be invoked when the crop overlay is released.
*/
public interface OnSetCropOverlayMovedListener {

/**
* Called when the crop overlay is moved
*
* @param rect The rect coordinates of the cropped overlay
*/
void onCropOverlayMoved(Rect rect);
}

/**
* Interface definition for a callback to be invoked when the crop overlay is released.
*/
public interface OnSetCropWindowChangeListener {

/**
* Called when the crop window is changed
*/
void onCropWindowChanged();
}

/**
* Interface definition for a callback to be invoked when image async loading is complete.
*/
Expand Down

0 comments on commit b8eaedc

Please sign in to comment.