Giter Site home page Giter Site logo

crackercat / perfectfloatwindow Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alonsol/perfectfloatwindow

0.0 0.0 0.0 257 KB

android全局悬浮窗,目前已经适配华为,小米,vivo,oppo,一加,三星,魅族,索尼,LG,IQOO,努比亚,中兴,金立,360,锤子等目前是市面上所有机型兼容android4.1至android11版本,支持androidX

Kotlin 56.50% Java 43.50%

perfectfloatwindow's Introduction

PerfectFloatWindow

Android悬浮窗,绝对是目前相关悬浮窗开源库最完美的适配方案。目前已经适配华为,小米,vivo,oppo,一加,三星,魅族,索尼,LG,IQOO,努比亚,中兴,金立,360,锤子等目前是市面上主流机型包括非主流机型,兼容4.4以上包括android11版本。调用方便,配置少,后续会新增更多功功能,绝对满足你的定制化需求

特性

  1. 支持悬浮窗内容自定义

  2. 内部已处理权限校验,以及设置页面跳转

  3. 支持builder模式,方便动态配置

  4. 支持悬浮窗手势滑动

  5. 适配vivo,oppo等第三方权限管理器跳转

  6. 支持应用内以及应用外全局弹窗

  7. 权限开启弹窗支持用户自定义

1.初始化悬浮窗控件

        //定义悬浮窗助手
        floatHelper = FloatClient.Builder()
            .with(this)
            .addView(view)
            //是否需要展示默认权限提示弹窗,建议使用自己的项目中弹窗样式(默认开启)
            .enableDefaultPermissionDialog(false)
            .setClickTarget(MainActivity::class.java)
            .addPermissionCallback(object : IFloatPermissionCallback {
                override fun onPermissionResult(granted: Boolean) {
                    //(建议使用addPermissionCallback回调中添加自己的弹窗)
                    Toast.makeText(this@MainActivity, "granted -> $granted", Toast.LENGTH_SHORT)
                        .show()
                    if (!granted) {
                        //申请权限
                        floatHelper?.requestPermission()
                    }
                }
            })
            .build()

2.开启默认弹窗,默认开启(建议开发者根据自己的样式进行)

    enableDefaultPermissionDialog(true)

3.悬浮窗权限回调 用户设置该回调后,可以处理自己的回调逻辑,设置该监听后,enableDefaultPermissionDialog选项失效

    addPermissionCallback(object : IFloatPermissionCallback {
                override fun onPermissionResult(granted: Boolean) {
                    //(建议使用addPermissionCallback回调中添加自己的弹窗)
                    //granted = true 权限通过 granted = false 权限拒绝
                    if (!granted) {
                        //申请权限
                        floatHelper?.requestPermission()
                    }
                }
            })

4.申请悬浮窗权限

    floatHelper?.requestPermission()

5.设置点击跳转目标

    floatHelper?.setClickTarget(MainActivity::class.java)

6.开启悬浮窗

    floatHelper?.show()

7.关闭悬浮窗

    floatHelper?.dismiss()

8.关闭悬浮窗并释放资源

    override fun onDestroy() {
        super.onDestroy()
        floatHelper?.release()
    }

9.更新悬浮窗控件

    private fun initCountDown() {
        countDownTimer = object : CountDownTimer(Long.MAX_VALUE, 1000) {
            override fun onTick(millisUntilFinished: Long) {
                //更新悬浮窗内容(这里根据自己的业务进行扩展)
                tvContent.text = getLeftTime(millisUntilFinished)
            }

            override fun onFinish() {

            }
        }
        countDownTimer?.start()
    }

    fun getLeftTime(time: Long): String {
        val formatter = SimpleDateFormat("HH:mm:ss")
        formatter.timeZone = TimeZone.getTimeZone("GMT+00:00")
        return formatter.format(time)
    }

10.权限申请

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

11.配置

    implementation 'com.alonsol:floatserver:1.0.0'

结语

PerfectFloatWindow做了大量的机型测试,满足绝大部分市场上机型,欢迎大家提供宝贵意见

perfectfloatwindow's People

Contributors

alonsol 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.