Skip to content

Commit

Permalink
Merge pull request #1 from Innovatube/image-listener
Browse files Browse the repository at this point in the history
add ImageListener interface
  • Loading branch information
tuanthnguyen authored Aug 31, 2018
2 parents 06f6cfb + f3cbba7 commit 6d94d69
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions library/src/main/java/com/steelkiwi/cropiwa/CropIwaView.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class CropIwaView extends FrameLayout {
private CropSaveCompleteListener cropSaveCompleteListener;

private CropIwaResultReceiver cropIwaResultReceiver;
private SetImageListener setImageListener;

public CropIwaView(Context context) {
super(context);
Expand Down Expand Up @@ -112,14 +113,14 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
public boolean onInterceptTouchEvent(MotionEvent ev) {
//I think this "redundant" if statements improve code readability
try {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
gestureDetector.onDown(ev);
return false;
}
if (overlayView.isResizing() || overlayView.isDraggingCropArea()) {
return false;
}
return true;
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
gestureDetector.onDown(ev);
return false;
}
if (overlayView.isResizing() || overlayView.isDraggingCropArea()) {
return false;
}
return true;
} catch (IllegalArgumentException e) {
//e.printStackTrace();
return false;
Expand Down Expand Up @@ -208,11 +209,18 @@ public void setCropSaveCompleteListener(CropSaveCompleteListener cropSaveComplet
this.cropSaveCompleteListener = cropSaveCompleteListener;
}

public void setImageListener(SetImageListener setImageListener) {
this.setImageListener = setImageListener;
}

private class BitmapLoadListener implements CropIwaBitmapManager.BitmapLoadListener {

@Override
public void onBitmapLoaded(Uri imageUri, Bitmap bitmap) {
setImage(bitmap);
if (setImageListener != null) {
setImageListener.onSuccess();
}
}

@Override
Expand All @@ -222,6 +230,9 @@ public void onLoadFailed(Throwable e) {
if (errorListener != null) {
errorListener.onError(e);
}
if (setImageListener != null) {
setImageListener.onError(e);
}
}
}

Expand Down Expand Up @@ -270,4 +281,10 @@ public interface CropSaveCompleteListener {
public interface ErrorListener {
void onError(Throwable e);
}

public interface SetImageListener {
void onSuccess();

void onError(Throwable e);
}
}

0 comments on commit 6d94d69

Please sign in to comment.