Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added GestureUCropView to handle touch event conflicts. #626

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 33 additions & 34 deletions ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.yalantis.ucrop.model.AspectRatio;
import com.yalantis.ucrop.util.SelectedStateListDrawable;
import com.yalantis.ucrop.view.CropImageView;
import com.yalantis.ucrop.view.GestureCropImageView;
import com.yalantis.ucrop.view.OverlayView;
import com.yalantis.ucrop.view.TransformImageView;
import com.yalantis.ucrop.view.UCropView;
Expand Down Expand Up @@ -102,7 +101,7 @@ public class UCropActivity extends AppCompatActivity {
private boolean mShowLoader = true;

private UCropView mUCropView;
private GestureCropImageView mGestureCropImageView;
private CropImageView mCropImageView;
private OverlayView mOverlayView;
private ViewGroup mWrapperStateAspectRatio, mWrapperStateRotate, mWrapperStateScale;
private ViewGroup mLayoutAspectRatio, mLayoutRotate, mLayoutScale;
Expand Down Expand Up @@ -181,8 +180,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
protected void onStop() {
super.onStop();
if (mGestureCropImageView != null) {
mGestureCropImageView.cancelAllAnimations();
if (mCropImageView != null) {
mCropImageView.cancelAllAnimations();
}
}

Expand All @@ -196,7 +195,7 @@ private void setImageData(@NonNull Intent intent) {

if (inputUri != null && outputUri != null) {
try {
mGestureCropImageView.setImageUri(inputUri, outputUri);
mCropImageView.setImageUri(inputUri, outputUri);
} catch (Exception e) {
setResultError(e);
finish();
Expand Down Expand Up @@ -230,9 +229,9 @@ private void processOptions(@NonNull Intent intent) {
}

// Crop image view options
mGestureCropImageView.setMaxBitmapSize(intent.getIntExtra(UCrop.Options.EXTRA_MAX_BITMAP_SIZE, CropImageView.DEFAULT_MAX_BITMAP_SIZE));
mGestureCropImageView.setMaxScaleMultiplier(intent.getFloatExtra(UCrop.Options.EXTRA_MAX_SCALE_MULTIPLIER, CropImageView.DEFAULT_MAX_SCALE_MULTIPLIER));
mGestureCropImageView.setImageToWrapCropBoundsAnimDuration(intent.getIntExtra(UCrop.Options.EXTRA_IMAGE_TO_CROP_BOUNDS_ANIM_DURATION, CropImageView.DEFAULT_IMAGE_TO_CROP_BOUNDS_ANIM_DURATION));
mCropImageView.setMaxBitmapSize(intent.getIntExtra(UCrop.Options.EXTRA_MAX_BITMAP_SIZE, CropImageView.DEFAULT_MAX_BITMAP_SIZE));
mCropImageView.setMaxScaleMultiplier(intent.getFloatExtra(UCrop.Options.EXTRA_MAX_SCALE_MULTIPLIER, CropImageView.DEFAULT_MAX_SCALE_MULTIPLIER));
mCropImageView.setImageToWrapCropBoundsAnimDuration(intent.getIntExtra(UCrop.Options.EXTRA_IMAGE_TO_CROP_BOUNDS_ANIM_DURATION, CropImageView.DEFAULT_IMAGE_TO_CROP_BOUNDS_ANIM_DURATION));

// Overlay view options
mOverlayView.setFreestyleCropEnabled(intent.getBooleanExtra(UCrop.Options.EXTRA_FREE_STYLE_CROP, OverlayView.DEFAULT_FREESTYLE_CROP_MODE != OverlayView.FREESTYLE_CROP_MODE_DISABLE));
Expand Down Expand Up @@ -261,21 +260,21 @@ private void processOptions(@NonNull Intent intent) {
if (mWrapperStateAspectRatio != null) {
mWrapperStateAspectRatio.setVisibility(View.GONE);
}
mGestureCropImageView.setTargetAspectRatio(aspectRatioX / aspectRatioY);
mCropImageView.setTargetAspectRatio(aspectRatioX / aspectRatioY);
} else if (aspectRatioList != null && aspectRationSelectedByDefault < aspectRatioList.size()) {
mGestureCropImageView.setTargetAspectRatio(aspectRatioList.get(aspectRationSelectedByDefault).getAspectRatioX() /
mCropImageView.setTargetAspectRatio(aspectRatioList.get(aspectRationSelectedByDefault).getAspectRatioX() /
aspectRatioList.get(aspectRationSelectedByDefault).getAspectRatioY());
} else {
mGestureCropImageView.setTargetAspectRatio(CropImageView.SOURCE_IMAGE_ASPECT_RATIO);
mCropImageView.setTargetAspectRatio(CropImageView.SOURCE_IMAGE_ASPECT_RATIO);
}

// Result bitmap max size options
int maxSizeX = intent.getIntExtra(UCrop.EXTRA_MAX_SIZE_X, 0);
int maxSizeY = intent.getIntExtra(UCrop.EXTRA_MAX_SIZE_Y, 0);

if (maxSizeX > 0 && maxSizeY > 0) {
mGestureCropImageView.setMaxResultImageSizeX(maxSizeX);
mGestureCropImageView.setMaxResultImageSizeY(maxSizeY);
mCropImageView.setMaxResultImageSizeX(maxSizeX);
mCropImageView.setMaxResultImageSizeY(maxSizeY);
}
}

Expand Down Expand Up @@ -356,10 +355,10 @@ private void setupAppBar() {

private void initiateRootViews() {
mUCropView = findViewById(R.id.ucrop);
mGestureCropImageView = mUCropView.getCropImageView();
mCropImageView = mUCropView.getCropImageView();
mOverlayView = mUCropView.getOverlayView();

mGestureCropImageView.setTransformImageListener(mImageListener);
mCropImageView.setTransformImageListener(mImageListener);

((ImageView) findViewById(R.id.image_view_logo)).setColorFilter(mLogoColor, PorterDuff.Mode.SRC_ATOP);

Expand Down Expand Up @@ -463,9 +462,9 @@ private void setupAspectRatioWidget(@NonNull Intent intent) {
cropAspectRatioView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mGestureCropImageView.setTargetAspectRatio(
mCropImageView.setTargetAspectRatio(
((AspectRatioTextView) ((ViewGroup) v).getChildAt(0)).getAspectRatio(v.isSelected()));
mGestureCropImageView.setImageToWrapCropBounds();
mCropImageView.setImageToWrapCropBounds();
if (!v.isSelected()) {
for (ViewGroup cropAspectRatioView : mCropAspectRatioViews) {
cropAspectRatioView.setSelected(cropAspectRatioView == v);
Expand All @@ -482,17 +481,17 @@ private void setupRotateWidget() {
.setScrollingListener(new HorizontalProgressWheelView.ScrollingListener() {
@Override
public void onScroll(float delta, float totalDistance) {
mGestureCropImageView.postRotate(delta / ROTATE_WIDGET_SENSITIVITY_COEFFICIENT);
mCropImageView.postRotate(delta / ROTATE_WIDGET_SENSITIVITY_COEFFICIENT);
}

@Override
public void onScrollEnd() {
mGestureCropImageView.setImageToWrapCropBounds();
mCropImageView.setImageToWrapCropBounds();
}

@Override
public void onScrollStart() {
mGestureCropImageView.cancelAllAnimations();
mCropImageView.cancelAllAnimations();
}
});

Expand Down Expand Up @@ -520,22 +519,22 @@ private void setupScaleWidget() {
@Override
public void onScroll(float delta, float totalDistance) {
if (delta > 0) {
mGestureCropImageView.zoomInImage(mGestureCropImageView.getCurrentScale()
+ delta * ((mGestureCropImageView.getMaxScale() - mGestureCropImageView.getMinScale()) / SCALE_WIDGET_SENSITIVITY_COEFFICIENT));
mCropImageView.zoomInImage(mCropImageView.getCurrentScale()
+ delta * ((mCropImageView.getMaxScale() - mCropImageView.getMinScale()) / SCALE_WIDGET_SENSITIVITY_COEFFICIENT));
} else {
mGestureCropImageView.zoomOutImage(mGestureCropImageView.getCurrentScale()
+ delta * ((mGestureCropImageView.getMaxScale() - mGestureCropImageView.getMinScale()) / SCALE_WIDGET_SENSITIVITY_COEFFICIENT));
mCropImageView.zoomOutImage(mCropImageView.getCurrentScale()
+ delta * ((mCropImageView.getMaxScale() - mCropImageView.getMinScale()) / SCALE_WIDGET_SENSITIVITY_COEFFICIENT));
}
}

@Override
public void onScrollEnd() {
mGestureCropImageView.setImageToWrapCropBounds();
mCropImageView.setImageToWrapCropBounds();
}

@Override
public void onScrollStart() {
mGestureCropImageView.cancelAllAnimations();
mCropImageView.cancelAllAnimations();
}
});
((HorizontalProgressWheelView) findViewById(R.id.scale_scroll_wheel)).setMiddleLineColor(mActiveWidgetColor);
Expand All @@ -554,13 +553,13 @@ private void setScaleText(float scale) {
}

private void resetRotation() {
mGestureCropImageView.postRotate(-mGestureCropImageView.getCurrentAngle());
mGestureCropImageView.setImageToWrapCropBounds();
mCropImageView.postRotate(-mCropImageView.getCurrentAngle());
mCropImageView.setImageToWrapCropBounds();
}

private void rotateByAngle(int angle) {
mGestureCropImageView.postRotate(angle);
mGestureCropImageView.setImageToWrapCropBounds();
mCropImageView.postRotate(angle);
mCropImageView.setImageToWrapCropBounds();
}

private final View.OnClickListener mStateClickListener = new View.OnClickListener() {
Expand Down Expand Up @@ -616,8 +615,8 @@ private void changeSelectedTab(int stateViewId) {
}

private void setAllowedGestures(int tab) {
mGestureCropImageView.setScaleEnabled(mAllowedGestures[tab] == ALL || mAllowedGestures[tab] == SCALE);
mGestureCropImageView.setRotateEnabled(mAllowedGestures[tab] == ALL || mAllowedGestures[tab] == ROTATE);
mUCropView.setScaleEnabled(mAllowedGestures[tab] == ALL || mAllowedGestures[tab] == SCALE);
mUCropView.setRotateEnabled(mAllowedGestures[tab] == ALL || mAllowedGestures[tab] == ROTATE);
}

/**
Expand All @@ -642,11 +641,11 @@ protected void cropAndSaveImage() {
mShowLoader = true;
supportInvalidateOptionsMenu();

mGestureCropImageView.cropAndSaveImage(mCompressFormat, mCompressQuality, new BitmapCropCallback() {
mCropImageView.cropAndSaveImage(mCompressFormat, mCompressQuality, new BitmapCropCallback() {

@Override
public void onBitmapCropped(@NonNull Uri resultUri, int offsetX, int offsetY, int imageWidth, int imageHeight) {
setResultUri(resultUri, mGestureCropImageView.getTargetAspectRatio(), offsetX, offsetY, imageWidth, imageHeight);
setResultUri(resultUri, mCropImageView.getTargetAspectRatio(), offsetX, offsetY, imageWidth, imageHeight);
finish();
}

Expand Down
Loading