Browse Source

Merge branch 'ProjectSave_and_Load'

faterhenry 6 years ago
parent
commit
92a1c1db83

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

@@ -11,6 +11,6 @@ object Config {
     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)
-
+    const val PROJECT_FILE_NAME = "index"
     val PDF_FOLDER = File(ROOT, "pdf")
 }

+ 45 - 27
src/main/java/com/bomostory/sceneeditmodule/SceneEditActivity.kt

@@ -1,6 +1,7 @@
 package com.example.tfat.myapplication
 
 import android.app.Activity
+import android.app.ProgressDialog
 import android.content.DialogInterface
 import android.content.Intent
 import android.support.v7.app.AppCompatActivity
@@ -10,7 +11,6 @@ import android.graphics.drawable.Drawable
 import android.support.v7.widget.RecyclerView
 import android.view.*
 import android.widget.PopupWindow
-import com.bomostory.sceneeditmodule.Config
 import com.bomostory.sceneeditmodule.MovieEditActivity
 import com.example.tfat.myapplication.navigationbar.NavigationBarView
 import com.example.tfat.myapplication.navigationbar.actor.ActorAdapter
@@ -28,14 +28,12 @@ import com.bomostory.sceneeditmodule.view.OnTouchBoMoSceneListener
 import com.example.tfat.myapplication.navigationbar.RecordFinishView
 import com.example.tfat.myapplication.navigationbar.actor.LayerManagementDialog
 import kotlinx.android.synthetic.main.control_actor_dialog.view.*
-import java.io.File
-import java.io.FileWriter
 import com.bomostory.sceneeditmodule.utils.FileUtils
 import com.bomostory.sceneeditmodule.view.LayerView
 import android.util.DisplayMetrics
-
-
-
+import io.reactivex.android.schedulers.AndroidSchedulers
+import io.reactivex.schedulers.Schedulers
+import java.util.concurrent.CopyOnWriteArrayList
 
 class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener, EditActorView.OnActorChangeListener,
         OnTouchBoMoSceneListener.OnSceneMoveListener, DialogInterface.OnDismissListener, FileUtils.OnSaveActorImage,
@@ -61,6 +59,7 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         const val ACTOR_INIT_POSITION_X = 200
         const val ACTOR_INIT_POSITION_Y = 200
         const val BACKGROUND_MOVE_RATE = 32
+        val listeners = CopyOnWriteArrayList<Runnable>()
     }
 
     override fun onCreate(savedInstanceState: Bundle?) {
@@ -81,7 +80,19 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
             }
         }
         ic_scene_edit_activity_back.setOnClickListener {
-            this.onBackPressed()
+            val pd = ProgressDialog(this).apply {
+                setCancelable(false)
+            }
+            FileUtils.saveProject(project, 1920,1080)
+                    .subscribeOn(Schedulers.io())
+                    .observeOn(AndroidSchedulers.mainThread())
+                    .doOnSubscribe { pd.show() }
+                    .doFinally {
+                        pd.dismiss()
+                        this.onBackPressed()}
+                    .subscribe {
+                        listeners.forEach {it.run()}
+                    }
         }
         initControlBarView()
         initNavigationBarView()
@@ -160,30 +171,36 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
                     navigationBar.removeAllViews()
                     var recordFinishView = RecordFinishView(this)
                     recordFinishView.setOnNextSceneClickListener(View.OnClickListener {
-                        switchScene(currentSceneIndex + 1)
-                    })
-                    recordFinishView.setOnFinishClickListener(View.OnClickListener {
+                        currentSceneIndex++
                         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
+                            it.scenes?.let{
+                                when(currentSceneIndex < it.size){
+                                    true -> {
+                                        switchToPreViewLayer()
+                                        sceneEditView.scene = it[currentSceneIndex]
+                                    }
+                                    false -> {
+                                        currentSceneIndex = 0
+                                        sceneEditView.scene = it[currentSceneIndex]
                                     }
                                 }
                             }
                         }
-                        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()
+                        initControlBarView()
+                        initNavigationBarView()
+                    })
+                    recordFinishView.setOnFinishClickListener(View.OnClickListener {
+                        val pd = ProgressDialog(this).apply {
+                            setCancelable(false)
                         }
+                        FileUtils.saveProject(project, 1920,1080)
+                                .subscribeOn(Schedulers.io())
+                                .observeOn(AndroidSchedulers.mainThread())
+                                .doOnSubscribe { pd.show() }
+                                .doFinally { pd.dismiss() }
+                                .subscribe {
+                                    listeners.forEach {it.run()}
+                                }
                         val intent = Intent(this, MovieEditActivity::class.java)
                         intent.putExtra(MovieEditActivity.PROJECT_KEY, Gson().toJson(project))
                         startActivity(intent)
@@ -399,6 +416,7 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
             scene.backgroundPath = resourceThemeBitmap[position]
             project.story?.let {
                 it.scenes?.let{
+                    scene.sceneWidth = monitorSize.widthPixels
                     it.add(scene)
                 }
             }
@@ -562,12 +580,12 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
 
 
     override fun onSceneMove(dX: Int) {
-        if ( (BACKGROUND_MOVE_RATE * 69) >= (swipeX + dX) && (swipeX + dX) > (-(BACKGROUND_MOVE_RATE * 69))) {
+        if ( (BACKGROUND_MOVE_RATE * 35) >= (swipeX + dX) && (swipeX + dX) > (-(BACKGROUND_MOVE_RATE * 35))) {
             sceneEditView.x = swipeX + dX
             if (isRecord) {
                 record?.tracks.let {
                     val track = Track()
-                    track.positionX = dX
+                    track.positionX = swipeX + dX
                     track.time = System.currentTimeMillis() - startRecordTime
                     record.tracks.add(track)
                 }

+ 7 - 3
src/main/java/com/bomostory/sceneeditmodule/navigationbar/dialogue/DialogueView.kt

@@ -102,9 +102,13 @@ class DialogueView: LinearLayout{
         iv_dialogue_view_yellow.setOnClickListener {
             this.dialogueData.apply {
                 clear()
-                add(R.drawable.ic_speechbubble_b1)
-                add(R.drawable.ic_speechbubble_w2)
-                add(R.drawable.ic_speechbubble_w3)
+                add(R.drawable.ic_speechbubble_y1)
+                add(R.drawable.ic_speechbubble_y2)
+                add(R.drawable.ic_speechbubble_y3)
+                add(R.drawable.ic_speechbubble_y4)
+                add(R.drawable.ic_speechbubble_y5)
+                add(R.drawable.ic_speechbubble_y6)
+                add(R.drawable.ic_speechbubble_y7)
             }
             this.dialogueListeners.apply {
                 clear()

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

@@ -5,9 +5,14 @@ import android.graphics.Bitmap
 import android.net.Uri
 import android.provider.MediaStore
 import com.bomostory.sceneeditmodule.Config
+import com.bomostory.sceneeditmodule.SceneDrawer
+import com.bomostory.sceneeditmodule.basicdata.Project
+import com.google.gson.Gson
+import io.reactivex.Completable
 import java.io.BufferedOutputStream
 import java.io.File
 import java.io.FileOutputStream
+import java.io.FileWriter
 
 object FileUtils {
     fun saveImageForActor(context: Context, uri: Uri, fileName: String){
@@ -30,6 +35,52 @@ object FileUtils {
         }
     }
 
+    fun saveProject(project: Project, scaleWidth: Int, scaleHeight: Int): Completable {
+        return Completable.create {
+            try {
+                val fileWriter = FileWriter(File(File(Config.PROJECTS_FOLDER, project.name),Config.PROJECT_FILE_NAME))
+                fileWriter.write(Gson().toJson(project))
+                fileWriter.flush()
+                when (project.story?.scenes?.size) {
+                    1 -> {
+                        var fileOutputStream = FileOutputStream(project.scene1File)
+                        project.story?.let {
+                            it.scenes?.let {
+                                SceneDrawer.drawScene(it[0], 0, scaleWidth, scaleHeight)?.compress(Bitmap.CompressFormat.PNG,
+                                        100, fileOutputStream)
+                                fileOutputStream.flush()
+                                fileOutputStream.close()
+                            }
+                        }
+                    }
+                    else -> {
+                        var fileOutputStream = FileOutputStream(project.scene1File)
+                        project.story?.let {
+                            it.scenes?.let {
+                                SceneDrawer.drawScene(it[0], 0, scaleWidth, scaleHeight)?.compress(Bitmap.CompressFormat.PNG,
+                                        100, fileOutputStream)
+                                fileOutputStream.flush()
+                                fileOutputStream.close()
+                            }
+                        }
+                        fileOutputStream = FileOutputStream(project.scene2File)
+                        project.story?.let {
+                            it.scenes?.let {
+                                SceneDrawer.drawScene(it[1], 0, scaleWidth, scaleHeight)?.compress(Bitmap.CompressFormat.PNG,
+                                        100, fileOutputStream)
+                                fileOutputStream.flush()
+                                fileOutputStream.close()
+                            }
+                        }
+                    }
+                }
+            } catch (e: Exception) {
+                e.printStackTrace()
+            }
+            it.onComplete()
+        }
+    }
+
     interface OnSaveActorImage {
         fun onSaveActorImage(filePath: String)
     }

+ 5 - 0
src/main/res/drawable/ic_speechbubble_y1.xml

@@ -0,0 +1,5 @@
+<vector android:height="24dp" android:viewportHeight="80"
+    android:viewportWidth="100" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillColor="#212121" android:pathData="M96,0H4C1.8,0 0,1.8 0,4v72c0,2.2 1.8,4 4,4h92c2.2,0 4,-1.8 4,-4V4C100,1.8 98.2,0 96,0L96,0z"/>
+    <path android:fillColor="#FFF573" android:pathData="M96,1c1.7,0 3,1.3 3,3v72c0,1.7 -1.3,3 -3,3H4c-1.7,0 -3,-1.3 -3,-3V4c0,-1.7 1.3,-3 3,-3H96"/>
+</vector>

+ 5 - 0
src/main/res/drawable/ic_speechbubble_y2.xml

@@ -0,0 +1,5 @@
+<vector android:height="24dp" android:viewportHeight="80"
+    android:viewportWidth="100" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillColor="#212121" android:pathData="M50,0C22.4,0 0,17.9 0,40s22.4,40 50,40s50,-17.9 50,-40S77.6,0 50,0L50,0z"/>
+    <path android:fillColor="#FFF573" android:pathData="M50,1c27,0 49,17.5 49,39S77,79 50,79S1,61.5 1,40S23,1 50,1"/>
+</vector>

+ 5 - 0
src/main/res/drawable/ic_speechbubble_y3.xml

@@ -0,0 +1,5 @@
+<vector android:height="24dp" android:viewportHeight="80"
+    android:viewportWidth="100" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillColor="#212121" android:pathData="M91.2,0H8.9C4,0 0,3.6 0,8v48.1c0,4.4 4,8 8.9,8h50.4L78.8,80l-2.6,-15.8h14.9c4.9,0 8.9,-3.6 8.9,-8V8C100.1,3.6 96.1,0 91.2,0L91.2,0z"/>
+    <path android:fillColor="#FFF573" android:pathData="M91.2,1c2.3,0 4.4,0.9 5.9,2.4C98.4,4.7 99,6.3 99,8v48.2c0,3.9 -3.6,7 -7.9,7H76.2H75l0.2,1.2l2.2,13.2L60,63.3l-0.3,-0.2h-0.4H8.9c-4.4,0 -7.9,-3.1 -7.9,-7V8c0,-3.9 3.6,-7 7.9,-7H91.2"/>
+</vector>

File diff suppressed because it is too large
+ 5 - 0
src/main/res/drawable/ic_speechbubble_y4.xml


+ 5 - 0
src/main/res/drawable/ic_speechbubble_y5.xml

@@ -0,0 +1,5 @@
+<vector android:height="24dp" android:viewportHeight="81"
+    android:viewportWidth="100" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillColor="#212121" android:pathData="M50,0C22.4,0 0,15.5 0,34.6C0,51.8 17.8,66 41.3,68.8c4.9,8.5 13,10.4 18.4,11.2c-6.2,-4.9 -6,-10.8 -6,-10.8C79.6,67.9 100,53 100,34.6C100,15.5 77.6,0 50,0L50,0z"/>
+    <path android:fillColor="#FFF573" android:pathData="M50,1c27,0 49,15.1 49,33.6c0,8.5 -4.6,16.6 -13,22.9c-8.5,6.3 -20,10.1 -32.4,10.7h-0.9v0.9c0,0.2 -0.1,4.7 3.9,9.2c-5.1,-1.2 -10.7,-3.7 -14.4,-10.1l-0.3,-0.4l-0.5,-0.1C18,65 1,51.1 1,34.6C1,16.1 23,1 50,1"/>
+</vector>

+ 5 - 0
src/main/res/drawable/ic_speechbubble_y6.xml

@@ -0,0 +1,5 @@
+<vector android:height="24dp" android:viewportHeight="80"
+    android:viewportWidth="100" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillColor="#212121" android:pathData="M50,0C22.4,0 0,15.8 0,35.3s22.4,35.3 50,35.3s50,-15.8 50,-35.3S77.6,0 50,0L50,0zM85.1,64.8c-3.1,0 -5.6,2 -5.6,4.4s2.5,4.4 5.6,4.4s5.6,-2 5.6,-4.4C90.7,66.7 88.2,64.8 85.1,64.8L85.1,64.8zM90.5,74.6c-2,0 -3.7,1.2 -3.7,2.7s1.7,2.7 3.7,2.7s3.7,-1.2 3.7,-2.7C94.2,75.8 92.5,74.6 90.5,74.6L90.5,74.6z"/>
+    <path android:fillColor="#FFF573" android:pathData="M50,1c27,0 49,15.4 49,34.3S77,69.6 50,69.6S1,54.2 1,35.3S23,1 50,1M85.1,65.8c2.5,0 4.6,1.5 4.6,3.4s-2.1,3.4 -4.6,3.4s-4.6,-1.5 -4.6,-3.4S82.6,65.8 85.1,65.8M90.5,75.6c1.4,0 2.7,0.8 2.7,1.7c0,0.9 -1.3,1.7 -2.7,1.7s-2.7,-0.8 -2.7,-1.7S89.1,75.6 90.5,75.6"/>
+</vector>

File diff suppressed because it is too large
+ 5 - 0
src/main/res/drawable/ic_speechbubble_y7.xml


File diff suppressed because it is too large
+ 4 - 2
src/main/res/drawable/ic_swipe_b.xml