🚀 Floaty is a customizable floating widget for your Android apps that allows you to add a floating widget to your app's interface.
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2: Add the Floaty dependency to your app's build.gradle file:(Check out sample app for full implementation)
dependencies {
implementation("com.github.Breens-Mbaka:Floaty:1.0.1")
}
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<service
android:name=".FloatyWidget"
android:enabled="true"
android:exported="false" />
Step 5: Configure the floating widget by providing the custom layout resource ID in your Kotlin code:
CustomLayoutConfiguration.customLayoutResourceId = R.layout.floating_widget
Step 6. Show floating widget but make sure the overlay permission is granted or else request user to give permission
// N.B ⚠️: The methods to check for overlay permission & to request overlay permission
// are already provided so just call them
val showFloatingWidgetButton = findViewById<Button>(R.id.showFloatingWidgetButton)
showFloatingWidgetButton.setOnClickListener {
if (checkOverlayDisplayPermission(context = this)) {
showFloatingWidget(context = this)
} else {
requestOverlayDisplayPermission(context = this, activity = this)
}
}
Step 7: If permission to overlay other apps is granted, start the service that will show the floating widget:
private fun showFloatingWidget(context: MainActivity) {
context.startService(
Intent(
context,
FloatyWidget::class.java,
),
)
}
// In your Activity/Fragment send an intent to a broadcast receiver that will close the widget
val closeWidgetButton = findViewById<Button>(R.id.closeWidgetButton)
closeWidgetButton.setOnClickListener {
val closeFloatingWidgetIntent = Intent(ACTION)
sendBroadcast(closeFloatingWidgetIntent)
}
// In your Activity/Fragment send an intent to a broadcast receiver that will close the widget
override fun onDestroy() {
super.onDestroy()
val closeFloatingWidgetIntent = Intent(ACTION)
sendBroadcast(closeFloatingWidgetIntent)
}
CustomLayoutConfiguration.floatingWidgetWidth = 0.45f //Configure width of the floating widget
CustomLayoutConfiguration.floatyWidgetHeight = 0.30f //Configure height of the floating widget
CustomLayoutConfiguration.floatingWidgetPosition = Gravity.TOP //Configure the psosition of the floating widget on the screen
If you encounter any issues or have feature requests, please create a new issue in this repository.
Support it by joining stargazers for this repository. ⭐
Also follow me for my next creations! 🤩
Copyright 2023 Breens-Mbaka
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.