|
@@ -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]
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|