[6.2.6]
[taxi-p] [子线程加载图片]
This commit is contained in:
@@ -22,6 +22,8 @@ import android.view.animation.DecelerateInterpolator;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils;
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
|
||||
import com.mogo.och.bus.R;
|
||||
|
||||
import me.jessyan.autosize.AutoSizeConfig;
|
||||
@@ -128,12 +130,15 @@ public class SlidePanelView extends View {
|
||||
textGradient.setLocalMatrix(gradientMatrix);
|
||||
textPaint.setShader(textGradient);
|
||||
textPaint.getFontMetrics(blockTextMetrics);
|
||||
int size = AutoSizeUtils.dp2px(getContext(), 120);
|
||||
BitmapFactory.Options opts = new BitmapFactory.Options(); //todo yakun 优化
|
||||
opts.inDensity = (int) AutoSizeConfig.getInstance().getInitDensity();
|
||||
bmBlock = BitmapFactory.decodeResource(getResources(), R.drawable.bus_base_slide_block,opts);
|
||||
bmBlock = Bitmap.createScaledBitmap(bmBlock, size, size, true);
|
||||
blockWidth = bmBlock.getWidth();
|
||||
ThreadUtils.getCpuPool().execute(() -> {
|
||||
int size = AutoSizeUtils.dp2px(getContext(), 120);
|
||||
BitmapFactory.Options opts = new BitmapFactory.Options(); //todo yakun 优化
|
||||
opts.inDensity = (int) AutoSizeConfig.getInstance().getInitDensity();
|
||||
bmBlock = BitmapFactory.decodeResource(getResources(), R.drawable.bus_base_slide_block,opts);
|
||||
bmBlock = Bitmap.createScaledBitmap(bmBlock, size, size, true);
|
||||
blockWidth = bmBlock.getWidth();
|
||||
UiThreadHandler.post(this::requestLayout,UiThreadHandler.MODE.QUEUE);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -151,14 +156,16 @@ public class SlidePanelView extends View {
|
||||
textMarginRight = NORMAL_TEXT_MARGIN_RIGHT;
|
||||
}
|
||||
|
||||
if (widthMode == MeasureSpec.AT_MOST) {
|
||||
// 宽度根据图片大小,字符串长度,各种间隔确定
|
||||
// 高度根据图片大小和上下间隔确定
|
||||
textPaint.getTextBounds(blockText, 0, blockText.length(), textRect);
|
||||
widthSize = BLOCK_START_X * 2 + bmBlock.getWidth() + textMarginLeft + textMarginRight + textRect.width();
|
||||
heightSize = BLOCK_START_Y * 2 + bmBlock.getHeight();
|
||||
widthMeasureSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode);
|
||||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, heightMode);
|
||||
if(bmBlock!=null) {
|
||||
if (widthMode == MeasureSpec.AT_MOST) {
|
||||
// 宽度根据图片大小,字符串长度,各种间隔确定
|
||||
// 高度根据图片大小和上下间隔确定
|
||||
textPaint.getTextBounds(blockText, 0, blockText.length(), textRect);
|
||||
widthSize = BLOCK_START_X * 2 + bmBlock.getWidth() + textMarginLeft + textMarginRight + textRect.width();
|
||||
heightSize = BLOCK_START_Y * 2 + bmBlock.getHeight();
|
||||
widthMeasureSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode);
|
||||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, heightMode);
|
||||
}
|
||||
}
|
||||
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
@@ -262,11 +269,13 @@ 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);
|
||||
// 画滑块
|
||||
canvas.drawBitmap(bmBlock, (float) (BLOCK_START_X + blockOffset), (float) BLOCK_START_Y, blockPaint);
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnSlidePanelMoveToEndListener {
|
||||
|
||||
@@ -3,13 +3,24 @@ package com.magic.mogo.och.charter.view
|
||||
import android.animation.ObjectAnimator
|
||||
import android.animation.ValueAnimator
|
||||
import android.content.Context
|
||||
import android.graphics.*
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.LinearGradient
|
||||
import android.graphics.Matrix
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Rect
|
||||
import android.graphics.RectF
|
||||
import android.graphics.Shader
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.animation.DecelerateInterpolator
|
||||
import com.magic.mogo.och.charter.R
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
|
||||
import me.jessyan.autosize.AutoSizeConfig
|
||||
import me.jessyan.autosize.utils.AutoSizeUtils
|
||||
|
||||
@@ -82,12 +93,15 @@ class SlidePanelView @JvmOverloads constructor(
|
||||
textGradient!!.setLocalMatrix(gradientMatrix)
|
||||
textPaint.shader = textGradient
|
||||
textPaint.getFontMetrics(blockTextMetrics)
|
||||
val size = AutoSizeUtils.dp2px(context, 120f)
|
||||
val opts = BitmapFactory.Options()
|
||||
opts.inDensity = AutoSizeConfig.getInstance().initDensity.toInt()
|
||||
bmBlock = BitmapFactory.decodeResource(resources, R.drawable.charter_base_slide_block, opts)
|
||||
bmBlock = Bitmap.createScaledBitmap(bmBlock!!, size, size, true)
|
||||
blockWidth = bmBlock!!.getWidth()
|
||||
ThreadUtils.getIoPool().execute {
|
||||
val size = AutoSizeUtils.dp2px(context, 120f)
|
||||
val opts = BitmapFactory.Options()
|
||||
opts.inDensity = AutoSizeConfig.getInstance().initDensity.toInt()
|
||||
bmBlock = BitmapFactory.decodeResource(resources, R.drawable.charter_base_slide_block, opts)
|
||||
bmBlock = Bitmap.createScaledBitmap(bmBlock!!, size, size, true)
|
||||
blockWidth = bmBlock!!.getWidth()
|
||||
UiThreadHandler.post({ requestLayout() }, UiThreadHandler.MODE.QUEUE)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
@@ -104,15 +118,17 @@ class SlidePanelView @JvmOverloads constructor(
|
||||
textMarginLeft = NORMAL_TEXT_MARGIN_LEFT
|
||||
textMarginRight = NORMAL_TEXT_MARGIN_RIGHT
|
||||
}
|
||||
if (widthMode == MeasureSpec.AT_MOST) {
|
||||
// 宽度根据图片大小,字符串长度,各种间隔确定
|
||||
// 高度根据图片大小和上下间隔确定
|
||||
textPaint.getTextBounds(blockText, 0, blockText.length, textRect)
|
||||
widthSize =
|
||||
BLOCK_START_X * 2 + bmBlock!!.width + textMarginLeft + textMarginRight + textRect.width()
|
||||
heightSize = BLOCK_START_Y * 2 + bmBlock!!.height
|
||||
widthMeasureSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode)
|
||||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, heightMode)
|
||||
if(bmBlock!=null) {
|
||||
if (widthMode == MeasureSpec.AT_MOST) {
|
||||
// 宽度根据图片大小,字符串长度,各种间隔确定
|
||||
// 高度根据图片大小和上下间隔确定
|
||||
textPaint.getTextBounds(blockText, 0, blockText.length, textRect)
|
||||
widthSize =
|
||||
BLOCK_START_X * 2 + bmBlock!!.width + textMarginLeft + textMarginRight + textRect.width()
|
||||
heightSize = BLOCK_START_Y * 2 + bmBlock!!.height
|
||||
widthMeasureSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode)
|
||||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, heightMode)
|
||||
}
|
||||
}
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
||||
}
|
||||
@@ -201,22 +217,24 @@ class SlidePanelView @JvmOverloads constructor(
|
||||
// 画文字
|
||||
gradientMatrix.setTranslate(matrixTranslate, 0f)
|
||||
textGradient!!.setLocalMatrix(gradientMatrix)
|
||||
canvas.save()
|
||||
canvas.drawText(
|
||||
blockText,
|
||||
(blockWidth + BLOCK_START_X + textMarginLeft).toFloat(),
|
||||
textOffset,
|
||||
textPaint
|
||||
)
|
||||
canvas.restore()
|
||||
// 画滑块
|
||||
if(bmBlock!=null) {
|
||||
canvas.save()
|
||||
canvas.drawText(
|
||||
blockText,
|
||||
(blockWidth + BLOCK_START_X + textMarginLeft).toFloat(),
|
||||
textOffset,
|
||||
textPaint
|
||||
)
|
||||
canvas.restore()
|
||||
// 画滑块
|
||||
|
||||
canvas.drawBitmap(
|
||||
bmBlock!!,
|
||||
(BLOCK_START_X + blockOffset).toFloat(),
|
||||
BLOCK_START_Y.toFloat(),
|
||||
blockPaint
|
||||
)
|
||||
canvas.drawBitmap(
|
||||
bmBlock!!,
|
||||
(BLOCK_START_X + blockOffset).toFloat(),
|
||||
BLOCK_START_Y.toFloat(),
|
||||
blockPaint
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
interface OnSlidePanelMoveToEndListener {
|
||||
|
||||
@@ -22,6 +22,8 @@ import android.view.animation.DecelerateInterpolator;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils;
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
|
||||
import com.mogo.och.bus.R;
|
||||
|
||||
import me.jessyan.autosize.AutoSizeConfig;
|
||||
@@ -127,12 +129,15 @@ public class SlidePanelView extends View {
|
||||
textGradient.setLocalMatrix(gradientMatrix);
|
||||
textPaint.setShader(textGradient);
|
||||
textPaint.getFontMetrics(blockTextMetrics);
|
||||
int size = AutoSizeUtils.dp2px(getContext(), 120);
|
||||
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);
|
||||
blockWidth = bmBlock.getWidth();
|
||||
ThreadUtils.getCpuPool().execute(() -> {
|
||||
int size = AutoSizeUtils.dp2px(getContext(), 120);
|
||||
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);
|
||||
blockWidth = bmBlock.getWidth();
|
||||
UiThreadHandler.post(this::requestLayout,UiThreadHandler.MODE.QUEUE);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -149,15 +154,16 @@ public class SlidePanelView extends View {
|
||||
textMarginLeft = NORMAL_TEXT_MARGIN_LEFT;
|
||||
textMarginRight = NORMAL_TEXT_MARGIN_RIGHT;
|
||||
}
|
||||
|
||||
if (widthMode == MeasureSpec.AT_MOST) {
|
||||
// 宽度根据图片大小,字符串长度,各种间隔确定
|
||||
// 高度根据图片大小和上下间隔确定
|
||||
textPaint.getTextBounds(blockText, 0, blockText.length(), textRect);
|
||||
widthSize = BLOCK_START_X * 2 + bmBlock.getWidth() + textMarginLeft + textMarginRight + textRect.width();
|
||||
heightSize = BLOCK_START_Y * 2 + bmBlock.getHeight();
|
||||
widthMeasureSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode);
|
||||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, heightMode);
|
||||
if(bmBlock!=null) {
|
||||
if (widthMode == MeasureSpec.AT_MOST) {
|
||||
// 宽度根据图片大小,字符串长度,各种间隔确定
|
||||
// 高度根据图片大小和上下间隔确定
|
||||
textPaint.getTextBounds(blockText, 0, blockText.length(), textRect);
|
||||
widthSize = BLOCK_START_X * 2 + bmBlock.getWidth() + textMarginLeft + textMarginRight + textRect.width();
|
||||
heightSize = BLOCK_START_Y * 2 + bmBlock.getHeight();
|
||||
widthMeasureSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode);
|
||||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, heightMode);
|
||||
}
|
||||
}
|
||||
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
@@ -261,11 +267,13 @@ public class SlidePanelView extends View {
|
||||
// 画文字
|
||||
gradientMatrix.setTranslate(matrixTranslate, 0);
|
||||
textGradient.setLocalMatrix(gradientMatrix);
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnSlidePanelMoveToEndListener {
|
||||
|
||||
@@ -21,6 +21,8 @@ import android.view.animation.DecelerateInterpolator;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils;
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
|
||||
import com.mogo.och.sweeper.R;
|
||||
|
||||
/**
|
||||
@@ -124,9 +126,11 @@ public class SlidePanelView extends View {
|
||||
textGradient.setLocalMatrix(gradientMatrix);
|
||||
textPaint.setShader(textGradient);
|
||||
textPaint.getFontMetrics(blockTextMetrics);
|
||||
|
||||
bmBlock = BitmapFactory.decodeResource(getResources(), R.drawable.sweeper_base_slide_block);
|
||||
blockWidth = bmBlock.getWidth();
|
||||
ThreadUtils.getCpuPool().execute(() -> {
|
||||
bmBlock = BitmapFactory.decodeResource(getResources(), R.drawable.sweeper_base_slide_block);
|
||||
blockWidth = bmBlock.getWidth();
|
||||
UiThreadHandler.post(this::requestLayout,UiThreadHandler.MODE.QUEUE);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -143,17 +147,17 @@ public class SlidePanelView extends View {
|
||||
textMarginLeft = NORMAL_TEXT_MARGIN_LEFT;
|
||||
textMarginRight = NORMAL_TEXT_MARGIN_RIGHT;
|
||||
}
|
||||
|
||||
if (widthMode == MeasureSpec.AT_MOST) {
|
||||
// 宽度根据图片大小,字符串长度,各种间隔确定
|
||||
// 高度根据图片大小和上下间隔确定
|
||||
textPaint.getTextBounds(blockText, 0, blockText.length(), textRect);
|
||||
widthSize = BLOCK_START_X * 2 + bmBlock.getWidth() + textMarginLeft + textMarginRight + textRect.width();
|
||||
heightSize = BLOCK_START_Y * 2 + bmBlock.getHeight();
|
||||
widthMeasureSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode);
|
||||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, heightMode);
|
||||
if(bmBlock!=null) {
|
||||
if (widthMode == MeasureSpec.AT_MOST) {
|
||||
// 宽度根据图片大小,字符串长度,各种间隔确定
|
||||
// 高度根据图片大小和上下间隔确定
|
||||
textPaint.getTextBounds(blockText, 0, blockText.length(), textRect);
|
||||
widthSize = BLOCK_START_X * 2 + bmBlock.getWidth() + textMarginLeft + textMarginRight + textRect.width();
|
||||
heightSize = BLOCK_START_Y * 2 + bmBlock.getHeight();
|
||||
widthMeasureSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode);
|
||||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, heightMode);
|
||||
}
|
||||
}
|
||||
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
|
||||
@@ -255,11 +259,13 @@ public class SlidePanelView extends View {
|
||||
// 画文字
|
||||
gradientMatrix.setTranslate(matrixTranslate, 0);
|
||||
textGradient.setLocalMatrix(gradientMatrix);
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnSlidePanelMoveToEndListener {
|
||||
|
||||
Reference in New Issue
Block a user