Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
罗孟伟 committed Feb 1, 2018
1 parent 60d3f05 commit 3b73763
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,16 @@ public class PictureMultiCuttingActivity extends AppCompatActivity {
private int mCompressQuality = DEFAULT_COMPRESS_QUALITY;
private int[] mAllowedGestures = new int[]{SCALE, ROTATE, ALL};
private List<CutInfo> cutInfos = new ArrayList<>();
/**
* 是否可拖动裁剪框
*/
private boolean isDragFrame;

/**
* 图片是否可拖动或旋转
*/
private boolean scaleEnabled, rotateEnabled;

private int cutIndex;

@Override
Expand Down Expand Up @@ -218,8 +227,13 @@ private void setImageData(@NonNull Intent intent) {
if (inputUri != null && outputUri != null) {
try {
boolean isGif = FileUtils.isGif(inputUri.getPath());
mGestureCropImageView.setRotateEnabled(isGif ? false : rotateEnabled);
mGestureCropImageView.setScaleEnabled(isGif ? false : scaleEnabled);
if (isGif) {
mGestureCropImageView.setRotateEnabled(false);
mGestureCropImageView.setScaleEnabled(false);
} else {
mGestureCropImageView.setRotateEnabled(rotateEnabled);
mGestureCropImageView.setScaleEnabled(scaleEnabled);
}
mGestureCropImageView.setImageUri(inputUri, outputUri);
} catch (Exception e) {
setResultError(e);
Expand Down Expand Up @@ -259,6 +273,7 @@ private void processOptions(@NonNull Intent intent) {
mGestureCropImageView.setImageToWrapCropBoundsAnimDuration(intent.getIntExtra(UCropMulti.Options.EXTRA_IMAGE_TO_CROP_BOUNDS_ANIM_DURATION, CropImageView.DEFAULT_IMAGE_TO_CROP_BOUNDS_ANIM_DURATION));

// Overlay view options
mOverlayView.setDragFrame(isDragFrame);
mOverlayView.setFreestyleCropEnabled(intent.getBooleanExtra(UCropMulti.Options.EXTRA_FREE_STYLE_CROP, false));
circleDimmedLayer = intent.getBooleanExtra(UCropMulti.Options.EXTRA_CIRCLE_DIMMED_LAYER, OverlayView.DEFAULT_CIRCLE_DIMMED_LAYER);
mOverlayView.setDimmedColor(intent.getIntExtra(UCropMulti.Options.EXTRA_DIMMED_LAYER_COLOR, getResources().getColor(R.color.ucrop_color_default_dimmed)));
Expand Down Expand Up @@ -632,8 +647,8 @@ private void setWidgetState(@IdRes int stateViewId) {
}

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

/**
Expand Down
19 changes: 19 additions & 0 deletions ucrop/src/main/java/com/yalantis/ucrop/UCrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ public static class Options {

public static final String EXTRA_UCROP_ROOT_VIEW_BACKGROUND_COLOR = EXTRA_PREFIX + ".UcropRootViewBackgroundColor";

public static final String EXTRA_ROTATE = EXTRA_PREFIX + ".rotate";
public static final String EXTRA_SCALE = EXTRA_PREFIX + ".scale";

public static final String EXTRA_DRAG_CROP_FRAME = EXTRA_PREFIX + ".DragCropFrame";

private final Bundle mOptionBundle;

Expand Down Expand Up @@ -384,6 +388,21 @@ public void setShowCropGrid(boolean show) {
mOptionBundle.putBoolean(EXTRA_SHOW_CROP_GRID, show);
}

/**
* @param isDragFrame - 是否可拖动裁剪框
*/
public void setDragFrameEnabled(boolean isDragFrame) {
mOptionBundle.putBoolean(EXTRA_DRAG_CROP_FRAME, isDragFrame);
}

public void setScaleEnabled(boolean scaleEnabled) {
mOptionBundle.putBoolean(EXTRA_SCALE, scaleEnabled);
}

public void setRotateEnabled(boolean rotateEnabled) {
mOptionBundle.putBoolean(EXTRA_ROTATE, rotateEnabled);
}

/**
* @param count - crop grid rows count.
*/
Expand Down
26 changes: 24 additions & 2 deletions ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ public class UCropActivity extends AppCompatActivity {
private Bitmap.CompressFormat mCompressFormat = DEFAULT_COMPRESS_FORMAT;
private int mCompressQuality = DEFAULT_COMPRESS_QUALITY;
private int[] mAllowedGestures = new int[]{SCALE, ROTATE, ALL};
/**
* 是否可拖动裁剪框
*/
private boolean isDragFrame;

/**
* 图片是否可拖动或旋转
*/
private boolean scaleEnabled, rotateEnabled;

@Override
public void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -186,6 +195,8 @@ private void setImageData(@NonNull Intent intent) {

if (inputUri != null && outputUri != null) {
try {
mGestureCropImageView.setRotateEnabled(rotateEnabled);
mGestureCropImageView.setScaleEnabled(scaleEnabled);
mGestureCropImageView.setImageUri(inputUri, outputUri);
} catch (Exception e) {
setResultError(e);
Expand Down Expand Up @@ -227,6 +238,8 @@ private void processOptions(@NonNull Intent intent) {
// Overlay view options
mOverlayView.setFreestyleCropEnabled(intent.getBooleanExtra(UCrop.Options.EXTRA_FREE_STYLE_CROP, false));

mOverlayView.setDragFrame(isDragFrame);

mOverlayView.setDimmedColor(intent.getIntExtra(UCrop.Options.EXTRA_DIMMED_LAYER_COLOR, getResources().getColor(R.color.ucrop_color_default_dimmed)));
mOverlayView.setCircleDimmedLayer(intent.getBooleanExtra(UCrop.Options.EXTRA_CIRCLE_DIMMED_LAYER, OverlayView.DEFAULT_CIRCLE_DIMMED_LAYER));

Expand Down Expand Up @@ -270,6 +283,13 @@ private void processOptions(@NonNull Intent intent) {
}

private void setupViews(@NonNull Intent intent) {
scaleEnabled = intent.getBooleanExtra(UCrop.Options.EXTRA_SCALE, true);

rotateEnabled = intent.getBooleanExtra(UCrop.Options.EXTRA_ROTATE, true);

// 是否可拖动裁剪框
isDragFrame = intent.getBooleanExtra(UCrop.Options.EXTRA_DRAG_CROP_FRAME, true);

mStatusBarColor = intent.getIntExtra(UCrop.Options.EXTRA_STATUS_BAR_COLOR, ContextCompat.getColor(this, R.color.ucrop_color_statusbar));
mToolbarColor = intent.getIntExtra(UCrop.Options.EXTRA_TOOL_BAR_COLOR, ContextCompat.getColor(this, R.color.ucrop_color_toolbar));
if (mToolbarColor == -1) {
Expand Down Expand Up @@ -596,8 +616,10 @@ private void setWidgetState(@IdRes int stateViewId) {
}

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

/**
Expand Down
9 changes: 9 additions & 0 deletions ucrop/src/main/java/com/yalantis/ucrop/UCropMulti.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ public static class Options {

public static final String EXTRA_FREE_STATUS_FONT = EXTRA_PREFIX + ".StatusFont";

public static final String EXTRA_DRAG_CROP_FRAME = EXTRA_PREFIX + ".DragCropFrame";

public static final String EXTRA_ROTATE = EXTRA_PREFIX + ".rotate";
public static final String EXTRA_SCALE = EXTRA_PREFIX + ".scale";

Expand Down Expand Up @@ -399,6 +401,13 @@ public void setRotateEnabled(boolean rotateEnabled) {
mOptionBundle.putBoolean(EXTRA_ROTATE, rotateEnabled);
}

/**
* @param isDragFrame - 是否可拖动裁剪框
*/
public void setDragFrameEnabled(boolean isDragFrame) {
mOptionBundle.putBoolean(EXTRA_DRAG_CROP_FRAME, isDragFrame);
}

/**
* @param count - crop grid rows count.
*/
Expand Down
32 changes: 26 additions & 6 deletions ucrop/src/main/java/com/yalantis/ucrop/view/OverlayView.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
* This must have LAYER_TYPE_SOFTWARE to draw itself properly.
*/
public class OverlayView extends View {

public static final boolean DEFAULT_DRAG_FRAME = true;
public static final boolean DEFAULT_SHOW_CROP_FRAME = true;
public static final boolean DEFAULT_SHOW_CROP_GRID = true;
public static final boolean DEFAULT_CIRCLE_DIMMED_LAYER = false;
public static final boolean DEFAULT_FREESTYLE_CROP_ENABLED = false;
public static final int DEFAULT_CROP_GRID_ROW_COUNT = 2;
public static final int DEFAULT_CROP_GRID_COLUMN_COUNT = 2;

private boolean mIsDragFrame = DEFAULT_DRAG_FRAME;
private final RectF mCropViewRect = new RectF();
private final RectF mTempRect = new RectF();

Expand Down Expand Up @@ -104,6 +104,14 @@ public void setFreestyleCropEnabled(boolean freestyleCropEnabled) {
mIsFreestyleCropEnabled = freestyleCropEnabled;
}

public boolean ismIsDragFrame() {
return mIsDragFrame;
}

public void setDragFrame(boolean mIsDragFrame) {
this.mIsDragFrame = mIsDragFrame;
}

/**
* Setter for {@link #mCircleDimmedLayer} variable.
*
Expand Down Expand Up @@ -328,16 +336,28 @@ private void updateCropViewRect(float touchX, float touchY) {
switch (mCurrentTouchCornerIndex) {
// resize rectangle
case 0:
mTempRect.set(touchX, touchY, mCropViewRect.right, mCropViewRect.bottom);
// 是否可拖动裁剪框
if (mIsDragFrame) {
mTempRect.set(touchX, touchY, mCropViewRect.right, mCropViewRect.bottom);
}
break;
case 1:
mTempRect.set(mCropViewRect.left, touchY, touchX, mCropViewRect.bottom);
// 是否可拖动裁剪框
if (mIsDragFrame) {
mTempRect.set(mCropViewRect.left, touchY, touchX, mCropViewRect.bottom);
}
break;
case 2:
mTempRect.set(mCropViewRect.left, mCropViewRect.top, touchX, touchY);
// 是否可拖动裁剪框
if (mIsDragFrame) {
mTempRect.set(mCropViewRect.left, mCropViewRect.top, touchX, touchY);
}
break;
case 3:
mTempRect.set(touchX, mCropViewRect.top, mCropViewRect.right, touchY);
// 是否可拖动裁剪框
if (mIsDragFrame) {
mTempRect.set(touchX, mCropViewRect.top, mCropViewRect.right, touchY);
}
break;
// move rectangle
case 4:
Expand Down

0 comments on commit 3b73763

Please sign in to comment.