소스 검색

Merge branch 'settings-auto-swipe'

faterhenry 6 년 전
부모
커밋
aef47c9e92

+ 124 - 65
src/main/java/com/bomostory/sceneeditmodule/SceneEditActivity.kt

@@ -26,6 +26,8 @@ import com.example.tfat.myapplication.navigationbar.actor.LayerManagementDialog
 import kotlinx.android.synthetic.main.control_actor_dialog.view.*
 import com.bomostory.sceneeditmodule.utils.FileUtils
 import android.util.DisplayMetrics
+import android.util.Log
+import android.widget.RadioGroup
 import com.bomostory.sceneeditmodule.EditTextDialog
 import com.bomostory.sceneeditmodule.screen.movie.MovieEditActivity
 import com.example.tfat.myapplication.navigationbar.EditSceneView
@@ -41,7 +43,10 @@ import com.bomostory.sceneeditmodule.DialogueColorData
 import com.bomostory.sceneeditmodule.SceneDrawer
 import com.bomostory.sceneeditmodule.navigationbar.brush.BrushView
 import com.bomostory.sceneeditmodule.screen.view.*
+import kotlinx.android.synthetic.main.movie_item_view.*
+import kotlinx.android.synthetic.main.navigation_bar_view.view.*
 import kotlinx.android.synthetic.main.popupview_color_dialog.view.*
+import kotlinx.android.synthetic.main.popupview_setting.view.*
 import kotlinx.android.synthetic.main.scene_brush_view.view.*
 import java.util.*
 
@@ -62,6 +67,7 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
     private var resourceActorBitmap = ArrayList<ArrayList<String>>()
     private lateinit var sceneAdapter: SceneAdapter
     private var isRecord = false
+    private var isAutoSwipe = false
     private var layerManagementDialog = LayerManagementDialog()
     private var editTextDialog = EditTextDialog()
     private val monitorSize = DisplayMetrics()
@@ -78,6 +84,7 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         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>()
     }
 
@@ -121,7 +128,7 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
                     }
         }
         initControlBarView()
-        initNavigationBarView()
+        initNavigationFunction()
         initRecord()
     }
 
@@ -182,54 +189,25 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         })
     }
 
-    private fun initNavigationBarView() {
+    private fun initNavigationBarView(position: Int) {
         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 {
-                        initBrushView()
-                    })
-                    navigationBarView.setonClickDialogueBtn(View.OnClickListener {
-                        initDialogueView()
-                    })
-                    navigationBarView.setonClickImageBtn(View.OnClickListener {
-                        pickFromGallery()
-                    })
+                if (position != currentSceneIndex) {
+                    initNavigationFunction()
                 } else {
                     navigationBar.removeAllViews()
                     var editSceneView = EditSceneView(this)
                     navigationBar.addView(editSceneView)
                     setControlSceneView()
                     editSceneView.setOnClickDoneListener(View.OnClickListener {
-                        val pd = ProgressDialog(this).apply {
-                                     setCancelable(false)
-                                 }
-                    FileUtils.saveProject(this, 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)
+                        initNavigationFunction()
                     })
                     editSceneView.setOnClickStartOverListener(View.OnClickListener {
                         project.story?.let {
                             it.scenes?.let{
                                 it[currentSceneIndex].record = null
                                 sceneEditView.scene = it[currentSceneIndex]
-                                initNavigationBarView()
+                                initNavigationBarView(currentSceneIndex)
                             }
                         }
                     })
@@ -260,8 +238,8 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
                                     }
                                     false -> sceneEditView.scene = it[currentSceneIndex]
                                 }
-                                initNavigationBarView()
-                                initControlSceneView()
+                                initNavigationBarView(currentSceneIndex)
+                                setControlSceneView()
                             }
                         }
                     })
@@ -270,6 +248,63 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         }
     }
 
+    private fun initNavigationFunction(){
+        var navigationBarView = NavigationBarView(this)
+        navigationBar.addView(navigationBarView)
+        navigationBarView.setonClickSceneBtn(View.OnClickListener {
+            initControlSceneView()
+        })
+        navigationBarView.setonClickActorBtn(View.OnClickListener {
+            initActorRecyclerView()
+        })
+        navigationBarView.setonClickBrushBtn(View.OnClickListener {
+            initBrushView()
+        })
+        navigationBarView.setonClickDialogueBtn(View.OnClickListener {
+            initDialogueView()
+        })
+        navigationBarView.setonClickImageBtn(View.OnClickListener {
+            pickFromGallery()
+        })
+        navigationBarView.setonClickSettingBtn(View.OnClickListener {
+            var popupWindow = PopupWindow(this)
+            popupWindow.contentView = createSettingPopupView(popupWindow)
+            popupWindow.width = ViewGroup.LayoutParams.WRAP_CONTENT
+            popupWindow.height = ViewGroup.LayoutParams.WRAP_CONTENT
+            popupWindow.isOutsideTouchable = true
+            var valueXInPixels = resources.getDimension(R.dimen.popup_view_setting_height) + resources.getDimension(R.dimen.navigation_bar_height)
+            popupWindow.showAsDropDown(navigationBarView.settings, 0, -(valueXInPixels).toInt(), Gravity.CENTER_HORIZONTAL)
+
+        })
+    }
+
+    private fun createSettingPopupView(popupWindow: PopupWindow): View{
+        val popupView = LayoutInflater.from(this).inflate(R.layout.popupview_setting, null)
+        when (isAutoSwipe) {
+            true -> {
+                popupView.rb_manual.isChecked  = false
+                popupView.rb_auto_swipe.isChecked = true
+            }
+            false -> {
+                popupView.rb_manual.isChecked  = true
+                popupView.rb_auto_swipe.isChecked = false
+            }
+        }
+
+        popupView.rg_settings.setOnCheckedChangeListener(object : RadioGroup.OnCheckedChangeListener{
+            override fun onCheckedChanged(group: RadioGroup?, checkedId: Int) {
+                when (checkedId) {
+                    popupView.rb_manual.id -> {
+                        isAutoSwipe = false
+                    }
+                    popupView.rb_auto_swipe.id ->{
+                        isAutoSwipe = true
+                    }
+                }
+            }
+        })
+        return popupView
+    }
     private fun initBrushView(){
         if (navigationBar.getChildAt(0) is BrushView) {
             navigationBar.removeAllViews()
@@ -299,7 +334,6 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
                 var brush = paint_view.brush
                 brush.brushSize = p1
                 paint_view.brush = brush
-                //paint_view.brushType = 0
             }
             override fun onStartTrackingTouch(p0: SeekBar?) {
             }
@@ -310,7 +344,7 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
             navigationBar.removeAllViews()
             paint_view.visibility = View.INVISIBLE
             startRecord.visibility = View.VISIBLE
-            initNavigationBarView()
+            initNavigationBarView(currentSceneIndex)
             FileUtils.saveBitmapForActor(this, paint_view.bitmap, System.currentTimeMillis().toString())
             project.story?.let {
                 it.scenes?.let{
@@ -325,7 +359,6 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         paint_view.visibility = View.VISIBLE
         paint_view.setOnTouchListener(paint_view)
         paint_view.brush = initBrush
-        //paint_view.brushType = 0
     }
 
     private fun initActorRecyclerView() {
@@ -388,7 +421,7 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
             it.scenes?.let{
                 for (i in 0 until it.size) {
                     onSceneSelectedArrayList.add(switchScene(i))
-                    projectBitmaps.add(SceneDrawer.drawScene(this,it[i],0,1920,1080))
+                    projectBitmaps.add(SceneDrawer.drawScene(this,it[i],0,200,100))
                     recordTimeArrayList.add(it[i].record?.period)
                 }
             }
@@ -464,11 +497,39 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
                 tv_scene_activity_record_time.text = "Recording 00:00"
                 isRecord = false
                 record.period = System.currentTimeMillis() - startRecordTime
-                project.story?.let {
-                    it.scenes?.let{
-                        it[currentSceneIndex].record = record
+                if (!isAutoSwipe){
+                    project.story?.let {
+                        it.scenes?.let{
+                            it[currentSceneIndex].record = record
+                        }
+                    }
+                } else {
+                    var autoSwipeRecord = Record()
+                    autoSwipeRecord.period = record.period
+                    for (i in 0 until record.period step TIME_STEP_FOR_FPS)
+                    autoSwipeRecord.tracks.apply {
+                        var track = Track().apply {
+                            when (i <= record.period.div(2)){
+                                true -> {
+                                    positionX = (-monitorSize.widthPixels.div(2)) + i.div(TIME_STEP_FOR_FPS).toInt() * monitorSize.widthPixels.div(record.period.div(2 * TIME_STEP_FOR_FPS).toInt())
+                                    time = i
+                                }
+                                false -> {
+                                    var j = i - record.period.div(2)
+                                    positionX = (monitorSize.widthPixels.div(2)) - j.div(TIME_STEP_FOR_FPS).toInt() * monitorSize.widthPixels.div(record.period.div(2 * TIME_STEP_FOR_FPS).toInt())
+                                    time = i
+                                }
+                            }
+                        }
+                        add(track)
+                    }
+                    project.story?.let {
+                        it.scenes?.let{
+                            it[currentSceneIndex].record = autoSwipeRecord
+                        }
                     }
                 }
+
                 startRecord.setImageDrawable(resources.getDrawable(R.drawable.ic_btn_record))
                 navigationBar.visibility = View.VISIBLE
                 initControlBarView()
@@ -498,15 +559,29 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
                 }
             }
             initControlBarView()
-            initNavigationBarView()
+            initNavigationBarView(currentSceneIndex)
         })
         recordFinishView.setOnFinishClickListener(View.OnClickListener {
-            initNavigationBarView()
+            val pd = ProgressDialog(this).apply {
+                         setCancelable(false)
+                     }
+            FileUtils.saveProject(this, 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)
         })
         navigationBar.addView(recordFinishView)
     }
     private fun switchScene(position: Int): View.OnClickListener {
         return View.OnClickListener {
+            var oldSceneIndex = currentSceneIndex
             currentSceneIndex = position
             switchToPreViewLayer()
             project.story?.let {
@@ -516,7 +591,7 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
             }
             record = Record()
             initControlBarView()
-            initNavigationBarView()
+            initNavigationBarView(oldSceneIndex)
         }
     }
 
@@ -601,7 +676,7 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         return View.OnClickListener {
             addScene(position)
             initControlSceneView()
-            initNavigationBarView()
+            initNavigationBarView(currentSceneIndex)
         }
     }
 
@@ -621,22 +696,6 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         }
     }
 
-    private fun addScene(index: Int, backgroundPath: String?){
-        var scene = Scene()
-        for (i in 5 until 0){
-            val layer = Layer()
-            layer.id = i
-            scene.layers.add(layer)
-        }
-        scene.backgroundPath = backgroundPath
-        project.story?.let {
-            it.scenes?.let{
-                scene.sceneWidth = monitorSize.widthPixels
-                it.add(scene)
-            }
-        }
-    }
-
     private fun replaceScene(position: Int): View.OnClickListener {
         return View.OnClickListener {
             project.story?.let {
@@ -646,7 +705,7 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
                 }
             }
             initControlSceneView()
-            initNavigationBarView()
+            initNavigationBarView(currentSceneIndex)
         }
     }
     private fun setActorPositionZ(actors: ArrayList<Actor>){

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

@@ -13,7 +13,6 @@ class NavigationBarView : RelativeLayout{
     private lateinit var actor : RelativeLayout
     private lateinit var brush : RelativeLayout
     private lateinit var dialogue : RelativeLayout
-    private lateinit var settings : ImageButton
 
     constructor(context : Context) : super(context) {
         initView()
@@ -52,6 +51,10 @@ class NavigationBarView : RelativeLayout{
         dialogue.setOnClickListener(onClickListener)
     }
 
+    fun setonClickSettingBtn(onClickListener: OnClickListener) {
+        settings.setOnClickListener(onClickListener)
+    }
+
     fun setonClickImageBtn(onClickListener: OnClickListener) {
         layout_navigation_bar_image.setOnClickListener(onClickListener)
     }

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

@@ -23,7 +23,7 @@ class RecordFinishView : RelativeLayout{
 
     private fun initView(){
         val inflater = LayoutInflater.from(context)
-        var rootView = inflater.inflate(R.layout.record_finish_view, this, true)
+        inflater.inflate(R.layout.record_finish_view, this, true)
     }
 
     fun setOnFinishClickListener(onClickListener: OnClickListener) {

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

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+    <solid android:color="#ffffff" />
+    <corners android:radius="4dp" />
+</shape>

+ 1 - 1
src/main/res/layout/activity_scene_edit.xml

@@ -11,7 +11,7 @@
     <RelativeLayout
         android:id="@+id/bar"
         android:layout_width="match_parent"
-        android:layout_height="128dp"
+        android:layout_height="@dimen/navigation_bar_height"
         app:layout_constraintTop_toTopOf="parent">
         <ImageView
             android:id="@+id/ic_scene_edit_activity_back"

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

@@ -125,7 +125,7 @@
             android:layout_width="104dp"
             android:layout_height="match_parent"
             android:layout_toRightOf="@id/layout_navigation_bar_image">
-            <Button
+            <ImageView
                 android:id="@+id/settings_btn"
                 android:layout_margin="7dp"
                 android:layout_width="24dp"
@@ -133,7 +133,7 @@
                 android:scaleType="center"
                 android:background="#212121"
                 android:layout_centerHorizontal="true"
-                android:drawableTop="@drawable/ic_settings" />
+                android:src="@drawable/ic_settings" />
             <TextView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"

+ 43 - 0
src/main/res/layout/popupview_setting.xml

@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="192dp"
+    android:layout_height="wrap_content"
+    android:background="@drawable/btn_round_corner_white"
+    android:padding="24dp"
+    android:orientation="vertical">
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text = "Settings"
+        android:textColor="#de000000"
+        android:textSize="20sp"
+        android:paddingBottom="24dp"/>
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text = "Recording Mode"
+        android:textColor="#99000000"
+        android:textSize="16sp"
+        android:paddingBottom="24dp"/>
+    <RadioGroup
+        android:id="@+id/rg_settings"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:orientation="vertical">
+        <RadioButton
+            android:id="@+id/rb_manual"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textColor="#4e342e"
+            android:textSize="16sp"
+            android:text="Manual"
+            android:checked="true"/>
+        <RadioButton
+            android:id="@+id/rb_auto_swipe"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textColor="#4e342e"
+            android:textSize="16sp"
+            android:text="Auto Swipe" />
+    </RadioGroup>
+</LinearLayout>

+ 2 - 0
src/main/res/values/dimens.xml

@@ -7,4 +7,6 @@
     <dimen name="actor_width">120dp</dimen>
     <dimen name="edit_actor_padding">24dp</dimen>
     <dimen name="dialogue_padding">50dp</dimen>
+    <dimen name="popup_view_setting_height">208dp</dimen>
+    <dimen name="navigation_bar_height">128dp</dimen>
 </resources>