diff --git a/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/bubble/FloatingBubble.kt b/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/bubble/FloatingBubble.kt
index 359bede..e05d74f 100644
--- a/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/bubble/FloatingBubble.kt
+++ b/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/bubble/FloatingBubble.kt
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Point
import android.graphics.PointF
+import android.util.Log
import android.view.*
import androidx.dynamicanimation.animation.SpringAnimation
import androidx.dynamicanimation.animation.SpringForce
@@ -20,10 +21,10 @@ import kotlin.math.abs
class FloatingBubble(
private val context: Context,
private val forceDragging: Boolean = false,
-// private val ignoreSwipeGesture: Boolean = true,
containCompose: Boolean,
private val listener: FloatingBubbleListener? = null,
- onDispatchKeyEvent: ((KeyEvent) -> Boolean?)? = null
+ onDispatchKeyEvent: ((KeyEvent) -> Boolean?)? = null,
+ private val triggerClickableAreaPx: Float = 1f,
) : Bubble(
context = context,
root = LayoutInflater.from(context).inflate(R.layout.bubble, null).apply {
@@ -160,11 +161,16 @@ class FloatingBubble(
)
}
- private val MAX_XY_MOVE = 1f
private var ignoreClick: Boolean = false
@SuppressLint("ClickableViewAccessibility")
private fun customTouch() {
+ val MAX_XY_MOVE = triggerClickableAreaPx
+
+// val smallestWidth = context.resources.configuration.smallestScreenWidthDp
+// Log.d("<> smallest width", smallestWidth.toString())
+// MAX_XY_MOVE = smallestWidth / 30f
+// Log.d("<> MAX XY move", MAX_XY_MOVE.toString())
fun handleMovement(event: MotionEvent) {
when (event.action) {
diff --git a/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/service/expandable/BubbleBuilder.kt b/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/service/expandable/BubbleBuilder.kt
index 04eb8eb..76b1059 100644
--- a/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/service/expandable/BubbleBuilder.kt
+++ b/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/service/expandable/BubbleBuilder.kt
@@ -37,8 +37,8 @@ class BubbleBuilder(
internal var isBottomBackgroundEnabled = false
internal var distanceToClosePx = 200
-
internal var closeBubbleBottomPaddingPx = 80
+ internal var triggerClickablePerimeterPx = 5f
internal var listener: FloatingBubbleListener? = null
internal var behavior: CloseBubbleBehavior = CloseBubbleBehavior.FIXED_CLOSE_BUBBLE
@@ -74,6 +74,21 @@ class BubbleBuilder(
}
+ /**
+ * Set the clickable perimeter of the bubble in pixels (default = 5f).
+ *
+ * For example, when the bubble is dragged, it will still perform a click if
+ * the new location (when the bubble is released) is not further than the last location by the specified pixel amount.
+ *
+ * @param f The size of the clickable area in pixels.
+ * @return This BubbleBuilder instance for method chaining.
+ */
+ @Discouraged("the name will be changed if I found a better one")
+ fun triggerClickablePerimeterPx(f: Float): BubbleBuilder{
+ this.triggerClickablePerimeterPx = f
+ return this
+ }
+
fun bubbleDraggable(b: Boolean): BubbleBuilder{
isBubbleDraggable = b
return this
diff --git a/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/service/expandable/ExpandableBubbleService.kt b/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/service/expandable/ExpandableBubbleService.kt
index 10ff669..b9ee238 100644
--- a/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/service/expandable/ExpandableBubbleService.kt
+++ b/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/service/expandable/ExpandableBubbleService.kt
@@ -2,6 +2,7 @@ package com.torrydo.floatingbubbleview.service.expandable
import android.content.Context
import android.content.res.Configuration
+import android.graphics.PointF
import androidx.dynamicanimation.animation.SpringForce
import com.torrydo.floatingbubbleview.CloseBubbleBehavior
import com.torrydo.floatingbubbleview.FloatingBubbleListener
@@ -11,6 +12,7 @@ import com.torrydo.floatingbubbleview.bubble.FloatingBubble
import com.torrydo.floatingbubbleview.bubble.FloatingCloseBubble
import com.torrydo.floatingbubbleview.service.FloatingBubbleService
import com.torrydo.floatingbubbleview.sez
+import kotlin.math.abs
abstract class ExpandableBubbleService : FloatingBubbleService() {
@@ -42,34 +44,31 @@ abstract class ExpandableBubbleService : FloatingBubbleService() {
this._context = context
if (bubbleBuilder != null) {
- // setup bubble
+ // setup bubble ------------------------------------------------------------------------
+ bubble = FloatingBubble(
+ context,
+ forceDragging = bubbleBuilder.forceDragging,
+ containCompose = bubbleBuilder.bubbleCompose != null,
+ listener = bubbleBuilder.listener,
+ triggerClickableAreaPx = bubbleBuilder.triggerClickablePerimeterPx
+ )
if (bubbleBuilder.bubbleView != null) {
- bubble = FloatingBubble(
- context,
- forceDragging = bubbleBuilder.forceDragging,
- containCompose = false,
- listener = bubbleBuilder.listener
- )
bubble!!.rootGroup.addView(bubbleBuilder.bubbleView)
} else {
- bubble = FloatingBubble(
- context,
- forceDragging = bubbleBuilder.forceDragging,
- containCompose = true,
- listener = bubbleBuilder.listener
- )
bubble!!.rootGroup.addView(bubbleBuilder.bubbleCompose)
}
+
bubble!!.mListener = CustomBubbleListener(
bubble!!,
bubbleBuilder.isAnimateToEdgeEnabled,
closeBehavior = bubbleBuilder.behavior,
- isCloseBubbleEnabled = true
+ isCloseBubbleEnabled = true,
+ triggerClickableAreaPx = bubbleBuilder.triggerClickablePerimeterPx
)
bubble!!.layoutParams = bubbleBuilder.defaultLayoutParams()
bubble!!.isDraggable = bubbleBuilder.isBubbleDraggable
- // setup close-bubble
+ // setup close-bubble ------------------------------------------------------------------
if (bubbleBuilder.closeView != null) {
closeBubble = FloatingCloseBubble(
context,
@@ -93,25 +92,18 @@ abstract class ExpandableBubbleService : FloatingBubbleService() {
// setup expanded-bubble
expandedBuilder?.apply {
- if (expandedView != null) {
- expandedBubble =
- FloatingBubble(
- context,
- containCompose = false,
- forceDragging = false,
- onDispatchKeyEvent = expandedBuilder.onDispatchKeyEvent
- )
- expandedBubble!!.rootGroup.addView(expandedView)
- } else {
- expandedBubble =
- FloatingBubble(
- context,
- containCompose = true,
- forceDragging = false,
- onDispatchKeyEvent = expandedBuilder.onDispatchKeyEvent
- )
+ expandedBubble = FloatingBubble(
+ context,
+ containCompose = expandedCompose != null,
+ forceDragging = false,
+ onDispatchKeyEvent = expandedBuilder.onDispatchKeyEvent,
+ )
+ if (expandedCompose != null) {
expandedBubble!!.rootGroup.addView(expandedCompose)
+ } else {
+ expandedBubble!!.rootGroup.addView(expandedView)
}
+
expandedBubble!!.mListener = CustomBubbleListener(
expandedBubble!!,
mAnimateToEdge = expandedBuilder.isAnimateToEdgeEnabled,
@@ -202,13 +194,17 @@ abstract class ExpandableBubbleService : FloatingBubbleService() {
private val mBubble: FloatingBubble,
private val mAnimateToEdge: Boolean,
private val closeBehavior: CloseBubbleBehavior = CloseBubbleBehavior.FIXED_CLOSE_BUBBLE,
- private val isCloseBubbleEnabled: Boolean = true
+ private val isCloseBubbleEnabled: Boolean = true,
+ private val triggerClickableAreaPx: Float = 1f
) : FloatingBubbleListener {
private var isCloseBubbleVisible = false
+ private var onDownLocation = PointF(0f, 0f)
+
override fun onFingerDown(x: Float, y: Float) {
mBubble.safeCancelAnimation()
+ onDownLocation = PointF(x, y)
}
override fun onFingerMove(x: Float, y: Float) {
@@ -228,8 +224,11 @@ abstract class ExpandableBubbleService : FloatingBubbleService() {
}
}
if (isCloseBubbleEnabled && isCloseBubbleVisible.not()) {
- tryShowCloseBubbleAndBackground()
- isCloseBubbleVisible = true
+ // TODO: check if close-bubble should be shown
+ if (abs(onDownLocation.x - x) > triggerClickableAreaPx || abs(onDownLocation.y - y) > triggerClickableAreaPx) {
+ tryShowCloseBubbleAndBackground()
+ isCloseBubbleVisible = true
+ }
}
}
@@ -278,7 +277,7 @@ abstract class ExpandableBubbleService : FloatingBubbleService() {
sez.refresh()
createBubbles(this, configBubble(), configExpandedBubble())
- when(state){
+ when (state) {
1 -> minimize()
2 -> expand()
}
diff --git a/README.md b/README.md
index 5869a28..5b774e2 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ An Android library that creates floating bubbles on top of the screen 🎨, supp
-
Find this library useful? 🥰 Don't forget to show some love by giving a -Star⭐-
+ Like this project? 🥰 Don't forget to show some love by giving a Star⭐
| Bubble | Custom |
| :-: | :-: |
@@ -249,6 +249,7 @@ public class MyServiceJava extends ExpandableBubbleService {
.closeBubbleView(ViewHelper.fromDrawable(this, R.drawable.ic_close_bubble))
.closeBubbleStyle(R.style.default_close_bubble_style)
.distanceToClose(100)
+ .triggerClickablePerimeterPx(5f)
.closeBehavior(CloseBubbleBehavior.FIXED_CLOSE_BUBBLE)
.startLocation(100, 100)
.enableAnimateToEdge(true)
@@ -347,6 +348,9 @@ class MyServiceKt : ExpandableBubbleService() {
override fun onFingerDown(x: Float, y: Float) {} // ..., when finger tap the bubble
})
+ // set the clickable perimeter of the bubble in pixels (default = 5f)
+ .triggerClickablePerimeterPx(5f)
+
}
override fun configExpandedBubble(): ExpandedBubbleBuilder? {
diff --git a/app/build.gradle b/app/build.gradle
index e94127e..7e90326 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -39,6 +39,7 @@ android {
kotlinCompilerExtensionVersion "1.3.2"
kotlinCompilerVersion '1.3.2'
}
+ namespace 'com.torrydo.testfloatingbubble'
}
dependencies {
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 5ff5e6a..6bb27e2 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -1,6 +1,5 @@
-
+
diff --git a/app/src/main/java/com/torrydo/testfloatingbubble/MyServiceKt.kt b/app/src/main/java/com/torrydo/testfloatingbubble/MyServiceKt.kt
index 61f995b..8face45 100644
--- a/app/src/main/java/com/torrydo/testfloatingbubble/MyServiceKt.kt
+++ b/app/src/main/java/com/torrydo/testfloatingbubble/MyServiceKt.kt
@@ -38,6 +38,8 @@ class MyServiceKt : ExpandableBubbleService() {
// set bubble view
.bubbleView(imgView)
+ .triggerClickablePerimeterPx(5f)
+
// or our sweetie, Jetpack Compose
// .bubbleCompose {
// BubbleCompose(expand = { expand() })
diff --git a/build.gradle b/build.gradle
index 96f3814..188e728 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,7 +5,7 @@ buildscript {
mavenCentral()
}
dependencies {
- classpath 'com.android.tools.build:gradle:7.3.1'
+ classpath 'com.android.tools.build:gradle:8.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20"
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.24.0' // NEW
diff --git a/gradle.properties b/gradle.properties
index 6db83b6..9653a1a 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -27,8 +27,8 @@ RELEASE_SIGNING_ENABLED=true
GROUP=io.github.torrydo
POM_ARTIFACT_ID=floating-bubble-view
-VERSION_NAME=0.6.4
-#prev: 0.6.3
+VERSION_NAME=0.6.5
+#prev: 0.6.4
POM_NAME=FloatingBubbleView
POM_PACKAGING=aar
@@ -47,4 +47,7 @@ POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=TorryDo
POM_DEVELOPER_NAME=Nguyen Do Tri
-POM_DEVELOPER_URL=https://github.com/TorryDo
\ No newline at end of file
+POM_DEVELOPER_URL=https://github.com/TorryDo
+android.defaults.buildfeatures.buildconfig=true
+android.nonTransitiveRClass=false
+android.nonFinalResIds=false
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index a75451d..856ce98 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
#Wed Dec 07 11:26:08 ICT 2022
distributionBase=GRADLE_USER_HOME
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME