Floating windows engine for Android
Windows:
Other:
To use (MainActivity.kt
)
import pexty.floatingapp.window.BaseWindow
Initialize (MainActivity.kt
)
val baseWindow = BaseWindow(
this, // context
800, // window width
800, // window height
0, // window position X at screen (0 - default value)
0, // window position Y at screen (0 - default value)
"My Window", // window title ("Floating Window" - default value)
0 // flags (0 - default value)
)
Open window (MainActivity.kt
)
baseWindow.open()
Close window (MainActivity.kt
)
baseWindow.close()
Kill window (MainActivity.kt
) - it differs from the close()
function in that it does not send a request to the window to close it, but closes it immediately by force
baseWindow.kill()
BaseWindow.FLAG_WINDOW_NOT_DRAGGABLE
(If specified cancels the flag FloatingObject.FLAG_DRAGGABLE
)
const val FLAG_WINDOW_NOT_DRAGGABLE = 1 shl 0
This class extends BaseWindow
.
To use (MainActivity.kt
)
import pexty.floatingapp.window.FloatingWindow
Initialize (MainActivity.kt
)
val floatingWindow = FloatingWindow(
this, // context
800, // window width
800, // window height
0, // window position X at screen (0 - default value)
0, // window position Y at screen (0 - default value)
"My Window", // window title ("Floating Window" - default value)
0 // flags (0 - default value)
)
Set content view (MainActivity.kt
)
floatingWindow.setContentView(ImageView(this))
Get content view (MainActivity.kt
)
println(floatingWindow.getContentView())
Remove content view (MainActivity.kt
)
floatingWindow.removeContentView()
Set content background color (MainActivity.kt
)
floatingWindow.setContentBackgroundColor(Color.BLACK)
object
(final class
in Java) for controlling all flosting windows.
To use (MainActivity.kt
)
import pexty.floatingapp.window.WindowManager
Calls all windows close()
method (MainActivity.kt
)
WindowManager.closeAll()
Calls all windows kill()
method (MainActivity.kt
)
WindowManager.killAll()
Calls all windows close()
method, but if after this method was called window is not closed, then calls kill()
wethod for that window (MainActivity.kt
)
WindowManager.softKillAll()
Allows you to check/get the necessary permissions.
To use (MainActivity.kt
)
import pexty.floatingapp.FloatingPermissions
Check permissions (MainActivity.kt
)
if (FloatingPermissions.has(this))
print("Has permissions!")
else
print("Needs permissions!")
Get permissions (MainActivity.kt
)
if (!FloatingPermissions.has(this))
FloatingPermissions.take(this)
Allows you to make floating view
To use (MainActivity.kt
)
import pexty.floatingapp.FloatingObject
Initialize (MainActivity.kt
)
val floatingObject = FloatingObject(
this, // context
view, // our view
12, // position X at screen
15, // position Y at screen
FloatingObject.FLAG_DRAGGABLE // flags (0 - defaul value)
)
FloatingObject.FLAG_DRAGGABLE
(allows to move an object across the screen)
const val FLAG_DRAGGABLE = 1 shl 0
FloatingObject.FLAG_LAYOUT_NO_LIMITS
const val FLAG_LAYOUT_NO_LIMITS = 1 shl 1
FloatingObject.FLAG_LAYOUT_IN_SCREEN
const val FLAG_LAYOUT_IN_SCREEN = 1 shl 2
FloatingObject.FLAG_ANDROID_SECURE
const val FLAG_ANDROID_SECURE = 1 shl 3
FloatingObject.FLAG_ANDROID_FOCUSABLE
(If specified cancels the flag WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
)
const val FLAG_ANDROID_FOCUSABLE = 1 shl 4
Making our view in activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TableLayout
android:id="@+id/tableLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="#ffffff">
</TableLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Inserting our view into FloatingObject in MainActivity.kt
package com.pexty.studios.floating.windows.engine
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TableLayout
import pexty.floatingapp.FloatingObject
class MainActivityfake0: AppCompatActivity() {
lateinit tableLayout: TableLayout
lateinit floatingObject: FloatingObject
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
tableLayout = findViewById<TableLayout>(R.id.tableLayout)
floatingObject = FloatingObject(this, tableLayout, _flags=FloatingObject.FLAG_DRAGGABLE or FloatingObject.FLAG_LAYOUT_NO_LIMITS)
floatingObject.create()
}
override fun onDestroy() {
floatingObject.destroy()
super.onDestroy()
}
}