Skip to content

Commit

Permalink
fix: bubble displays incorrecly in landscape mode.
Browse files Browse the repository at this point in the history
the bubble cannot reach the bottom of the screen in landscape mode.
  • Loading branch information
dofire committed Apr 29, 2023
1 parent f75f120 commit f918a6d
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 28 deletions.
17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

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

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

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

3 changes: 1 addition & 2 deletions .idea/misc.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ abstract class FloatingBubbleService : Service() {
}
}
else -> {
Log.d("<>", "change undefine: ");
// Log.d("<>", "change undefine: ");
}
}
orientation = newOrientation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ internal class FloatingBubbleView(
if (isAboveStatusBar) {
newPoint.y = safeTopY
} else if (isUnderSoftNavBar) {
newPoint.y = safeBottomY
if(ScreenInfo.isPortrait){
newPoint.y = safeBottomY
} else if(newPoint.y - ScreenInfo.softNavBarHeightPx > safeBottomY){
newPoint.y = safeBottomY + (ScreenInfo.softNavBarHeightPx)
}
}
//endregion

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.torrydo.floatingbubbleview

import android.util.Log
import android.view.LayoutInflater
import android.view.WindowManager
import androidx.core.content.OnConfigurationChangedProvider
import com.torrydo.floatingbubbleview.databinding.CloseBubbleBinding

internal class FloatingCloseBubbleView(
Expand All @@ -14,7 +12,7 @@ internal class FloatingCloseBubbleView(
) {

companion object {
internal const val DEFAULT_PADDING_BOTTOM_PX = 20
internal const val DEFAULT_PADDING_BOTTOM_PX = 30
}

private var LIMIT_FLY_HEIGHT: Int
Expand Down Expand Up @@ -54,6 +52,10 @@ internal class FloatingCloseBubbleView(
ScreenInfo.statusBarHeightPx -
DEFAULT_PADDING_BOTTOM_PX

if (ScreenInfo.isLandscape) {
baseY = baseY - DEFAULT_PADDING_BOTTOM_PX + ScreenInfo.softNavBarHeightPx
}

centerCloseBubbleX = halfScreenWidth
centerCloseBubbleY = baseY + halfHeightPx

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import android.content.res.Configuration
import android.content.res.Resources
import android.os.Build
import android.util.DisplayMetrics
import android.util.Log
import android.util.Size
import android.view.Display
import android.view.WindowInsets
import android.view.WindowManager
import android.view.WindowMetrics
import androidx.annotation.RequiresApi
Expand All @@ -21,6 +23,9 @@ internal object ScreenInfo {
internal var statusBarHeightPx = 0
internal var softNavBarHeightPx = 0

var isPortrait = true
val isLandscape get() = isPortrait.not()


// methods -------------------------------------------------------------------------------------
fun onOrientationChanged(context: Context) {
Expand All @@ -32,9 +37,13 @@ internal object ScreenInfo {
if(it.height >= it.width){ // portrait
widthPx = it.width
heightPx = it.height

isPortrait = true
}else{
widthPx = it.width - statusBarHeightPx - softNavBarHeightPx
heightPx = it.height

isPortrait = false
}
}

Expand Down
42 changes: 23 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 🍀Floating Bubble View
An Android library that adds floating bubbles to your home screen 🎨, supports both XML and 💘 Jetpack Compose

&nbsp;
<br>

https://user-images.githubusercontent.com/85553681/223082521-789146d2-c8f7-4e54-a4d7-f281cd495404.mp4

Expand Down Expand Up @@ -400,16 +400,11 @@ public class MyService extends FloatingBubbleService {

...

/**
* Sets up a notification for Bubble on Android 8 and up.
*
* @param channelId The ID of the notification channel.
* @return The notification instance.
*/
@NonNull
// config the initial notification for Bubble on Android 8 and up.
// return null if you want to show the notification later.
@Override
public Notification setupNotificationBuilder(@NonNull String channelId) {
return new NotificationCompat.Builder(this, channelId)
public Notification initialNotification() {
return new NotificationCompat.Builder(this, channelId())
.setOngoing(true)
.setSmallIcon(R.drawable.ic_rounded_blue_diamond)
.setContentTitle("bubble is running")
Expand Down Expand Up @@ -446,19 +441,16 @@ public class MyService extends FloatingBubbleService {
```kotlin
class MyService : FloatingBubbleService() {

/**
* Sets up a notification for Bubble on Android 8 and up.
* @param channelId The ID of the notification channel.
* @return The notification instance.
*/
override fun setupNotificationBuilder(channelId: String): Notification {
return NotificationCompat.Builder(this, channelId)
// config the initial notification for Bubble on Android 8 and up.
// return null if you want to show the notification later.
open fun initialNotification(): Notification? {
return NotificationCompat.Builder(this, channelId())
.setOngoing(true)
.setSmallIcon(R.drawable.ic_rounded_blue_diamond)
.setContentTitle("bubble is running")
.setContentText("click to do nothing")
.setPriority(NotificationCompat.PRIORITY_MIN)
.setPriority(PRIORITY_MIN)
.setCategory(Notification.CATEGORY_SERVICE)
.setSilent(true)
.build()
}

Expand All @@ -470,6 +462,17 @@ class MyService : FloatingBubbleService() {

</details>

<details><summary>Notice since Android 13 ⚠ </summary>
<br/>

Starting in Android 13 (API level 33), notifications are only visible if the "POST_NOTIFICATIONS" permission is granted.<br/>

> The service will run normally even if the notification is not visible. 🍀
> P/s: You still need to initialize the notification before showing any view.
</details>

### 3, Check if bubble is running

```java
Expand Down Expand Up @@ -544,6 +547,7 @@ fun SomeComposable(){
| `showExpandableView()` | Displays the expandable-view |
| `removeExpandableView()` | Removes the expandable-view |
| `removeAllViews()` | Removes all views |
| `notify(Notification)` | Displays or updates notification |

<!-- | `updateNotification()`| Updates the displayed notification by calling (again) `setupNotificationBuilder()` | -->

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<!-- <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>-->
<!-- <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>-->

<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
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.5.2
#prev: 0.5.1
VERSION_NAME=0.5.3
#prev: 0.5.2

POM_NAME=FloatingBubbleView
POM_PACKAGING=aar
Expand Down

0 comments on commit f918a6d

Please sign in to comment.