Ver Fonte

Merge branch 'LayerManagement_and_Insert_Image_Actor'

faterhenry há 6 anos atrás
pai
commit
594b583d4d

+ 0 - 1
build.gradle

@@ -46,7 +46,6 @@ dependencies {
 
     implementation project(':Bomo_for_Android_trackWidgetModule')
     implementation project(':Bomo_for_Android_cloudModule')
-    implementation project(':Bomo_for_Android_encodeModule')
 }
 repositories {
     mavenCentral()

+ 2 - 0
src/main/java/com/bomostory/sceneeditmodule/Config.kt

@@ -6,6 +6,8 @@ import java.io.File
 object Config {
     private const val ASSETS_FOLDER_PATH = "/Android/yuheng"
     private const val PROJECTS_FOLDER_PATH = "/Android/yuheng/project"
+    private const val IMAGE_FOLDER_PATH = "/Android/yuheng/image"
+    val IMAGE_FOLDER = File(Environment.getExternalStorageDirectory(), IMAGE_FOLDER_PATH)
     val ASSETS_FOLDER = File(Environment.getExternalStorageDirectory(), ASSETS_FOLDER_PATH)
     val PROJECTS_FOLDER = File(Environment.getExternalStorageDirectory(), PROJECTS_FOLDER_PATH)
 }

+ 205 - 128
src/main/java/com/bomostory/sceneeditmodule/SceneEditActivity.kt

@@ -1,12 +1,12 @@
 package com.example.tfat.myapplication
 
+import android.app.Activity
 import android.content.DialogInterface
 import android.content.Intent
 import android.support.v7.app.AppCompatActivity
 import android.support.v7.widget.LinearLayoutManager
 import android.os.Bundle
 import android.graphics.drawable.Drawable
-import android.os.Environment
 import android.support.v7.widget.RecyclerView
 import android.view.*
 import android.widget.PopupWindow
@@ -22,28 +22,39 @@ import com.bomostory.sceneeditmodule.navigationbar.actor.SelectActorView
 import com.google.gson.Gson
 import kotlinx.android.synthetic.main.activity_scene_edit.*
 import com.bomostory.sceneeditmodule.basicdata.*
-import com.bomostory.sceneeditmodule.layermanagement.LayerAdapter
 import com.bomostory.sceneeditmodule.view.EditActorView
 import com.bomostory.sceneeditmodule.view.OnTouchBoMoSceneListener
 import com.bomostory.sceneeditmodule.view.SceneView1
 import com.example.tfat.myapplication.navigationbar.RecordFinishView
-import com.example.tfat.myapplication.navigationbar.actor.ActorControlDialog
+import com.example.tfat.myapplication.navigationbar.actor.LayerManagementDialog
 import kotlinx.android.synthetic.main.control_actor_dialog.view.*
-import kotlinx.android.synthetic.main.layer_management_fragment.*
 import java.io.File
 import java.io.FileWriter
+import com.bomostory.sceneeditmodule.utils.FileUtils
 
-class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener, EditActorView.OnActorChangeListener, OnTouchBoMoSceneListener.OnSceneMoveListener, DialogInterface.OnDismissListener {
+
+class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener, EditActorView.OnActorChangeListener,
+        OnTouchBoMoSceneListener.OnSceneMoveListener, DialogInterface.OnDismissListener, FileUtils.OnSaveActorImage,
+        LayerManagementDialog.OnLayerChange {
 
     private lateinit var project: Project
     private var currentSceneIndex = 0
     private var currentLayerIndex = 6
+    private var startRecordTime = 0L
+    private var record = Record()
     private var resourceThemeBitmap = ArrayList<String>()
     private var resourceActorBitmap = ArrayList<ArrayList<String>>()
     private lateinit var sceneAdapter: SceneAdapter
     private var isRecord = false
-    private var record = Record()
-    private var startRecordTime = 0L
+    private var layerManagementDialog = LayerManagementDialog()
+    companion object {
+        const val PHOTO_FROM_GALLERY = 1
+        const val LAYER_MANAGEMENT = "layer_management"
+        const val ACTOR_HEIGHT = 200
+        const val ACTOR_WIDTH = 200
+        const val ACTOR_INIT_POSITION_X = 200
+        const val ACTOR_INIT_POSITION_Y = 200
+    }
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
@@ -60,29 +71,12 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
                 sceneEditView.scene = it[0]
             }
         }
+        ic_scene_edit_activity_back.setOnClickListener {
+            this.onBackPressed()
+        }
         initControlBarView()
         initNavigationBarView()
-        startRecord.setOnClickListener(View.OnClickListener {
-            if (!isRecord) {
-                startRecord.setImageDrawable(resources.getDrawable(R.drawable.ic_btn_record_stop))
-                startRecordTime = System.currentTimeMillis()
-                isRecord = true
-                preViewLayer()
-                navigationBar.visibility = View.INVISIBLE
-            } else {
-                isRecord = false
-                record.period = System.currentTimeMillis() - startRecordTime
-                project.story?.let {
-                    it.scenes?.let{
-                        it[currentSceneIndex].record = record
-                    }
-                }
-                startRecord.setImageDrawable(resources.getDrawable(R.drawable.ic_btn_record))
-                navigationBar.visibility = View.VISIBLE
-                initControlSceneView()
-                initNavigationBarView()
-            }
-        })
+        initRecord()
     }
 
     override fun onResume() {
@@ -98,7 +92,99 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         }
     }
 
-    private fun initActorRecyclerView(sceneView: SceneView1) {
+    private fun initControlBarView() {
+        controlBarView.setBtnSelected(6)
+        controlBarView.setonClickSwipeLayerBtn(View.OnClickListener {
+            switchToPreViewLayer()
+        })
+        controlBarView.setonClickLayerSceneBtn(View.OnClickListener {
+            layerManagementDialog = LayerManagementDialog()
+            project.story?.let {
+                it.scenes?.let{
+                    layerManagementDialog.setData(it[currentSceneIndex])
+                }
+            }
+            layerManagementDialog.setListener(this)
+            layerManagementDialog.show(supportFragmentManager,LAYER_MANAGEMENT)
+        })
+        controlBarView.setonClickLayerBackgroundBtn(View.OnClickListener {
+            switchLayer(4)
+        })
+        controlBarView.setonClickLayer4Btn(View.OnClickListener {
+            switchLayer(3)
+        })
+        controlBarView.setonClickLayer3Btn(View.OnClickListener {
+            switchLayer(2)
+        })
+        controlBarView.setonClickLayer2Btn(View.OnClickListener {
+            switchLayer(1)
+        })
+        controlBarView.setonClickLayer1Btn(View.OnClickListener {
+            switchLayer(0)
+        })
+    }
+
+    private fun initNavigationBarView() {
+        project.story?.let {
+            it.scenes?.let {
+                if (it[currentSceneIndex].record == null) {
+                    var navigationBarView = NavigationBarView(this)
+                    navigationBar.addView(navigationBarView)
+                    navigationBarView.setonClickSceneBtn(View.OnClickListener {
+                        initControlSceneView()
+                    })
+                    navigationBarView.setonClickActorBtn(View.OnClickListener {
+                        initActorRecyclerView()
+                    })
+                    navigationBarView.setonClickBrushBtn(View.OnClickListener {
+
+                    })
+                    navigationBarView.setonClickDialogueBtn(View.OnClickListener {
+
+                    })
+                    navigationBarView.setonClickImageBtn(View.OnClickListener {
+                        pickFromGallery()
+                    })
+                } else {
+                    navigationBar.removeAllViews()
+                    var recordFinishView = RecordFinishView(this)
+                    recordFinishView.setOnNextSceneClickListener(View.OnClickListener {
+                        switchScene(currentSceneIndex + 1)
+                    })
+                    recordFinishView.setOnFinishClickListener(View.OnClickListener {
+                        project.story?.let {
+                            it.scenes?.let {
+                                when (it.size) {
+                                    1 -> project.scene1 = it[0].backgroundPath
+                                    else -> {
+                                        project.scene1 = it[0].backgroundPath
+                                        project.scene2 = it[1].backgroundPath
+                                    }
+                                }
+                            }
+                        }
+                        val dir = File(Config.PROJECTS_FOLDER,"")
+                        dir.mkdir()
+                        val file = File(Config.PROJECTS_FOLDER, project.name + ".json")
+                        try {
+                            val fileWriter = FileWriter(file)
+                            fileWriter.write(Gson().toJson(project))
+                            fileWriter.flush()
+                        } catch (e: Exception) {
+                            e.printStackTrace()
+                        }
+                        val story = project.story
+                        val intent = Intent(this, MovieEditActivity::class.java)
+                        intent.putExtra(MovieEditActivity.PROJECT_KEY, Gson().toJson(story))
+                        startActivity(intent)
+                    })
+                    navigationBar.addView(recordFinishView)
+                }
+            }
+        }
+    }
+
+    private fun initActorRecyclerView() {
         if (viewContainer.getChildAt(0) is SelectActorView) {
             viewContainer.removeAllViews()
             return
@@ -175,7 +261,30 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         sceneRecyclerView.adapter = sceneAdapter
         viewContainer.removeAllViews()
         viewContainer.addView(controlSceneView)
-        //navigationBar.visibility = View.GONE
+    }
+
+    private fun initRecord(){
+        startRecord.setOnClickListener(View.OnClickListener {
+            if (!isRecord) {
+                startRecord.setImageDrawable(resources.getDrawable(R.drawable.ic_btn_record_stop))
+                startRecordTime = System.currentTimeMillis()
+                isRecord = true
+                switchToPreViewLayer()
+                navigationBar.visibility = View.INVISIBLE
+            } else {
+                isRecord = false
+                record.period = System.currentTimeMillis() - startRecordTime
+                project.story?.let {
+                    it.scenes?.let{
+                        it[currentSceneIndex].record = record
+                    }
+                }
+                startRecord.setImageDrawable(resources.getDrawable(R.drawable.ic_btn_record))
+                navigationBar.visibility = View.VISIBLE
+                initControlSceneView()
+                initNavigationBarView()
+            }
+        })
     }
 
 
@@ -193,38 +302,6 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         }
     }
 
-    private fun initControlBarView() {
-        controlBarView.setBtnSelected(6)
-        controlBarView.setonClickSwipeLayerBtn(View.OnClickListener {
-            preViewLayer()
-        })
-        controlBarView.setonClickLayerSceneBtn(View.OnClickListener {
-            //TO DO
-            val actorControlDialog = ActorControlDialog()
-            project.story?.let {
-                it.scenes?.let{
-                    actorControlDialog.setData(it[currentSceneIndex])
-                }
-            }
-            actorControlDialog.show(supportFragmentManager,"Q")
-        })
-        controlBarView.setonClickLayerBackgroundBtn(View.OnClickListener {
-            switchLayer(4)
-        })
-        controlBarView.setonClickLayer4Btn(View.OnClickListener {
-            switchLayer(3)
-        })
-        controlBarView.setonClickLayer3Btn(View.OnClickListener {
-            switchLayer(2)
-        })
-        controlBarView.setonClickLayer2Btn(View.OnClickListener {
-            switchLayer(1)
-        })
-        controlBarView.setonClickLayer1Btn(View.OnClickListener {
-            switchLayer(0)
-        })
-    }
-
     private fun switchLayer(layerIndex: Int){
         viewContainer.removeAllViews()
         currentLayerIndex = layerIndex
@@ -250,7 +327,7 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         setActorDropLayer()
     }
 
-    private fun preViewLayer(){
+    private fun switchToPreViewLayer(){
         viewContainer.removeAllViews()
         currentLayerIndex = 6
         controlBarView.setBtnSelected(currentLayerIndex)
@@ -287,63 +364,6 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         }
     }
 
-    private fun initNavigationBarView() {
-        project.story?.let {
-            it.scenes?.let {
-                if (it[currentSceneIndex].record == null) {
-                    var navigationBarView = NavigationBarView(this)
-                    navigationBar.addView(navigationBarView)
-                    navigationBarView.setonClickSceneBtn(View.OnClickListener {
-                        initControlSceneView()
-                    })
-                    navigationBarView.setonClickActorBtn(View.OnClickListener {
-                        initActorRecyclerView(sceneEditView)
-                    })
-                    navigationBarView.setonClickBrushBtn(View.OnClickListener {
-
-                    })
-                    navigationBarView.setonClickDialogueBtn(View.OnClickListener {
-
-                    })
-                } else {
-                    navigationBar.removeAllViews()
-                    var recordFinishView = RecordFinishView(this)
-                    recordFinishView.setOnNextSceneClickListener(View.OnClickListener {
-                        switchScene(currentSceneIndex + 1)
-                    })
-                    recordFinishView.setOnFinishClickListener(View.OnClickListener {
-                        project.story?.let {
-                            it.scenes?.let {
-                                when (it.size) {
-                                    1 -> project.scene1 = it[0].backgroundPath
-                                    else -> {
-                                        project.scene1 = it[0].backgroundPath
-                                        project.scene2 = it[1].backgroundPath
-                                    }
-                                }
-                            }
-                        }
-                        val dir = File(Config.PROJECTS_FOLDER,"")
-                        dir.mkdir()
-                        val file = File(Config.PROJECTS_FOLDER, project.name + ".json")
-                        try {
-                            val fileWriter = FileWriter(file)
-                            fileWriter.write(Gson().toJson(project))
-                            fileWriter.flush()
-                        } catch (e: Exception) {
-                            e.printStackTrace()
-                        }
-
-                        val intent = Intent(this, MovieEditActivity::class.java)
-                        intent.putExtra(MovieEditActivity.PROJECT_KEY, Gson().toJson(project))
-                        startActivity(intent)
-                    })
-                    navigationBar.addView(recordFinishView)
-                }
-            }
-        }
-    }
-
     private fun addScene(position: Int): View.OnClickListener {
         return View.OnClickListener {
             var scene = Scene()
@@ -363,15 +383,28 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         }
     }
 
-    override fun onActorDropFinish(positionX: Int, positionY: Int, resourcePath: String) {
+    private fun setActorPositionZ(actors: ArrayList<Actor>){
+        for (actor in actors) {
+            actor.positionZ = actors.indexOf(actor)
+        }
+    }
+
+    private fun pickFromGallery() {
+        val intent = Intent()
+        intent.type = "image/*"
+        intent.action = Intent.ACTION_GET_CONTENT
+        startActivityForResult(intent, PHOTO_FROM_GALLERY)
+    }
+
+    private fun addActor(positionX: Int, positionY: Int, resourcePath: String) {
         project.story?.let {
             it.scenes?.let{
                 val actorData = Actor()
                 actorData.positionX = positionX
                 actorData.positionY = positionY
                 actorData.positionZ = it[currentSceneIndex].layers[currentLayerIndex].actors.size
-                actorData.sideLength = 200
-                actorData.sideHeight = 200
+                actorData.sideLength = ACTOR_WIDTH
+                actorData.sideHeight = ACTOR_HEIGHT
                 actorData.resourcePath = resourcePath
                 actorData.parentLayerIndex = currentLayerIndex
                 actorData.isMoveable = true
@@ -382,6 +415,10 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         setActorDropLayer()
     }
 
+    override fun onActorDropFinish(positionX: Int, positionY: Int, resourcePath: String) {
+        addActor(positionX, positionY, resourcePath)
+    }
+
     override fun onActorChange(actor: Actor) {
         project.story?.let {
             it.scenes?.let {
@@ -435,7 +472,7 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
                         isMoveable = true
                     }
                     it[currentSceneIndex].layers[currentLayerIndex].actors.add(actorData)
-                    setActorPositionZ(it[currentLayerIndex].layers[currentLayerIndex].actors)
+                     setActorPositionZ(it[currentSceneIndex].layers[currentLayerIndex].actors)
                     sceneEditView.scene = it[currentSceneIndex]
                     popupWindow.dismiss()
                 }
@@ -492,13 +529,53 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         }
     }
 
-    private fun setActorPositionZ(actors: ArrayList<Actor>){
-        for (actor in actors) {
-            actor.positionZ = actors.indexOf(actor)
+    override fun onDismiss(dialog: DialogInterface?) {
+        project.story?.let {
+            it.scenes?.let {
+                sceneEditView.scene = it[currentSceneIndex]
+            }
+        }
+        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)
         }
+        initControlBarView()
     }
 
-    override fun onDismiss(dialog: DialogInterface?) {
+    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
+        super.onActivityResult(requestCode, resultCode, data)
+        when (requestCode) {
+            PHOTO_FROM_GALLERY ->
+                when (resultCode) {
+                    Activity.RESULT_OK -> if (data != null) {
+                        FileUtils.saveImageForActor(this, data.data, System.currentTimeMillis().toString())
+                    }
+                    Activity.RESULT_CANCELED -> {
+                    }
+                }
+        }
+    }
+
+    override fun onSaveActorImage(filePath: String) {
+        addActor(ACTOR_INIT_POSITION_X, ACTOR_INIT_POSITION_Y, filePath)
+    }
 
+    override fun onLayerChange(layerFrom: Int, layerTo: Int, position: Int){
+        project.story?.let {
+            it.scenes?.let {
+                var actor = it[currentSceneIndex].layers[layerFrom - 1].actors[position]
+                it[currentSceneIndex].layers[layerTo - 1].actors.add(actor)
+                it[currentSceneIndex].layers[layerFrom - 1].actors.removeAt(position)
+                layerManagementDialog.setData(it[currentSceneIndex])
+                setActorPositionZ(it[currentSceneIndex].layers[layerFrom - 1].actors)
+                setActorPositionZ(it[currentSceneIndex].layers[layerTo - 1].actors)
+                sceneEditView.scene = it[currentSceneIndex]
+            }
+        }
     }
 }

+ 0 - 109
src/main/java/com/bomostory/sceneeditmodule/layermanagement/ActorControlDialog.kt

@@ -1,109 +0,0 @@
-package com.example.tfat.myapplication.navigationbar.actor
-
-import android.content.Context
-import android.content.DialogInterface
-import android.os.Bundle
-import android.support.v4.app.DialogFragment
-import android.support.v7.widget.LinearLayoutManager
-import android.view.LayoutInflater
-import android.view.View
-import android.view.ViewGroup
-import com.bomostory.sceneeditmodule.basicdata.Actor
-import com.bomostory.sceneeditmodule.basicdata.Scene
-import com.bomostory.sceneeditmodule.layermanagement.LayerAdapter
-import com.example.tfat.myapplication.R
-import kotlinx.android.synthetic.main.layer_management_fragment.view.*
-import kotlin.collections.ArrayList
-
-class ActorControlDialog : DialogFragment() {
-
-    private var listener: DialogInterface.OnDismissListener? = null
-    //private val layerListeners = ArrayList<View.OnClickListener>()
-    private val layer1Data = ArrayList<Actor>()
-    private val layer1Adapter = LayerAdapter(layer1Data)
-    private val layer2Data = ArrayList<Actor>()
-    private val layer2Adapter = LayerAdapter(layer2Data)
-    private val layer3Data = ArrayList<Actor>()
-    private val layer3Adapter = LayerAdapter(layer3Data)
-    private val layer4Data = ArrayList<Actor>()
-    private val layer4Adapter = LayerAdapter(layer4Data)
-    private val layer5Data = ArrayList<Actor>()
-    private val layer5Adapter = LayerAdapter(layer5Data)
-
-    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
-        return inflater.inflate(R.layout.layer_management_fragment, container).apply {
-            layer1.apply {
-                adapter = layer1Adapter
-                layoutManager = LinearLayoutManager(context).apply {
-                    orientation = LinearLayoutManager.HORIZONTAL
-                }
-            }
-            layer2.apply {
-                adapter = layer2Adapter
-                layoutManager = LinearLayoutManager(context).apply {
-                    orientation = LinearLayoutManager.HORIZONTAL
-                }
-            }
-            layer3.apply {
-                adapter = layer3Adapter
-                layoutManager = LinearLayoutManager(context).apply {
-                    orientation = LinearLayoutManager.HORIZONTAL
-                }
-            }
-            layer4.apply {
-                adapter = layer4Adapter
-                layoutManager = LinearLayoutManager(context).apply {
-                    orientation = LinearLayoutManager.HORIZONTAL
-                }
-            }
-            layer5.apply {
-                adapter = layer5Adapter
-                layoutManager = LinearLayoutManager(context).apply {
-                    orientation = LinearLayoutManager.HORIZONTAL
-                }
-            }
-        }
-    }
-
-    override fun onDismiss(dialog: DialogInterface?) {
-        super.onDismiss(dialog)
-        listener?.onDismiss(dialog)
-    }
-
-    override fun onAttach(context: Context) {
-        super.onAttach(context)
-        if (context is DialogInterface.OnDismissListener) {
-            listener = context
-        } else {
-            throw RuntimeException(context.toString() + " must implement OnFragmentInteractionListener")
-        }
-    }
-
-    override fun onDetach() {
-        super.onDetach()
-        listener = null
-    }
-
-    fun setData(scene: Scene){
-        this.layer1Data.apply {
-            clear()
-            addAll(scene.layers[0].actors)
-        }
-        this.layer2Data.apply {
-            clear()
-            addAll(scene.layers[1].actors)
-        }
-        this.layer3Data.apply {
-            clear()
-            addAll(scene.layers[2].actors)
-        }
-        this.layer4Data.apply {
-            clear()
-            addAll(scene.layers[3].actors)
-        }
-        this.layer5Data.apply {
-            clear()
-            addAll(scene.layers[4].actors)
-        }
-    }
-}

+ 8 - 6
src/main/java/com/bomostory/sceneeditmodule/layermanagement/LayerAdapter.kt

@@ -2,21 +2,22 @@ package com.bomostory.sceneeditmodule.layermanagement
 
 import android.graphics.drawable.Drawable
 import android.support.v7.widget.RecyclerView
-import android.view.LayoutInflater
-import android.view.View
-import android.view.ViewGroup
+import android.view.*
 import com.bomostory.sceneeditmodule.basicdata.Actor
 import com.example.tfat.myapplication.R
 import kotlinx.android.synthetic.main.actor_item.view.*
 
 
-class LayerAdapter (var data: ArrayList<Actor>) : RecyclerView.Adapter<LayerAdapter.ViewHolder>() {
+class LayerAdapter (actorData: ArrayList<Actor>, actorListeners: ArrayList<View.OnTouchListener>) : RecyclerView.Adapter<LayerAdapter.ViewHolder>() {
+
+    var data = actorData
+    private var listeners = actorListeners
     override fun getItemCount(): Int {
         return data.size
     }
 
     override fun onBindViewHolder(holder: ViewHolder, position: Int) {
-        holder.bind(data[position])
+        holder.bind(data[position],listeners[position])
     }
 
     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
@@ -25,8 +26,9 @@ class LayerAdapter (var data: ArrayList<Actor>) : RecyclerView.Adapter<LayerAdap
     }
 
     class ViewHolder (view : View) : RecyclerView.ViewHolder(view) {
-        fun bind(actor: Actor) {
+        fun bind(actor: Actor, onTouchListener: View.OnTouchListener?) {
             itemView.actor_image.setImageDrawable(Drawable.createFromPath(actor.resourcePath))
+            itemView.setOnTouchListener(onTouchListener)
         }
     }
 }

+ 244 - 0
src/main/java/com/bomostory/sceneeditmodule/layermanagement/LayerManagementDialog.kt

@@ -0,0 +1,244 @@
+package com.example.tfat.myapplication.navigationbar.actor
+
+import android.content.ClipData
+import android.content.ClipDescription
+import android.content.Context
+import android.content.DialogInterface
+import android.graphics.Color
+import android.os.Bundle
+import android.support.v4.app.DialogFragment
+import android.support.v7.widget.LinearLayoutManager
+import android.view.*
+import com.bomostory.sceneeditmodule.basicdata.Actor
+import com.bomostory.sceneeditmodule.basicdata.Scene
+import com.bomostory.sceneeditmodule.layermanagement.LayerAdapter
+import com.example.tfat.myapplication.R
+import kotlinx.android.synthetic.main.layer_management_fragment.*
+import kotlinx.android.synthetic.main.layer_management_fragment.view.*
+import kotlin.collections.ArrayList
+
+class LayerManagementDialog : DialogFragment() {
+
+    private var listener: DialogInterface.OnDismissListener? = null
+    private var layerChangeListener: OnLayerChange? = null
+    private val layer1Data = ArrayList<Actor>()
+    private val layer1Listeners = ArrayList<View.OnTouchListener>()
+    private val layer1Adapter = LayerAdapter(layer1Data, layer1Listeners)
+    private val layer2Data = ArrayList<Actor>()
+    private val layer2Listeners = ArrayList<View.OnTouchListener>()
+    private val layer2Adapter = LayerAdapter(layer2Data, layer2Listeners)
+    private val layer3Data = ArrayList<Actor>()
+    private val layer3Listeners = ArrayList<View.OnTouchListener>()
+    private val layer3Adapter = LayerAdapter(layer3Data, layer3Listeners)
+    private val layer4Data = ArrayList<Actor>()
+    private val layer4Listeners = ArrayList<View.OnTouchListener>()
+    private val layer4Adapter = LayerAdapter(layer4Data, layer4Listeners)
+    private val layer5Data = ArrayList<Actor>()
+    private val layer5Listeners = ArrayList<View.OnTouchListener>()
+    private val layer5Adapter = LayerAdapter(layer5Data, layer5Listeners)
+    private var selectLayer = 0
+
+    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
+        return inflater.inflate(R.layout.layer_management_fragment, container).apply {
+            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
+            rv_layer_management_layer1.apply {
+                adapter = layer1Adapter
+                layoutManager = LinearLayoutManager(context).apply {
+                    orientation = LinearLayoutManager.HORIZONTAL
+                }
+            }
+            layout_layer_management_layer1.apply {
+                setOnDragListener(onDragListener(1))
+                setOnClickListener(onClickLayerListener(1))
+            }
+            rv_layer_management_layer2.apply {
+                adapter = layer2Adapter
+                layoutManager = LinearLayoutManager(context).apply {
+                    orientation = LinearLayoutManager.HORIZONTAL
+                }
+            }
+            layout_layer_management_layer2.apply {
+                setOnDragListener(onDragListener(2))
+                setOnClickListener(onClickLayerListener(2))
+            }
+            rv_layer_management_layer3.apply {
+                adapter = layer3Adapter
+                layoutManager = LinearLayoutManager(context).apply {
+                    orientation = LinearLayoutManager.HORIZONTAL
+                }
+            }
+            layout_layer_management_layer3.apply {
+                setOnDragListener(onDragListener(3))
+                setOnClickListener(onClickLayerListener(3))
+            }
+            rv_layer_management_layer4.apply {
+                adapter = layer4Adapter
+                layoutManager = LinearLayoutManager(context).apply {
+                    orientation = LinearLayoutManager.HORIZONTAL
+                }
+            }
+            layout_layer_management_layer4.apply {
+                setOnDragListener(onDragListener(4))
+                setOnClickListener(onClickLayerListener(4))
+            }
+            rv_layer_management_layer5.apply {
+                adapter = layer5Adapter
+                layoutManager = LinearLayoutManager(context).apply {
+                    orientation = LinearLayoutManager.HORIZONTAL
+                }
+            }
+            layout_layer_management_layer5.apply {
+                setOnDragListener(onDragListener(5))
+                setOnClickListener(onClickLayerListener(5))
+            }
+        }
+    }
+
+    override fun onDismiss(dialog: DialogInterface?) {
+        super.onDismiss(dialog)
+        listener?.onDismiss(dialog)
+    }
+
+    override fun onAttach(context: Context) {
+        super.onAttach(context)
+        if (context is DialogInterface.OnDismissListener) {
+            listener = context
+        } else {
+            throw RuntimeException(context.toString() + " must implement OnFragmentInteractionListener")
+        }
+    }
+
+    override fun onDetach() {
+        super.onDetach()
+        listener = null
+    }
+
+    fun setData(scene: Scene){
+        this.layer1Data.apply {
+            clear()
+            addAll(scene.layers[0].actors)
+        }
+        this.layer2Data.apply {
+            clear()
+            addAll(scene.layers[1].actors)
+        }
+        this.layer3Data.apply {
+            clear()
+            addAll(scene.layers[2].actors)
+        }
+        this.layer4Data.apply {
+            clear()
+            addAll(scene.layers[3].actors)
+        }
+        this.layer5Data.apply {
+            clear()
+            addAll(scene.layers[4].actors)
+        }
+        this.layer1Listeners.apply {
+            clear()
+            for (i in 0 until layer1Data.size) {
+                add(onActorTouchListener(1,i))
+            }
+        }
+        this.layer2Listeners.apply {
+            clear()
+            for (i in 0 until layer2Data.size) {
+                add(onActorTouchListener(2,i))
+            }
+        }
+        this.layer3Listeners.apply {
+            clear()
+            for (i in 0 until layer3Data.size) {
+                add(onActorTouchListener(3,i))
+            }
+        }
+        this.layer4Listeners.apply {
+            clear()
+            for (i in 0 until layer4Data.size) {
+                add(onActorTouchListener(4,i))
+            }
+        }
+        this.layer5Listeners.apply {
+            clear()
+            for (i in 0 until layer5Data.size) {
+                add(onActorTouchListener(5,i))
+            }
+        }
+        this.layer1Adapter.notifyDataSetChanged()
+        this.layer2Adapter.notifyDataSetChanged()
+        this.layer3Adapter.notifyDataSetChanged()
+        this.layer4Adapter.notifyDataSetChanged()
+        this.layer5Adapter.notifyDataSetChanged()
+    }
+
+    fun setListener(onLayerChange: OnLayerChange){
+        layerChangeListener = onLayerChange
+    }
+
+    private fun onDragListener(layer: Int) : View.OnDragListener {
+        return View.OnDragListener {v, event ->
+            when (event.action) {
+                DragEvent.ACTION_DRAG_STARTED -> {
+                    return@OnDragListener true
+                }
+                DragEvent.ACTION_DROP -> {
+                    val actorPositionZ = event.clipData.getItemAt(0).text.toString().toInt()
+                    layerChangeListener?.onLayerChange(selectLayer, layer, actorPositionZ)
+                    return@OnDragListener true
+                }
+            }
+            return@OnDragListener true
+        }
+    }
+
+    private fun onClickLayerListener(layer: Int) : View.OnClickListener {
+        return View.OnClickListener {
+            selectLayer = layer
+            layout_layer_management_layer1.setBackgroundColor(Color.parseColor("#ffffff"))
+            layout_layer_management_layer2.setBackgroundColor(Color.parseColor("#ffffff"))
+            layout_layer_management_layer3.setBackgroundColor(Color.parseColor("#ffffff"))
+            layout_layer_management_layer4.setBackgroundColor(Color.parseColor("#ffffff"))
+            layout_layer_management_layer5.setBackgroundColor(Color.parseColor("#ffffff"))
+            it.setBackgroundColor(Color.parseColor("#efeae1"))
+        }
+    }
+
+    private fun onActorTouchListener(layer: Int,position: Int) : View.OnTouchListener {
+        return View.OnTouchListener {view, motionEvent ->
+            when (motionEvent.action) {
+                MotionEvent.ACTION_DOWN -> {
+                    when (layer == selectLayer) {
+                        true -> {
+                            val item = ClipData.Item(position.toString())
+                            val mimeTypes = arrayOf(ClipDescription.MIMETYPE_TEXT_PLAIN)
+                            val dragData = ClipData(null, mimeTypes, item)
+                            val shadow = View.DragShadowBuilder(view)
+                            view.startDrag(dragData, shadow, null, View.DRAG_FLAG_GLOBAL)
+                        }
+                        false -> {
+                            selectLayer = layer
+                            layout_layer_management_layer1.setBackgroundColor(Color.parseColor("#ffffff"))
+                            layout_layer_management_layer2.setBackgroundColor(Color.parseColor("#ffffff"))
+                            layout_layer_management_layer3.setBackgroundColor(Color.parseColor("#ffffff"))
+                            layout_layer_management_layer4.setBackgroundColor(Color.parseColor("#ffffff"))
+                            layout_layer_management_layer5.setBackgroundColor(Color.parseColor("#ffffff"))
+                            when(selectLayer){
+                                1 -> layout_layer_management_layer1.setBackgroundColor(Color.parseColor("#efeae1"))
+                                2 -> layout_layer_management_layer2.setBackgroundColor(Color.parseColor("#efeae1"))
+                                3 -> layout_layer_management_layer3.setBackgroundColor(Color.parseColor("#efeae1"))
+                                4 -> layout_layer_management_layer4.setBackgroundColor(Color.parseColor("#efeae1"))
+                                5 -> layout_layer_management_layer5.setBackgroundColor(Color.parseColor("#efeae1"))
+                            }
+                        }
+                    }
+
+                }
+            }
+            return@OnTouchListener true
+        }
+    }
+
+    interface OnLayerChange{
+        fun onLayerChange(layerFrom: Int, layerTo: Int, position: Int)
+    }
+}

+ 5 - 1
src/main/java/com/bomostory/sceneeditmodule/navigationbar/NavigationBarView.kt

@@ -6,13 +6,13 @@ import android.view.LayoutInflater
 import android.widget.ImageButton
 import android.widget.RelativeLayout
 import com.example.tfat.myapplication.R
+import kotlinx.android.synthetic.main.navigation_bar_view.view.*
 
 class NavigationBarView : RelativeLayout{
     private lateinit var scene : RelativeLayout
     private lateinit var actor : RelativeLayout
     private lateinit var brush : RelativeLayout
     private lateinit var dialogue : RelativeLayout
-    private lateinit var image : ImageButton
     private lateinit var settings : ImageButton
 
     constructor(context : Context) : super(context) {
@@ -57,4 +57,8 @@ class NavigationBarView : RelativeLayout{
     fun setonClickDialogueBtn(onClickListener: OnClickListener) {
         dialogue.setOnClickListener(onClickListener)
     }
+
+    fun setonClickImageBtn(onClickListener: OnClickListener) {
+        layout_navigation_bar_image.setOnClickListener(onClickListener)
+    }
 }

+ 36 - 0
src/main/java/com/bomostory/sceneeditmodule/utils/FileUtils.kt

@@ -0,0 +1,36 @@
+package com.bomostory.sceneeditmodule.utils
+
+import android.content.Context
+import android.graphics.Bitmap
+import android.net.Uri
+import android.provider.MediaStore
+import com.bomostory.sceneeditmodule.Config
+import java.io.BufferedOutputStream
+import java.io.File
+import java.io.FileOutputStream
+
+object FileUtils {
+    fun saveImageForActor(context: Context, uri: Uri, fileName: String){
+        val dir = File(Config.IMAGE_FOLDER,"")
+        dir.mkdir()
+        val file = File(Config.IMAGE_FOLDER, fileName)
+        try {
+            val bitmap = MediaStore.Images.Media.getBitmap(context.contentResolver, uri)
+            val bos = BufferedOutputStream(FileOutputStream(file))
+            bitmap.compress(Bitmap.CompressFormat.JPEG, 80, bos)
+            bos.flush()
+            bos.close()
+            if (context is OnSaveActorImage) {
+                context.onSaveActorImage(file.path)
+            } else {
+                throw RuntimeException(context.toString() + " must implement OnFragmentInteractionListener")
+            }
+        } catch (e: Exception) {
+            e.printStackTrace()
+        }
+    }
+
+    interface OnSaveActorImage {
+        fun onSaveActorImage(filePath: String)
+    }
+}

+ 17 - 9
src/main/res/drawable/actor_resize_circle.xml

@@ -1,12 +1,20 @@
 <?xml version="1.0" encoding="utf-8"?>
-<shape
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:shape="oval">
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+    <item>
+        <shape
+            xmlns:android="http://schemas.android.com/apk/res/android"
+            android:shape="oval">
 
-    <solid
-        android:color="#4e342e"/>
+            <solid
+                android:color="#4e342e"/>
 
-    <size
-        android:width="24dp"
-        android:height="24dp"/>
-</shape>
+            <stroke
+                android:width="2dp"
+                android:color="#ffffff" />
+
+            <size
+                android:width="24dp"
+                android:height="24dp"/>
+        </shape>
+    </item>
+</layer-list>

+ 10 - 0
src/main/res/drawable/bg_layer_management_dialog.xml

@@ -0,0 +1,10 @@
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+  <solid
+      android:color="#ffffff"/>
+  <corners
+      android:topLeftRadius="8dp"
+      android:topRightRadius="8dp"
+      android:bottomRightRadius="8dp"
+      android:bottomLeftRadius="8dp"/>
+</shape>

+ 6 - 0
src/main/res/drawable/ic_button_back_01.xml

@@ -0,0 +1,6 @@
+<vector android:height="24dp" android:viewportHeight="48"
+    android:viewportWidth="48" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillAlpha=".9" android:fillColor="#FFF"
+        android:fillType="evenOdd" android:pathData="M24,24m-20,0a20,20 0,1 1,40 0a20,20 0,1 1,-40 0"/>
+    <path android:fillColor="#4E342E" android:fillType="nonZero" android:pathData="M32,23H19.83l5.59,-5.59L24,16l-8,8 8,8 1.41,-1.41L19.83,25H32z"/>
+</vector>

+ 11 - 9
src/main/res/layout/activity_scene_edit.xml

@@ -7,11 +7,20 @@
     android:background="#212121"
     tools:context=".SceneEditActivity">
 
-    <ImageView
+    <RelativeLayout
         android:id="@+id/bar"
         android:layout_width="match_parent"
         android:layout_height="128dp"
-        app:layout_constraintTop_toTopOf="parent" />
+        app:layout_constraintTop_toTopOf="parent">
+        <ImageView
+            android:id="@+id/ic_scene_edit_activity_back"
+            android:layout_width="48dp"
+            android:layout_height="48dp"
+            android:layout_marginLeft="24dp"
+            android:layout_marginTop="36dp"
+            android:layout_alignParentStart="true"
+            android:src="@drawable/ic_button_back_01"/>
+    </RelativeLayout>
 
      <com.bomostory.sceneeditmodule.view.SceneView1
         android:id="@+id/sceneEditView"
@@ -20,13 +29,6 @@
         android:background="@android:color/holo_blue_dark"
         app:layout_constraintTop_toBottomOf="@+id/bar"/>
 
-    <!--<RelativeLayout-->
-        <!--android:id="@+id/sceneEditView"-->
-        <!--android:layout_width="1024dp"-->
-        <!--android:layout_height="512dp"-->
-        <!--android:background="#212121"-->
-        <!--app:layout_constraintTop_toBottomOf="@+id/bar" />-->
-
     <RelativeLayout
         android:id="@+id/viewContainer"
         android:layout_width="match_parent"

+ 2 - 5
src/main/res/layout/actor_item.xml

@@ -4,14 +4,11 @@
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:orientation="vertical">
-    <RelativeLayout
-        android:padding="16dp"
-        android:layout_width="128dp"
-        android:layout_height="128dp">
+
         <ImageView
             android:id="@+id/actor_image"
             android:scaleType="centerCrop"
             android:layout_width="96dp"
             android:layout_height="96dp"/>
-    </RelativeLayout>
+
 </LinearLayout>

+ 95 - 27
src/main/res/layout/layer_management_fragment.xml

@@ -1,32 +1,100 @@
 <?xml version="1.0" encoding="utf-8"?>
 <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
-    android:layout_width="wrap_content"
+    android:layout_width="832dp"
     android:layout_height="wrap_content"
-    android:background="#ffffff">
-    <android.support.v7.widget.RecyclerView
-        android:id="@+id/layer1"
-        android:layout_width="832dp"
-        android:layout_height="120dp"
-        app:layout_constraintTop_toTopOf="parent" />
-    <android.support.v7.widget.RecyclerView
-        android:id="@+id/layer2"
-        android:layout_width="832dp"
-        android:layout_height="120dp"
-        app:layout_constraintTop_toBottomOf="@+id/layer1"/>
-    <android.support.v7.widget.RecyclerView
-        android:id="@+id/layer3"
-        android:layout_width="832dp"
-        android:layout_height="120dp"
-        app:layout_constraintTop_toBottomOf="@id/layer2" />
-    <android.support.v7.widget.RecyclerView
-        android:id="@+id/layer4"
-        android:layout_width="832dp"
-        android:layout_height="120dp"
-        app:layout_constraintTop_toBottomOf="@id/layer3" />
-    <android.support.v7.widget.RecyclerView
-        android:id="@+id/layer5"
-        android:layout_width="832dp"
-        android:layout_height="120dp"
-        app:layout_constraintTop_toBottomOf="@id/layer4" />
+    android:background="@drawable/bg_layer_management_dialog">
+    <LinearLayout
+        android:id="@+id/tv_layer_management_title"
+        android:layout_width="match_parent"
+        android:layout_height="37dp"
+        android:orientation="vertical"
+        app:layout_constraintTop_toTopOf="parent">
+        <TextView
+            android:layout_width="match_parent"
+            android:layout_height="36dp"
+            android:text="Layer Management"
+            android:gravity="center"
+            android:textColor="#99000000"
+            android:textSize="16sp"/>
+        <View
+            android:layout_width="wrap_content"
+            android:layout_height="1dp"
+            android:background="#33000000"/>
+    </LinearLayout>
+    <LinearLayout
+        android:id="@+id/layout_layer_management_layer1"
+        android:layout_width="match_parent"
+        android:layout_height="121dp"
+        android:orientation="vertical"
+        app:layout_constraintTop_toBottomOf="@+id/tv_layer_management_title">
+        <android.support.v7.widget.RecyclerView
+            android:id="@+id/rv_layer_management_layer1"
+            android:layout_width="wrap_content"
+            android:layout_height="120dp"/>
+        <View
+            android:layout_width="wrap_content"
+            android:layout_height="1dp"
+            android:background="#33000000"/>
+    </LinearLayout>
+    <LinearLayout
+        android:id="@+id/layout_layer_management_layer2"
+        android:layout_width="match_parent"
+        android:layout_height="121dp"
+        android:orientation="vertical"
+        app:layout_constraintTop_toBottomOf="@id/layout_layer_management_layer1">
+        <android.support.v7.widget.RecyclerView
+            android:id="@+id/rv_layer_management_layer2"
+            android:layout_width="wrap_content"
+            android:layout_height="120dp"/>
+        <View
+            android:layout_width="wrap_content"
+            android:layout_height="1dp"
+            android:background="#33000000"/>
+    </LinearLayout>
+    <LinearLayout
+        android:id="@+id/layout_layer_management_layer3"
+        android:layout_width="match_parent"
+        android:layout_height="121dp"
+        android:orientation="vertical"
+        app:layout_constraintTop_toBottomOf="@id/layout_layer_management_layer2">
+        <android.support.v7.widget.RecyclerView
+            android:id="@+id/rv_layer_management_layer3"
+            android:layout_width="wrap_content"
+            android:layout_height="120dp"/>
+        <View
+            android:layout_width="wrap_content"
+            android:layout_height="1dp"
+            android:background="#33000000"/>
+    </LinearLayout>
+    <LinearLayout
+        android:id="@+id/layout_layer_management_layer4"
+        android:layout_width="match_parent"
+        android:layout_height="121dp"
+        android:orientation="vertical"
+        app:layout_constraintTop_toBottomOf="@id/layout_layer_management_layer3">
+        <android.support.v7.widget.RecyclerView
+            android:id="@+id/rv_layer_management_layer4"
+            android:layout_width="wrap_content"
+            android:layout_height="120dp"/>
+        <View
+            android:layout_width="wrap_content"
+            android:layout_height="1dp"
+            android:background="#33000000"/>
+    </LinearLayout>
+    <LinearLayout
+        android:id="@+id/layout_layer_management_layer5"
+        android:layout_width="match_parent"
+        android:layout_height="121dp"
+        android:orientation="vertical"
+        app:layout_constraintTop_toBottomOf="@id/layout_layer_management_layer4">
+        <android.support.v7.widget.RecyclerView
+            android:id="@+id/rv_layer_management_layer5"
+            android:layout_width="wrap_content"
+            android:layout_height="120dp"/>
+        <View
+            android:layout_width="wrap_content"
+            android:layout_height="1dp"
+            android:background="#33000000"/>
+    </LinearLayout>
  </android.support.constraint.ConstraintLayout>

+ 4 - 4
src/main/res/layout/navigation_bar_view.xml

@@ -99,11 +99,11 @@
                 android:textColor="#ffecb3"/>
         </RelativeLayout>
         <RelativeLayout
-            android:id="@+id/image"
+            android:id="@+id/layout_navigation_bar_image"
             android:layout_width="104dp"
             android:layout_height="match_parent"
             android:layout_toRightOf="@id/dialogue">
-            <Button
+            <ImageView
                 android:id="@+id/image_btn"
                 android:layout_margin="7dp"
                 android:layout_width="24dp"
@@ -111,7 +111,7 @@
                 android:scaleType="center"
                 android:background="#212121"
                 android:layout_centerHorizontal="true"
-                android:drawableTop="@drawable/ic_image"/>
+                android:src="@drawable/ic_image"/>
             <TextView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
@@ -124,7 +124,7 @@
             android:id="@+id/settings"
             android:layout_width="104dp"
             android:layout_height="match_parent"
-            android:layout_toRightOf="@id/image">
+            android:layout_toRightOf="@id/layout_navigation_bar_image">
             <Button
                 android:id="@+id/settings_btn"
                 android:layout_margin="7dp"