Kaynağa Gözat

choose-theme`

faterhenry 6 yıl önce
ebeveyn
işleme
81b78b2da4

+ 6 - 2
src/main/AndroidManifest.xml

@@ -12,12 +12,16 @@
         android:theme="@style/AppTheme">
         <activity
             android:name=".SceneEditActivity"
-            android:screenOrientation="landscape"></activity>
+            android:screenOrientation="landscape" />
         <activity
             android:name="com.bomostory.sceneeditmodule.screen.movie.MovieEditActivity"
             android:configChanges="orientation|keyboardHidden|screenSize"
+            android:label="@string/title_activity_movie_edit"
+            android:screenOrientation="landscape" />
+        <activity
+            android:name="com.bomostory.sceneeditmodule.ChooseThemeActivity">
             android:screenOrientation="landscape"
-            android:label="@string/title_activity_movie_edit" />
+        </activity>
     </application>
 
 </manifest>

+ 124 - 0
src/main/java/com/bomostory/sceneeditmodule/ChooseThemeActivity.kt

@@ -0,0 +1,124 @@
+package com.bomostory.sceneeditmodule
+
+import android.content.Context
+import android.content.Intent
+import android.graphics.drawable.Drawable
+import android.support.v7.app.AppCompatActivity
+import android.os.Bundle
+import android.support.v4.view.PagerAdapter
+import android.util.AttributeSet
+import android.view.LayoutInflater
+import android.view.View
+import com.bomostory.sceneeditmodule.basicdata.OtherThemes
+import com.example.tfat.myapplication.R
+import com.google.gson.Gson
+import kotlinx.android.synthetic.main.activity_choose_theme.*
+import android.widget.LinearLayout
+import kotlinx.android.synthetic.main.theme_page_view.view.*
+import android.view.ViewGroup
+import com.bomostory.sceneeditmodule.basicdata.ThemeActorResource
+import com.example.tfat.myapplication.SceneEditActivity
+
+
+class ChooseThemeActivity : AppCompatActivity() {
+
+    private lateinit var otherThemes: OtherThemes
+    private var pageList = ArrayList<ThemePageView>()
+    private var resourceObjectPath = ArrayList<String>()
+    private var resourceActorPath = ThemeActorResource()
+    private var coverPath = ArrayList<String>()
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+        setContentView(R.layout.activity_choose_theme)
+        otherThemes = Gson().fromJson<OtherThemes>(intent.getStringExtra("other_theme"), OtherThemes::class.java)
+        for (i in 0 until otherThemes.themes.size) {
+            var theme = otherThemes.themes[i]
+            val path = "${theme.assetFolder.path}/${theme.themeAssetIndex.largeFile}"
+            coverPath.add(path)
+        }
+        for (i in 0 until coverPath.size)  {
+            var themePageView = ThemePageView(this).apply {
+                iv_themePageView_cover.setImageDrawable(Drawable.createFromPath(coverPath[i]))
+                iv_themePageView_cover.setOnClickListener {
+                    resourceActorPath.actorPath = ArrayList<ArrayList<String>>().apply {
+                        otherThemes.themes[i].themeAssetIndex.contains.actor.forEach {
+                            add(ArrayList<String>().apply {
+                                it.value.values.forEach {
+                                    val path = "${otherThemes.themes[i].assetFolder.path}/${it.smallFile}"
+                                    add(path)
+                                }
+                            })
+                        }
+                    }
+                    resourceObjectPath = java.util.ArrayList<String>().apply {
+                        otherThemes.themes[i].themeAssetIndex.contains.obj.values.forEach {
+                            val path = "${otherThemes.themes[i].assetFolder.path}/${it.smallFile}"
+                            add(path)
+                        }
+                    }
+                    val intent = Intent(this@ChooseThemeActivity, SceneEditActivity::class.java).apply {
+                        putExtra("project", intent.getStringExtra("project"))
+                        putExtra("other_theme", Gson().toJson(otherThemes))
+                        putExtra("resource_actor", Gson().toJson(resourceActorPath))
+                        putStringArrayListExtra("resource_object", resourceObjectPath)
+                    }
+                    startActivity(intent)
+                    finish()
+                }
+            }
+            pageList.add(themePageView)
+        }
+        viewPager_newStory.adapter =  SamplePagerAdapter(pageList)
+    }
+    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 class SamplePagerAdapter(pageList: ArrayList<ThemePageView>) : PagerAdapter() {
+        var pageList = pageList
+
+        override fun getCount(): Int {
+            return pageList.size
+        }
+        override fun isViewFromObject(p0: View, p1: Any): Boolean {
+            return p1 == p0
+        }
+
+        override fun instantiateItem(container: ViewGroup, position: Int): Any {
+            container.addView(pageList[position])
+            return pageList[position]
+        }
+
+        override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
+            container.removeView(`object` as View)
+        }
+    }
+    private class ThemePageView : LinearLayout {
+
+        constructor(context: Context) : super(context) {
+            initView()
+        }
+
+        constructor(context: Context, attrs: AttributeSet): super(context, attrs) {
+            initView()
+        }
+
+        constructor(context: Context, attrs: AttributeSet, defStyle: Int): super(context, attrs, defStyle) {
+            initView()
+        }
+
+        private fun initView() {
+            val inflater = LayoutInflater.from(context)
+            inflater.inflate(R.layout.theme_page_view, this, true)
+        }
+    }
+}

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

@@ -64,6 +64,7 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         BrushView.OnSelectBrush {
 
     private lateinit var project: Project
+    private lateinit var otherThemes: OtherThemes
     private var currentSceneIndex = 0
     private var currentLayerIndex = 6
     private var startRecordTime = 0L
@@ -92,7 +93,6 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         const val ACTOR_INIT_POSITION_Y = 200
         const val BACKGROUND_MOVE_RATE = 32
         const val BRUSH_SIZE = 16
-        const val INIT_SCENE_NUMBER = 11
         const val TIME_STEP_FOR_FPS = 33L
         val listeners = CopyOnWriteArrayList<Runnable>()
     }
@@ -105,14 +105,26 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         actionBar?.hide()
         supportActionBar?.hide()
         project = Gson().fromJson<Project>(intent.getStringExtra("project"), Project::class.java)
+        otherThemes = when(intent.getStringExtra("other_theme")){
+            null -> OtherThemes()
+            else -> Gson().fromJson<OtherThemes>(intent.getStringExtra("other_theme"), OtherThemes::class.java)
+        }
         resourceThemeBitmap = project.sceneResource as ArrayList<String>
         resourceThemeBitmap.add(File(Config.ASSETS_FOLDER, Config.PROJECT_WHITE_FILE_NAME).path)
-        resourceActorBitmap = project.actorResource as ArrayList<ArrayList<String>>
-        resourceObjectPath = ArrayList<String>().apply {
-            project.themeAssetIndex.contains.obj.values.forEach {
-                val path = "${project.assetFolder.path}/${it.smallFile}"
-                add(path)
+        resourceActorBitmap = when(intent.getStringExtra("resource_actor")) {
+            null -> { project.actorResource as ArrayList<ArrayList<String>>}
+            else -> { Gson().fromJson<ThemeActorResource>(intent.getStringExtra("resource_actor"), ThemeActorResource::class.java).actorPath}
+        }
+        resourceObjectPath = when(intent.getStringArrayListExtra("resource_object")) {
+            null -> {
+                ArrayList<String>().apply {
+                    project.themeAssetIndex.contains.obj.values.forEach {
+                        val path = "${project.assetFolder.path}/${it.smallFile}"
+                        add(path)
+                    }
+                }
             }
+            else -> {intent.getStringArrayListExtra("resource_object")}
         }
         windowManager.defaultDisplay.getMetrics(monitorSize)
         var layoutPrams = sceneEditView.layoutParams
@@ -417,6 +429,15 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
                 initActorRecyclerView()
             }
         }
+        selectActorView.btn_choose_theme.setOnClickListener {
+            if (!otherThemes.themes.isEmpty()) {
+                var intent = Intent(this, ChooseThemeActivity::class.java)
+                intent.putExtra("project", Gson().toJson(project))
+                intent.putExtra("other_theme", Gson().toJson(otherThemes))
+                startActivity(intent)
+                finish()
+        }
+        }
     }
     private fun initDialogueView(){
         if (viewContainer.getChildAt(0) is DialogueView) {
@@ -792,9 +813,6 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
                     initActorRecyclerView()
                 }
             }
-            selectActorView.btn_choose_theme.setOnClickListener {
-                /////TFTA
-            }
             viewContainer.addView(selectActorView)
         }
     }

+ 8 - 0
src/main/java/com/bomostory/sceneeditmodule/basicdata/OtherThemes.kt

@@ -0,0 +1,8 @@
+package com.bomostory.sceneeditmodule.basicdata
+
+import com.example.bomocloud.theme.ThemeAssetIndex
+import java.io.File
+
+class OtherThemes (
+        var themes: ArrayList<Theme> = ArrayList()
+)

+ 9 - 0
src/main/java/com/bomostory/sceneeditmodule/basicdata/Theme.kt

@@ -0,0 +1,9 @@
+package com.bomostory.sceneeditmodule.basicdata
+
+import com.example.bomocloud.theme.ThemeAssetIndex
+import java.io.File
+
+data class Theme (
+        val themeAssetIndex: ThemeAssetIndex,
+        var assetFolder: File
+)

+ 5 - 0
src/main/java/com/bomostory/sceneeditmodule/basicdata/ThemeActorResource.kt

@@ -0,0 +1,5 @@
+package com.bomostory.sceneeditmodule.basicdata
+
+class ThemeActorResource {
+    var actorPath = ArrayList<ArrayList<String>>()
+}

+ 32 - 0
src/main/res/layout/activity_choose_theme.xml

@@ -0,0 +1,32 @@
+<?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"
+xmlns:tools="http://schemas.android.com/tools"
+android:layout_width="match_parent"
+android:layout_height="match_parent"
+tools:context="com.bomostory.sceneeditmodule.ChooseThemeActivity">
+<ImageView
+    android:id="@+id/go_back_view"
+    android:layout_width="match_parent"
+    android:layout_height="114dp"
+    app:layout_constraintTop_toTopOf="parent"/>
+<TextView
+    android:id="@+id/tv_newStory_themeName"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:gravity="center"
+    app:layout_constraintTop_toBottomOf="@+id/go_back_view"
+    android:textSize="34sp"/>
+<android.support.v4.view.ViewPager
+    android:id="@+id/viewPager_newStory"
+    android:clipToPadding="false"
+    android:paddingRight="208dp"
+    android:paddingLeft="208dp"
+    android:layout_width="0dp"
+    android:layout_height="0dp"
+    app:layout_constraintBottom_toBottomOf="parent"
+    app:layout_constraintLeft_toLeftOf="parent"
+    app:layout_constraintRight_toRightOf="parent"
+    app:layout_constraintTop_toBottomOf="@+id/tv_newStory_themeName">
+</android.support.v4.view.ViewPager>
+</android.support.constraint.ConstraintLayout>

+ 21 - 0
src/main/res/layout/theme_page_view.xml

@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_height="match_parent">
+
+    <ImageView
+        android:id="@+id/iv_themePageView_cover"
+        android:layout_width="480dp"
+        android:layout_height="480dp"
+        android:layout_marginTop="36dp"
+        android:background="@color/white"
+        android:elevation="12dp"
+        android:padding="4dp"
+        android:scaleType="centerCrop"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toRightOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+
+</android.support.constraint.ConstraintLayout>