From 3144d61fd0aa8e48328e6869eeabe854a4b50a96 Mon Sep 17 00:00:00 2001 From: lixiaopeng Date: Fri, 17 Jan 2020 15:24:50 +0800 Subject: [PATCH 1/2] opt --- .../com/mogo/module/tanlu/fragment/TanluCardViewFragment.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/mogo-module-tanlu/src/main/java/com/mogo/module/tanlu/fragment/TanluCardViewFragment.java b/modules/mogo-module-tanlu/src/main/java/com/mogo/module/tanlu/fragment/TanluCardViewFragment.java index 77fcf0ee3a..007b241a4c 100644 --- a/modules/mogo-module-tanlu/src/main/java/com/mogo/module/tanlu/fragment/TanluCardViewFragment.java +++ b/modules/mogo-module-tanlu/src/main/java/com/mogo/module/tanlu/fragment/TanluCardViewFragment.java @@ -955,6 +955,9 @@ public class TanluCardViewFragment extends MvpFragment> * 绘制线路 */ private void drawMapLine(List
pointList) { + //避免人为操作,刷新 + mMogoStatusManager.setUserInteractionStatus(TanluConstants.MODEL_NAME, true, true); + int intervalNum = Utils.getIntervalValue(pointList.size()); Logger.d(TAG, "drawMapLine intervalNum = " + intervalNum + ">>> pointList.size =" + pointList.size()); int listSize = pointList.size(); From 4cdc00641850d4ebc9183eec044fa8a69bbaea37 Mon Sep 17 00:00:00 2001 From: tongchenfei Date: Fri, 17 Jan 2020 15:39:00 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Glide=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E6=97=B6=E4=BD=BF=E5=9B=BE=E7=89=87=E5=8F=98?= =?UTF-8?q?=E6=88=90=E5=9C=86=E8=A7=92=E7=9A=84=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/glide/GlideBlurTransformation.java | 2 +- .../glide/GlideRoundedCornersTransform.java | 169 ++++++++++++++++++ 2 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 foudations/mogo-utils/src/main/java/com/mogo/utils/glide/GlideRoundedCornersTransform.java diff --git a/foudations/mogo-utils/src/main/java/com/mogo/utils/glide/GlideBlurTransformation.java b/foudations/mogo-utils/src/main/java/com/mogo/utils/glide/GlideBlurTransformation.java index 41f1db3614..d8f753a4c9 100644 --- a/foudations/mogo-utils/src/main/java/com/mogo/utils/glide/GlideBlurTransformation.java +++ b/foudations/mogo-utils/src/main/java/com/mogo/utils/glide/GlideBlurTransformation.java @@ -15,7 +15,7 @@ import com.bumptech.glide.load.resource.bitmap.CenterCrop; /** * 使用Glide加载图片时,使该图片进行高斯模糊 * 基本用法:Glide.with(this).load(userInfo.headImgurl).apply(RequestOptions.bitmapTransform(GlideBlurTransformation(this))).into(ivCardBg) - * + * 如果想用多个Transform可以使用{@link com.bumptech.glide.load.MultiTransformation} 进行Transform的融合 * @author tongchenfei */ public class GlideBlurTransformation extends CenterCrop { diff --git a/foudations/mogo-utils/src/main/java/com/mogo/utils/glide/GlideRoundedCornersTransform.java b/foudations/mogo-utils/src/main/java/com/mogo/utils/glide/GlideRoundedCornersTransform.java new file mode 100644 index 0000000000..7d0ad513bb --- /dev/null +++ b/foudations/mogo-utils/src/main/java/com/mogo/utils/glide/GlideRoundedCornersTransform.java @@ -0,0 +1,169 @@ +package com.mogo.utils.glide; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapShader; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.RectF; + +import androidx.annotation.NonNull; + +import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; +import com.bumptech.glide.load.resource.bitmap.CenterCrop; +import com.mogo.utils.BuildConfig; +import com.mogo.utils.R; + +import java.security.MessageDigest; + +/** + * Glide加载图片,使图片变成圆角图片工具 + * 基本用法Glide.with(this).load(imgUrl).apply(RequestOptions.bitmapTransform(GlideRoundedCornersTransform(this))).into(imageView) + * 如果想用多个Transform可以使用{@link com.bumptech.glide.load.MultiTransformation} 进行Transform的融合 + * @author tongchenfei + */ +public class GlideRoundedCornersTransform extends CenterCrop { + private float mRadius; + private CornerType mCornerType; + private static final int VERSION = 1; + private static final String ID = BuildConfig.LIBRARY_PACKAGE_NAME + "GlideRoundedCornersTransform." + VERSION; + private static final byte[] ID_BYTES = ID.getBytes(CHARSET); + + /** + * 待处理的圆角枚举 + */ + public enum CornerType { + ALL, + TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, + TOP, BOTTOM, LEFT, RIGHT, + TOP_LEFT_BOTTOM_RIGHT, + TOP_RIGHT_BOTTOM_LEFT, + TOP_LEFT_TOP_RIGHT_BOTTOM_RIGHT, + TOP_RIGHT_BOTTOM_RIGHT_BOTTOM_LEFT, + TOP_LEFT_TOP_RIGHT + } + + public GlideRoundedCornersTransform(float radius, CornerType cornerType) { + super(); + mRadius = radius; + mCornerType = cornerType; + } + + @Override + protected Bitmap transform(@NonNull BitmapPool pool,@NonNull Bitmap toTransform, int outWidth, int outHeight) { + Bitmap transform = super.transform(pool, toTransform, outWidth, outHeight); + return roundCrop(pool, transform); + } + + private Bitmap roundCrop(BitmapPool pool, Bitmap source) { + if (source == null) { + return null; + } + int width = source.getWidth(); + int height = source.getHeight(); + Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); + + if (result == null) { + result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config + .ARGB_8888); + } + Canvas canvas = new Canvas(result); + Paint paint = new Paint(); + paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader + .TileMode.CLAMP)); + paint.setAntiAlias(true); + + Path path = new Path(); + drawRoundRect(canvas, paint, path, width, height); + + return result; + } + + private void drawRoundRect(Canvas canvas, Paint paint, Path path, int width, int height) { + float[] rids; + switch (mCornerType) { + case ALL: + rids = new float[]{mRadius, mRadius, mRadius, mRadius, mRadius, mRadius, mRadius, mRadius}; + drawPath(rids, canvas, paint, path, width, height); + break; + case TOP_LEFT: + rids = new float[]{mRadius, mRadius, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; + drawPath(rids, canvas, paint, path, width, height); + break; + case TOP_RIGHT: + rids = new float[]{0.0f, 0.0f, mRadius, mRadius, 0.0f, 0.0f, 0.0f, 0.0f}; + drawPath(rids, canvas, paint, path, width, height); + break; + case BOTTOM_RIGHT: + rids = new float[]{0.0f, 0.0f, 0.0f, 0.0f, mRadius, mRadius, 0.0f, 0.0f}; + drawPath(rids, canvas, paint, path, width, height); + break; + case BOTTOM_LEFT: + rids = new float[]{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, mRadius, mRadius}; + drawPath(rids, canvas, paint, path, width, height); + break; + case TOP: + rids = new float[]{mRadius, mRadius, mRadius, mRadius, 0.0f, 0.0f, 0.0f, 0.0f}; + drawPath(rids, canvas, paint, path, width, height); + break; + case BOTTOM: + rids = new float[]{0.0f, 0.0f, 0.0f, 0.0f, mRadius, mRadius, mRadius, mRadius}; + drawPath(rids, canvas, paint, path, width, height); + break; + case LEFT: + rids = new float[]{mRadius, mRadius, 0.0f, 0.0f, 0.0f, 0.0f, mRadius, mRadius}; + drawPath(rids, canvas, paint, path, width, height); + break; + case RIGHT: + rids = new float[]{0.0f, 0.0f, mRadius, mRadius, mRadius, mRadius, 0.0f, 0.0f}; + drawPath(rids, canvas, paint, path, width, height); + break; + case TOP_LEFT_BOTTOM_RIGHT: + rids = new float[]{mRadius, mRadius, 0.0f, 0.0f, mRadius, mRadius, 0.0f, 0.0f}; + drawPath(rids, canvas, paint, path, width, height); + break; + case TOP_RIGHT_BOTTOM_LEFT: + rids = new float[]{0.0f, 0.0f, mRadius, mRadius, 0.0f, 0.0f, mRadius, mRadius}; + drawPath(rids, canvas, paint, path, width, height); + break; + case TOP_LEFT_TOP_RIGHT_BOTTOM_RIGHT: + rids = new float[]{mRadius, mRadius, mRadius, mRadius, mRadius, mRadius, 0.0f, 0.0f}; + drawPath(rids, canvas, paint, path, width, height); + break; + case TOP_RIGHT_BOTTOM_RIGHT_BOTTOM_LEFT: + rids = new float[]{0.0f, 0.0f, mRadius, mRadius, mRadius, mRadius, mRadius, mRadius}; + drawPath(rids, canvas, paint, path, width, height); + break; + case TOP_LEFT_TOP_RIGHT: + rids = new float[]{mRadius, mRadius, mRadius, mRadius, 0.0f, 0.0f, 0.0f, 0.0f}; + drawPath(rids, canvas, paint, path, width, height); + break; + default: + throw new RuntimeException("RoundedCorners type not belong to CornerType"); + } + } + + /** + * @param rids 圆角的半径,依次为左上角xy半径,右上角,右下角,左下角 + */ + private void drawPath(float[] rids, Canvas canvas, Paint paint, Path path, int width, int height) { + path.addRoundRect(new RectF(0, 0, width, height), rids, Path.Direction.CW); + canvas.drawPath(path, paint); + } + + @Override + public boolean equals(Object o) { + return o instanceof GlideRoundedCornersTransform; + } + + @Override + public int hashCode() { + return ID.hashCode(); + } + + @Override + public void updateDiskCacheKey(MessageDigest messageDigest) { + messageDigest.update(ID_BYTES); + } +}