Giter Club home page Giter Club logo

androidfloatingwindowsengine's Introduction

AndroidFloatingWindowsEngine

Floating windows engine for Android

First API Version (OLD)

Navigation

Preview

Screenshot_1647277648 image

How to use

Navigation

Windows:

Other:

BaseWindow

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()

Flags

BaseWindow.FLAG_WINDOW_NOT_DRAGGABLE (If specified cancels the flag FloatingObject.FLAG_DRAGGABLE)

const val FLAG_WINDOW_NOT_DRAGGABLE = 1 shl 0

FloatingWindow

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)

WindowManager

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()

FloatingPermissions

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)

FloatingObject

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)
)

Flags

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

FloatingObject (Example)

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()
    }
}

androidfloatingwindowsengine's People

Contributors

aratakileo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.