|
@@ -1,21 +1,33 @@
|
|
package com.bomostory.sceneeditmodule.screen.draw
|
|
package com.bomostory.sceneeditmodule.screen.draw
|
|
|
|
|
|
|
|
+import android.app.Activity
|
|
import android.arch.lifecycle.Observer
|
|
import android.arch.lifecycle.Observer
|
|
import android.arch.lifecycle.ViewModelProviders
|
|
import android.arch.lifecycle.ViewModelProviders
|
|
|
|
+import android.content.Intent
|
|
import android.graphics.Color
|
|
import android.graphics.Color
|
|
-import android.graphics.drawable.ColorDrawable
|
|
|
|
import android.support.v7.app.AppCompatActivity
|
|
import android.support.v7.app.AppCompatActivity
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
|
|
+import android.view.Gravity
|
|
|
|
+import android.view.LayoutInflater
|
|
import android.view.View
|
|
import android.view.View
|
|
|
|
+import android.view.ViewGroup
|
|
|
|
+import android.widget.PopupWindow
|
|
import android.widget.SeekBar
|
|
import android.widget.SeekBar
|
|
|
|
+import com.bomostory.sceneeditmodule.basicdata.Project
|
|
|
|
+import com.bomostory.sceneeditmodule.utils.FileUtils
|
|
import com.example.tfat.myapplication.R
|
|
import com.example.tfat.myapplication.R
|
|
|
|
+import com.google.gson.Gson
|
|
import com.kdanmobile.kdanbrushlib.model.KdanBrush
|
|
import com.kdanmobile.kdanbrushlib.model.KdanBrush
|
|
import com.kdanmobile.kdanbrushlib.widget.DrawView
|
|
import com.kdanmobile.kdanbrushlib.widget.DrawView
|
|
import kotlinx.android.synthetic.main.activity_draw.*
|
|
import kotlinx.android.synthetic.main.activity_draw.*
|
|
|
|
+import kotlinx.android.synthetic.main.popupview_set_color.view.*
|
|
|
|
+import kotlinx.android.synthetic.main.scene_brush_view.view.*
|
|
|
|
|
|
-class DrawActivity : AppCompatActivity() {
|
|
|
|
|
|
+class DrawActivity : AppCompatActivity() , FileUtils.OnSaveActorImage{
|
|
private lateinit var viewModel: DrawViewModel
|
|
private lateinit var viewModel: DrawViewModel
|
|
private lateinit var drawView: DrawView
|
|
private lateinit var drawView: DrawView
|
|
|
|
+ private lateinit var popupView: View
|
|
|
|
+ private var popupWindow = PopupWindow()
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
super.onCreate(savedInstanceState)
|
|
@@ -27,18 +39,27 @@ class DrawActivity : AppCompatActivity() {
|
|
drawViewLayout.addView(drawView)
|
|
drawViewLayout.addView(drawView)
|
|
|
|
|
|
//TODO change button to your widget
|
|
//TODO change button to your widget
|
|
- pencil.setOnClickListener(this::onClickPencil)
|
|
|
|
- crayon.setOnClickListener(this::onClickCrayon)
|
|
|
|
- pen.setOnClickListener(this::onClickPen)
|
|
|
|
- chineseBrush.setOnClickListener(this::onClickChineseBrush)
|
|
|
|
- eraser.setOnClickListener(this::onClickEraser)
|
|
|
|
|
|
+ brush_view.iv_brush_view_brush1.setOnClickListener(this::onClickPencil)
|
|
|
|
+ brush_view.iv_brush_view_brush2.setOnClickListener(this::onClickCrayon)
|
|
|
|
+ brush_view.iv_brush_view_brush3.setOnClickListener(this::onClickPen)
|
|
|
|
+ brush_view.iv_brush_view_brush4.setOnClickListener(this::onClickChineseBrush)
|
|
|
|
+ brush_view.iv_brush_view_brush5.setOnClickListener(this::onClickEraser)
|
|
|
|
|
|
//TODO change button to your widget
|
|
//TODO change button to your widget
|
|
- color1.setOnClickListener(this::onColor1Selected)
|
|
|
|
- color2.setOnClickListener(this::onColor2Selected)
|
|
|
|
- color3.setOnClickListener(this::onColor3Selected)
|
|
|
|
-
|
|
|
|
- brushSizeSeekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
|
|
|
|
|
+ brush_view.iv_brush_view_color1.setOnClickListener(this::onColor1Selected)
|
|
|
|
+ brush_view.iv_brush_view_color2.setOnClickListener(this::onColor2Selected)
|
|
|
|
+ brush_view.iv_brush_view_color3.setOnClickListener(this::onColor3Selected)
|
|
|
|
+ brush_view.iv_brush_view_color4.setOnClickListener(this::onColor4Selected)
|
|
|
|
+ brush_view.iv_brush_view_color5.setOnClickListener(this::onColor5Selected)
|
|
|
|
+ brush_view.iv_brush_view_color6.setOnClickListener(this::onColor6Selected)
|
|
|
|
+ brush_view.iv_brush_view_color7.setOnClickListener(this::onColor7Selected)
|
|
|
|
+ brush_view.iv_brush_view_color8.setOnClickListener(this::onColor8Selected)
|
|
|
|
+ brush_view.iv_brush_view_color9.setOnClickListener(this::onColor9Selected)
|
|
|
|
+ brush_view.iv_brush_view_color10.setOnClickListener(this::onColor10Selected)
|
|
|
|
+ brush_view.btn_brush_view_tune.setOnClickListener(this::onTuneSelected)
|
|
|
|
+ brush_view.btn_brush_view_done.setOnClickListener(this::onDoneClick)
|
|
|
|
+
|
|
|
|
+ brush_view.seek_bar_brush_view_size.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
|
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
|
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
|
if (fromUser) onBrushSizeChanged(progress)
|
|
if (fromUser) onBrushSizeChanged(progress)
|
|
}
|
|
}
|
|
@@ -46,82 +67,114 @@ class DrawActivity : AppCompatActivity() {
|
|
override fun onStartTrackingTouch(seekBar: SeekBar?) {}
|
|
override fun onStartTrackingTouch(seekBar: SeekBar?) {}
|
|
override fun onStopTrackingTouch(seekBar: SeekBar?) {}
|
|
override fun onStopTrackingTouch(seekBar: SeekBar?) {}
|
|
})
|
|
})
|
|
- colorRValue.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
|
|
|
- override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
|
|
|
- if (fromUser) onColorRValueChanged(progress)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- override fun onStartTrackingTouch(seekBar: SeekBar?) {}
|
|
|
|
- override fun onStopTrackingTouch(seekBar: SeekBar?) {}
|
|
|
|
- })
|
|
|
|
- colorGValue.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
|
|
|
- override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
|
|
|
- if (fromUser) onColorGValueChanged(progress)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- override fun onStartTrackingTouch(seekBar: SeekBar?) {}
|
|
|
|
- override fun onStopTrackingTouch(seekBar: SeekBar?) {}
|
|
|
|
-
|
|
|
|
- })
|
|
|
|
- colorBValue.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
|
|
|
- override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
|
|
|
- if (fromUser) onColorBValueChanged(progress)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- override fun onStartTrackingTouch(seekBar: SeekBar?) {}
|
|
|
|
- override fun onStopTrackingTouch(seekBar: SeekBar?) {}
|
|
|
|
-
|
|
|
|
- })
|
|
|
|
- colorAValue.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
|
|
|
- override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
|
|
|
- if (fromUser) onColorAValueChanged(progress)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- override fun onStartTrackingTouch(seekBar: SeekBar?) {}
|
|
|
|
- override fun onStopTrackingTouch(seekBar: SeekBar?) {}
|
|
|
|
-
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
viewModel.initBrush(drawView)
|
|
viewModel.initBrush(drawView)
|
|
viewModel.initColor(resources)
|
|
viewModel.initColor(resources)
|
|
viewModel.currentBrushLiveData.observe(this, Observer(this::onBrushChanged))
|
|
viewModel.currentBrushLiveData.observe(this, Observer(this::onBrushChanged))
|
|
viewModel.currentColorIndexLiveData.observe(this, Observer(this::onColorIndexChanged))
|
|
viewModel.currentColorIndexLiveData.observe(this, Observer(this::onColorIndexChanged))
|
|
- viewModel.color1LiveData.observe(this, Observer(this::onColor1Changed))
|
|
|
|
- viewModel.color2LiveData.observe(this, Observer(this::onColor2Changed))
|
|
|
|
- viewModel.color3LiveData.observe(this, Observer(this::onColor3Changed))
|
|
|
|
|
|
+// viewModel.color1LiveData.observe(this, Observer(this::onColor1Changed))
|
|
|
|
+// viewModel.color2LiveData.observe(this, Observer(this::onColor2Changed))
|
|
|
|
+// viewModel.color3LiveData.observe(this, Observer(this::onColor3Changed))
|
|
viewModel.selectPencil()
|
|
viewModel.selectPencil()
|
|
|
|
+ popupView = LayoutInflater.from(this).inflate(R.layout.popupview_set_color, null)
|
|
}
|
|
}
|
|
|
|
|
|
private fun onClickPencil(view: View) {
|
|
private fun onClickPencil(view: View) {
|
|
viewModel.selectPencil()
|
|
viewModel.selectPencil()
|
|
|
|
+ brush_view.setBrush1()
|
|
}
|
|
}
|
|
|
|
|
|
private fun onClickCrayon(view: View) {
|
|
private fun onClickCrayon(view: View) {
|
|
viewModel.selectCrayon()
|
|
viewModel.selectCrayon()
|
|
|
|
+ brush_view.setBrush2()
|
|
}
|
|
}
|
|
|
|
|
|
private fun onClickPen(view: View) {
|
|
private fun onClickPen(view: View) {
|
|
viewModel.selectPen()
|
|
viewModel.selectPen()
|
|
|
|
+ brush_view.setBrush3()
|
|
}
|
|
}
|
|
|
|
|
|
private fun onClickChineseBrush(view: View) {
|
|
private fun onClickChineseBrush(view: View) {
|
|
viewModel.selectChineseBrush()
|
|
viewModel.selectChineseBrush()
|
|
|
|
+ brush_view.setBrush4()
|
|
}
|
|
}
|
|
|
|
|
|
private fun onClickEraser(view: View) {
|
|
private fun onClickEraser(view: View) {
|
|
viewModel.selectEraser()
|
|
viewModel.selectEraser()
|
|
|
|
+ brush_view.setBrush5()
|
|
}
|
|
}
|
|
|
|
|
|
private fun onColor1Selected(view: View?) {
|
|
private fun onColor1Selected(view: View?) {
|
|
viewModel.selectColor(0)
|
|
viewModel.selectColor(0)
|
|
|
|
+ brush_view.setColor1()
|
|
|
|
+ popupWindow.dismiss()
|
|
}
|
|
}
|
|
|
|
|
|
private fun onColor2Selected(view: View?) {
|
|
private fun onColor2Selected(view: View?) {
|
|
viewModel.selectColor(1)
|
|
viewModel.selectColor(1)
|
|
|
|
+ brush_view.setColor2()
|
|
|
|
+ popupWindow.dismiss()
|
|
}
|
|
}
|
|
|
|
|
|
private fun onColor3Selected(view: View?) {
|
|
private fun onColor3Selected(view: View?) {
|
|
viewModel.selectColor(2)
|
|
viewModel.selectColor(2)
|
|
|
|
+ brush_view.setColor3()
|
|
|
|
+ popupWindow.dismiss()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun onColor4Selected(view: View?) {
|
|
|
|
+ viewModel.selectColor(3)
|
|
|
|
+ brush_view.setColor4()
|
|
|
|
+ popupWindow.dismiss()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun onColor5Selected(view: View?) {
|
|
|
|
+ viewModel.selectColor(4)
|
|
|
|
+ brush_view.setColor5()
|
|
|
|
+ popupWindow.dismiss()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun onColor6Selected(view: View?) {
|
|
|
|
+ viewModel.selectColor(5)
|
|
|
|
+ brush_view.setColor6()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun onColor7Selected(view: View?) {
|
|
|
|
+ viewModel.selectColor(6)
|
|
|
|
+ brush_view.setColor7()
|
|
|
|
+ popupWindow.dismiss()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun onColor8Selected(view: View?) {
|
|
|
|
+ viewModel.selectColor(7)
|
|
|
|
+ brush_view.setColor8()
|
|
|
|
+ popupWindow.dismiss()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun onColor9Selected(view: View?) {
|
|
|
|
+ viewModel.selectColor(8)
|
|
|
|
+ brush_view.setColor9()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun onColor10Selected(view: View?) {
|
|
|
|
+ viewModel.selectColor(9)
|
|
|
|
+ brush_view.setColor10()
|
|
|
|
+ popupWindow.dismiss()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun onTuneSelected(view: View?){
|
|
|
|
+ popupWindow.dismiss()
|
|
|
|
+ viewModel.selectColor(10)
|
|
|
|
+ brush_view.initColorState()
|
|
|
|
+ popupWindow.contentView = createPopupView()
|
|
|
|
+ popupWindow.width = ViewGroup.LayoutParams.WRAP_CONTENT
|
|
|
|
+ popupWindow.height = ViewGroup.LayoutParams.WRAP_CONTENT
|
|
|
|
+ popupWindow.isOutsideTouchable = false
|
|
|
|
+ var valueXInPixels = resources.getDimension(R.dimen.popup_view_set_color_height)
|
|
|
|
+ popupWindow.showAsDropDown(brush_view, 0, -valueXInPixels.toInt(), Gravity.RIGHT)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun onDoneClick(view: View?) {
|
|
|
|
+ FileUtils.saveBitmapForActor(this, Gson().fromJson<Project>(intent.getStringExtra("project"), Project::class.java), drawView.drawerBitmap, System.currentTimeMillis().toString())
|
|
}
|
|
}
|
|
|
|
|
|
private fun onBrushSizeChanged(brushSize: Int) {
|
|
private fun onBrushSizeChanged(brushSize: Int) {
|
|
@@ -132,12 +185,12 @@ class DrawActivity : AppCompatActivity() {
|
|
kdanBrush?.apply {
|
|
kdanBrush?.apply {
|
|
drawView.brush = this
|
|
drawView.brush = this
|
|
|
|
|
|
- brushSize.text = "${this.radius.value}"
|
|
|
|
- brushSizeSeekBar.max = this.radius.max
|
|
|
|
- colorRValue.progress = Color.red(this.color)
|
|
|
|
- colorGValue.progress = Color.green(this.color)
|
|
|
|
- colorBValue.progress = Color.blue(this.color)
|
|
|
|
- colorAValue.progress = Color.alpha(this.color)
|
|
|
|
|
|
+ brush_view.tv_brush_view_size.text = "${"Size :"}${this.radius.value}"
|
|
|
|
+ brush_view.seek_bar_brush_view_size.max = this.radius.max
|
|
|
|
+ popupView.sb_set_color_r.progress = Color.red(this.color)
|
|
|
|
+ popupView.sb_set_color_g.progress = Color.green(this.color)
|
|
|
|
+ popupView.sb_set_color_b.progress = Color.blue(this.color)
|
|
|
|
+ popupView.sb_set_color_a.progress = Color.alpha(this.color)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -161,15 +214,66 @@ class DrawActivity : AppCompatActivity() {
|
|
viewModel.setColorAValue(colorAValue)
|
|
viewModel.setColorAValue(colorAValue)
|
|
}
|
|
}
|
|
|
|
|
|
- private fun onColor1Changed(colorDrawable: ColorDrawable?) {
|
|
|
|
- color1.background = colorDrawable
|
|
|
|
- }
|
|
|
|
|
|
+// private fun onColor1Changed(colorDrawable: ColorDrawable?) {
|
|
|
|
+// color1.background = colorDrawable
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// private fun onColor2Changed(colorDrawable: ColorDrawable?) {
|
|
|
|
+// color2.background = colorDrawable
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// private fun onColor3Changed(colorDrawable: ColorDrawable?) {
|
|
|
|
+// color3.background = colorDrawable
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ private fun createPopupView(): View{
|
|
|
|
+
|
|
|
|
+ popupView.sb_set_color_r.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
|
|
|
+ override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
|
|
|
+ if (fromUser) onColorRValueChanged(progress)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onStartTrackingTouch(seekBar: SeekBar?) {}
|
|
|
|
+ override fun onStopTrackingTouch(seekBar: SeekBar?) {}
|
|
|
|
+ })
|
|
|
|
|
|
- private fun onColor2Changed(colorDrawable: ColorDrawable?) {
|
|
|
|
- color2.background = colorDrawable
|
|
|
|
|
|
+ popupView.sb_set_color_g.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
|
|
|
+ override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
|
|
|
+ if (fromUser) onColorGValueChanged(progress)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onStartTrackingTouch(seekBar: SeekBar?) {}
|
|
|
|
+ override fun onStopTrackingTouch(seekBar: SeekBar?) {}
|
|
|
|
+
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ popupView.sb_set_color_b.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
|
|
|
+ override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
|
|
|
+ if (fromUser) onColorBValueChanged(progress)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onStartTrackingTouch(seekBar: SeekBar?) {}
|
|
|
|
+ override fun onStopTrackingTouch(seekBar: SeekBar?) {}
|
|
|
|
+
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ popupView.sb_set_color_a.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
|
|
|
+ override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
|
|
|
+ if (fromUser) onColorAValueChanged(progress)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onStartTrackingTouch(seekBar: SeekBar?) {}
|
|
|
|
+ override fun onStopTrackingTouch(seekBar: SeekBar?) {}
|
|
|
|
+
|
|
|
|
+ })
|
|
|
|
+ return popupView
|
|
}
|
|
}
|
|
|
|
|
|
- private fun onColor3Changed(colorDrawable: ColorDrawable?) {
|
|
|
|
- color3.background = colorDrawable
|
|
|
|
|
|
+ override fun onSaveActorImage(filePath: String) {
|
|
|
|
+ var intent = Intent().apply {
|
|
|
|
+ putExtra("brush_bitmap", filePath)
|
|
|
|
+ }
|
|
|
|
+ this.setResult(Activity.RESULT_OK, intent)
|
|
|
|
+ this.finish()
|
|
}
|
|
}
|
|
}
|
|
}
|