[bugfix]
[滑动图片内存过大后重新decode]
This commit is contained in:
yangyakun
2024-03-28 14:15:21 +08:00
parent 0cfb46e8e9
commit d804bf82e1
7 changed files with 49 additions and 12 deletions

View File

@@ -22,9 +22,12 @@ import android.view.animation.DecelerateInterpolator;
import androidx.annotation.Nullable;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.eagle.core.utilcode.util.ConvertUtils;
import com.mogo.eagle.core.utilcode.util.ThreadUtils;
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
import com.mogo.och.bus.R;
import com.mogo.och.common.module.manager.orderlogmanager.OchChainLogManager;
import me.jessyan.autosize.AutoSizeConfig;
import me.jessyan.autosize.utils.AutoSizeUtils;
@@ -130,9 +133,13 @@ public class SlidePanelView extends View {
textGradient.setLocalMatrix(gradientMatrix);
textPaint.setShader(textGradient);
textPaint.getFontMetrics(blockTextMetrics);
decodeImage();
}
private void decodeImage(){
ThreadUtils.getCpuPool().execute(() -> {
int size = AutoSizeUtils.dp2px(getContext(), 120);
BitmapFactory.Options opts = new BitmapFactory.Options(); //todo yakun 优化
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inDensity = (int) AutoSizeConfig.getInstance().getInitDensity();
bmBlock = BitmapFactory.decodeResource(getResources(), R.drawable.bus_base_slide_block,opts);
bmBlock = Bitmap.createScaledBitmap(bmBlock, size, size, true);
@@ -269,13 +276,24 @@ public class SlidePanelView extends View {
// 画文字
gradientMatrix.setTranslate(matrixTranslate, 0);
textGradient.setLocalMatrix(gradientMatrix);
if(bmBlock!=null) {
canvas.save();
canvas.drawText(blockText, (float) (blockWidth + BLOCK_START_X + textMarginLeft), (float) textOffset, textPaint);
canvas.restore();
// 画滑块
canvas.drawBitmap(bmBlock, (float) (BLOCK_START_X + blockOffset), (float) BLOCK_START_Y, blockPaint);
if (bmBlock != null) {
if(bmBlock.getByteCount()>=5*1024*1024){
OchChainLogManager.writeChainLog("崩溃兜底策略",
"图片大小监听"+ ConvertUtils.byte2FitMemorySize(bmBlock.getByteCount()),true,OchChainLogManager.EVENT_KEY_INFE_ERROR);
bmBlock.recycle();
bmBlock = null;
blockWidth = 0;
decodeImage();
}else {
// 画滑块
canvas.drawBitmap(bmBlock, (float) (BLOCK_START_X + blockOffset), (float) BLOCK_START_Y, blockPaint);
CallerLogger.d(TAG,"图片大小监听"+ ConvertUtils.byte2FitMemorySize(bmBlock.getByteCount()));
}
}
}
public interface OnSlidePanelMoveToEndListener {

View File

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@@ -19,6 +19,8 @@ object OchChainLogManager {
const val EVENT_KEY_INFE_WITH_TRAJECTORY = "event_key_och_trajectory_info"
const val EVENT_KEY_INFE_WITH_MUSIC = "event_key_och_music_info"
const val EVENT_KEY_INFE_WITH_BUS = "event_key_och_bus_info"
// 需要举行观察的
const val EVENT_KEY_INFE_ERROR = "event_key_och_error"
/**
* @param Info 订单详细信息

View File

@@ -22,9 +22,12 @@ import android.view.animation.DecelerateInterpolator;
import androidx.annotation.Nullable;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.eagle.core.utilcode.util.ConvertUtils;
import com.mogo.eagle.core.utilcode.util.ThreadUtils;
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
import com.mogo.och.bus.R;
import com.mogo.och.common.module.manager.orderlogmanager.OchChainLogManager;
import me.jessyan.autosize.AutoSizeConfig;
import me.jessyan.autosize.utils.AutoSizeUtils;
@@ -129,6 +132,10 @@ public class SlidePanelView extends View {
textGradient.setLocalMatrix(gradientMatrix);
textPaint.setShader(textGradient);
textPaint.getFontMetrics(blockTextMetrics);
decodeImage();
}
private void decodeImage(){
ThreadUtils.getCpuPool().execute(() -> {
int size = AutoSizeUtils.dp2px(getContext(), 120);
BitmapFactory.Options opts = new BitmapFactory.Options();
@@ -259,21 +266,31 @@ public class SlidePanelView extends View {
lastX = 0;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// 画背景
canvas.drawRoundRect(bgRectF, (float) getHeight() / 2, (float) getHeight() / 2, bgPaint);
canvas.drawRoundRect(bgRectF, (float) getHeight() / 2.0f, (float) getHeight() / 2.0f, bgPaint);
// 画文字
gradientMatrix.setTranslate(matrixTranslate, 0);
textGradient.setLocalMatrix(gradientMatrix);
if(bmBlock!=null) {
canvas.save();
canvas.drawText(blockText, (float) (blockWidth + BLOCK_START_X + textMarginLeft), (float) textOffset, textPaint);
canvas.restore();
// 画滑块
canvas.drawBitmap(bmBlock, (float) (BLOCK_START_X + blockOffset), (float) BLOCK_START_Y, blockPaint);
canvas.save();
canvas.drawText(blockText, (float) (blockWidth + BLOCK_START_X + textMarginLeft), (float) textOffset, textPaint);
canvas.restore();
if (bmBlock != null) {
if(bmBlock.getByteCount()>=5*1024*1024){
OchChainLogManager.writeChainLog("崩溃兜底策略",
"图片大小监听"+ ConvertUtils.byte2FitMemorySize(bmBlock.getByteCount()),true,OchChainLogManager.EVENT_KEY_INFE_ERROR);
bmBlock.recycle();
bmBlock = null;
blockWidth = 0;
decodeImage();
}else {
// 画滑块
canvas.drawBitmap(bmBlock, (float) (BLOCK_START_X + blockOffset), (float) BLOCK_START_Y, blockPaint);
CallerLogger.d(TAG,"图片大小监听"+ ConvertUtils.byte2FitMemorySize(bmBlock.getByteCount()));
}
}
}
public interface OnSlidePanelMoveToEndListener {

View File

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB