Skip to content

Commit

Permalink
Feature/drag effect (#10)
Browse files Browse the repository at this point in the history
* 드래그 된 곳까지 색 칠하기

* 드래그 된 곳 까지 인덱스에 따라 색깔 다르게 하기

* index에 따라 드래그 아이템, 리플 효과 색깔 변경
  • Loading branch information
tak8997 authored Oct 27, 2019
1 parent e049ea6 commit 4d10fb7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
11 changes: 11 additions & 0 deletions library/src/main/java/com/tak8997/library/ItemColor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.tak8997.library

import android.graphics.Color

enum class ItemColor(val color: Int) {

Purple(Color.parseColor("#5f14d3")),
Green(Color.parseColor("#a4c639")),
Blue(Color.parseColor("#0009ff")),
Red(Color.parseColor("#ff2222"))
}
23 changes: 22 additions & 1 deletion library/src/main/java/com/tak8997/library/RippleDragDrop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class RippleDragDrop @JvmOverloads constructor(
override fun onDraw(canvas: Canvas?) {
super.onDraw(canvas)

dragBgPaint.color = getDragColor(selectedIndex).color
dragBgPaint.alpha = 100
dragBgPaint.isAntiAlias = true
dragRectF.left = 0f
dragRectF.top = selectedItemPositionY
dragRectF.right = width.toFloat()
Expand Down Expand Up @@ -122,6 +125,7 @@ class RippleDragDrop @JvmOverloads constructor(

val item = dragDropItems[index]
item.setSelection(true)
item.setColor(getDragColor(selectedIndex))
selectedItemPositionY = item.y

if (selectedIndex != index) {
Expand Down Expand Up @@ -171,4 +175,21 @@ class RippleDragDrop @JvmOverloads constructor(
private fun deselectAll() {
dragDropItems.forEach { it.setSelection(false) }
}
}

private fun getDragColor(selecteIndex: Int): ItemColor {
return when (val itemSize = dragDropItems.size) {
1,2 -> return if (selecteIndex == 1) ItemColor.Purple else ItemColor.Red
3 -> return when (selecteIndex) {
2 -> ItemColor.Purple
1 -> ItemColor.Green
else -> ItemColor.Red
}
else -> when {
selecteIndex >= itemSize * 3 / 4 -> ItemColor.Purple
selecteIndex >= itemSize * 2 / 4 -> ItemColor.Green
selecteIndex >= itemSize * 1 / 4 -> ItemColor.Blue
else -> ItemColor.Red
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ internal class RippleDragDropItem @JvmOverloads constructor(
fun getSelection(): Boolean {
return layoutSelected.visibility == View.VISIBLE
}

fun setColor(itemColor: ItemColor) {
imageSelected.setColorFilter(itemColor.color)
rippleEffect.setColor(itemColor)
}
}
6 changes: 6 additions & 0 deletions library/src/main/java/com/tak8997/library/RippleEffect.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,10 @@ internal class RippleEffect @JvmOverloads constructor(
fun stopRipple() {
animatorSet.end()
}

fun setColor(itemColor: ItemColor) {
paint.isAntiAlias = true
paint.style = Paint.Style.FILL_AND_STROKE
paint.color = itemColor.color
}
}

0 comments on commit 4d10fb7

Please sign in to comment.