Code Monkey home page Code Monkey logo

notchfit's Introduction

NotchFit 智能刘海屏适配库

优点:使用简单,刘海参数智能判断,一键式刘海参数回调,无需考虑机型和系统版本差异,适配O版本和P及以上版本。

刘海屏存在于系统O版本、P版本及以上版本,由于google P版本刘海api推出较晚,导致O版本刘海屏的不同厂商的机型有各自不同的 适配方式,再者不同手机系统刘海区域使用设置也有所不同,有的默认开启,有的默认关闭,导致刘海屏适配比较繁琐和复杂,此库 处理了以上所有的问题,并智能判断刘海区域的使用方式和刘海参数的获取,给开发者更好的刘海适配体验!

引入方式

旧版本:(1.4.2及以前)

repositories {
    jcenter()
}
compile 'com.wcl.notchfit:notchfit:1.4.2'

新版本:(1.5及以后)

repositories {
   jcenter()
}
compile 'io.github.wcl9900:NotchFit:1.5'

特点

1.支持多种刘海区域参数获取

    private String manufacturer; //手机厂商
    private boolean notchEnable; //是否显示刘海屏
    private NotchPosition notchPosition; //刘海所在屏幕位置(上、左、右)
    private int notchWidth;           //刘海屏宽度px
    private int notchHeight;          //刘海屏高度px

2.刘海区域位置检测适配

1).顶部适配

name

2).左部适配

name

3).右部适配

name

使用方式

1.沉浸适配

name

  NotchFit.fit(this, NotchScreenType.TRANSLUCENT, new OnNotchCallBack() {
        @Override
        public void onNotchReady(NotchProperty notchProperty) {
            if(notchProperty.isNotchEnable()){
                ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) listParent.getLayoutParams();
                marginLayoutParams.topMargin = notchProperty.getNotchHeight();
                listParent.requestLayout();
            }
        }
   });

2.全屏适配

name

  NotchFit.fit(this, NotchScreenType.FULL_SCREEN, new OnNotchCallBack() {
              @Override
              public void onNotchReady(NotchProperty notchProperty) {
                  if(notchProperty.isNotchEnable()){
                      ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) listParent.getLayoutParams();
                      marginLayoutParams.topMargin = notchProperty.getNotchHeight();
                      listParent.requestLayout();
                  }
              }
          });

3.黑条填充

应用场景:不想对app中的具体全屏UI做针对性刘海适配,可通过此接口一键黑条填充适配!!!

name

 NotchFit.fitUnUse(this);
 
更多使用方式请查看demo

notchfit's People

Contributors

tenglong9900 avatar wcl9900 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

notchfit's Issues

华为手机适配时崩溃

系统版本 Android 9,level 28
设备机型 华为 ANE AL00

Attempt to invoke virtual method 'android.view.DisplayCutout android.view.WindowInsets.getDisplayCutout()' on a null object reference
com.wcl.notchfit.core.AbstractNotch.isNotchEnable_P(AbstractNotch.java:151)

Crash,传感器监听超限

Fatal Exception: java.lang.IllegalStateException
register failed, the sensor listeners size has exceeded the maximum limit 128
android.hardware.SystemSensorManager.registerListenerImpl (SystemSensorManager.java:181)
android.hardware.SensorManager.registerListener (SensorManager.java:821)
android.hardware.SensorManager.registerListener (SensorManager.java:728)
android.view.OrientationEventListener.enable (OrientationEventListener.java:93)
com.wcl.notchfit.position.NotchPositionWrapper.onPosition (NotchPositionWrapper.java:53)
com.wcl.notchfit.NotchFit.fit (NotchFit.java:55)

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.