Coder Social home page Coder Social logo

rockystevejobs / enfloatingview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from leotyndale/enfloatingview

0.0 2.0 0.0 1.75 MB

🔥应用内悬浮窗,无需一切权限,适配所有ROM和厂商,no permission floating view.

Home Page: https://imuxuan.com

Java 100.00%

enfloatingview's Introduction

Logo

EnFloatingView

Jcenter Muxuan Website

《移动开发架构设计实战》

点击购买

豆瓣酱

==========================

English

无需一切权限,不受各种国产ROM限制,默认可以显示的应用内悬浮窗。

传统方案

对于传统悬浮窗和一些古老的“黑科技”悬浮窗的实现,想必已经有很多成熟的案例了,实现策略基本为以下两种:

  1. TYPE_SYSTEM_ALERT类型
mWindowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams()
layoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;

​ 需要权限:

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" ></uses>
  1. TYPE_TOAST / TYPE_PHONE 类型

​ 7.1.1以下不需要权限声明,在魅族、华为、小米等机型上默认隐藏,需要引导用户打开悬浮窗。

传统方案的问题

第一种方案因为存在各种限制,不能被众多开发采纳,故而比较流行的悬浮窗实现方式是第二种。

但是,我们有自己的原则:

  • 不能接受7.1.1以上机型,使用第二种方式实现悬浮窗仍需要用户主动授予权限的操作?
  • 不能接受在魅族、华为、小米等机型上默认隐藏,需要引导用户打开悬浮窗,就像这样

权限管理

功能

  • 应用内显示,无需申请任何权限
  • 应用内显示,所有机型都可以默认显示悬浮窗,无需引导用户做更多设置
  • 支持拖拽
  • 超出屏幕限制移动
  • 可自动吸附到屏幕边缘

基本使用规则

1.在gralde的dependencies中加入

    compile 'com.imuxuan:floatingview:1.6'

2.在基类Activity(注意必须是基类Activity)中的onStart和onStop(或者安卓原生ActivityLifeCycle监听)中添加如下代码

    @Override
    protected void onStart() {
        super.onStart();
        FloatingView.get().attach(this);
    }

    @Override
    protected void onStop() {
        super.onStop();
        FloatingView.get().detach(this);
    }

3.展示悬浮窗

    FloatingView.get().add();

扩展用法

1.销毁悬浮窗

    FloatingView.get().remove();

2.添加点击事件

    FloatingView.get().listener(new MagnetViewListener() {
         @Override
         public void onRemove(FloatingMagnetView magnetView) {
             Toast.makeText(TestActivity.this, "我没了", Toast.LENGTH_SHORT).show();
         }

         @Override
         public void onClick(FloatingMagnetView magnetView) {
             Toast.makeText(TestActivity.this, "点到我了", Toast.LENGTH_SHORT).show();
         }
     });

3.获得悬浮窗View

    FloatingView.get().getView();

4.设置悬浮窗icon

    FloatingView.get().icon(R.drawable.XXXXX);

5.设置悬浮窗View

    FloatingView.get().customView(new View());
    or
    FloatingView.get().customView(R.layout.XXXXX);

6.设置悬浮窗位置等布局参数

    FloatingView.get().layoutParams(new ViewGroup.LayoutParams());

效果图

预览图

更新记录

1.6

修复横竖屏切换错位 & 添加到布局时偶发崩溃

1.5

修复内存泄露问题

1.4

适配折叠屏

1.3

增加自定义layout等API

1.2

修复拖拽失效

1.1

点击监听问题处理

1.0

创建项目

enfloatingview's People

Contributors

leotyndale avatar

Watchers

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