From cfe262eee2723e02a2a07475eac94a88b800488a Mon Sep 17 00:00:00 2001 From: chenjuntao Date: Mon, 17 Apr 2023 17:13:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=82=AC=E6=B5=AE?= =?UTF-8?q?=E7=AA=97=E5=9B=BE=E7=89=87=E5=A4=A7=E5=B0=8F=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E6=82=AC=E6=B5=AE=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=9B=B4=E6=94=B9=E4=B8=BA1=E7=A7=92=20https?= =?UTF-8?q?://jira.shanqu.cc/browse/GHZS-2074?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../floatingwindow/FloatingWindowManager.kt | 9 ++++---- .../common/view/WrapContentDraweeView.kt | 23 ++++++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/feature/floating-window/src/main/java/com/gh/gamecenter/floatingwindow/FloatingWindowManager.kt b/feature/floating-window/src/main/java/com/gh/gamecenter/floatingwindow/FloatingWindowManager.kt index a113bdb1f9..7ed4b4259d 100644 --- a/feature/floating-window/src/main/java/com/gh/gamecenter/floatingwindow/FloatingWindowManager.kt +++ b/feature/floating-window/src/main/java/com/gh/gamecenter/floatingwindow/FloatingWindowManager.kt @@ -53,7 +53,7 @@ internal object FloatingWindowManager { private const val WINDOW_ACTION_EXPAND = 4 - private const val EXPAND_DELAY = 500L + private const val EXPAND_DELAY = 1000L private const val SHRINK_AND_EXPAND_ANIMATION_DURATION = 300L private val TAG_VIEW_STATUS = com.gh.gamecenter.common.R.string.app_name @@ -221,8 +221,8 @@ internal object FloatingWindowManager { } } - // 限制最大宽度为 65dp,避免加载过大图片,比实际显示略大一点点,方便后续根据图片大小进行处理 - iv?.setTag(ImageUtils.TAG_TARGET_WIDTH, 65F.dip2px()) + // 限制最大宽度为 256dp,后续根据图片大小进行处理 + iv?.setTag(ImageUtils.TAG_TARGET_WIDTH, 256F.dip2px()) // 添加加载回调,避免网络差出现图片没有但是有关闭按钮的情况 iv?.loadingCallback = object : WrapContentDraweeView.LoadingCallback { override fun loaded() { @@ -231,7 +231,8 @@ internal object FloatingWindowManager { } } } - iv?.setMaxAndMinSizeLimit(64F.dip2px(), 48F.dip2px()) + iv?.setMaxAndMinSizeLimit(64, 48) + iv?.setSubsampleSize(4) ImageUtils.display(iv, entity.image) view?.setOnClickListener { diff --git a/module_common/src/main/java/com/gh/gamecenter/common/view/WrapContentDraweeView.kt b/module_common/src/main/java/com/gh/gamecenter/common/view/WrapContentDraweeView.kt index efdf56a569..48b332e214 100644 --- a/module_common/src/main/java/com/gh/gamecenter/common/view/WrapContentDraweeView.kt +++ b/module_common/src/main/java/com/gh/gamecenter/common/view/WrapContentDraweeView.kt @@ -10,6 +10,7 @@ import com.facebook.drawee.controller.BaseControllerListener import com.facebook.drawee.interfaces.DraweeController import com.facebook.drawee.view.SimpleDraweeView import com.facebook.imagepipeline.image.ImageInfo +import com.gh.gamecenter.common.utils.dip2px class WrapContentDraweeView @JvmOverloads constructor( context: Context, @@ -22,10 +23,12 @@ class WrapContentDraweeView @JvmOverloads constructor( // 可显示的最大和最小尺寸 private var mMaxSize = -1 private var mMinSize = -1 + // 切换成可显示的最大和最小尺寸前是否需要除以固定的值 + private var mSubsampleSize = 1 // we set a listener and update the view's aspect ratio depending on the loaded image private val mListener = object : BaseControllerListener() { - override fun onIntermediateImageSet(id: String?, @Nullable imageInfo: ImageInfo?) { + override fun onIntermediateImageSet(id: String?, imageInfo: ImageInfo?) { if (mMaxSize != -1) { resizeToFitMaximumOrMinimumSize(imageInfo) } @@ -35,7 +38,7 @@ class WrapContentDraweeView @JvmOverloads constructor( loadingCallback?.loaded() } - override fun onFinalImageSet(id: String?, @Nullable imageInfo: ImageInfo?, @Nullable animatable: Animatable?) { + override fun onFinalImageSet(id: String?, imageInfo: ImageInfo?, animatable: Animatable?) { if (mMaxSize != -1) { resizeToFitMaximumOrMinimumSize(imageInfo) } @@ -52,12 +55,20 @@ class WrapContentDraweeView @JvmOverloads constructor( /** * 设置最大和最小尺寸 + * 单位为 dp */ fun setMaxAndMinSizeLimit(maxSize: Int, minSize: Int) { mMaxSize = maxSize mMinSize = minSize } + /** + * 取样的倍率(如传入值为 4 即表示取原图的 1/4 作为小样) + */ + fun setSubsampleSize(subsampleSize: Int) { + mSubsampleSize = subsampleSize + } + /** * 根据设置的最大和最小尺寸来改变的显示大小 * @@ -68,8 +79,8 @@ class WrapContentDraweeView @JvmOverloads constructor( private fun resizeToFitMaximumOrMinimumSize(imageInfo: ImageInfo?) { imageInfo ?: return - val originalImageHeight = imageInfo.height - val originalImageWidth = imageInfo.width + val originalImageHeight = imageInfo.height / mSubsampleSize + val originalImageWidth = imageInfo.width / mSubsampleSize var resizedImageHeight = originalImageHeight var resizedImageWidth = originalImageHeight @@ -97,8 +108,8 @@ class WrapContentDraweeView @JvmOverloads constructor( } updateLayoutParams { - height = resizedImageHeight - width = resizedImageWidth + height = resizedImageHeight.toFloat().dip2px() + width = resizedImageWidth.toFloat().dip2px() } }