Skip to content

Commit

Permalink
cleanup, fix expanded-bubble size issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dofire committed Sep 21, 2023
1 parent 14b6fb6 commit 22ce0e5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.torrydo.floatingbubbleview

import android.content.Context
import android.util.AttributeSet
import android.view.KeyEvent
import android.view.MotionEvent
import android.widget.LinearLayout

Expand All @@ -16,6 +17,19 @@ internal open class MyBubbleLayout(
internal var ignoreChildEvent: (MotionEvent) -> Boolean = { false }
internal var doOnTouchEvent: (MotionEvent) -> Unit = {}

private var onDispatchKeyEvent: ((KeyEvent) -> Boolean?)? = null

fun setOnDispatchKeyEvent(callback: ((KeyEvent) -> Boolean?)){
onDispatchKeyEvent = callback
}

override fun dispatchKeyEvent(event: KeyEvent?): Boolean {
if (onDispatchKeyEvent != null && event != null) {
return onDispatchKeyEvent!!(event) ?: super.dispatchKeyEvent(event)
}
return super.dispatchKeyEvent(event)
}

override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
val b = ev?.let{
doOnTouchEvent(it)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +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 android.widget.FrameLayout
import androidx.dynamicanimation.animation.SpringAnimation
import androidx.dynamicanimation.animation.SpringForce
import com.torrydo.floatingbubbleview.AnimHelper
Expand All @@ -28,12 +26,9 @@ class FloatingBubble(
onDispatchKeyEvent: ((KeyEvent) -> Boolean?)? = null
) : Bubble(
context = context,
root = object : MyBubbleLayout(context) {
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
if(onDispatchKeyEvent != null){
return onDispatchKeyEvent(event) ?: super.dispatchKeyEvent(event)
}
return super.dispatchKeyEvent(event)
root = LayoutInflater.from(context).inflate(R.layout.bubble, null).apply {
if (onDispatchKeyEvent != null) {
(this as MyBubbleLayout).setOnDispatchKeyEvent(onDispatchKeyEvent)
}
},
containCompose = containCompose
Expand Down Expand Up @@ -154,33 +149,23 @@ class FloatingBubble(
endY = y,
event = object : AnimHelper.Event {
override fun onUpdatePoint(x: Float, y: Float) {

layoutParams.x = x.toInt()
layoutParams.y = y.toInt()

// builder.listener?.onMove(x.toFloat(), y.toFloat()) // don't call this line, it'll spam multiple MotionEvent.OnActionMove
update()

}
},
stiffness = stiffness,
)
}

private fun getX() = context.resources.configuration.smallestScreenWidthDp

// private val MAX_XY_MOVE = 80f
private val MAX_XY_MOVE = 1f
private var ignoreClick: Boolean = false

@SuppressLint("ClickableViewAccessibility")
private fun customTouch() {

val dpi = getX()
val max_xy_move = dpi / 22
// Log.d("<>", "dpi | xy: ${dpi} - ${max_xy_move}");
// Log.d("<>", "sdfasfasdf ${context.resources.configuration}: ");


fun handleMovement(event: MotionEvent) {
when (event.action) {
MotionEvent.ACTION_DOWN -> {
Expand Down Expand Up @@ -220,7 +205,9 @@ class FloatingBubble(
}

MotionEvent.ACTION_MOVE -> {
ignoreClick = abs(event.rawX - rawPointOnDown.x) > max_xy_move || abs(event.rawY - rawPointOnDown.y) > max_xy_move
if (abs(event.rawX - rawPointOnDown.x) > MAX_XY_MOVE || abs(event.rawY - rawPointOnDown.y) > MAX_XY_MOVE) {
ignoreClick = true
}
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ class MyServiceKt : ExpandableBubbleService() {
return BubbleBuilder(this)

// set bubble view
// .bubbleView(imgView)
.bubbleView(imgView)

// or our sweetie, Jetpack Compose
.bubbleCompose {
BubbleCompose(expand = { expand() })
}
// .bubbleCompose {
// BubbleCompose(expand = { expand() })
// }
// .forceDragging(false)

// set style for the bubble, fade animation by default
Expand Down

0 comments on commit 22ce0e5

Please sign in to comment.