Skip to content

add composables to WindowManager with a function call

License

Notifications You must be signed in to change notification settings

aabadaa/Fly-view

Repository files navigation

Fly-view

this library enables you to add a composable view to the window manager easily using a foreground service

Demo

flyView-demo.webm

Setup

Step 1 Add this in your root build.gradle at the end of repositories:

	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

Step 2 Add the dependency, get the last version from

	dependencies {
	        implementation 'com.github.aabadaa:Fly-view:Tag'
	}

Usage

At first you need to define a FlyViewInfo like this:

        val controller = ExampleController()
        FlyViewInfo(controller = controller, onRemove = {
            controller.x = 10
            controller.auto = false
            delay(1000)
        }) {
            DraggableFlyView(autoGoToBorder = controller.auto) {
                BackHandler(true) {
                    Log.i(ContentValues.TAG, "createFlyView: backHandler")
                    removeView()
                }
                Column(modifier = Modifier.background(Color.White)) {
                    Text(text = "test ${controller.x}")
                    Button(onClick = removeView) {
                        Text("Close")
                    }
                    Button(onClick = {
                        controller.x++
                    }) {
                        Text("x++")
                    }
                    Button(onClick = { controller.auto = controller.auto.not() }) {
                        Text(text = controller.auto.toString())
                    }
                }
            }
        }
    }

Then you can call show method to launch the service, for example:

FlyViewService.show(context, "example")

Be sure that there is a defined FlyViewInfo object that is associated to the passed key.
Check the full example here

Docs

FlyViewInfo

A holder to all information needed for the FlyView
@property controller used to send bundles from anywhere to the FlyView
@property onRemove pass a lambda which will be called before removing the FlyView
@property params a WindowManager.LayoutParams that passed when adding the FlyView
@property keyDispatcher this will be passed to the FlyView to handle key events
@property content the content of the flyView
@property flyView the android.view.View object that will be added to the WindowManager
@property removeView call it in your view to remove it
@property params pass your lambda that updates the view's layout params to update it

FlyViewService

has a static show method to show a FlyViewInfo that you added to the infoProviders
@param context a context to start the service
@param key the key you used to add your FlyViewInfo to the infoProviders
@param bundle an optional bundle that will be passed to your controller FlyController.update method

License

Designed and developed by 2023 AbdulAleem Alsayed

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.