Browse Source

首页地图改用系统配置图标

Frankensteinly 7 tháng trước cách đây
mục cha
commit
09b5debe8d

+ 15 - 0
app/src/main/java/com/grkj/iscs/model/Constants.kt

@@ -54,4 +54,19 @@ object Constants {
     /*************************  虹软ArcSoft  *************************/
     const val APP_ID = "B9dYbnfw5ZDSQjTbN5YTQ16VNUha11vgDQAsqx3t8JLF"
     const val SDK_KEY = "6qqWaHLhMAqsXtqiBZ7imDyzcc7tYpqeBenbv1HWMicc"
+
+    /*************************  作业票类型  *************************/
+    data class TicketType(val type: Int, val key: String)
+
+    private val TICKET_REPAIR = TicketType(0, "icon.permit.maintenance")
+    private val TICKET_PRE_MAINTENANCE = TicketType(1, "icon.permit.pm")
+    private val TICKET_CHANGE_SHIFTS = TicketType(2, "icon.permit.shift")
+    private val TICKET_CLEAN = TicketType(3, "icon.permit.clean")
+    private val TICKET_SWITCH_PRODUCT = TicketType(4, "icon.permit.changeover")
+
+    private val mTicketTypeList = mutableListOf(TICKET_REPAIR, TICKET_PRE_MAINTENANCE, TICKET_CHANGE_SHIFTS, TICKET_CLEAN, TICKET_SWITCH_PRODUCT)
+
+    fun getTicketKey(type: Int?): String? {
+        return mTicketTypeList.find { it.type == type }?.key
+    }
 }

+ 6 - 1
app/src/main/java/com/grkj/iscs/model/vo/ticket/WorkstationTicketListRespVO.kt

@@ -1,5 +1,7 @@
 package com.grkj.iscs.model.vo.ticket
 
+import android.graphics.Bitmap
+
 data class WorkstationTicketListRespVO(
     /** 作业票ID  */
     val ticketId: Long?,
@@ -39,5 +41,8 @@ data class WorkstationTicketListRespVO(
 
     val workstationId: Long?,
 
-    val machineryId: Long?
+    val machineryId: Long?,
+
+    // APP自用
+    var bitmap: Bitmap?
 )

+ 1 - 1
app/src/main/java/com/grkj/iscs/util/ArcSoftUtil.kt

@@ -67,7 +67,7 @@ object ArcSoftUtil {
         val activeFileInfo = ActiveFileInfo()
         val res = FaceEngine.getActiveFileInfo(context, activeFileInfo)
         if (res == ErrorInfo.MOK) {
-            LogUtil.e("initEngine:  getActiveFileInfo: $activeFileInfo")
+            LogUtil.i("initEngine:  getActiveFileInfo: $activeFileInfo")
         }
     }
 

+ 5 - 1
app/src/main/java/com/grkj/iscs/util/BitmapUtil.kt

@@ -61,7 +61,8 @@ object BitmapUtil {
 
     fun loadBitmapFromUrl(
         ctx: Context,
-        url: String,
+        url: String?,
+        placeholder: Int? = null,
         reqWidth: Int? = null,
         reqHeight: Int? = null,
         callback: (Bitmap?) -> Unit
@@ -73,6 +74,9 @@ object BitmapUtil {
             if (reqWidth != null && reqHeight != null) {
                 builder.override(reqWidth, reqHeight)
             }
+            if (placeholder != null) {
+                builder.placeholder(placeholder)
+            }
             builder.listener(object : RequestListener<Bitmap> {
                 override fun onLoadFailed(
                     e: GlideException?,

+ 1 - 1
app/src/main/java/com/grkj/iscs/util/SPUtils.kt

@@ -208,7 +208,7 @@ object SPUtils {
         }
     }
 
-    fun getAttributeValue(context: Context, key: String): String? {
+    fun getAttributeValue(context: Context, key: String?): String? {
         val list = getSystemAttribute(context)
         if (list.isEmpty()) {
             return null

+ 25 - 6
app/src/main/java/com/grkj/iscs/view/fragment/WorkshopFragment.kt

@@ -1,5 +1,6 @@
 package com.grkj.iscs.view.fragment
 
+import android.graphics.Bitmap
 import android.graphics.PointF
 import android.widget.ImageView
 import com.grkj.iscs.R
@@ -8,6 +9,8 @@ import com.grkj.iscs.model.Constants
 import com.grkj.iscs.model.bo.PageChangeBO
 import com.grkj.iscs.model.vo.ticket.WorkstationTicketListRespVO
 import com.grkj.iscs.util.BitmapUtil
+import com.grkj.iscs.util.Executor
+import com.grkj.iscs.util.SPUtils
 import com.grkj.iscs.util.ToastUtils
 import com.grkj.iscs.util.log.LogUtil
 import com.grkj.iscs.view.base.BaseMvpFragment
@@ -26,10 +29,7 @@ class WorkshopFragment(val changePage: (PageChangeBO) -> Unit) :
 
     private lateinit var jobStatisticList: MutableList<JobStatistics>
     private var markLayer: CustomMarkLayer? = null
-    private val mPointList = mutableListOf(
-        CustomPoint(PointF(600f, 260f), "R&R", 8, mutableListOf()),
-        CustomPoint(PointF(800f, 480f), "CCO", 7, mutableListOf())
-    )
+    private val mPointList = mutableListOf<CustomPoint>()
     private var mMapPicWidth = 1
 
     override val viewBinding: FragmentWorkshopBinding
@@ -82,11 +82,30 @@ class WorkshopFragment(val changePage: (PageChangeBO) -> Unit) :
                         }
                         mPointList.forEach { itPoint ->
                             itPoint.ticketList = it.filter { it.workstationId == itPoint.workstationId }.toMutableList()
+                            itPoint.ticketList.forEach { itTicket ->
+                                if (itTicket.ticketType == null) {
+                                    itTicket.bitmap = BitmapUtil.getResizedBitmapFromMipmap(requireContext(), R.mipmap.ticket_type_placeholder, 60, 60)
+                                } else {
+                                    BitmapUtil.loadBitmapFromUrl(
+                                        requireContext(),
+                                        SPUtils.getAttributeValue(requireContext(), Constants.getTicketKey(itTicket.ticketType.toInt())),
+                                        R.mipmap.ticket_type_placeholder,
+                                        60, 60
+                                    ) { itBitmap ->
+                                        itTicket.bitmap = itBitmap ?: BitmapUtil.getResizedBitmapFromMipmap(requireContext(), R.mipmap.ticket_type_placeholder, 60, 60)
+                                    }
+                                }
+                            }
                         }
                         mBinding?.rvStatistics?.adapter?.notifyDataSetChanged()
 
-
-                        mBinding?.mapview?.refresh()
+                        Executor.repeatOnMain({
+                            val isAllBitmapLoaded = mPointList.all { it.ticketList.all { it.bitmap != null } }
+                            if (isAllBitmapLoaded) {
+                                mBinding?.mapview?.refresh()
+                            }
+                            return@repeatOnMain !isAllBitmapLoaded
+                        }, 100, true)
                     }
                 }
             }

+ 12 - 31
app/src/main/java/com/grkj/iscs/view/widget/CustomMarkLayer.kt

@@ -28,12 +28,6 @@ class CustomMarkLayer @JvmOverloads constructor(
     private var btnIndex: Int
     private var currentZoom = 0f
     private var currentDegree = 0f
-    private lateinit var icon: Bitmap
-    private lateinit var iconRepair: Bitmap
-    private lateinit var iconPreMaintenance: Bitmap
-    private lateinit var iconChangeShifts: Bitmap
-    private lateinit var iconClean: Bitmap
-    private lateinit var iconSwitchProduct: Bitmap
 
     init {
         num = -1
@@ -43,12 +37,6 @@ class CustomMarkLayer @JvmOverloads constructor(
 
     private fun initLayer() {
         radiusMark = setValue(10.0f)
-        icon = BitmapFactory.decodeResource(mapView.resources, R.mipmap.map_repair)
-        iconRepair = BitmapFactory.decodeResource(mapView.resources, R.mipmap.map_repair)
-        iconPreMaintenance = BitmapFactory.decodeResource(mapView.resources, R.mipmap.map_pre_maintenance)
-        iconChangeShifts = BitmapFactory.decodeResource(mapView.resources, R.mipmap.map_change_shifts)
-        iconClean = BitmapFactory.decodeResource(mapView.resources, R.mipmap.map_clean)
-        iconSwitchProduct = BitmapFactory.decodeResource(mapView.resources, R.mipmap.map_switch_product)
         paint = Paint()
         paint.isAntiAlias = true
         paint.style = Paint.Style.FILL_AND_STROKE
@@ -81,20 +69,20 @@ class CustomMarkLayer @JvmOverloads constructor(
                 for (j in list.indices) {
                     val ticketX = if (list.size % 2 == 0) { // 偶数个
                         if (j + 1 <= list.size / 2) {
-                            pointList[i].pos.x - icon.width * (list.size / 2 - j - 0.5f) / currentZoom
+                            pointList[i].pos.x - list[j].bitmap!!.width * (list.size / 2 - j - 0.5f) / currentZoom
                         } else {
-                            pointList[i].pos.x + icon.width * (j - list.size / 2 + 0.5f) / currentZoom
+                            pointList[i].pos.x + list[j].bitmap!!.width * (j - list.size / 2 + 0.5f) / currentZoom
                         }
                     } else {    // 奇数个
                         if (j + 1 <= list.size / 2) {
-                            pointList[i].pos.x - icon.width * (list.size / 2 - j) / currentZoom
+                            pointList[i].pos.x - list[j].bitmap!!.width * (list.size / 2 - j) / currentZoom
                         } else {
-                            pointList[i].pos.x + icon.width * (j - list.size / 2) / currentZoom
+                            pointList[i].pos.x + list[j].bitmap!!.width * (j - list.size / 2) / currentZoom
                         }
                     }
                     val rotatedPoint = rotatePoint(
                         ticketX,
-                        pointList[i].pos.y - icon.height / currentZoom,
+                        pointList[i].pos.y - list[j].bitmap!!.height / currentZoom,
                         pointList[i].pos.x,
                         pointList[i].pos.y,
                         currentDegree
@@ -106,7 +94,7 @@ class CustomMarkLayer @JvmOverloads constructor(
                         rotatedPoint.second
                     )
 
-                    if (distance <= icon.width / 2 / currentZoom) {
+                    if (distance <= list[j].bitmap!!.width / 2 / currentZoom) {
                         num = i
                         btnIndex = j
                         isClickMark = true
@@ -178,29 +166,22 @@ class CustomMarkLayer @JvmOverloads constructor(
                     if (list.isNotEmpty()) {
                         for (j in list.indices) {
                             canvas.drawBitmap(
-                                when(list[j].ticketType) {
-                                    "0" -> iconRepair
-                                    "1" -> iconPreMaintenance
-                                    "2" -> iconChangeShifts
-                                    "3" -> iconClean
-                                    "4" -> iconSwitchProduct
-                                    else -> iconRepair
-                                },
+                                list[j].bitmap!!,
                                 // 偶数个
                                 if (list.size % 2 == 0) {
                                     if (j + 1 <= list.size / 2) {
-                                        goal[0] - icon.width * (list.size / 2 - j)
+                                        goal[0] - list[j].bitmap!!.width * (list.size / 2 - j)
                                     } else {
-                                        goal[0] + icon.width * (j - list.size / 2)
+                                        goal[0] + list[j].bitmap!!.width * (j - list.size / 2)
                                     }
                                 } else {    // 奇数个
                                     if (j + 1 <= list.size / 2) {
-                                        goal[0] - icon.width * (list.size / 2 - j + 0.5f)
+                                        goal[0] - list[j].bitmap!!.width * (list.size / 2 - j + 0.5f)
                                     } else {
-                                        goal[0] + icon.width * (j - list.size / 2 - 0.5f)
+                                        goal[0] + list[j].bitmap!!.width * (j - list.size / 2 - 0.5f)
                                     }
                                 },
-                                goal[1] - icon.height / 2 * 3,
+                                goal[1] - list[j].bitmap!!.height / 2 * 3,
                                 paint
                             )
                         }

+ 0 - 3
app/src/main/java/com/grkj/iscs/view/widget/CustomStationLayer.kt

@@ -1,8 +1,6 @@
 package com.grkj.iscs.view.widget
 
-import android.content.Context
 import android.graphics.Bitmap
-import android.graphics.BitmapFactory
 import android.graphics.Canvas
 import android.graphics.Color
 import android.graphics.Matrix
@@ -17,7 +15,6 @@ import com.onlylemi.mapview.library.layer.MapBaseLayer
 import kotlin.math.cos
 import kotlin.math.sin
 
-
 class CustomStationLayer @JvmOverloads constructor(
     mapView: MapView?,
     private var pointList: List<IsolationPoint> = mutableListOf()

BIN
app/src/main/res/mipmap/ticket_type_placeholder.png