Skip to content

Commit

Permalink
Bugfix/bubble touch (#65)
Browse files Browse the repository at this point in the history
* increase XY dragging threshold of the bubble

* fix: close-bubble being shown when click bubble

* add triggerClickablePerimeterPx API, upgrade version, README

* update jdk 17 to fix github ci file
  • Loading branch information
dofire authored Mar 27, 2024
1 parent dbd83b1 commit 3234d16
Show file tree
Hide file tree
Showing 17 changed files with 104 additions and 56 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/publish-maven-central.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
- name: Checkout github repo
uses: actions/checkout@v2

- name: set up JDK 11
uses: actions/setup-java@v2
- name: set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '11'
java-version: '17'
distribution: 'adopt'
cache: gradle

Expand Down
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.

2 changes: 1 addition & 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 @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
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 triggerClickablePerimeterPx = 5f

internal var listener: FloatingBubbleListener? = null
internal var behavior: CloseBubbleBehavior = CloseBubbleBehavior.FIXED_CLOSE_BUBBLE
Expand Down Expand Up @@ -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
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.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,
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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ An Android library that creates floating bubbles on top of the screen 🎨, supp

<div align="center">

<h6> Find this library useful? 🥰 Don't forget to show some love by giving a &nbsp; -Star⭐- </h6>
<h6> Like this project? 🥰 Don't forget to show some love by giving a Star⭐ </h6>

| Bubble | Custom |
| :-: | :-: |
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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? {
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class MyServiceKt : ExpandableBubbleService() {
// set bubble view
.bubbleView(imgView)

.triggerClickablePerimeterPx(5f)

// or our sweetie, Jetpack Compose
// .bubbleCompose {
// BubbleCompose(expand = { expand() })
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
9 changes: 6 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 3234d16

Please sign in to comment.