Skip to content

Commit

Permalink
修改设置图片最大高度逻辑,升级gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
yuruiyin committed Aug 27, 2019
1 parent 4510e5a commit 3f713fe
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dependencies {

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

// implementation 'com.github.yuruiyin:RichEditor:0.1.9'
// implementation 'com.github.yuruiyin:RichEditor:0.2.0'

implementation 'com.google.android:flexbox:1.0.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ class MainActivity : AppCompatActivity() {
) {
// val blockImageSpanVm = BlockImageSpanVm(this, imageVm) // 不指定宽高,使用组件默认宽高
val blockImageSpanVm =
BlockImageSpanVm(blockImageSpanObtainObject, imageWidth, imageMaxHeight) // 指定宽高
BlockImageSpanVm(blockImageSpanObtainObject, imageWidth) // 指定宽高
blockImageSpanVm.isFromDraft = isFromDraft
richEditText.insertBlockImage(realImagePath, blockImageSpanVm) { blockImageSpan ->
val spanObtainObject = blockImageSpan.blockImageSpanVm.spanObject
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {

}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Apr 29 10:57:31 CST 2019
#Tue Aug 27 11:43:20 CST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ public class RichEditText extends LineHeightEditText {
private int imageSpanPaddingBottom;
private int imageSpanPaddingLeft;
private int imageSpanPaddingRight;
// 内部限制的图片最大高度
private int internalImageMaxHeight;

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

mRichInputConnection = new RichInputConnectionWrapper(null, true);
setMovementMethod(new LongClickableLinkMovementMethod());
Expand Down Expand Up @@ -315,11 +312,10 @@ public void insertBlockImage(Drawable drawable, @NonNull BlockImageSpanVm blockI
int editTextWidth = getWidthWithoutPadding();
int imageWidth = blockImageSpanVm.getWidth();
int resImageWidth = imageWidth > editTextWidth ? editTextWidth : imageWidth;
int imageMaxHeight = blockImageSpanVm.getMaxHeight() > internalImageMaxHeight
? internalImageMaxHeight : blockImageSpanVm.getMaxHeight();
int imageMaxHeight = blockImageSpanVm.getMaxHeight();
int resImageHeight = (int) (originHeight * 1.0 / originWidth * resImageWidth);
resImageHeight = resImageHeight > imageMaxHeight ? imageMaxHeight : resImageHeight;
// 控制显示出来的图片的高度不会大于宽度的2倍
// 控制显示出来的图片的高度不会大于宽度的3倍
double maxHeightWidthRadio = AppConfig.IMAGE_MAX_HEIGHT_WIDTH_RATIO;
resImageHeight = resImageHeight > resImageWidth * maxHeightWidthRadio
? (int) (resImageWidth * maxHeightWidthRadio)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;

import com.yuruiyin.richeditor.R;
import com.yuruiyin.richeditor.config.AppConfig;

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

public BlockImageSpanVm(Context context, T spanObject) {
this.width = (int) context.getResources().getDimension(R.dimen.rich_editor_image_width);
this.maxHeight = (int) context.getResources().getDimension(R.dimen.rich_editor_image_max_height);
this.width = (int) context.getResources().getDimension(R.dimen.rich_editor_default_image_width);
this.maxHeight = (int) (this.width * AppConfig.IMAGE_MAX_HEIGHT_WIDTH_RATIO);
this.spanObject = spanObject;
}

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

public BlockImageSpanVm(T spanObject, int width) {
this.width = width;
this.maxHeight = (int) (width * AppConfig.IMAGE_MAX_HEIGHT_WIDTH_RATIO);
this.spanObject = spanObject;
}

public int getWidth() {
return width;
}
Expand Down
5 changes: 2 additions & 3 deletions richeditor/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
<dimen name="rich_editor_image_span_padding_right">1dp</dimen>
<dimen name="rich_editor_image_span_padding_left">1dp</dimen>

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

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

0 comments on commit 3f713fe

Please sign in to comment.