Skip to content

Commit

Permalink
rename onViewMove of DraggableListener to onPositionChanged for b…
Browse files Browse the repository at this point in the history
…etter description
  • Loading branch information
hyuwah authored and Muhamad Wahyudin committed Jan 29, 2020
1 parent b363a7e commit 4439948
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 26 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ There's an interface `DraggableListener` to listen to the `View` while being dra

```kotlin
interface DraggableListener {
fun onViewMove(view: View)
fun onPositionChanged(view: View)
}
```
Just pass the implementation of the interface to `makeDraggable` method

```kotlin
someView.makeDraggable(object: DraggableListener{
override fun onViewMove(view: View){
override fun onPositionChanged(view: View){
// Do something, get coordinates of view, etc
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class DraggableImageView(context: Context, attrs: AttributeSet) : ImageView(cont
newY = min(yMax.toFloat(), newY)
v.y = newY

draggableListener?.onViewMove(v)
draggableListener?.onPositionChanged(v)
}
MotionEvent.ACTION_UP -> {
when (stickyAxis) {
Expand All @@ -88,14 +88,14 @@ class DraggableImageView(context: Context, attrs: AttributeSet) : ImageView(cont
if (mAnimate)
v.animate().x(xMax.toFloat())
.setDuration(Draggable.DURATION_MILLIS)
.setUpdateListener { draggableListener?.onViewMove(v) }
.setUpdateListener { draggableListener?.onPositionChanged(v) }
.start()
else
v.x = xMax.toFloat()
} else {
if (mAnimate)
v.animate().x(0F).setDuration(Draggable.DURATION_MILLIS)
.setUpdateListener { draggableListener?.onViewMove(v) }
.setUpdateListener { draggableListener?.onPositionChanged(v) }
.start()
else
v.x = 0F
Expand All @@ -106,20 +106,24 @@ class DraggableImageView(context: Context, attrs: AttributeSet) : ImageView(cont
if (mAnimate)
v.animate().y(yMax.toFloat())
.setDuration(Draggable.DURATION_MILLIS)
.setUpdateListener { draggableListener?.onViewMove(v) }
.setUpdateListener { draggableListener?.onPositionChanged(v) }
.start()
else
v.y = yMax.toFloat()
} else {
if (mAnimate)
v.animate().y(0F)
.setDuration(Draggable.DURATION_MILLIS)
.setUpdateListener { draggableListener?.onViewMove(v) }
.setUpdateListener { draggableListener?.onPositionChanged(v) }
.start()
else {
if (mAnimate)
v.animate().y(0F).setDuration(Draggable.DURATION_MILLIS)
.setUpdateListener { draggableListener?.onViewMove(v) }
.setUpdateListener {
draggableListener?.onPositionChanged(
v
)
}
.start()
else
v.y = 0F
Expand All @@ -131,14 +135,14 @@ class DraggableImageView(context: Context, attrs: AttributeSet) : ImageView(cont
if (mAnimate)
v.animate().x(xMax.toFloat())
.setDuration(Draggable.DURATION_MILLIS)
.setUpdateListener { draggableListener?.onViewMove(v) }
.setUpdateListener { draggableListener?.onPositionChanged(v) }
.start()
else
v.x = xMax.toFloat()
} else {
if (mAnimate)
v.animate().x(0F).setDuration(Draggable.DURATION_MILLIS)
.setUpdateListener { draggableListener?.onViewMove(v) }
.setUpdateListener { draggableListener?.onPositionChanged(v) }
.start()
v.x = 0F
}
Expand All @@ -147,14 +151,14 @@ class DraggableImageView(context: Context, attrs: AttributeSet) : ImageView(cont
if (mAnimate)
v.animate().y(yMax.toFloat())
.setDuration(Draggable.DURATION_MILLIS)
.setUpdateListener { draggableListener?.onViewMove(v) }
.setUpdateListener { draggableListener?.onPositionChanged(v) }
.start()
else
v.y = yMax.toFloat()
} else {
if (mAnimate)
v.animate().y(0F).setDuration(Draggable.DURATION_MILLIS)
.setUpdateListener { draggableListener?.onViewMove(v) }
.setUpdateListener { draggableListener?.onPositionChanged(v) }
.start()
else
v.y = 0F
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import android.view.View

interface DraggableListener {

fun onViewMove(view: View)
fun onPositionChanged(view: View)

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fun View.makeDraggable(
newY = min(yMax.toFloat(), newY)
v.y = newY

draggableListener?.onViewMove(v)
draggableListener?.onPositionChanged(v)
}
MotionEvent.ACTION_UP -> {
when (stickyAxis) {
Expand All @@ -56,14 +56,14 @@ fun View.makeDraggable(
if (animated)
v.animate().x(xMax.toFloat())
.setDuration(DURATION_MILLIS)
.setUpdateListener { draggableListener?.onViewMove(v) }
.setUpdateListener { draggableListener?.onPositionChanged(v) }
.start()
else
v.x = xMax.toFloat()
} else {
if (animated)
v.animate().x(0F).setDuration(DURATION_MILLIS)
.setUpdateListener { draggableListener?.onViewMove(v) }
.setUpdateListener { draggableListener?.onPositionChanged(v) }
.start()
else
v.x = 0F
Expand All @@ -74,20 +74,20 @@ fun View.makeDraggable(
if (animated)
v.animate().y(yMax.toFloat())
.setDuration(DURATION_MILLIS)
.setUpdateListener { draggableListener?.onViewMove(v) }
.setUpdateListener { draggableListener?.onPositionChanged(v) }
.start()
else
v.y = yMax.toFloat()
} else {
if (animated)
v.animate().y(0F)
.setDuration(DURATION_MILLIS)
.setUpdateListener { draggableListener?.onViewMove(v) }
.setUpdateListener { draggableListener?.onPositionChanged(v) }
.start()
else {
if (animated)
v.animate().y(0F).setDuration(DURATION_MILLIS)
.setUpdateListener { draggableListener?.onViewMove(v) }
.setUpdateListener { draggableListener?.onPositionChanged(v) }
.start()
else
v.y = 0F
Expand All @@ -99,14 +99,14 @@ fun View.makeDraggable(
if (animated)
v.animate().x(xMax.toFloat())
.setDuration(DURATION_MILLIS)
.setUpdateListener { draggableListener?.onViewMove(v) }
.setUpdateListener { draggableListener?.onPositionChanged(v) }
.start()
else
v.x = xMax.toFloat()
} else {
if (animated)
v.animate().x(0F).setDuration(DURATION_MILLIS)
.setUpdateListener { draggableListener?.onViewMove(v) }
.setUpdateListener { draggableListener?.onPositionChanged(v) }
.start()
v.x = 0F
}
Expand All @@ -115,14 +115,14 @@ fun View.makeDraggable(
if (animated)
v.animate().y(yMax.toFloat())
.setDuration(DURATION_MILLIS)
.setUpdateListener { draggableListener?.onViewMove(v) }
.setUpdateListener { draggableListener?.onPositionChanged(v) }
.start()
else
v.y = yMax.toFloat()
} else {
if (animated)
v.animate().y(0F).setDuration(DURATION_MILLIS)
.setUpdateListener { draggableListener?.onViewMove(v) }
.setUpdateListener { draggableListener?.onPositionChanged(v) }
.start()
else
v.y = 0F
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.hyuwah.draggableview;

import android.support.v4.view.ViewPropertyAnimatorListener;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
Expand Down Expand Up @@ -34,7 +35,7 @@ public void onClick(View v) {
}

@Override
public void onViewMove(@NotNull View view) {
public void onPositionChanged(@NotNull View view) {
TextView textView = findViewById(R.id.tv_coordinate);
textView.setText("X: " + view.getX() + "\tY: " + view.getY());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MainActivity : AppCompatActivity() {
var currentStickyAxis = Draggable.STICKY.AXIS_X

val llTestDraggableListener = object : DraggableListener {
override fun onViewMove(view: View) {
override fun onPositionChanged(view: View) {
tv_ll_1.text = "X: ${view.x}"
tv_ll_2.text = "Y: ${view.y}"
}
Expand All @@ -37,7 +37,7 @@ class MainActivity : AppCompatActivity() {

// Set on view move listener
dvTest.setListener(object : DraggableListener {
override fun onViewMove(view: View) {
override fun onPositionChanged(view: View) {
tv_test_draggable.text = "Icon Coordinates\nX: ${view.x}\nY: ${view.y}"
}
})
Expand Down

0 comments on commit 4439948

Please sign in to comment.