|
@@ -0,0 +1,337 @@
|
|
|
+/*
|
|
|
+ * ********************************************************************************************************************
|
|
|
+ *
|
|
|
+ * iFHS7.
|
|
|
+ * ;BBMBMBMc rZMBMBR BMB
|
|
|
+ * MBEr:;PBM, 7MBMMEOBB: BBB RBW
|
|
|
+ * XK: BO SB. :SZ MBM. c;; ir BBM :FFr :SSF: ;xBMB:r iuGXv. i:. iF2;
|
|
|
+ * DBBM0r. :D S7 ;XMBMB GMBMu. MBM: BMB MBMBBBMBMS WMBMBMBBK MBMBMBM BMBRBMBW .MBMBMBMBB
|
|
|
+ * :JMRMMD .. , 1MMRM1; ;MBMBBR: MBM ;MB: BMB: MBM. RMBr sBMH BM0 UMB, BMB. KMBv
|
|
|
+ * ;. XOW B1; :uM: 1RE, i .2BMBs rMB. MBO MBO JMB; MBB MBM BBS 7MBMBOBM: MBW :BMc
|
|
|
+ * OBRJ.SEE MRDOWOR, 3DE:7OBM . ;BMB RMR7BM BMB MBB. BMB ,BMR .BBZ MMB rMB, BMM rMB7
|
|
|
+ * :FBRO0D0 RKXSXPR. JOKOOMPi BMBSSWBMB; BMBB: MBMB0ZMBMS .BMBOXRBMB MBMDE RBM2;SMBM; MBB xBM2
|
|
|
+ * iZGE O0SHSPO. uGZ7. sBMBMBDL :BMO OZu:BMBK, rRBMB0; ,EBMB xBMBr:ER. RDU :OO;
|
|
|
+ * ,BZ, 1D0 RPSFHXR. xWZ .SMr . .BBB
|
|
|
+ * :0BMRDG RESSSKR. 2WOMBW; BMBMR
|
|
|
+ * i0BM: SWKHKGO MBDv
|
|
|
+ * .UB OOGDM. MK, Copyright (c) 2015-2019. 斯伯坦机器人
|
|
|
+ * , XMW ..
|
|
|
+ * r All rights reserved.
|
|
|
+ *
|
|
|
+ * ********************************************************************************************************************
|
|
|
+ */
|
|
|
+
|
|
|
+package com.sybotan.android.demo.activities
|
|
|
+
|
|
|
+import android.annotation.SuppressLint
|
|
|
+import android.graphics.PointF
|
|
|
+import android.os.Bundle
|
|
|
+import android.view.Gravity
|
|
|
+import android.widget.*
|
|
|
+import cn.sagacloud.android.cadengine.FloorScene
|
|
|
+import cn.sagacloud.android.cadengine.Lasso
|
|
|
+import cn.sagacloud.android.cadengine.items.*
|
|
|
+import cn.sagacloud.android.cadengine.types.*
|
|
|
+import cn.sagacloud.android.cadengine.types.Space
|
|
|
+import com.framework.mvvm.model.db.entity.task.InfosforBuild
|
|
|
+import com.framework.mvvm.model.db.entity.task.ObjectEntity
|
|
|
+import com.google.gson.Gson
|
|
|
+import com.sybotan.android.demo.R
|
|
|
+import com.sybotan.android.demo.bean.RelConfigEntityPackClass
|
|
|
+import com.sybotan.android.demo.bean.SpaceInfo
|
|
|
+import com.sybotan.android.demo.bean.SpaceNameModel
|
|
|
+import com.sybotan.android.demo.bean.result.*
|
|
|
+import com.sybotan.android.demo.entitiies.Floor
|
|
|
+import com.sybotan.android.demo.retrofit.Constant
|
|
|
+import com.sybotan.android.demo.tools.CommonUtils
|
|
|
+import com.sybotan.android.demo.tools.ToastUtils
|
|
|
+import com.sybotan.android.demo.view.SelectListSinglePopupWindow
|
|
|
+import com.sybotan.android.demo.viewmodel.ChooseSpaceVM
|
|
|
+import com.sybotan.android.graphy.SGraphyView
|
|
|
+import com.sybotan.base.utils.SJsonUtil
|
|
|
+import org.jetbrains.anko.doAsync
|
|
|
+import org.jetbrains.anko.uiThread
|
|
|
+import org.kodein.di.DI
|
|
|
+import org.kodein.di.DIAware
|
|
|
+import org.kodein.di.android.closestDI
|
|
|
+import java.lang.StringBuilder
|
|
|
+import kotlin.collections.ArrayList
|
|
|
+
|
|
|
+/**
|
|
|
+ * 平面图选择空间
|
|
|
+ */
|
|
|
+class ChooseSpaceActivity : BaseActivity(), DIAware {
|
|
|
+
|
|
|
+ override val di: DI by closestDI()
|
|
|
+
|
|
|
+ /** viewModel */
|
|
|
+ lateinit var chooseSpaceVM: ChooseSpaceVM
|
|
|
+
|
|
|
+ /** 建筑Id */
|
|
|
+ private lateinit var buildingId: String
|
|
|
+
|
|
|
+ /** 楼层Id */
|
|
|
+ private lateinit var floorId: String
|
|
|
+ private lateinit var projectId: String
|
|
|
+ private lateinit var deviceId: String
|
|
|
+ private var scale: Float = 0f
|
|
|
+ private lateinit var area: ServeAreaItem
|
|
|
+ private lateinit var centerPoint: PointF
|
|
|
+ private lateinit var position: Position
|
|
|
+ var tunableSpaceList = ArrayList<TunableSpaceItem>()
|
|
|
+ var spaceIdList = ArrayList<String>()
|
|
|
+
|
|
|
+ /** 楼层地图 */
|
|
|
+ private lateinit var floorMap: String
|
|
|
+
|
|
|
+ var scene = FloorScene()
|
|
|
+ private val gson = Gson()
|
|
|
+ private lateinit var floors: ArrayList<Floor>
|
|
|
+ private lateinit var groupRelConfigEntity: RelConfigEntityPackClass
|
|
|
+
|
|
|
+ private lateinit var graphyView: SGraphyView
|
|
|
+ private lateinit var close: TextView
|
|
|
+ private lateinit var save: TextView
|
|
|
+ private lateinit var floorTv: TextView
|
|
|
+ private lateinit var spaceName: TextView
|
|
|
+ private lateinit var root: LinearLayout
|
|
|
+ private lateinit var spaces: ArrayList<ObjectEntity>
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建Activity时的回调函数
|
|
|
+ *
|
|
|
+ * @param savedInstanceState
|
|
|
+ */
|
|
|
+ override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
+ super.onCreate(savedInstanceState)
|
|
|
+ setContentView(R.layout.activity_choose_space)
|
|
|
+ initView()
|
|
|
+
|
|
|
+ /** 初始化数据 */
|
|
|
+ initData()
|
|
|
+ graphyView.scene = scene
|
|
|
+
|
|
|
+ /** 点击监听 */
|
|
|
+ initListener()
|
|
|
+ /** 图形点击-poc业务 */
|
|
|
+ initSingleTopUp()
|
|
|
+ /** 网络请求回调处理 */
|
|
|
+ initViewModel()
|
|
|
+
|
|
|
+ return
|
|
|
+ } // Function onCreate()
|
|
|
+
|
|
|
+
|
|
|
+ private fun initView() {
|
|
|
+ graphyView = findViewById(R.id.graphyView)
|
|
|
+ close = findViewById(R.id.close)
|
|
|
+ save = findViewById(R.id.save)
|
|
|
+ floorTv = findViewById(R.id.floorTv)
|
|
|
+ root = findViewById(R.id.root)
|
|
|
+ spaceName = findViewById(R.id.spaceName)
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化数据
|
|
|
+ */
|
|
|
+ private fun initData() {
|
|
|
+ val params = intent.getBundleExtra("params")!!
|
|
|
+ buildingId = params.getString("buildingId", "")!!
|
|
|
+ floorId = params.getString("floorId", "")!!
|
|
|
+ floorMap = params.getString("floorMap", "")!!
|
|
|
+ projectId = params.getString("projectId", "")!!
|
|
|
+ deviceId = params.getString("deviceId", "")!!
|
|
|
+ scale = params.getFloat("scale")!!
|
|
|
+ centerPoint = params.getParcelable("centerPoint")!!
|
|
|
+ groupRelConfigEntity = (params.getSerializable("groupRelConfigEntity") as RelConfigEntityPackClass?)!!
|
|
|
+ position = (params.getSerializable("position") as Position?)!!
|
|
|
+ val p = Point()
|
|
|
+ p.mX = position.x.toFloat()
|
|
|
+ p.mY = position.y.toFloat()
|
|
|
+ val equipItem = EquipItem(this, p)
|
|
|
+ equipItem.zOrder = 100000f
|
|
|
+ scene.addItem(equipItem)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 图形点击事件
|
|
|
+ * */
|
|
|
+ private fun initSingleTopUp() {
|
|
|
+ scene.setOnSingleTopUp(object : FloorScene.OnSingleTopUp {
|
|
|
+ @SuppressLint("SetJavaScriptEnabled")
|
|
|
+ override fun onSingUp(x: Float, y: Float) {
|
|
|
+
|
|
|
+ for (space in tunableSpaceList) {
|
|
|
+ val isContain = Lasso.isPolygonContainsPoint(space.mPoints, android.graphics.Point(x.toInt(), -y.toInt()))
|
|
|
+ if (isContain && space.data.floorName == floorTv.text.toString()) {
|
|
|
+ scene.removeItem(space)
|
|
|
+ tunableSpaceList.remove(space)
|
|
|
+ initSpaceName()
|
|
|
+ for (sp in spaces) {
|
|
|
+ val info = gson.fromJson(sp.infos, SpaceInfo::class.java)
|
|
|
+ val isContains = Lasso.isPolygonContainsPointZ(info.outline!![0][0], android.graphics.Point(x.toInt(), -y.toInt()))
|
|
|
+ if (isContains) {
|
|
|
+ if (spaceIdList.contains(sp.id)) {
|
|
|
+ spaceIdList.remove(sp.id)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (space in scene.spaceList) {
|
|
|
+ val isContain = Lasso.isPolygonContainsPoint(space.mPoints, android.graphics.Point(x.toInt(), -y.toInt()))
|
|
|
+ if (isContain) {
|
|
|
+ val tunableSpace = TunableSpace()
|
|
|
+ tunableSpace.outLine = space.data.outLine
|
|
|
+ tunableSpace.name = space.data.name
|
|
|
+ tunableSpace.floorName = floorTv.text.toString()
|
|
|
+ tunableSpace.floorId = floorId
|
|
|
+ val item = TunableSpaceItem(tunableSpace)
|
|
|
+ item.zOrder = 99996f
|
|
|
+ tunableSpaceList.add(item)
|
|
|
+ scene.addItem(item)
|
|
|
+ initSpaceName()
|
|
|
+ for (sp in spaces) {
|
|
|
+ val obj = sp.infos!!.asJsonObject
|
|
|
+ val info = gson.fromJson(obj, SpaceInfo::class.java)
|
|
|
+ val isContains = Lasso.isPolygonContainsPointZ(info!!.outline!![0][0], android.graphics.Point(x.toInt(), -y.toInt()))
|
|
|
+ if (isContains) {
|
|
|
+ spaceIdList.add(sp.id)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面全部监听事件
|
|
|
+ */
|
|
|
+ private fun initListener() {
|
|
|
+ floorTv.setOnClickListener {
|
|
|
+ val pop = SelectListSinglePopupWindow(this)
|
|
|
+ pop.setGenList(floors, Constant.TYPE5)
|
|
|
+ pop.setTitle(true, "选择对象")
|
|
|
+ pop.showAtLocation(root, Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL, 0, 0)
|
|
|
+ pop.setOnItemClickListener {
|
|
|
+ val floor = floors[it]
|
|
|
+ floorTv.text = floor.localName
|
|
|
+ floorId = floor.id
|
|
|
+ chooseSpaceVM.getFloorMap(floorId)
|
|
|
+ chooseSpaceVM.getSpaces(floorId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ close.setOnClickListener { finish() }
|
|
|
+ save.setOnClickListener {
|
|
|
+ if (CommonUtils.IsNull(tunableSpaceList)) {
|
|
|
+ ToastUtils.showMyToast("请绘制服务区域")
|
|
|
+ return@setOnClickListener
|
|
|
+ }
|
|
|
+ chooseSpaceVM.insRel(deviceId, spaceIdList, groupRelConfigEntity)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化viewModel
|
|
|
+ */
|
|
|
+ private fun initViewModel() {
|
|
|
+ chooseSpaceVM = ChooseSpaceVM(this.application, { name, params ->
|
|
|
+ when (name) {
|
|
|
+ /** 加载地图 */
|
|
|
+ ChooseSpaceVM.MAP_LOAD -> {
|
|
|
+ val floorOfflineData = gson.fromJson(params.toString(), FloorData::class.java)
|
|
|
+ doAsync {
|
|
|
+ scene.loadData(floorOfflineData)
|
|
|
+ uiThread {
|
|
|
+ graphyView.setCenterPoint(centerPoint, scale)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 物业空间 */
|
|
|
+ ChooseSpaceVM.SERVE_AREAS -> {
|
|
|
+ val param = params as ArrayList<TunableSpace>
|
|
|
+ for (space in param) {
|
|
|
+ spaceIdList.add(space.id!!)
|
|
|
+ val item = TunableSpaceItem(space)
|
|
|
+ item.zOrder = 99996f
|
|
|
+ if (space.floorId == floorId) {
|
|
|
+ scene.addItem(item)
|
|
|
+ }
|
|
|
+ tunableSpaceList.add(item)
|
|
|
+ }
|
|
|
+ initSpaceName()
|
|
|
+ }
|
|
|
+ ChooseSpaceVM.FLOORS_LIST -> {
|
|
|
+ floors = params as ArrayList<Floor>
|
|
|
+ for (floor in floors) {
|
|
|
+ if (floorId == floor.id) {
|
|
|
+ floorTv.setText(floor.localName)
|
|
|
+ chooseSpaceVM.getSpaces(floorId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ChooseSpaceVM.FLOOR_MAP -> {
|
|
|
+ val floorOfflineData = SJsonUtil.fromJson(params.toString(), FloorData::class.java)
|
|
|
+ doAsync {
|
|
|
+ scene = FloorScene()
|
|
|
+ graphyView.scene = scene
|
|
|
+ scene.loadData(floorOfflineData!!)
|
|
|
+ uiThread {
|
|
|
+ initSingleTopUp()
|
|
|
+ for (space in tunableSpaceList) {
|
|
|
+ if (space.data.floorId == floorId) {
|
|
|
+ scene.addItem(space)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ initSpaceName()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ChooseSpaceVM.SPACES -> {
|
|
|
+ spaces = params as ArrayList<ObjectEntity>
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }, this, buildingId, floorId, projectId)
|
|
|
+ chooseSpaceVM.getMap()
|
|
|
+ chooseSpaceVM.getFloorList()
|
|
|
+ chooseSpaceVM.getRel(deviceId, groupRelConfigEntity)
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun initSpaceName() {
|
|
|
+ val sb = StringBuilder()
|
|
|
+ val others = ArrayList<SpaceNameModel>()
|
|
|
+ sb.append(floorTv.text.toString()).append(":")
|
|
|
+ for (space in tunableSpaceList) {
|
|
|
+ if (space.data.floorName == floorTv.text.toString()) {
|
|
|
+ sb.append(space.data.name).append("、")
|
|
|
+ } else {
|
|
|
+ var has = false
|
|
|
+ for (other in others) {
|
|
|
+ if (other.name == space.data.floorName) {
|
|
|
+ other.size++
|
|
|
+ has = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!has) {
|
|
|
+ others.add(SpaceNameModel(space.data.floorName, 1))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sb.append("\n\n其他层:\n")
|
|
|
+ for (other in others) {
|
|
|
+ sb.append("${other.name}(${other.size})、")
|
|
|
+ }
|
|
|
+ spaceName.text = sb.toString()
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+} // Class GraphyActivity
|