Skip to content

Commit 3f713fe

Browse files
committed
修改设置图片最大高度逻辑,升级gradle
1 parent 4510e5a commit 3f713fe

File tree

7 files changed

+18
-16
lines changed

7 files changed

+18
-16
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ dependencies {
4242

4343
implementation 'com.google.code.gson:gson:2.8.5'
4444

45-
// implementation 'com.github.yuruiyin:RichEditor:0.1.9'
45+
// implementation 'com.github.yuruiyin:RichEditor:0.2.0'
4646

4747
implementation 'com.google.android:flexbox:1.0.0'
4848
}

app/src/main/java/com/yuruiyin/richeditor/sample/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ class MainActivity : AppCompatActivity() {
410410
) {
411411
// val blockImageSpanVm = BlockImageSpanVm(this, imageVm) // 不指定宽高,使用组件默认宽高
412412
val blockImageSpanVm =
413-
BlockImageSpanVm(blockImageSpanObtainObject, imageWidth, imageMaxHeight) // 指定宽高
413+
BlockImageSpanVm(blockImageSpanObtainObject, imageWidth) // 指定宽高
414414
blockImageSpanVm.isFromDraft = isFromDraft
415415
richEditText.insertBlockImage(realImagePath, blockImageSpanVm) { blockImageSpan ->
416416
val spanObtainObject = blockImageSpan.blockImageSpanVm.spanObject

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88

99
}
1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.4.0'
11+
classpath 'com.android.tools.build:gradle:3.5.0'
1212
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1313
// NOTE: Do not place your application dependencies here; they belong
1414
// in the individual module build.gradle files
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Apr 29 10:57:31 CST 2019
1+
#Tue Aug 27 11:43:20 CST 2019
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

richeditor/src/main/java/com/yuruiyin/richeditor/RichEditText.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ public class RichEditText extends LineHeightEditText {
6464
private int imageSpanPaddingBottom;
6565
private int imageSpanPaddingLeft;
6666
private int imageSpanPaddingRight;
67-
// 内部限制的图片最大高度
68-
private int internalImageMaxHeight;
6967

7068
// 是否显示视频标识
7169
private boolean gIsShowVideoMark;
@@ -169,7 +167,6 @@ private void init(Context context, AttributeSet attrs) {
169167
imageSpanPaddingBottom = (int) mContext.getResources().getDimension(R.dimen.rich_editor_image_span_padding_bottom);
170168
imageSpanPaddingLeft = (int) mContext.getResources().getDimension(R.dimen.rich_editor_image_span_padding_left);
171169
imageSpanPaddingRight = (int) mContext.getResources().getDimension(R.dimen.rich_editor_image_span_padding_right);
172-
internalImageMaxHeight = (int) mContext.getResources().getDimension(R.dimen.rich_editor_image_max_height);
173170

174171
mRichInputConnection = new RichInputConnectionWrapper(null, true);
175172
setMovementMethod(new LongClickableLinkMovementMethod());
@@ -315,11 +312,10 @@ public void insertBlockImage(Drawable drawable, @NonNull BlockImageSpanVm blockI
315312
int editTextWidth = getWidthWithoutPadding();
316313
int imageWidth = blockImageSpanVm.getWidth();
317314
int resImageWidth = imageWidth > editTextWidth ? editTextWidth : imageWidth;
318-
int imageMaxHeight = blockImageSpanVm.getMaxHeight() > internalImageMaxHeight
319-
? internalImageMaxHeight : blockImageSpanVm.getMaxHeight();
315+
int imageMaxHeight = blockImageSpanVm.getMaxHeight();
320316
int resImageHeight = (int) (originHeight * 1.0 / originWidth * resImageWidth);
321317
resImageHeight = resImageHeight > imageMaxHeight ? imageMaxHeight : resImageHeight;
322-
// 控制显示出来的图片的高度不会大于宽度的2倍
318+
// 控制显示出来的图片的高度不会大于宽度的3倍
323319
double maxHeightWidthRadio = AppConfig.IMAGE_MAX_HEIGHT_WIDTH_RATIO;
324320
resImageHeight = resImageHeight > resImageWidth * maxHeightWidthRadio
325321
? (int) (resImageWidth * maxHeightWidthRadio)

richeditor/src/main/java/com/yuruiyin/richeditor/model/BlockImageSpanVm.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Context;
44

55
import com.yuruiyin.richeditor.R;
6+
import com.yuruiyin.richeditor.config.AppConfig;
67

78
/**
89
* Title: BlockImageSpan 相关数据
@@ -54,8 +55,8 @@ public class BlockImageSpanVm<T extends IBlockImageSpanObtainObject> {
5455
private boolean isFromDraft;
5556

5657
public BlockImageSpanVm(Context context, T spanObject) {
57-
this.width = (int) context.getResources().getDimension(R.dimen.rich_editor_image_width);
58-
this.maxHeight = (int) context.getResources().getDimension(R.dimen.rich_editor_image_max_height);
58+
this.width = (int) context.getResources().getDimension(R.dimen.rich_editor_default_image_width);
59+
this.maxHeight = (int) (this.width * AppConfig.IMAGE_MAX_HEIGHT_WIDTH_RATIO);
5960
this.spanObject = spanObject;
6061
}
6162

@@ -65,6 +66,12 @@ public BlockImageSpanVm(T spanObject, int width, int maxHeight) {
6566
this.spanObject = spanObject;
6667
}
6768

69+
public BlockImageSpanVm(T spanObject, int width) {
70+
this.width = width;
71+
this.maxHeight = (int) (width * AppConfig.IMAGE_MAX_HEIGHT_WIDTH_RATIO);
72+
this.spanObject = spanObject;
73+
}
74+
6875
public int getWidth() {
6976
return width;
7077
}

richeditor/src/main/res/values/dimens.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
<dimen name="rich_editor_image_span_padding_right">1dp</dimen>
2323
<dimen name="rich_editor_image_span_padding_left">1dp</dimen>
2424

25-
<!-- 限制图片最大的高度,避免调用方传递超级大的高度而导致长图限制超级长的问题 -->
26-
<dimen name="rich_editor_image_width">120dp</dimen>
27-
<dimen name="rich_editor_image_max_height">640dp</dimen>
25+
<!-- 默认图片宽度 -->
26+
<dimen name="rich_editor_default_image_width">120dp</dimen>
2827

2928
<!-- 图片类型(gif or长图)文字大小 -->
3029
<dimen name="rich_editor_image_type_text_size">10dp</dimen>

0 commit comments

Comments
 (0)