Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
罗孟伟 committed Dec 18, 2019
1 parent c0196ba commit 9b999e2
Show file tree
Hide file tree
Showing 30 changed files with 213 additions and 18 deletions.
6 changes: 6 additions & 0 deletions app/src/main/java/com/luck/pictureselector/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ public void onAddPicClick() {
.isGif(cb_isGif.isChecked())// 是否显示gif图片
.freeStyleCropEnabled(cb_styleCrop.isChecked())// 裁剪框是否可拖拽
.circleDimmedLayer(cb_crop_circular.isChecked())// 是否圆形裁剪
//.setCircleDimmedColor(ContextCompat.getColor(this, R.color.app_color_white))// 设置圆形裁剪背景色值
//.setCircleDimmedBorderColor(ContextCompat.getColor(getApplicationContext(), R.color.app_color_white))// 设置圆形裁剪边框色值
//.setCircleStrokeWidth(3)// 设置圆形裁剪边框粗细
.showCropFrame(cb_showCropFrame.isChecked())// 是否显示裁剪矩形边框 圆形裁剪时建议设为false
.showCropGrid(cb_showCropGrid.isChecked())// 是否显示裁剪矩形网格 圆形裁剪时建议设为false
.openClickSound(cb_voice.isChecked())// 是否开启点击声音
Expand Down Expand Up @@ -274,6 +277,9 @@ public void onAddPicClick() {
.isGif(cb_isGif.isChecked())// 是否显示gif图片
.freeStyleCropEnabled(cb_styleCrop.isChecked())// 裁剪框是否可拖拽
.circleDimmedLayer(cb_crop_circular.isChecked())// 是否圆形裁剪
//.setCircleDimmedColor(ContextCompat.getColor(this, R.color.app_color_white))// 设置圆形裁剪背景色值
//.setCircleDimmedBorderColor(ContextCompat.getColor(this, R.color.app_color_white))// 设置圆形裁剪边框色值
//.setCircleStrokeWidth(3)// 设置圆形裁剪边框粗细
.showCropFrame(cb_showCropFrame.isChecked())// 是否显示裁剪矩形边框 圆形裁剪时建议设为false
.showCropGrid(cb_showCropGrid.isChecked())// 是否显示裁剪矩形网格 圆形裁剪时建议设为false
.openClickSound(cb_voice.isChecked())// 是否开启点击声音
Expand Down
Binary file removed image/10.jpg
Binary file not shown.
Binary file removed image/11.jpg
Binary file not shown.
Binary file removed image/12.jpg
Binary file not shown.
Binary file removed image/13.jpg
Binary file not shown.
Binary file removed image/14.jpg
Binary file not shown.
Binary file removed image/15.jpg
Binary file not shown.
Binary file removed image/16.jpg
Binary file not shown.
Binary file removed image/17.jpg
Binary file not shown.
Binary file removed image/2.jpg
Binary file not shown.
Binary file removed image/3.jpg
Binary file not shown.
Binary file removed image/4.jpg
Binary file not shown.
Binary file removed image/5.jpg
Binary file not shown.
Binary file removed image/6.jpg
Binary file not shown.
Binary file removed image/7.jpg
Binary file not shown.
Binary file removed image/8.jpg
Binary file not shown.
Binary file removed image/9.jpg
Binary file not shown.
Binary file removed image/audio.jpg
Binary file not shown.
Binary file removed image/blue.jpg
Binary file not shown.
Binary file removed image/crop_white.jpg
Binary file not shown.
Binary file removed image/white.jpg
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ protected void startCrop(String originalPath) {
if (config.cropStyle.cropTitleColor != 0) {
titleColor = config.cropStyle.cropTitleColor;
}

isChangeStatusBarFontColor = config.cropStyle.isChangeStatusBarFontColor;
} else {
if (config.cropTitleBarBackgroundColor != 0) {
Expand Down Expand Up @@ -427,6 +428,9 @@ protected void startCrop(String originalPath) {
options.setToolbarColor(toolbarColor);
options.setStatusBarColor(statusColor);
options.setToolbarWidgetColor(titleColor);
options.setDimmedLayerColor(config.circleDimmedColor);
options.setDimmedLayerBorderColor(config.circleDimmedBorderColor);
options.setCircleStrokeWidth(config.circleStrokeWidth);
options.setCircleDimmedLayer(config.circleDimmedLayer);
options.setShowCropFrame(config.showCropFrame);
options.setShowCropGrid(config.showCropGrid);
Expand Down Expand Up @@ -511,6 +515,9 @@ protected void startCrop(ArrayList<CutInfo> list) {
options.setStatusBarColor(statusColor);
options.setToolbarWidgetColor(titleColor);
options.setCircleDimmedLayer(config.circleDimmedLayer);
options.setDimmedLayerColor(config.circleDimmedColor);
options.setDimmedLayerBorderColor(config.circleDimmedBorderColor);
options.setCircleStrokeWidth(config.circleStrokeWidth);
options.setShowCropFrame(config.showCropFrame);
options.setDragFrameEnabled(config.isDragFrame);
options.setShowCropGrid(config.showCropGrid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,33 @@ public PictureSelectionModel circleDimmedLayer(boolean circleDimmedLayer) {
return this;
}

/**
* @param circleDimmedColor setCircleDimmedColor
* @return
*/
public PictureSelectionModel setCircleDimmedColor(int circleDimmedColor) {
selectionConfig.circleDimmedColor = circleDimmedColor;
return this;
}

/**
* @param circleDimmedBorderColor setCircleDimmedBorderColor
* @return
*/
public PictureSelectionModel setCircleDimmedBorderColor(int circleDimmedBorderColor) {
selectionConfig.circleDimmedBorderColor = circleDimmedBorderColor;
return this;
}

/**
* @param circleStrokeWidth setCircleStrokeWidth
* @return
*/
public PictureSelectionModel setCircleStrokeWidth(int circleStrokeWidth) {
selectionConfig.circleStrokeWidth = circleStrokeWidth;
return this;
}

/**
* @param showCropFrame Whether to show crop frame
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.ColorInt;
import androidx.annotation.StyleRes;

import com.luck.picture.lib.style.PictureWindowAnimationStyle;
Expand Down Expand Up @@ -73,6 +74,11 @@ public final class PictureSelectionConfig implements Parcelable {
public boolean enableCrop;
public boolean freeStyleCropEnabled;
public boolean circleDimmedLayer;
@ColorInt
public int circleDimmedColor;
@ColorInt
public int circleDimmedBorderColor;
public int circleStrokeWidth;
public boolean showCropFrame;
public boolean showCropGrid;
public boolean hideBottomControls;
Expand Down Expand Up @@ -175,6 +181,9 @@ private void reset() {
previewEggs = false;
synOrAsy = true;
zoomAnim = true;
circleDimmedColor = 0;
circleDimmedBorderColor = 0;
circleStrokeWidth = 1;
isDragFrame = true;
compressSavePath = "";
suffixType = PictureFileUtils.POSTFIX;
Expand Down Expand Up @@ -228,6 +237,9 @@ public int describeContents() {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(this.chooseMode);
dest.writeInt(this.circleDimmedColor);
dest.writeInt(this.circleDimmedBorderColor);
dest.writeInt(this.circleStrokeWidth);
dest.writeByte(this.camera ? (byte) 1 : (byte) 0);
dest.writeByte(this.isSingleDirectReturn ? (byte) 1 : (byte) 0);
dest.writeParcelable(this.style, flags);
Expand Down Expand Up @@ -310,6 +322,9 @@ protected PictureSelectionConfig(Parcel in) {
this.cameraFileName = in.readString();
this.specifiedFormat = in.readString();
this.themeStyleId = in.readInt();
this.circleDimmedBorderColor = in.readInt();
this.circleStrokeWidth = in.readInt();
this.circleDimmedColor = in.readInt();
this.selectionMode = in.readInt();
this.maxSelectNum = in.readInt();
this.minSelectNum = in.readInt();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.yalantis.ucrop;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.PorterDuff;
Expand All @@ -22,9 +24,11 @@
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SimpleItemAnimator;

import android.os.ParcelFileDescriptor;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -44,6 +48,7 @@
import com.yalantis.ucrop.model.AspectRatio;
import com.yalantis.ucrop.model.CutInfo;
import com.yalantis.ucrop.util.FileUtils;
import com.yalantis.ucrop.util.ScreenUtils;
import com.yalantis.ucrop.util.SelectedStateListDrawable;
import com.yalantis.ucrop.view.CropImageView;
import com.yalantis.ucrop.view.GestureCropImageView;
Expand Down Expand Up @@ -88,7 +93,7 @@ public class PictureMultiCuttingActivity extends AppCompatActivity {
private static final int SCALE_WIDGET_SENSITIVITY_COEFFICIENT = 15000;
private static final int ROTATE_WIDGET_SENSITIVITY_COEFFICIENT = 42;
private RecyclerView mRecyclerView;
private PicturePhotoGalleryAdapter adapter;
private PicturePhotoGalleryAdapter mAdapter;
private String mToolbarTitle;
private ArrayList<CutInfo> list;
// Enables dynamic coloring
Expand Down Expand Up @@ -116,6 +121,7 @@ public class PictureMultiCuttingActivity extends AppCompatActivity {
private TextView mTextViewRotateAngle, mTextViewScalePercent;
private View mBlockingView;
private RelativeLayout uCropMultiplePhotoBox;
private int mScreenWidth;
private Bitmap.CompressFormat mCompressFormat = DEFAULT_COMPRESS_FORMAT;
private int mCompressQuality = DEFAULT_COMPRESS_QUALITY;
private int[] mAllowedGestures = new int[]{SCALE, ROTATE, ALL};
Expand All @@ -131,6 +137,8 @@ public class PictureMultiCuttingActivity extends AppCompatActivity {

private int cutIndex;

private int oldCutIndex;

/**
* 是否使用沉浸式,子类复写该方法来确定是否采用沉浸式
*
Expand Down Expand Up @@ -162,13 +170,13 @@ public void onCreate(Bundle savedInstanceState) {
}
setContentView(R.layout.ucrop_picture_activity_multi_cutting);
uCropMultiplePhotoBox = findViewById(R.id.ucrop_mulit_photobox);
mScreenWidth = ScreenUtils.getScreenWidth(this);
initLoadCutData();
addPhotoRecyclerView();
setupViews(intent);
setInitialState();
addBlockingView();
setImageData(intent);

}

/**
Expand All @@ -191,20 +199,27 @@ private void addPhotoRecyclerView() {
mRecyclerView.setId(R.id.id_recycler);
mRecyclerView.setBackgroundColor(ContextCompat.getColor(this, R.color.ucrop_color_widget_background));
RelativeLayout.LayoutParams lp =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, dip2px(80));
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
ScreenUtils.dip2px(this, 80));
mRecyclerView.setLayoutParams(lp);
LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
mLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
mRecyclerView.setLayoutManager(mLayoutManager);
// 解决调用 notifyItemChanged 闪烁问题,取消默认动画
((SimpleItemAnimator) mRecyclerView.getItemAnimator())
.setSupportsChangeAnimations(false);

resetCutDataStatus();
list.get(cutIndex).setCut(true);
adapter = new PicturePhotoGalleryAdapter(this, list);
mRecyclerView.setAdapter(adapter);
adapter.setOnItemClickListener((position, view) -> {
mAdapter = new PicturePhotoGalleryAdapter(this, list);
mRecyclerView.setAdapter(mAdapter);
mAdapter.setOnItemClickListener((position, view) -> {
if (cutIndex == position) {
return;
}
resetLastCropStatus();
cutIndex = position;
oldCutIndex = cutIndex;
resetCutData();
});

Expand All @@ -221,7 +236,7 @@ private void addPhotoRecyclerView() {
private void refreshPhotoRecyclerData() {
resetCutDataStatus();
list.get(cutIndex).setCut(true);
adapter.notifyDataSetChanged();
mAdapter.notifyItemChanged(cutIndex);

uCropMultiplePhotoBox.addView(mRecyclerView);
changeLayoutParams(mShowBottomControls);
Expand Down Expand Up @@ -357,6 +372,8 @@ private void processOptions(@NonNull Intent intent) {
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.setDimmedBorderColor(intent.getIntExtra(UCropMulti.Options.EXTRA_DIMMED_LAYER_BORDER_COLOR, getResources().getColor(R.color.ucrop_color_default_dimmed)));
mOverlayView.setDimmedStrokeWidth(intent.getIntExtra(UCropMulti.Options.EXTRA_CIRCLE_STROKE_WIDTH_LAYER, 1));
mOverlayView.setDimmedColor(intent.getIntExtra(UCropMulti.Options.EXTRA_DIMMED_LAYER_COLOR, getResources().getColor(R.color.ucrop_color_default_dimmed)));
mOverlayView.setCircleDimmedLayer(circleDimmedLayer);

Expand Down Expand Up @@ -776,7 +793,9 @@ protected void setResultUri(Uri uri, float resultAspectRatio, int offsetX, int o
info.setOffsetY(offsetY);
info.setImageWidth(imageWidth);
info.setImageHeight(imageHeight);
resetLastCropStatus();
cutIndex++;
oldCutIndex = cutIndex;
if (cutIndex >= list.size()) {
setResult(RESULT_OK, new Intent()
.putExtra(UCropMulti.EXTRA_OUTPUT_URI_LIST, list)
Expand All @@ -788,7 +807,16 @@ protected void setResultUri(Uri uri, float resultAspectRatio, int offsetX, int o
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* 重置上一次选中状态
*/
private void resetLastCropStatus() {
if (list.size() > oldCutIndex) {
list.get(oldCutIndex).setCut(false);
mAdapter.notifyItemChanged(cutIndex);
}
}

/**
Expand All @@ -815,9 +843,11 @@ protected void resetCutData() {
refreshPhotoRecyclerData();
setupViews(intent);
setImageData(intent);
// 预览图 一页5个,裁剪到第6个的时候滚动到最新位置,不然预览图片看不到
if (cutIndex >= 5) {
mRecyclerView.scrollToPosition(cutIndex);
int scrollWidth = cutIndex * ScreenUtils.dip2px(this, 60);
if (scrollWidth > mScreenWidth * 0.8) {
mRecyclerView.scrollBy(ScreenUtils.dip2px(this, 60), 0);
} else if (scrollWidth < mScreenWidth * 0.4) {
mRecyclerView.scrollBy(ScreenUtils.dip2px(this, -60), 0);
}
changeLayoutParams(mShowBottomControls);
}
Expand Down Expand Up @@ -851,7 +881,7 @@ public static String getLastImgType(String path) {
try {
int index = path.lastIndexOf(".");
if (index > 0) {
String imageType = path.substring(index, path.length());
String imageType = path.substring(index);
switch (imageType) {
case ".png":
case ".PNG":
Expand Down Expand Up @@ -894,7 +924,4 @@ protected void exitAnimation() {
overridePendingTransition(R.anim.ucrop_anim_fade_in, exitAnimation != 0 ? exitAnimation : R.anim.ucrop_close);
}

public int dip2px(float dpValue) {
return (int) (0.5f + dpValue * getResources().getDisplayMetrics().density);
}
}
25 changes: 24 additions & 1 deletion ucrop/src/main/java/com/yalantis/ucrop/UCrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ public static class Options {
public static final String EXTRA_IMAGE_TO_CROP_BOUNDS_ANIM_DURATION = EXTRA_PREFIX + ".ImageToCropBoundsAnimDuration";

public static final String EXTRA_DIMMED_LAYER_COLOR = EXTRA_PREFIX + ".DimmedLayerColor";
public static final String EXTRA_DIMMED_LAYER_BORDER_COLOR = EXTRA_PREFIX + ".DimmedLayerBorderColor";
public static final String EXTRA_CIRCLE_DIMMED_LAYER = EXTRA_PREFIX + ".CircleDimmedLayer";
public static final String EXTRA_CIRCLE_STROKE_WIDTH_LAYER = EXTRA_PREFIX + ".CircleStrokeWidth";

public static final String EXTRA_SHOW_CROP_FRAME = EXTRA_PREFIX + ".ShowCropFrame";
public static final String EXTRA_CROP_FRAME_COLOR = EXTRA_PREFIX + ".CropFrameColor";
Expand Down Expand Up @@ -360,7 +362,28 @@ public void setMaxBitmapSize(@IntRange(from = 100) int maxBitmapSize) {
* @param color - desired color of dimmed area around the crop bounds
*/
public void setDimmedLayerColor(@ColorInt int color) {
mOptionBundle.putInt(EXTRA_DIMMED_LAYER_COLOR, color);
if (color != 0) {
mOptionBundle.putInt(EXTRA_DIMMED_LAYER_COLOR, color);
}
}

/**
* @param color - desired border color of dimmed area around the crop bounds
*/
public void setDimmedLayerBorderColor(@ColorInt int color) {
if (color != 0) {
mOptionBundle.putInt(EXTRA_DIMMED_LAYER_BORDER_COLOR, color);
}
}


/**
* @param width Set the circular clipping border
*/
public void setCircleStrokeWidth(int width) {
if (width > 0) {
mOptionBundle.putInt(EXTRA_CIRCLE_STROKE_WIDTH_LAYER, width);
}
}

/**
Expand Down
2 changes: 2 additions & 0 deletions ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,10 @@ private void processOptions(@NonNull Intent intent) {

mOverlayView.setDragFrame(isDragFrame);

mOverlayView.setDimmedBorderColor(intent.getIntExtra(UCrop.Options.EXTRA_DIMMED_LAYER_BORDER_COLOR, getResources().getColor(R.color.ucrop_color_default_dimmed)));
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));
mOverlayView.setDimmedStrokeWidth(intent.getIntExtra(UCrop.Options.EXTRA_CIRCLE_STROKE_WIDTH_LAYER, 1));

mOverlayView.setShowCropFrame(intent.getBooleanExtra(UCrop.Options.EXTRA_SHOW_CROP_FRAME, OverlayView.DEFAULT_SHOW_CROP_FRAME));
mOverlayView.setCropFrameColor(intent.getIntExtra(UCrop.Options.EXTRA_CROP_FRAME_COLOR, getResources().getColor(R.color.ucrop_color_default_crop_frame)));
Expand Down
Loading

0 comments on commit 9b999e2

Please sign in to comment.