Browse Source

Fix EditActorView SizeChangeListener

cooperku_kdanmobile 6 years ago
parent
commit
6d05c2e3c8

+ 32 - 16
src/main/java/com/bomostory/sceneeditmodule/screen/view/EditActorView.kt

@@ -40,6 +40,7 @@ open class EditActorView @JvmOverloads constructor(
             }
             }
         }
         }
 
 
+    val MIN_ACTOR_SIZE = 160
     var actorCallback: OnActorChangeListener? = null
     var actorCallback: OnActorChangeListener? = null
 
 
     private fun initView() {
     private fun initView() {
@@ -105,6 +106,7 @@ open class EditActorView @JvmOverloads constructor(
         return View.OnTouchListener { view, motionEvent ->
         return View.OnTouchListener { view, motionEvent ->
             when (motionEvent.action) {
             when (motionEvent.action) {
                 MotionEvent.ACTION_DOWN -> {
                 MotionEvent.ACTION_DOWN -> {
+                    println("ACTION_DOWN")
                     val layoutParams = actor_layout.layoutParams as RelativeLayout.LayoutParams
                     val layoutParams = actor_layout.layoutParams as RelativeLayout.LayoutParams
                     sizeX = layoutParams.width
                     sizeX = layoutParams.width
                     sizeY = layoutParams.height
                     sizeY = layoutParams.height
@@ -116,13 +118,14 @@ open class EditActorView @JvmOverloads constructor(
                 MotionEvent.ACTION_MOVE -> {
                 MotionEvent.ACTION_MOVE -> {
                     var mx =  motionEvent.rawX.toInt() - positionX
                     var mx =  motionEvent.rawX.toInt() - positionX
                     var my =  motionEvent.rawY.toInt() - positionY
                     var my =  motionEvent.rawY.toInt() - positionY
-                    var dP = when (Math.abs(mx) > Math.abs(my)){
+//                    var dP = when (Math.abs(mx) > Math.abs(my)){
+                    var dP = when (my < mx){
                         true ->  my
                         true ->  my
                         false -> mx
                         false -> mx
                     }
                     }
                     var actorData = Actor().apply {
                     var actorData = Actor().apply {
-                        sideLength = sizeX + dP
-                        sideHeight = sizeY + dP
+                        sideLength = Math.max(MIN_ACTOR_SIZE, sizeX + dP)
+                        sideHeight = Math.max(MIN_ACTOR_SIZE, sizeY + dP)
                         this.positionX = x
                         this.positionX = x
                         this.positionY = y
                         this.positionY = y
                         resourcePath = actor.resourcePath
                         resourcePath = actor.resourcePath
@@ -140,6 +143,7 @@ open class EditActorView @JvmOverloads constructor(
                     actor = actorData
                     actor = actorData
                 }
                 }
                 MotionEvent.ACTION_UP -> {
                 MotionEvent.ACTION_UP -> {
+                    println("ACTION_UP")
                     actor.isSelect = true
                     actor.isSelect = true
                     actorCallback?.onActorChange(actor)
                     actorCallback?.onActorChange(actor)
                 }
                 }
@@ -155,6 +159,8 @@ open class EditActorView @JvmOverloads constructor(
         var sizeY = 0
         var sizeY = 0
         var x = 0
         var x = 0
         var y = 0
         var y = 0
+        var rightX = 0
+        var bottomY = 0
         return View.OnTouchListener { view, motionEvent ->
         return View.OnTouchListener { view, motionEvent ->
             when (motionEvent.action) {
             when (motionEvent.action) {
                 MotionEvent.ACTION_DOWN -> {
                 MotionEvent.ACTION_DOWN -> {
@@ -165,19 +171,21 @@ open class EditActorView @JvmOverloads constructor(
                     y = layoutParams.topMargin
                     y = layoutParams.topMargin
                     positionX = (motionEvent.rawX).toInt()
                     positionX = (motionEvent.rawX).toInt()
                     positionY = (motionEvent.rawY).toInt()
                     positionY = (motionEvent.rawY).toInt()
+                    rightX = x + sizeX
+                    bottomY = y + sizeY
                 }
                 }
                 MotionEvent.ACTION_MOVE -> {
                 MotionEvent.ACTION_MOVE -> {
                     val mx =  motionEvent.rawX.toInt() - positionX
                     val mx =  motionEvent.rawX.toInt() - positionX
                     val my =  motionEvent.rawY.toInt() - positionY
                     val my =  motionEvent.rawY.toInt() - positionY
-                    var dP = when (Math.abs(mx) > Math.abs(my)){
+                    var dP = when (my > mx){
                         true ->  my
                         true ->  my
                         false -> mx
                         false -> mx
                     }
                     }
                     var actorData = Actor().apply {
                     var actorData = Actor().apply {
-                        sideLength = sizeX - dP
-                        sideHeight = sizeY - dP
-                        this.positionX = x + dP
-                        this.positionY = y + dP
+                        sideLength = Math.max(MIN_ACTOR_SIZE, sizeX - dP)
+                        sideHeight = Math.max(MIN_ACTOR_SIZE, sizeY - dP)
+                        this.positionX = Math.min(rightX - MIN_ACTOR_SIZE, x + dP)
+                        this.positionY = Math.min(bottomY - MIN_ACTOR_SIZE, y + dP)
                         resourcePath = actor.resourcePath
                         resourcePath = actor.resourcePath
                         text = actor.text
                         text = actor.text
                         textColor = actor.textColor
                         textColor = actor.textColor
@@ -208,6 +216,7 @@ open class EditActorView @JvmOverloads constructor(
         var sizeY = 0
         var sizeY = 0
         var x = 0
         var x = 0
         var y = 0
         var y = 0
+        var bottomY = 0
         return View.OnTouchListener { view, motionEvent ->
         return View.OnTouchListener { view, motionEvent ->
             when (motionEvent.action) {
             when (motionEvent.action) {
                 MotionEvent.ACTION_DOWN -> {
                 MotionEvent.ACTION_DOWN -> {
@@ -218,19 +227,20 @@ open class EditActorView @JvmOverloads constructor(
                     y = layoutParams.topMargin
                     y = layoutParams.topMargin
                     positionX = (motionEvent.rawX).toInt()
                     positionX = (motionEvent.rawX).toInt()
                     positionY = (motionEvent.rawY).toInt()
                     positionY = (motionEvent.rawY).toInt()
+                    bottomY = y + sizeY
                 }
                 }
                 MotionEvent.ACTION_MOVE -> {
                 MotionEvent.ACTION_MOVE -> {
                     var mx =  motionEvent.rawX.toInt() - positionX
                     var mx =  motionEvent.rawX.toInt() - positionX
                     var my =  motionEvent.rawY.toInt() - positionY
                     var my =  motionEvent.rawY.toInt() - positionY
-                    var dP = when (Math.abs(mx) > Math.abs(my)){
+                    var dP = when (-mx < my){
                         true ->  my
                         true ->  my
-                        false -> mx
+                        false -> -mx
                     }
                     }
                     var actorData = Actor().apply {
                     var actorData = Actor().apply {
-                        sideLength = sizeX + mx
-                        sideHeight = sizeY - my
+                        sideLength = Math.max(MIN_ACTOR_SIZE, sizeX - dP)
+                        sideHeight = Math.max(MIN_ACTOR_SIZE, sizeY - dP)
                         this.positionX = x
                         this.positionX = x
-                        this.positionY = y + my
+                        this.positionY = Math.min(bottomY - MIN_ACTOR_SIZE, y + dP)
                         resourcePath = actor.resourcePath
                         resourcePath = actor.resourcePath
                         text = actor.text
                         text = actor.text
                         textColor = actor.textColor
                         textColor = actor.textColor
@@ -261,6 +271,7 @@ open class EditActorView @JvmOverloads constructor(
         var sizeY = 0
         var sizeY = 0
         var x = 0
         var x = 0
         var y = 0
         var y = 0
+        var rightX = 0
         return View.OnTouchListener { view, motionEvent ->
         return View.OnTouchListener { view, motionEvent ->
             when (motionEvent.action) {
             when (motionEvent.action) {
                 MotionEvent.ACTION_DOWN -> {
                 MotionEvent.ACTION_DOWN -> {
@@ -271,14 +282,19 @@ open class EditActorView @JvmOverloads constructor(
                     y = layoutParams.topMargin
                     y = layoutParams.topMargin
                     positionX = (motionEvent.rawX).toInt()
                     positionX = (motionEvent.rawX).toInt()
                     positionY = (motionEvent.rawY).toInt()
                     positionY = (motionEvent.rawY).toInt()
+                    rightX = x + sizeX
                 }
                 }
                 MotionEvent.ACTION_MOVE -> {
                 MotionEvent.ACTION_MOVE -> {
                     var mx =  motionEvent.rawX.toInt() - positionX
                     var mx =  motionEvent.rawX.toInt() - positionX
                     var my =  motionEvent.rawY.toInt() - positionY
                     var my =  motionEvent.rawY.toInt() - positionY
+                    var dP = when (-mx > my){
+                        true ->  my
+                        false -> -mx
+                    }
                     var actorData = Actor().apply {
                     var actorData = Actor().apply {
-                        sideLength = sizeX - mx
-                        sideHeight = sizeY + my
-                        this.positionX = x + mx
+                        sideLength = Math.max(MIN_ACTOR_SIZE, sizeX + dP)
+                        sideHeight = Math.max(MIN_ACTOR_SIZE, sizeY + dP)
+                        this.positionX = Math.min(rightX - MIN_ACTOR_SIZE, x - dP)
                         this.positionY = y
                         this.positionY = y
                         resourcePath = actor.resourcePath
                         resourcePath = actor.resourcePath
                         text = actor.text
                         text = actor.text