diff --git a/app/src/main/kotlin/bums/lunatic/launcher/view/FloatingActionButton.kt b/app/src/main/kotlin/bums/lunatic/launcher/view/FloatingActionButton.kt
index 1afe0b29..aec18e97 100644
--- a/app/src/main/kotlin/bums/lunatic/launcher/view/FloatingActionButton.kt
+++ b/app/src/main/kotlin/bums/lunatic/launcher/view/FloatingActionButton.kt
@@ -1084,7 +1084,12 @@ class FloatingActionButton : ImageButton {
if (animate) {
playHideAnimation()
}
- super.setVisibility(INVISIBLE)
+
+ if (this.isSelected) {
+ super.setVisibility(GONE)
+ } else {
+ super.setVisibility(INVISIBLE)
+ }
}
}
diff --git a/app/src/main/kotlin/bums/lunatic/launcher/view/FloatingActionMenu.kt b/app/src/main/kotlin/bums/lunatic/launcher/view/FloatingActionMenu.kt
index 7468d0db..6474baf2 100644
--- a/app/src/main/kotlin/bums/lunatic/launcher/view/FloatingActionMenu.kt
+++ b/app/src/main/kotlin/bums/lunatic/launcher/view/FloatingActionMenu.kt
@@ -11,10 +11,12 @@ import android.graphics.Color
import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.os.Handler
+import android.os.Looper
import android.text.TextUtils
import android.util.AttributeSet
import android.util.TypedValue
import android.view.ContextThemeWrapper
+import android.view.HapticFeedbackConstants
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
@@ -570,12 +572,24 @@ class FloatingActionMenu @JvmOverloads constructor(
}
})
+
+
mMenuButton!!.setOnTouchListener(object : OnTouchListener {
var dX: Float = 0f
var dY: Float = 0f
var startX: Float = 0f
var startY: Float = 0f
+ // ๐ก ๋กฑํด๋ฆญ ๊ฐ์ง๋ฅผ ์ํ ๋ณ์ ์ถ๊ฐ
+ private val longClickHandler = Handler(Looper.getMainLooper())
+ private var isLongClickPerformed = false
+ private val longClickRunnable = Runnable {
+ isLongClickPerformed = true
+ // ์ฌ๊ธฐ์ ๋กฑํด๋ฆญ ์ ์คํํ ๋์์ ๋ฃ์ผ์ธ์.
+ // ์: Vibrator ์คํ ๋๋ ํน์ ํจ์ ํธ์ถ
+ performLongClickAction()
+ }
+
override fun onTouch(v: View, event: MotionEvent): Boolean {
val oldX = v.x
val oldY = v.y
@@ -586,48 +600,52 @@ class FloatingActionMenu @JvmOverloads constructor(
dY = v.y - event.rawY
startX = event.rawX
startY = event.rawY
+
+ // ๐ก 1. 500ms ๋ค์ ๋กฑํด๋ฆญ์ผ๋ก ๊ฐ์ฃผํ๋๋ก ์์ฝ
+ isLongClickPerformed = false
+ longClickHandler.postDelayed(longClickRunnable, 500)
}
MotionEvent.ACTION_MOVE -> {
- if (!isDragMenuDisabled) {
- // 1. ๋๋๊ทธํ๋ ค๋ ๋ชฉํ ์ขํ ๊ณ์ฐ
- var newX = event.rawX + dX
- var newY = event.rawY + dY
+ // ๐ก 2. ์ฌ์ฉ์๊ฐ ์ผ์ ๊ฑฐ๋ฆฌ ์ด์ ์์ง์ด๋ฉด ๋กฑํด๋ฆญ ์์ฝ์ ์ทจ์ (๋๋๊ทธ๋ก ํ๋จ)
+ if (abs(startX - event.rawX) > 10 || abs(startY - event.rawY) > 10) {
+ longClickHandler.removeCallbacks(longClickRunnable)
+ }
- // 2. ํ๋ฉด ์ ์ฒด ๋๋น์ ๋์ด ๊ฐ์ ธ์ค๊ธฐ (ํ์ฌ FloatingActionMenu๊ฐ match_parent์ด๋ฏ๋ก ์์ฒด ํฌ๊ธฐ ์ฌ์ฉ)
- val menuWidth = this@FloatingActionMenu.width
- val menuHeight = this@FloatingActionMenu.height
+ if (!isDragMenuDisabled && !isLongClickPerformed) {
+ // ๋๋๊ทธ ๋ก์ง (๊ธฐ์กด๊ณผ ๋์ผ)
+ var newX = (event.rawX + dX).coerceIn(paddingLeft.toFloat(), (this@FloatingActionMenu.width - v.width - paddingRight).toFloat())
+ var newY = (event.rawY + dY).coerceIn(paddingTop.toFloat(), (this@FloatingActionMenu.height - v.height - paddingBottom).toFloat())
- // 3. ํ๋ฉด์ ๋ฒ์ด๋์ง ์๋๋ก ์ขํ ๊ฐ๋๊ธฐ (ํจ๋ฉ ํฌํจ)
- val minX = paddingLeft.toFloat()
- val maxX = (menuWidth - v.width - paddingRight).toFloat()
-
- val minY = paddingTop.toFloat()
- val maxY = (menuHeight - v.height - paddingBottom).toFloat()
-
- // coerceIn ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ์ต์~์ต๋ ๊ฐ ์ฌ์ด๋ก ๊ฐ์ ๋ณด์
- newX = newX.coerceIn(minX, maxX)
- newY = newY.coerceIn(minY, maxY)
-
- // 4. ๋ณด์ ๋ ์ขํ๋ก ๋ทฐ ์ด๋
v.x = newX
v.y = newY
-
- // 5. ํ์ ๋ฉ๋ด๋ค๋ ๋ฐ๋ ๋ฉ์ธ ๋ฒํผ ์์น์ ๋ง์ถฐ ๋ค์ ๊ทธ๋ฆฌ๊ธฐ
moveElements(v, newX, newY, oldX, oldY)
}
}
MotionEvent.ACTION_UP -> {
- // ๋๋๊ทธ๊ฐ ์๋๋ผ ๋จ์ ํด๋ฆญ(์ค์ฐจ 10ํฝ์
์ด๋ด)์ด์๋ค๋ฉด ๋ฉ๋ด ํ ๊ธ
+ // ๐ก 3. ์์ ๋ผ๋ฉด ์์ฝ๋ ๋กฑํด๋ฆญ ์ทจ์
+ longClickHandler.removeCallbacks(longClickRunnable)
+
+ // ๋กฑํด๋ฆญ์ด ์ด๋ฏธ ๋ฐ์ํ๋ค๋ฉด ํด๋ฆญ ์ด๋ฒคํธ๋ฅผ ๋ฌด์
+ if (isLongClickPerformed) return true
+
if (abs(startX - event.rawX) < 10 && abs(startY - event.rawY) < 10) {
toggle(mIsAnimated)
}
}
- else -> return false
+ MotionEvent.ACTION_CANCEL -> {
+ // ๐ก 4. ์ทจ์ ์ด๋ฒคํธ ๋ฐ์ ์์๋ ๋ฆฌ์ค๋ ์ ๊ฑฐ
+ longClickHandler.removeCallbacks(longClickRunnable)
+ }
}
return true
}
+
+ private fun performLongClickAction() {
+ mMenuButton!!.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
+ toggle(animate = mIsAnimated, true)
+ }
})
}
}
@@ -795,15 +813,15 @@ class FloatingActionMenu @JvmOverloads constructor(
return super.onTouchEvent(event)
}
- fun toggle(animate: Boolean) {
+ fun toggle(animate: Boolean, allShow: Boolean = false) {
if (this.isOpened) {
close(animate)
} else {
- open(animate)
+ open(animate, allShow)
}
}
- fun open(animate: Boolean) {
+ fun open(animate: Boolean, allShow : Boolean = false) {
if (!this.isOpened) {
if (this.isBackgroundEnabled) {
mShowBackgroundAnimator!!.start()
@@ -823,6 +841,10 @@ class FloatingActionMenu @JvmOverloads constructor(
mIsMenuOpening = true
for (i in getChildCount() - 1 downTo 0) {
val child = getChildAt(i)
+ if (allShow && !child.equals(mMenuButton) && child.getVisibility() == GONE) {
+ child.isSelected = true
+ child.visibility = View.INVISIBLE
+ }
if (child is FloatingActionButton && child.getVisibility() != GONE) {
counter++
@@ -877,6 +899,7 @@ class FloatingActionMenu @JvmOverloads constructor(
mIsMenuOpening = false
for (i in 0..