Skip to content

Commit

Permalink
fix: close-bubble being shown when click bubble
Browse files Browse the repository at this point in the history
  • Loading branch information
TorryDo committed Mar 18, 2024
1 parent f16844f commit 4f9286d
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 50 deletions.
19 changes: 19 additions & 0 deletions .idea/appInsightsSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions FloatingBubbleView/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ android {
composeOptions {
kotlinCompilerExtensionVersion "1.3.2"
}
namespace 'com.torrydo.floatingbubbleview'

}

Expand Down
3 changes: 1 addition & 2 deletions FloatingBubbleView/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.torrydo.floatingbubbleview">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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
}
}
}

Expand Down Expand Up @@ -278,7 +277,7 @@ abstract class ExpandableBubbleService : FloatingBubbleService() {
sez.refresh()
createBubbles(this, configBubble(), configExpandedBubble())

when(state){
when (state) {
1 -> minimize()
2 -> expand()
}
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ android {
kotlinCompilerExtensionVersion "1.3.2"
kotlinCompilerVersion '1.3.2'
}
namespace 'com.torrydo.testfloatingbubble'
}

dependencies {
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.torrydo.testfloatingbubble">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<!-- <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>-->
<!-- <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>-->
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
POM_DEVELOPER_URL=https://github.com/TorryDo
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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

2 comments on commit 4f9286d

@thproflord
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Torry, i just tested this in my app and is working beautiful, the touch is perfect and the drag is on point

@TorryDo
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thproflord TYSM, glad to hear that 😊

Please sign in to comment.