Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/v0.6.3 #48

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,18 +361,25 @@ class MyServiceKt : ExpandableBubbleService() {
.expandedCompose {
ExpandedCompose()
}
// handle key code
.onDispatchKeyEvent {
if(it.keyCode == KeyEvent.KEYCODE_BACK){
minimize()
}
null
}
// set start location in dp
.startLocation(0, 0)
// allow expanded bubble can be draggable or not
.draggable(true)
// fade animation by default
.style(null)
//
.fillMaxWidth(true)
// animate to the left/right side when release, trfalseue by default
.enableAnimateToEdge(true)
.dimAmount(0.9f)
// set background dimmer
.dimAmount(0.6f)
}
}
```
Expand Down
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
4 changes: 2 additions & 2 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.2
#prev: 0.6.1
VERSION_NAME=0.6.3
#prev: 0.6.2

POM_NAME=FloatingBubbleView
POM_PACKAGING=aar
Expand Down
Loading