[6.3.0]
[smallmap 对象优化]
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user