From 0425608cf0736249459eff22a208e60b3a6cc883 Mon Sep 17 00:00:00 2001 From: yangyakun Date: Wed, 27 Mar 2024 19:54:06 +0800 Subject: [PATCH] =?UTF-8?q?[6.3.0]=20[smallmap=20=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E4=BC=98=E5=8C=96]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../taxi/passenger/ui/simplemap/LineData.kt | 4 +- .../passenger/ui/simplemap/PaintDegree.kt | 49 ++++++++++++++++++ .../passenger/ui/simplemap/SimpleMapView.kt | 50 +++++++++++-------- 3 files changed, 78 insertions(+), 25 deletions(-) create mode 100644 OCH/taxi/pcommon/src/main/java/com/mogo/och/taxi/passenger/ui/simplemap/PaintDegree.kt diff --git a/OCH/taxi/pcommon/src/main/java/com/mogo/och/taxi/passenger/ui/simplemap/LineData.kt b/OCH/taxi/pcommon/src/main/java/com/mogo/och/taxi/passenger/ui/simplemap/LineData.kt index f9e185ffd3..1e27d1e4cc 100644 --- a/OCH/taxi/pcommon/src/main/java/com/mogo/och/taxi/passenger/ui/simplemap/LineData.kt +++ b/OCH/taxi/pcommon/src/main/java/com/mogo/och/taxi/passenger/ui/simplemap/LineData.kt @@ -1,5 +1,3 @@ package com.mogo.och.taxi.passenger.ui.simplemap -import android.graphics.Paint - -data class LineData(val startPoint:NearPointView, val endPoint: NearPointView, val distance:Float, var paint: Paint) +data class LineData(val startPoint:NearPointView, val endPoint: NearPointView, val distance:Float, var paintDegree: PaintDegree) diff --git a/OCH/taxi/pcommon/src/main/java/com/mogo/och/taxi/passenger/ui/simplemap/PaintDegree.kt b/OCH/taxi/pcommon/src/main/java/com/mogo/och/taxi/passenger/ui/simplemap/PaintDegree.kt new file mode 100644 index 0000000000..bbe940f2d5 --- /dev/null +++ b/OCH/taxi/pcommon/src/main/java/com/mogo/och/taxi/passenger/ui/simplemap/PaintDegree.kt @@ -0,0 +1,49 @@ +package com.mogo.och.taxi.passenger.ui.simplemap + +import android.graphics.Paint +import android.graphics.Path +import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger + +data class PaintDegree(var paint: Paint,var path:Path){ + + var next: PaintDegree? = null + + fun recycle() { + synchronized(sPoolSync) { + if (sPoolSize < MAX_POOL_SIZE) { + next = sPool + sPool = this + sPoolSize++ + } + CallerLogger.d("PaintDegree","缓存对象个数${sPoolSize}个") + } + } + + companion object { + var sPoolSync = Any() + private var sPool: PaintDegree? = null + private var sPoolSize = 0 + private var MAX_POOL_SIZE = 20 + + fun obtain(): PaintDegree { + return obtain(null,null) + } + + fun obtain(paint: Paint?,path:Path?): PaintDegree { + synchronized(sPoolSync) { + if (sPool != null) { + val m: PaintDegree = sPool!! + sPool = m.next + m.next = null + sPoolSize-- + CallerLogger.d("PaintDegree","取出一个对象个数${sPoolSize}个") + return m + } + CallerLogger.d("PaintDegree","创建一个对象 ${sPoolSize}个") + + return PaintDegree(paint?:Paint(),path?:Path()) + } + } + } + +} diff --git a/OCH/taxi/pcommon/src/main/java/com/mogo/och/taxi/passenger/ui/simplemap/SimpleMapView.kt b/OCH/taxi/pcommon/src/main/java/com/mogo/och/taxi/passenger/ui/simplemap/SimpleMapView.kt index 568b70f273..2dfb06723c 100644 --- a/OCH/taxi/pcommon/src/main/java/com/mogo/och/taxi/passenger/ui/simplemap/SimpleMapView.kt +++ b/OCH/taxi/pcommon/src/main/java/com/mogo/och/taxi/passenger/ui/simplemap/SimpleMapView.kt @@ -106,7 +106,8 @@ class SimpleMapView : View, SimpleMapViewModel.SimpleMapCallback { "DrawLineView_startPoint", "${startPoint.x}------${startPoint.y}--${startPoint.distance}--------${endPoint.x}------${endPoint.y}----${endPoint.distance}" ) - val path = Path() + val path = lineData.paintDegree.path + path.reset() val D = line4Point[0] val F = line4Point[1] val I = line4Point[2] @@ -118,10 +119,12 @@ class SimpleMapView : View, SimpleMapViewModel.SimpleMapCallback { startPointNextUse = I secondPointNextUse = G path.close() - canvas.drawPath(path,lineData.paint) + canvas.drawPath(path,lineData.paintDegree.paint) + lineData.paintDegree.recycle() }else{ val line4Point = getLine4Point(startPoint, endPoint, false) - val path = Path() + val path = lineData.paintDegree.path + path.reset() path.moveTo(startPointNextUse!!.x,startPointNextUse!!.y) path.lineTo(secondPointNextUse!!.x,secondPointNextUse!!.y) val tempStart = line4Point[0] @@ -130,8 +133,8 @@ class SimpleMapView : View, SimpleMapViewModel.SimpleMapCallback { path.lineTo(tempEnd.x,tempEnd.y) startPointNextUse = tempEnd secondPointNextUse = tempStart - canvas.drawPath(path,lineData.paint) - + canvas.drawPath(path,lineData.paintDegree.paint) + lineData.paintDegree.recycle() } } @@ -141,7 +144,8 @@ class SimpleMapView : View, SimpleMapViewModel.SimpleMapCallback { val endPoint = lineData.endPoint if(index==0) { val line4Point = getLine4Point(startPoint, endPoint, true) - val path = Path() + val path = lineData.paintDegree.path + path.reset() val D = line4Point[0] val F = line4Point[1] val I = line4Point[2] @@ -153,10 +157,12 @@ class SimpleMapView : View, SimpleMapViewModel.SimpleMapCallback { startPointNextUse = I secondPointNextUse = G path.close() - canvas.drawPath(path,lineData.paint) + canvas.drawPath(path,lineData.paintDegree.paint) + lineData.paintDegree.recycle() }else{ val line4Point = getLine4Point(startPoint, endPoint, false) - val path = Path() + val path = lineData.paintDegree.path + path.reset() path.moveTo(startPointNextUse!!.x,startPointNextUse!!.y) path.lineTo(secondPointNextUse!!.x,secondPointNextUse!!.y) val tempStart = line4Point[0] @@ -165,8 +171,8 @@ class SimpleMapView : View, SimpleMapViewModel.SimpleMapCallback { path.lineTo(tempEnd.x,tempEnd.y) startPointNextUse = tempEnd secondPointNextUse = tempStart - canvas.drawPath(path,lineData.paint) - + canvas.drawPath(path,lineData.paintDegree.paint) + lineData.paintDegree.recycle() } } }catch (e:Exception ){ @@ -552,8 +558,8 @@ class SimpleMapView : View, SimpleMapViewModel.SimpleMapCallback { var lastColor = Color.parseColor("#2ED3FF") nextPointList.forEachIndexed { index, triple -> - val paint = Paint() - paint.apply { + val paintegree = PaintDegree.obtain() + paintegree.paint.apply { strokeWidth = 20f isAntiAlias = true } @@ -570,7 +576,7 @@ class SimpleMapView : View, SimpleMapViewModel.SimpleMapCallback { ) as Int if (index == 0) { - paint.shader = LinearGradient( + paintegree.paint.shader = LinearGradient( widthView / 2f, heighView / 2f, triple.x, @@ -582,12 +588,12 @@ class SimpleMapView : View, SimpleMapViewModel.SimpleMapCallback { nextLineData.add( LineData( NearPointView(widthView / 2f, heighView / 2f, 0f), - triple, triple.distance, paint + triple, triple.distance, paintegree ) ) } else { val prePoint = nextPointList[index - 1] - paint.shader = LinearGradient( + paintegree.paint.shader = LinearGradient( prePoint.x, prePoint.y, triple.x, @@ -596,7 +602,7 @@ class SimpleMapView : View, SimpleMapViewModel.SimpleMapCallback { evaluateColor, Shader.TileMode.CLAMP ) - nextLineData.add(LineData(prePoint, triple, triple.distance, paint)) + nextLineData.add(LineData(prePoint, triple, triple.distance, paintegree)) } hasDraw += triple.distance Log.d( @@ -614,8 +620,8 @@ class SimpleMapView : View, SimpleMapViewModel.SimpleMapCallback { hasDraw = 0f lastColor = Color.parseColor("#2ED3FF") prePointList.forEachIndexed { index, triple -> - val paint = Paint() - paint.apply { + val paintegree = PaintDegree.obtain() + paintegree.paint.apply { strokeWidth = 20f isAntiAlias = true color = Color.RED @@ -634,7 +640,7 @@ class SimpleMapView : View, SimpleMapViewModel.SimpleMapCallback { ) as Int if (index == 0) { - paint.shader = LinearGradient( + paintegree.paint.shader = LinearGradient( widthView / 2f, heighView / 2f, triple.x, @@ -646,12 +652,12 @@ class SimpleMapView : View, SimpleMapViewModel.SimpleMapCallback { preLineData.add( LineData( NearPointView(widthView / 2f, heighView / 2f, 0f), - triple, triple.distance, paint + triple, triple.distance, paintegree ) ) } else { val prePoint = prePointList[index - 1] - paint.shader = LinearGradient( + paintegree.paint.shader = LinearGradient( prePoint.x, prePoint.y, triple.x, @@ -660,7 +666,7 @@ class SimpleMapView : View, SimpleMapViewModel.SimpleMapCallback { evaluateColor, Shader.TileMode.CLAMP ) - preLineData.add(LineData(prePoint, triple, triple.distance, paint)) + preLineData.add(LineData(prePoint, triple, triple.distance, paintegree)) } hasDraw += triple.distance Log.d(