[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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB