From a2ef2bbd443cb45b2b36eb287f533085973c254a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=AE=8F=E5=AE=87?= Date: Fri, 16 Apr 2021 17:53:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=9C=80=E4=BC=98=E8=B7=AF?= =?UTF-8?q?=E7=BA=BF=E7=9A=84=E9=A2=9C=E8=89=B2=E6=A2=AF=E5=BA=A6=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=20=E5=A2=9E=E5=8A=A0=E9=80=BB=E8=BE=91,3D=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=E5=85=B3=E9=97=AD=E9=81=93=E8=B7=AF=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E8=BF=9E=E7=BA=BF=E7=9A=84=E7=BB=98=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/gradle.xml | 1 + .../main/java/com/mogo/utils/ColorUtils.java | 91 +++++++++++-------- .../manager/impl/MoGoV2XPolylineManager.java | 4 +- .../v2x/overlay/V2XOptimalRouteOverlay.java | 17 +++- 4 files changed, 69 insertions(+), 44 deletions(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 83405b8de1..4ff10f68a5 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -91,6 +91,7 @@ diff --git a/foudations/mogo-utils/src/main/java/com/mogo/utils/ColorUtils.java b/foudations/mogo-utils/src/main/java/com/mogo/utils/ColorUtils.java index 8f04e09bb2..0269dd3316 100644 --- a/foudations/mogo-utils/src/main/java/com/mogo/utils/ColorUtils.java +++ b/foudations/mogo-utils/src/main/java/com/mogo/utils/ColorUtils.java @@ -1,5 +1,7 @@ package com.mogo.utils; +import android.graphics.Color; + import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; @@ -12,60 +14,73 @@ import java.util.regex.Pattern; public class ColorUtils { /** - * @return 获取渐变色集合 + * ARGB颜色 转 HEX颜色 */ - public static List gradient(String startColor, String endColor, int step) { - // 将HEX转为RGB - int[] sColor = hexToRgb(startColor); - int[] eColor = hexToRgb(endColor); - - // 计算每一步的差值 - int rStep = (eColor[0] - sColor[0]) / step; - int gStep = (eColor[1] - sColor[1]) / step; - int bStep = (eColor[2] - sColor[2]) / step; - - // 生成渐变色 - List gradientColorArr = new ArrayList<>(); - - for (int i = 0; i < step; i++) { - + public static String argbToHex(int alpha, int red, int green, int blue) { + if (alpha < 0 || alpha > 255 + || red < 0 || red > 255 + || green < 0 || green > 255 + || blue < 0 || blue > 255) { + return ""; } - - return gradientColorArr; + String alphaStr = Integer.toHexString(alpha); + String redStr = Integer.toHexString(red); + String greenStr = Integer.toHexString(green); + String blueStr = Integer.toHexString(blue); + return ("#" + alphaStr + redStr + greenStr + blueStr).toUpperCase(); } - /** - * HEX颜色 转 RGB颜色 + * HEX颜色 转 ARGB颜色 */ - public static int[] hexToRgb(String hex) { - int[] rgb = new int[3]; - if (!Pattern.matches("^#[0-9a-f[A-F]]{6}", hex)) { + public static int[] hexToArgb(String hex) { + int[] rgb = new int[4]; + if (!Pattern.matches("^#[0-9a-f[A-F]]{8}", hex)) { return rgb; } - String redStr = hex.substring(1, 3); - String greenStr = hex.substring(3, 5); - String blueStr = hex.substring(5); + String alphaStr = hex.substring(1, 3); + String redStr = hex.substring(3, 5); + String greenStr = hex.substring(5, 7); + String blueStr = hex.substring(7); - rgb[0] = Integer.valueOf(redStr, 16); - rgb[1] = Integer.valueOf(greenStr, 16); - rgb[2] = Integer.valueOf(blueStr, 16); + rgb[0] = Integer.valueOf(alphaStr, 16); + rgb[1] = Integer.valueOf(redStr, 16); + rgb[2] = Integer.valueOf(greenStr, 16); + rgb[3] = Integer.valueOf(blueStr, 16); return rgb; } /** - * RGB颜色 转 HEX颜色 + * 对传入颜色生成梯度透明的颜色集合 + * + * @param startColor 开始颜色 + * @param startColor 结束颜色 + * @param step 步长 + * @return 生成的梯度颜色集合 */ - public static String rgbToHex(int red, int green, int blue) { - if (red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 - || blue > 255) { - return ""; + public static List gradientAlpha(String startColor, String endColor, int step) { + // 将HEX转为RGB + int[] sColor = hexToArgb(startColor); + int[] eColor = hexToArgb(endColor); + + // 计算每一步的差值 + int aStep = (eColor[0] - sColor[0]) / step; + int rStep = (eColor[1] - sColor[1]) / step; + int gStep = (eColor[2] - sColor[2]) / step; + int bStep = (eColor[3] - sColor[3]) / step; + + // 生成渐变色 + List gradientColorArr = new ArrayList<>(); + + for (int i = 0; i < step; i++) { + gradientColorArr.add( + Color.argb(aStep * i + sColor[0], + rStep * i + sColor[1], + gStep * i + sColor[2], + bStep * i + sColor[3])); } - String redStr = Integer.toHexString(red); - String greenStr = Integer.toHexString(green); - String blueStr = Integer.toHexString(blue); - return ("#" + redStr + greenStr + blueStr).toUpperCase(); + return gradientColorArr; } } diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/manager/impl/MoGoV2XPolylineManager.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/manager/impl/MoGoV2XPolylineManager.java index 4e678071b6..825fba719d 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/manager/impl/MoGoV2XPolylineManager.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/manager/impl/MoGoV2XPolylineManager.java @@ -35,7 +35,9 @@ public class MoGoV2XPolylineManager implements IMoGoV2XPolylineManager { } if ((V2XServiceManager.getMoGoV2XStatusManager().isRoadEventPOIShow() || V2XServiceManager.getMoGoV2XStatusManager().isOtherSeekHelpPOIShow()) - && V2XServiceManager.getV2XStatusManager().getTargetMoGoLatLng() != null) { + && V2XServiceManager.getV2XStatusManager().getTargetMoGoLatLng() != null + && !V2XServiceManager.getMoGoStatusManager().isVrMode() + ) { // 连接线参数 MogoPolylineOptions options = new MogoPolylineOptions(); diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/overlay/V2XOptimalRouteOverlay.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/overlay/V2XOptimalRouteOverlay.java index 05d607611e..f59752afe4 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/overlay/V2XOptimalRouteOverlay.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/overlay/V2XOptimalRouteOverlay.java @@ -6,6 +6,7 @@ import com.mogo.map.overlay.IMogoPolyline; import com.mogo.map.overlay.MogoPolylineOptions; import com.mogo.module.v2x.V2XServiceManager; import com.mogo.module.v2x.utils.LocationUtils; +import com.mogo.utils.ColorUtils; import java.util.ArrayList; import java.util.List; @@ -22,16 +23,15 @@ public class V2XOptimalRouteOverlay { private MogoPolylineOptions mPolylineOptions; // 线路径集合 private List mPolylinePointList; + // 渐变色 + private List mPolylineColors; public V2XOptimalRouteOverlay() { mPolylineOptions = new MogoPolylineOptions(); - // 渐变色 - List colors = new ArrayList<>(); - colors.add(0xFFF95959); - // 线条粗细,渐变,渐变色值 - mPolylineOptions.width(25).useGradient(true).colorValues(colors); // 绘制路径集合 mPolylinePointList = new ArrayList<>(); + // 引导线颜色 + mPolylineColors = new ArrayList<>(); } /** @@ -43,8 +43,10 @@ public class V2XOptimalRouteOverlay { if (mMoGoPolyline != null) { mMoGoPolyline.remove(); mPolylinePointList.clear(); + mPolylineColors.clear(); } if (polylinePoint != null) { + // 将当前车辆位置放进去 mPolylinePointList.add(new MogoLatLng(carLocal.getLatitude(), carLocal.getLongitude())); // 过滤后台推送的推荐路线集合 @@ -54,8 +56,13 @@ public class V2XOptimalRouteOverlay { mPolylinePointList.add(polyline); } } + + mPolylineColors.addAll(ColorUtils.gradientAlpha("#002965ED", "#FF2965ED", mPolylinePointList.size()/2)); + // 替换路径集合 mPolylineOptions.points(mPolylinePointList); + // 线条粗细,渐变,渐变色值 + mPolylineOptions.width(25).useGradient(true).colorValues(mPolylineColors); // 绘制线 mMoGoPolyline = V2XServiceManager.getMogoOverlayManager().addPolyline(mPolylineOptions); }