/*
 * ********************************************************************************************************************
 *
 *               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.graphics.BitmapFactory
import android.graphics.PointF
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.util.SizeF
import com.fasterxml.jackson.databind.PropertyNamingStrategy
import com.sybotan.android.demo.R
import com.sybotan.android.demo.R.id.graphyView
import com.sybotan.android.demo.entitiies.Revit
import com.sybotan.android.demo.graphy.GraphyWallItem
import com.sybotan.android.graphy.SGraphyScene
import com.sybotan.android.graphy.events.SGraphyViewMoveEvent
import com.sybotan.android.graphy.items.SGraphyClockItem
import com.sybotan.base.utils.SJsonUtil
import kotlinx.android.synthetic.main.activity_graphy.*
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe

class GraphyActivity : AppCompatActivity() {
    companion object {
        private val TAG = GraphyActivity::class.java.name
    }

    val scene = SGraphyScene()

    @Subscribe
    fun test(msg: SGraphyViewMoveEvent) {
        Log.d(TAG, "msg=$msg")

    } // test()
    /**
     * 创建Activity时的回调函数
     *
     * @param   savedInstanceState
     */
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_graphy)
        // 注册eventbus
        EventBus.getDefault().register(this)

        loadWalls()

        val rect1 = scene.addRectItem(10f, 10f, 400f, 300f)
        rect1.moveTo(200f, 500f)
        rect1.zOrder = -1f

        val image = BitmapFactory.decodeResource(resources, R.drawable.ic_launcher123)
        val image1 = scene.addImageItem(image)
        image1.moveTo(300f,600f)


        val image2 = scene.addImageItem(image)
        image2.parent = rect1

        val clock = SGraphyClockItem(SizeF(1000f, 1000f))
        clock.zOrder = 10f
        scene.addItem(clock)

        graphyView.scene = scene

        return
    } // Function onCreate()

    /**
     * 加载墙数据
     */
    private fun loadWalls() {
//        val revit = SJsonUtil.fromJson<Revit>(applicationContext.assets.open("WallDatas.json"), PropertyNamingStrategy.UPPER_CAMEL_CASE)
//        Log.d(TAG, "name=${revit.name}")
//        Log.d(TAG, "${revit.floorDatas!![revit.floorDatas!!.size - 1].lines!!}")
//
//        Log.d(TAG, "line.size=${revit.floorDatas!![revit.floorDatas!!.size - 1].lines!!.size}")
//        //for ( line in revit.floorDatas!![revit.floorDatas!!.size - 1].lines!!) {
//        for ( line in revit.floorDatas!![0].lines!!) {
//            val pointList = ArrayList<PointF>()
//            Log.d(TAG, "point.size=${line.size}")
//            for (t in 0 until  line.size) {
//                val p1 = line[t].split(",")
//                val point = PointF(p1[0].toFloat() * 20  + 12000, -p1[1].toFloat() * 20  -20600)
//                pointList.add(point)
//            }
//            scene.addItem(GraphyWallItem(pointList))
//        }
//        println()

        return
    } // Function loadWalls()

} // Class GraphyActivity
