Convert Figma logo to code with AI

yhaolpz logoFloatWindow

Andorid 任意界面悬浮窗,实现悬浮窗如此简单

4,177
646
4,177
100

Top Related Projects

😍 A beautiful, fluid, and extensible dialogs API for Kotlin & Android.

:fire: Android developers should collect the following utils(updating).

32,645

ZXing ("Zebra Crossing") barcode scanning library for Java, Android

Render After Effects animations natively on Android and iOS, Web, and React Native

45,699

Square’s meticulous HTTP client for the JVM, Android, and GraalVM.

42,958

A type-safe HTTP client for Android and the JVM

Quick Overview

The FloatWindow project is a lightweight and customizable floating window library for Android. It allows developers to create and manage floating windows within their Android applications, providing a flexible and user-friendly interface.

Pros

  • Lightweight and Efficient: The library is designed to be lightweight and efficient, minimizing the impact on the overall performance of the application.
  • Customizable: Developers can easily customize the appearance and behavior of the floating windows, including size, position, and animation.
  • Easy Integration: The library provides a simple and straightforward API, making it easy to integrate into existing Android projects.
  • Cross-platform Compatibility: The library is compatible with a wide range of Android devices and versions, ensuring consistent behavior across different platforms.

Cons

  • Limited Functionality: While the library provides a solid foundation for creating floating windows, it may lack some advanced features or functionality that some developers might require.
  • Potential Compatibility Issues: As with any third-party library, there is a risk of compatibility issues with certain Android versions or device configurations.
  • Dependency on External Libraries: The library may have dependencies on other external libraries, which could increase the overall complexity of the project.
  • Potential Performance Impact: Depending on the complexity and usage of the floating windows, there may be a slight performance impact on the application.

Code Examples

Here are a few code examples demonstrating the usage of the FloatWindow library:

// Create a new floating window
FloatWindow floatWindow = new FloatWindow.Builder(this)
    .setView(R.layout.float_window_layout)
    .setWidth(WindowManager.LayoutParams.WRAP_CONTENT)
    .setHeight(WindowManager.LayoutParams.WRAP_CONTENT)
    .setX(100)
    .setY(100)
    .build();

// Show the floating window
floatWindow.show();

// Hide the floating window
floatWindow.hide();

// Remove the floating window
floatWindow.dismiss();

This code demonstrates how to create, show, hide, and remove a floating window using the FloatWindow library.

// Set the window's position
floatWindow.setPosition(100, 100);

// Set the window's size
floatWindow.setSize(300, 200);

// Set the window's background color
floatWindow.setBackgroundColor(Color.BLUE);

These code snippets show how to customize the position, size, and background color of the floating window.

// Set a click listener on the floating window
floatWindow.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // Handle the click event
    }
});

This code demonstrates how to set a click listener on the floating window to handle user interactions.

Getting Started

To get started with the FloatWindow library, follow these steps:

  1. Add the library to your project's dependencies:
dependencies {
    implementation 'com.yhaolpz:floatwindow:1.1.2'
}
  1. Create a new FloatWindow instance and configure it:
FloatWindow floatWindow = new FloatWindow.Builder(this)
    .setView(R.layout.float_window_layout)
    .setWidth(WindowManager.LayoutParams.WRAP_CONTENT)
    .setHeight(WindowManager.LayoutParams.WRAP_CONTENT)
    .setX(100)
    .setY(100)
    .build();
  1. Show the floating window:
floatWindow.show();
  1. Customize the floating window as needed:
floatWindow.setPosition(200, 300);
floatWindow.setSize(400, 300);
floatWindow.setBackgroundColor(Color.BLUE);
  1. Handle user interactions with the floating window:
floatWindow.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // Handle the click event
    }
});

That's it! You can now use the FloatWindow library to create and manage floating windows in your Android application.

Competitor Comparisons

😍 A beautiful, fluid, and extensible dialogs API for Kotlin & Android.

Pros of material-dialogs

  • Provides a wide range of customizable dialog options, including input fields, checkboxes, and radio buttons.
  • Supports Material Design guidelines, ensuring a consistent and visually appealing user interface.
  • Offers a variety of built-in themes and styles, making it easy to integrate with different app designs.

Cons of material-dialogs

  • Larger in size compared to FloatWindow, which may impact app size and performance.
  • Requires more setup and configuration to integrate into an existing project.
  • May have a steeper learning curve for developers unfamiliar with the library.

Code Comparison

FloatWindow

FloatWindow.with(this)
    .setView(R.layout.float_window)
    .setWidth(WindowManager.LayoutParams.WRAP_CONTENT)
    .setHeight(WindowManager.LayoutParams.WRAP_CONTENT)
    .setX(100)
    .setY(100)
    .setMoveType(MoveType.SLIDE)
    .setFilter(ActivateEvent.TOUCH_DOWN)
    .setPermissionListener(new PermissionListener() {
        @Override
        public void onSuccess() {
            // Permission granted
        }

        @Override
        public void onFail() {
            // Permission denied
        }
    })
    .build();

material-dialogs

MaterialDialog(this)
    .title(text = "Hello, World!")
    .message(text = "This is a material dialog.")
    .positiveButton(text = "OK") {
        // Handle positive button click
    }
    .negativeButton(text = "Cancel") {
        // Handle negative button click
    }
    .show()

:fire: Android developers should collect the following utils(updating).

Pros of AndroidUtilCode

  • Comprehensive set of utility functions covering a wide range of Android development tasks
  • Well-documented and actively maintained with regular updates
  • Provides a consistent and reliable set of tools to improve developer productivity

Cons of AndroidUtilCode

  • Larger in scope and size compared to FloatWindow, which may be overkill for some projects
  • Potential learning curve for developers unfamiliar with the library

Code Comparison

FloatWindow

FloatWindow.get()
    .setView(view)
    .setWidth(300)
    .setHeight(400)
    .setX(100)
    .setY(100)
    .show();

AndroidUtilCode

DeviceUtils.isDeviceRooted();
BarUtils.setStatusBarColor(activity, Color.BLUE);
ClickUtils.applySingleDebouncing(view, v -> {
    // handle click event
});
32,645

ZXing ("Zebra Crossing") barcode scanning library for Java, Android

Pros of zxing/zxing

  • Comprehensive library for 1D/2D barcode image processing
  • Supports a wide range of barcode formats, including QR codes, Aztec, and more
  • Actively maintained with regular updates and bug fixes

Cons of zxing/zxing

  • Larger codebase and more complex to integrate into a project
  • May have a steeper learning curve for developers new to barcode scanning

Code Comparison

zxing/zxing:

Result result = new MultiFormatReader().decode(bitmap);
String contents = result.getText();
BarcodeFormat format = result.getBarcodeFormat();

yhaolpz/FloatWindow:

FloatWindowManager.getInstance()
    .setLayout(R.layout.float_window)
    .setPosition(100, 100)
    .show();

Render After Effects animations natively on Android and iOS, Web, and React Native

Pros of Lottie-Android

  • Lottie-Android is a powerful and feature-rich library for rendering vector-based animations on Android. It provides a seamless integration with Lottie, a tool developed by Airbnb for creating and editing animations.
  • The library offers a wide range of customization options, allowing developers to fine-tune the animations to their specific needs.
  • Lottie-Android has a large and active community, with regular updates and a wealth of documentation and resources available.

Cons of Lottie-Android

  • The library can be more complex to set up and integrate into an existing project compared to FloatWindow.
  • Lottie-Android may have a higher learning curve for developers who are not familiar with Lottie or vector-based animations.
  • The library can be more resource-intensive than FloatWindow, especially for complex animations, which may impact the performance of the app.

Code Comparison

Lottie-Android:

LottieAnimationView animationView = findViewById(R.id.animation_view);
animationView.setAnimation("animation.json");
animationView.playAnimation();

FloatWindow:

FloatWindow.with(this)
    .setView(R.layout.float_window)
    .setWidth(ScreenUtil.getScreenWidth() / 2)
    .setHeight(ScreenUtil.getScreenHeight() / 3)
    .setX(100)
    .setY(100)
    .setMoveType(MoveType.SLIDE)
    .setFilter(true)
    .build()
    .show();
45,699

Square’s meticulous HTTP client for the JVM, Android, and GraalVM.

Pros of OkHttp

  • OkHttp is a widely-used, mature, and well-maintained HTTP client library for Java and Kotlin, with a large and active community.
  • It provides a simple and intuitive API for making HTTP requests, handling responses, and managing connection pooling.
  • OkHttp has excellent performance and supports features like caching, connection reuse, and automatic retries.

Cons of OkHttp

  • OkHttp is a general-purpose HTTP client library, while FloatWindow is a specific library for creating floating windows on Android.
  • The learning curve for OkHttp may be steeper than for a more specialized library like FloatWindow.
  • OkHttp may have a larger footprint in your app, as it includes a more comprehensive set of features.

Code Comparison

OkHttp (making a simple GET request):

OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
    .url("https://api.example.com/data")
    .build();
Response response = client.newCall(request).execute();

FloatWindow (creating a floating window):

FloatWindow.with(context)
    .setView(myView)
    .setWidth(300)
    .setHeight(400)
    .setX(100)
    .setY(100)
    .setMoveType(MoveType.SLIDE)
    .build()
    .show();
42,958

A type-safe HTTP client for Android and the JVM

Pros of Retrofit

  • Retrofit is a widely-used and well-established library for making HTTP requests in Android applications.
  • It provides a clean and intuitive API for defining and making API calls, with support for various response types.
  • Retrofit is highly extensible, with a large ecosystem of add-on libraries and tools.

Cons of Retrofit

  • Retrofit may have a steeper learning curve compared to simpler networking libraries, especially for developers new to Android development.
  • Retrofit may not be the best choice for simple, one-off HTTP requests, as it can be overkill for such use cases.

Code Comparison

Retrofit:

public interface GitHubService {
    @GET("users/{user}/repos")
    Call<List<Repo>> listRepos(@Path("user") String user);
}

FloatWindow:

public class FloatWindowManager {
    public static void createFloatWindow(Context context) {
        // Code to create a floating window
    }
}

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

FloatWindow 安卓任意界面悬浮窗

悬浮按钮图

特性:

1.支持拖动,提供自动贴边等动画

2.内部自动进行权限申请操作

3.可自由指定要显示悬浮窗的界面

4.应用退到后台时,悬浮窗会自动隐藏

5.除小米外,4.4~7.0 无需权限申请

6.位置及宽高可设置百分比值,轻松适配各分辨率

7.支持权限申请结果、位置等状态监听

8.链式调用,简洁清爽

集成:

第 1 步、在工程的 build.gradle 中添加:

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

第 2 步、在应用的 build.gradle 中添加:

	dependencies {
	        compile 'com.github.yhaolpz:FloatWindow:1.0.9'
	}

使用:

0.声明权限


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

1.基础使用

        FloatWindow
              .with(getApplicationContext())
              .setView(view)
              .setWidth(100)                               //设置控件宽高
              .setHeight(Screen.width,0.2f)
              .setX(100)                                   //设置控件初始位置
              .setY(Screen.height,0.3f)
              .setDesktopShow(true)                        //桌面显示
              .setViewStateListener(mViewStateListener)    //监听悬浮控件状态改变
              .setPermissionListener(mPermissionListener)  //监听权限申请结果
              .build();

宽高及位置可设像素值或屏幕宽/高百分比,默认宽高为 wrap_content;默认位置为屏幕左上角,x、y 为偏移量。

2.指定界面显示

              .setFilter(true, A_Activity.class, C_Activity.class)

此方法表示 A_Activity、C_Activity 显示悬浮窗,其他界面隐藏。

              .setFilter(false, B_Activity.class)

此方法表示 B_Activity 隐藏悬浮窗,其他界面显示。

注意:setFilter 方法参数可以识别该 Activity 的子类

也就是说,如果 A_Activity、C_Activity 继承自 BaseActivity,你可以这样设置:

              .setFilter(true, BaseActivity.class)

3.可拖动悬浮窗及回弹动画

              .setMoveType(MoveType.slide)
              .setMoveStyle(500, new AccelerateInterpolator())  //贴边动画时长为500ms,加速插值器

共提供 4 种 MoveType :

MoveType.slide : 可拖动,释放后自动贴边 (默认)

MoveType.back : 可拖动,释放后自动回到原位置

MoveType.active : 可拖动

MoveType.inactive : 不可拖动

setMoveStyle 方法可设置动画效果,只在 MoveType.slide 或 MoveType.back 模式下设置此项才有意义。默认减速插值器,默认动画时长为 300ms。

4.后续操作

        //手动控制
        FloatWindow.get().show();
        FloatWindow.get().hide();

        //修改显示位置
        FloatWindow.get().updateX(100);
        FloatWindow.get().updateY(100);

        //销毁
        FloatWindow.destroy();

以上操作应待悬浮窗初始化后进行。

5.多个悬浮窗


        FloatWindow
                .with(getApplicationContext())
                .setView(imageView)
                .build();

        FloatWindow
                .with(getApplicationContext())
                .setView(button)
                .setTag("new")
                .build();


        FloatWindow.get("new").show();
        FloatWindow.get("new").hide();
        FloatWindow.destroy("new");

创建第一个悬浮窗不需加 tag,之后再创建就需指定唯一 tag ,以此区分,方便进行后续操作。

举个栗子

点击查看 : 示例代码 。

最后:

悬浮按钮图

本人已尽量去兼容更多机型,但经济有限,如果你想帮助此库,提 Issues 标出当前版本不适配的机型即可,感谢~

更新日志

v1.0.9

修复拖动点击事件冲突

添加权限结果监听、位置等状态监听

支持贴边边距设置

v1.0.8

适配 4.4~8.0 及各大国产机型

支持桌面显示

v1.0.7

适配 Android 8.0

v1.0.6

支持悬浮窗拖动及相关动效

位置及宽高可设置百分比值

更改相关类名及使用方法

v1.0.5

修复未调用show显示悬浮窗bug

v1.0.4

返回桌面将会自动隐藏控件,无需再监听应用退到后台等操作

新增 Activity 过滤器,可自由指定哪些界面显示,哪些界面不显示

FixedFloatWindow 类改为 FFWindow

v1.0.3

修复已知 bug

新增 dismiss 方法

新增其他方案,如:所有版本都申请权限