package com.example.tfat.myapplication

import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager
import android.os.Bundle
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.support.v7.widget.RecyclerView
import android.util.Log
import android.view.View
import android.view.WindowManager
import android.widget.ImageView
import android.widget.RelativeLayout
import com.example.tfat.myapplication.controlbar.ControlBarView
import com.example.tfat.myapplication.navigationbar.NavigationBarView
import com.example.tfat.myapplication.navigationbar.actor.ActorAdapter
import com.example.tfat.myapplication.navigationbar.scene.AddSceneAdapter
import com.example.tfat.myapplication.navigationbar.scene.AddSceneView
import com.example.tfat.myapplication.navigationbar.scene.ControlSceneView
import com.example.tfat.myapplication.navigationbar.scene.SceneAdapter
import com.bomostory.sceneeditmodule.navigationbar.actor.SelectActorView
import org.json.JSONException
import org.json.JSONObject
import org.json.JSONArray
import android.os.Handler



class SceneEditActivity : AppCompatActivity() {
    private lateinit var currentSceneView : SceneView
    private var currentSceneIndex = 0
    private var sceneData = ArrayList<JSONObject>()
    private var resourceThemeBitmap = ArrayList<Int>()
    private var resourceActorBitmap = ArrayList<ArrayList<Int>>()
    private lateinit var sceneAdapter : SceneAdapter
    private lateinit var sceneEditView : RelativeLayout
    private lateinit var viewContainer :  RelativeLayout
    private lateinit var selectActorView : SelectActorView
    private lateinit var controlBarView : ControlBarView
    private lateinit var navigationBar : RelativeLayout
    private lateinit var startRecord : ImageView
    private var isRecord = false

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_scene_edit)
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN)
        actionBar?.hide()
        supportActionBar?.hide()
        viewContainer = findViewById(R.id.view_container)
        controlBarView = findViewById(R.id.control_bar_view)
        navigationBar = findViewById(R.id.navigation_bar)
        sceneEditView = findViewById(R.id.scene_edit_view)
        startRecord = findViewById(R.id.start_record)
        initThemeResource()
        initActorResource()
        currentSceneView = SceneView(this, initLayerViewList(), R.drawable.hill, false)
        sceneData.add(currentSceneIndex, sceneToJSONObject(currentSceneView))
        sceneEditView.addView(currentSceneView)
        initControlBarView(currentSceneView)
        initNavigationBarView()
        startRecord.setOnClickListener(View.OnClickListener {
            if(!isRecord){
                currentSceneView.setOnTouchListener(currentSceneView.onTouchBoMoSceneListener)
                for (actorView in currentSceneView.getAllActor()) actorView.setOnTouchListener(null)
                controlBarView.setBtnSelected(5)
                startRecord.setImageDrawable(resources.getDrawable(R.drawable.ic_btn_record_stop))
                viewContainer.removeAllViews()
                navigationBar.visibility = View.INVISIBLE
                controlBarView.visibility = View.INVISIBLE
                isRecord = true
                currentSceneView.setMode(true)
                currentSceneView.startRecordTime(System.currentTimeMillis())
            } else {
                startRecord.setImageDrawable(resources.getDrawable(R.drawable.ic_btn_record))
                navigationBar.visibility = View.VISIBLE
                controlBarView.visibility = View.VISIBLE
                currentSceneView.saveRecord()
                isRecord = false
                currentSceneView.setMode(false)
                currentSceneView.setonClickPlayListener(View.OnClickListener {
                    preView()
                })
                navigationBar.visibility = View.INVISIBLE
                initControlSceneView()
                currentSceneView.endRecordTime(System.currentTimeMillis())
            }
        })
    }

    override fun onResume() {
        super.onResume()
        window.decorView.apply {
            systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    or View.SYSTEM_UI_FLAG_FULLSCREEN
                    or View.SYSTEM_UI_FLAG_LOW_PROFILE
                    or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
        }
    }

    private fun drawableToBitmap(drawable: Drawable): Bitmap {
        if (drawable is BitmapDrawable) {
            return drawable.bitmap
        }
        val bitmap = Bitmap.createBitmap(drawable.intrinsicWidth, drawable.intrinsicHeight, Bitmap.Config.ARGB_8888)
        val canvas = Canvas(bitmap)
        drawable.setBounds(0, 0, canvas.width, canvas.height)
        drawable.draw(canvas)
        return bitmap
    }

    private fun initLayer(actorViewList: ArrayList<ActorView>): LayerView {
        return LayerView(this, actorViewList)
    }

    private fun initNewLayer(): LayerView {
        return LayerView(this)
    }

    private fun initLayerViewList(): ArrayList<LayerView> {
        var layerViewList = ArrayList<LayerView>()
        for (i in 0..4) {
            layerViewList.add(initNewLayer())
        }
        return layerViewList
    }

    private fun initActorRecyclerView(sceneView: SceneView) {
        if(viewContainer.getChildAt(0) is SelectActorView) {
            viewContainer.removeAllViews()
            return
        }
        var selectActorView = SelectActorView(this)
        var actorList = ArrayList<ArrayList<Bitmap>>()
        var bitmaps = ArrayList<Bitmap>()
        for (i in 0 until resourceActorBitmap.size) {
            for (j in 0 until resourceActorBitmap[i].size) {
                bitmaps.add(drawableToBitmap(resources.getDrawable(resourceActorBitmap[i][j])))
            }
            actorList.add(bitmaps)
            bitmaps = ArrayList()
        }
        val layoutManager = LinearLayoutManager(this)
        layoutManager.orientation = LinearLayoutManager.HORIZONTAL
        var actorAdapter = ActorAdapter(this, actorList, sceneView.getLayerView()[4])
        actorAdapter.setLayer(sceneView.getLayerView())
        var actorRecyclerView = selectActorView.findViewById<RecyclerView>(R.id.select_actor_recycler_view)
        actorRecyclerView.layoutManager = layoutManager
        actorRecyclerView.adapter = actorAdapter
        //actorRecyclerView.visibility = View.INVISIBLE
        viewContainer.removeAllViews()
        viewContainer.addView(selectActorView)
        if(viewContainer.getChildAt(0) is SelectActorView) {
            currentSceneView.setOnTouchListener(null)
            selectActorView = viewContainer.getChildAt(0) as SelectActorView
            for (actorView in currentSceneView.getAllActor()) actorView.setOnTouchListener(null)
            for (actorView in currentSceneView.getActor(4)) actorView.setOnTouchListener(actorView.actorOnTouchListener())
            var adapter = selectActorView.findViewById<RecyclerView>(R.id.select_actor_recycler_view).adapter as ActorAdapter
            adapter.setTargetLayer(currentSceneView.getLayerView()[4])
            controlBarView.setBtnSelected(1)
        }
    }

    private fun initControlSceneView() {
        if(viewContainer.getChildAt(0) is ControlSceneView) {
            viewContainer.removeAllViews()
            return
        }
        var projectBitmaps = ArrayList<Bitmap>()
        var onSceneSelectedArrayList = ArrayList<View.OnClickListener>()
        for (i in 0 until sceneData.size){
            onSceneSelectedArrayList.add(switchScene(i))
            projectBitmaps.add(drawableToBitmap(resources.getDrawable(sceneData[i].getInt("background"))))
        }
        sceneAdapter = SceneAdapter(this, projectBitmaps, onSceneSelectedArrayList, currentSceneIndex)
        var controlSceneView = ControlSceneView(this)
        controlSceneView.setonClickAddBtn(View.OnClickListener {
            viewContainer.removeAllViews()
            var addSceneView = AddSceneView(this)
            viewContainer.addView(addSceneView)
            val layoutManager = LinearLayoutManager(this)
            layoutManager.orientation = LinearLayoutManager.HORIZONTAL
            var onSceneSelectedArrayList = ArrayList<View.OnClickListener>()
            var bitmapResource = ArrayList<Bitmap>()
            for (i in 0 until  resourceThemeBitmap.size) {
                bitmapResource.add(drawableToBitmap(resources.getDrawable(resourceThemeBitmap[i])))
                onSceneSelectedArrayList.add(addScene(i))
            }
            var addSceneAdapter = AddSceneAdapter(this, bitmapResource, onSceneSelectedArrayList)
            var newSceneRecyclerView = addSceneView.findViewById<RecyclerView>(R.id.new_scene_recycler_view)
            newSceneRecyclerView.layoutManager = layoutManager
            newSceneRecyclerView.adapter = addSceneAdapter
        })
        controlSceneView.setonClickDuplicateBtn(View.OnClickListener {
            sceneData.removeAt(currentSceneIndex)
            sceneData.add(currentSceneIndex, sceneToJSONObject(currentSceneView))
            var projectBitmaps = ArrayList<Bitmap>()
            var onSceneSelectedArrayList = ArrayList<View.OnClickListener>()
            var newSceneView = SceneView(this, loadScene(sceneData[currentSceneIndex]), currentSceneView.getBackgroundTheme(), loadSceneIsRecord(sceneData[currentSceneIndex]))
            newSceneView.setRecord(sceneData[currentSceneIndex].getJSONObject("record"))
            sceneData.add(currentSceneIndex + 1, sceneToJSONObject(newSceneView))
            for (i in 0 until sceneData.size){
                onSceneSelectedArrayList.add(switchScene(i))
                projectBitmaps.add(drawableToBitmap(resources.getDrawable(sceneData[i].getInt("background"))))
            }
            sceneAdapter.update(projectBitmaps, onSceneSelectedArrayList)
        })
        val layoutManager = LinearLayoutManager(this)
        layoutManager.orientation = LinearLayoutManager.HORIZONTAL
        var sceneRecyclerView = controlSceneView.findViewById<RecyclerView>(R.id.scene_recycler_view)
        sceneRecyclerView.layoutManager = layoutManager
        sceneRecyclerView.adapter = sceneAdapter
        viewContainer.removeAllViews()
        viewContainer.addView(controlSceneView)
    }

    private fun switchScene(position: Int) : View.OnClickListener {
        return View.OnClickListener {
            sceneEditView.removeAllViews()
            sceneData.removeAt(currentSceneIndex)
            sceneData.add(currentSceneIndex, sceneToJSONObject(currentSceneView))
            var sceneViewQQ = SceneView(this, loadScene(sceneData[position]), sceneData[position].getInt("background"), sceneData[position].getBoolean("isRecord"))
            sceneViewQQ.setRecord(sceneData[position].getJSONObject("record"))
            currentSceneView = sceneViewQQ
            currentSceneIndex = position
            sceneEditView.addView(sceneViewQQ)
            sceneAdapter.updateCurrentScene(currentSceneIndex)
            initControlBarView(sceneViewQQ)
            initNavigationBarView()
            sceneViewQQ.setonClickPlayListener(View.OnClickListener {
                preView()
            })
        }
    }

    private fun initControlBarView(sceneView: SceneView) {
        sceneView.setOnTouchListener(sceneView.onTouchBoMoSceneListener)
        for (actorView in sceneView.getAllActor()) actorView.setOnTouchListener(null)
        controlBarView.setBtnSelected(5)
        controlBarView.setonClickLayerSceneBtn(View.OnClickListener {
            if(viewContainer.getChildAt(0) is SelectActorView) {
                selectActorView = viewContainer.getChildAt(0) as SelectActorView
                var adapter = selectActorView.findViewById<RecyclerView>(R.id.select_actor_recycler_view).adapter as ActorAdapter
                adapter.setTargetLayer(sceneView.getLayerView()[1])
            }
            sceneView.setOnTouchListener(sceneView.onTouchBoMoSceneListener)
            for (actorView in sceneView.getAllActor()) actorView.setOnTouchListener(null)
            controlBarView.setBtnSelected(5)
        })
        controlBarView.setonClickLayerBackgroundBtn(View.OnClickListener {
            if(viewContainer.getChildAt(0) is SelectActorView) {
                selectActorView = viewContainer.getChildAt(0) as SelectActorView
                var adapter = selectActorView.findViewById<RecyclerView>(R.id.select_actor_recycler_view).adapter as ActorAdapter
                adapter.setTargetLayer(sceneView.getLayerView()[0])
            }
            sceneView.setOnTouchListener(null)
            for (actorView in sceneView.getAllActor()) actorView.setOnTouchListener(null)
            for (actorView in sceneView.getActor(0)) actorView.setOnTouchListener(actorView.actorOnTouchListener())
            controlBarView.setBtnSelected(0)
        })
        controlBarView.setonClickLayer1Btn(View.OnClickListener {
            if(viewContainer.getChildAt(0) is SelectActorView) {
                selectActorView = viewContainer.getChildAt(0) as SelectActorView
                var adapter = selectActorView.findViewById<RecyclerView>(R.id.select_actor_recycler_view).adapter as ActorAdapter
                adapter.setTargetLayer(sceneView.getLayerView()[4])
            }
            sceneView.setOnTouchListener(null)
            for (actorView in sceneView.getAllActor()) actorView.setOnTouchListener(null)
            for (actorView in sceneView.getActor(4)) actorView.setOnTouchListener(actorView.actorOnTouchListener())
            controlBarView.setBtnSelected(1)
        })
        controlBarView.setonClickLayer2Btn(View.OnClickListener {
            if(viewContainer.getChildAt(0) is SelectActorView) {
                selectActorView = viewContainer.getChildAt(0) as SelectActorView
                var adapter = selectActorView.findViewById<RecyclerView>(R.id.select_actor_recycler_view).adapter as ActorAdapter
                adapter.setTargetLayer(sceneView.getLayerView()[3])
            }
            sceneView.setOnTouchListener(null)
            for (actorView in sceneView.getAllActor()) actorView.setOnTouchListener(null)
            for (actorView in sceneView.getActor(3)) actorView.setOnTouchListener(actorView.actorOnTouchListener())
            controlBarView.setBtnSelected(2)
        })
        controlBarView.setonClickLayer3Btn(View.OnClickListener {
            if(viewContainer.getChildAt(0) is SelectActorView) {
                selectActorView = viewContainer.getChildAt(0) as SelectActorView
                var adapter = selectActorView.findViewById<RecyclerView>(R.id.select_actor_recycler_view).adapter as ActorAdapter
                adapter.setTargetLayer(sceneView.getLayerView()[2])
            }
            sceneView.setOnTouchListener(null)
            for (actorView in sceneView.getAllActor()) actorView.setOnTouchListener(null)
            for (actorView in sceneView.getActor(2)) actorView.setOnTouchListener(actorView.actorOnTouchListener())
            controlBarView.setBtnSelected(3)
        })
        controlBarView.setonClickLayer4Btn(View.OnClickListener {
            if(viewContainer.getChildAt(0) is SelectActorView) {
                selectActorView = viewContainer.getChildAt(0) as SelectActorView
                var adapter = selectActorView.findViewById<RecyclerView>(R.id.select_actor_recycler_view).adapter as ActorAdapter
                adapter.setTargetLayer(sceneView.getLayerView()[1])
            }
            sceneView.setOnTouchListener(null)
            for (actorView in sceneView.getAllActor()) actorView.setOnTouchListener(null)
            for (actorView in sceneView.getActor(1)) actorView.setOnTouchListener(actorView.actorOnTouchListener())
            controlBarView.setBtnSelected(4)
        })
    }

    private fun initNavigationBarView() {
        if (currentSceneView.getIsRecord()){
            var navigationBarView = NavigationBarView(this)
            navigationBar.addView(navigationBarView)
            navigationBarView.setonClickSceneBtn(View.OnClickListener {
                initControlSceneView()
            })
            navigationBarView.setonClickActorBtn(View.OnClickListener {
                initActorRecyclerView(currentSceneView)
            })
            navigationBarView.setonClickBrushBtn(View.OnClickListener {
                preView()
            })
            navigationBarView.setonClickDialogueBtn(View.OnClickListener {

            })
        } else {

        }
    }

    private fun sceneToJSONObject(sceneView: SceneView) : JSONObject {
        var layerViewList = sceneView.getLayerView()
        val sceneObject = JSONObject()
        val jsonObject = JSONObject()
        val jsonArray = JSONArray()
        val layer1Object = JSONObject()
        val layer1Actor = JSONArray()
        val layer2Object = JSONObject()
        val layer2Actor = JSONArray()
        val layer3Object = JSONObject()
        val layer3Actor = JSONArray()
        val layer4Object = JSONObject()
        val layer4Actor = JSONArray()
        var layer0 = layerViewList[0]
        for (actor in layer0.actorViewList) {
            val obj0 = JSONObject()
            obj0.put("resource", actor.getData().bitmap.toString())
            obj0.put("positionX", actor.getData().x)
            obj0.put("positionY", actor.getData().y)
            obj0.put("size", actor.getData().size)
            jsonArray.put(obj0)
        }
        jsonObject.put("id", 0)
        jsonObject.put("name", "layer0")
        jsonObject.put("actor", jsonArray)
        sceneObject.put("layer0", jsonObject)

        var layer1 = layerViewList[1]
        for (actor in layer1.actorViewList) {
            val actorInLayer1 = JSONObject()
            actorInLayer1.put("resource", actor.getData().bitmap.toString())
            actorInLayer1.put("positionX", actor.getData().x)
            actorInLayer1.put("positionY", actor.getData().y)
            actorInLayer1.put("size", actor.getData().size)
            layer1Actor.put(actorInLayer1)
        }
        layer1Object.put("id", 1)
        layer1Object.put("name", "layer1")
        layer1Object.put("actor", layer1Actor)
        sceneObject.put("layer1", layer1Object)

        var layer2 = layerViewList[2]
        for (actor in layer2.actorViewList) {
            val obj0 = JSONObject()
            obj0.put("resource", actor.getData().bitmap.toString())
            obj0.put("positionX", actor.getData().x)
            obj0.put("positionY", actor.getData().y)
            obj0.put("size", actor.getData().size)
            layer2Actor.put(obj0)
        }
        layer2Object.put("id", 2)
        layer2Object.put("name", "layer2")
        layer2Object.put("actor", layer2Actor)
        sceneObject.put("layer2", layer2Object)

        var layer3 = layerViewList[3]
        for (actor in layer3.actorViewList) {
            val obj0 = JSONObject()
            obj0.put("resource", actor.getData().bitmap.toString())
            obj0.put("positionX", actor.getData().x)
            obj0.put("positionY", actor.getData().y)
            obj0.put("size", actor.getData().size)
            layer3Actor.put(obj0)
        }
        layer3Object.put("id", 3)
        layer3Object.put("name", "layer3")
        layer3Object.put("actor", layer3Actor)
        sceneObject.put("layer3", layer3Object)

        var layer4 = layerViewList[4]
        for (actor in layer4.actorViewList) {
            val obj0 = JSONObject()
            obj0.put("resource", actor.getData().bitmap.toString())
            obj0.put("positionX", actor.getData().x)
            obj0.put("positionY", actor.getData().y)
            obj0.put("size", actor.getData().size)
            layer4Actor.put(obj0)
        }
        layer4Object.put("id", 4)
        layer4Object.put("name", "layer4")
        layer4Object.put("actor", layer4Actor)
        sceneObject.put("layer4", layer4Object)
        Log.d("TEST12345666","YYYYYY = " + sceneView.getIsRecord())
        sceneObject.put("isRecord", sceneView.getIsRecord())
        sceneObject.put("record", sceneView.getRecord())
        sceneObject.put("background", sceneView.getBackgroundTheme())
        return sceneObject
    }

    private fun loadScene(sceneObject : JSONObject) : ArrayList<LayerView> {
        var layerViewList = ArrayList<LayerView>()
        var jsonText = sceneObject.toString()
        var layerObject = JSONObject()
        try {
            val jsonObject1 = JSONObject(jsonText)
            for (i in 0..4) {
                when (i) {
                    0 -> {
                        layerObject = jsonObject1.getJSONObject("layer0")
                        Log.d("TEST12345", "0000000")
                    }
                    1 -> {
                        layerObject = jsonObject1.getJSONObject("layer1")
                        Log.d("TEST12345", "11111")
                    }
                    2 -> {
                        layerObject = jsonObject1.getJSONObject("layer2")
                        Log.d("TEST12345", "2222")
                    }
                    3 -> {
                        layerObject = jsonObject1.getJSONObject("layer3")
                        Log.d("TEST12345", "333")
                    }
                    4 -> {
                        layerObject = jsonObject1.getJSONObject("layer4")
                        Log.d("TEST12345", "44444")
                    }
                }
                val name = layerObject.getInt("id")
                val title = layerObject.getString("name")
                val array = layerObject.getJSONArray("actor")
                Log.d("TEST12345", "name:$name, tittle:$title")
                var actorViewList = ArrayList<ActorView>()
                for (i in 0 until array.length()) {
                    val jsonObject = array.getJSONObject(i)
                    val bitmap = jsonObject.getString("resource")
                    val x = jsonObject.getInt("positionX")
                    val y = jsonObject.getInt("positionY")
                    val size = jsonObject.getInt("size")
                    var actorData = ActorData(drawableToBitmap(resources.getDrawable(R.drawable.ic_bird_g_1)),
                            x, y, size)
                    var actorView = ActorView(this, actorData)
                    actorViewList.add(actorView)
                }
                layerViewList.add(initLayer(actorViewList))
            }
        } catch (e: JSONException) {
            e.printStackTrace()
        }
        return layerViewList
    }

    private fun loadSceneIsRecord(sceneObject : JSONObject) : Boolean{
        return sceneObject.getBoolean("isRecord")
    }

    private fun addScene(position: Int) : View.OnClickListener {
        return View.OnClickListener {
            var sceneView = SceneView(this, initLayerViewList(), resourceThemeBitmap[position],false)
            sceneData.add(sceneToJSONObject(sceneView))
            initControlSceneView()
        }
    }

    private fun initThemeResource(){
        resourceThemeBitmap.add(R.drawable.hill)
        resourceThemeBitmap.add(R.drawable.sky)
        resourceThemeBitmap.add(R.drawable.green)
    }

    private fun initActorResource(){
        var actorList = ArrayList<Int>()
        actorList.add(R.drawable.ic_bird_g_1)
        actorList.add(R.drawable.ic_bird_g_1)
        actorList.add(R.drawable.ic_bird_g_1)
        actorList.add(R.drawable.ic_bird_g_1)
        actorList.add(R.drawable.ic_bird_g_1)
        resourceActorBitmap.add(actorList)
        resourceActorBitmap.add(actorList)
        resourceActorBitmap.add(actorList)
        resourceActorBitmap.add(actorList)
        resourceActorBitmap.add(actorList)
        resourceActorBitmap.add(actorList)
        resourceActorBitmap.add(actorList)
        resourceActorBitmap.add(actorList)
        resourceActorBitmap.add(actorList)
        resourceActorBitmap.add(actorList)
        resourceActorBitmap.add(actorList)
        resourceActorBitmap.add(actorList)
    }

    private fun preView() {
        currentSceneView.setPlayViewGone()
        var bomoLayer1 = currentSceneView.getLayerView()[4]
        var bomoLayer2 = currentSceneView.getLayerView()[3]
        var bomoLayer3 = currentSceneView.getLayerView()[2]
        var bomoLayer4 = currentSceneView.getLayerView()[1]
        var bomo_background = currentSceneView.getLayerView()[0]
        var recordObject = currentSceneView.getRecord()
        for (i in 0 until recordObject.length()) {
            val array = recordObject.getJSONObject(i.toString()).getJSONArray("record")
            for (i in 0 until array.length()) {
                val handler = Handler()
                val jsonObject = array.getJSONObject(i)
                var playTime = jsonObject.getLong("time")
                var x = jsonObject.getInt("positionX")
                handler.postDelayed(Runnable {
                    bomoLayer1.layout(x, bomoLayer1.y.toInt(), x + bomoLayer1.width, bomoLayer1.height + bomoLayer1.y.toInt())
                    bomoLayer2.layout(x / 2, bomoLayer2.y.toInt(), x / 2 + bomoLayer2.width, bomoLayer2.height + bomoLayer2.y.toInt())
                    bomoLayer3.layout(x / 4, bomoLayer3.y.toInt(), x / 4 + bomoLayer3.width, bomoLayer3.height + bomoLayer3.y.toInt())
                    bomoLayer4.layout(x / 8, bomoLayer4.y.toInt(), x / 8 + bomoLayer4.width, bomoLayer4.height + bomoLayer4.y.toInt())
                    bomo_background.layout(x / 32, bomo_background.y.toInt(), x / 32 + bomo_background.width, bomo_background.height + bomo_background.y.toInt())
                }, playTime)
            }
        }
        var handler = Handler( )
        handler.postDelayed(Runnable {
            currentSceneView.setPlayViewVis()
        }, currentSceneView.endRecordTime - currentSceneView.startRecordTime)
    }
}
