diff --git a/.idea/appInsightsSettings.xml b/.idea/appInsightsSettings.xml index 371f2e2..1e3e418 100644 --- a/.idea/appInsightsSettings.xml +++ b/.idea/appInsightsSettings.xml @@ -3,6 +3,25 @@ - + diff --git a/FloatingBubbleView/build.gradle b/FloatingBubbleView/build.gradle index f83b950..9b0f756 100644 --- a/FloatingBubbleView/build.gradle +++ b/FloatingBubbleView/build.gradle @@ -40,6 +40,7 @@ android { composeOptions { kotlinCompilerExtensionVersion "1.3.2" } + namespace 'com.torrydo.floatingbubbleview' } diff --git a/FloatingBubbleView/src/main/AndroidManifest.xml b/FloatingBubbleView/src/main/AndroidManifest.xml index 2b58885..cc88a01 100644 --- a/FloatingBubbleView/src/main/AndroidManifest.xml +++ b/FloatingBubbleView/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + 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 1a3ec63..e05d74f 100644 --- a/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/bubble/FloatingBubble.kt +++ b/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/bubble/FloatingBubble.kt @@ -21,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 { @@ -161,11 +161,11 @@ class FloatingBubble( ) } - private var MAX_XY_MOVE = 5f 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()) 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..4276cec 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 triggerClickableAreaPx = 5f internal var listener: FloatingBubbleListener? = null internal var behavior: CloseBubbleBehavior = CloseBubbleBehavior.FIXED_CLOSE_BUBBLE 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..a8ec3db 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.triggerClickableAreaPx + ) 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.triggerClickableAreaPx ) 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/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/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..7479dcf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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