Skip to content

Commit

Permalink
适配小米全面屏
Browse files Browse the repository at this point in the history
  • Loading branch information
princekin-f committed Dec 10, 2019
1 parent 50ea802 commit cb4bfb8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion easyfloat/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
compileSdkVersion 28

defaultConfig {
minSdkVersion 19
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand Down
19 changes: 19 additions & 0 deletions easyfloat/src/main/java/com/lzf/easyfloat/utils/DisplayUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.os.Build
import android.provider.Settings
import android.util.Log
import android.view.*
import com.lzf.easyfloat.permission.rom.RomUtils

/**
* @author: liuzhenfeng
Expand Down Expand Up @@ -101,10 +102,15 @@ object DisplayUtils {
*/
@SuppressLint("PrivateApi")
fun isNavigationBarShow(context: Context): Boolean {

// 如果是小米全面屏,并且开启手势操作,则导航栏是隐藏的
if (isMiuiFullScreen(context)) return false

var hasNavigationBar = false
val rs = context.resources
val id = rs.getIdentifier("config_showNavigationBar", "bool", "android")
if (id > 0) hasNavigationBar = rs.getBoolean(id)

try {
val systemPropertiesClass = Class.forName("android.os.SystemProperties")
val m = systemPropertiesClass.getMethod("get", String::class.java)
Expand All @@ -125,4 +131,17 @@ object DisplayUtils {
return hasNavigationBar
}

/**
* 不包含导航栏的有效高度(没有导航栏,或者已去除导航栏的高度)
*/
fun rejectedNavHeight(context: Context) =
getScreenHeight(context) - getNavigationBarCurrentHeight(context)

/**
* 是否是小米全面屏,并且开启了手势操作
*/
private fun isMiuiFullScreen(context: Context) =
RomUtils.checkIsMiuiRom() &&
Settings.Global.getInt(context.contentResolver, "force_fsg_nav_bar", 0) != 0

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal class TouchUtils(val context: Context, val config: FloatConfig) {
private var parentRect: Rect = Rect()
// 悬浮的父布局高度、宽度
private var parentHeight = 0
private var parentWidth = 0
private val parentWidth = DisplayUtils.getScreenWidth(context)
// 起点坐标
private var lastX = 0f
private var lastY = 0f
Expand All @@ -39,10 +39,6 @@ internal class TouchUtils(val context: Context, val config: FloatConfig) {
private val location = IntArray(2)
// 屏幕可用高度 - 浮窗自身高度 的剩余高度
private var emptyHeight = 0
// 屏幕高度
private val screenHeight = DisplayUtils.getScreenHeight(context)
// 虚拟导航栏高度
private val navigationBarHeight = DisplayUtils.getNavigationBarCurrentHeight(context)
// 是否包含状态栏
private var hasStatusBar = true

Expand All @@ -69,10 +65,8 @@ internal class TouchUtils(val context: Context, val config: FloatConfig) {
// 记录触摸点的位置
lastX = event.rawX
lastY = event.rawY
windowManager.defaultDisplay.getRectSize(parentRect)
parentWidth = parentRect.width()
// 可用高度 = 屏幕高度 - 导航栏
parentHeight = screenHeight - navigationBarHeight
// 可用高度需要每次获取,因为虚拟导航栏的状态可能是变化的
parentHeight = DisplayUtils.rejectedNavHeight(context)
// 获取在整个屏幕内的绝对坐标
view.getLocationOnScreen(location)
// 通过绝对高度和相对高度比较,判断包含顶部状态栏
Expand Down
Binary file modified example/release/EasyFloat.apk
Binary file not shown.

0 comments on commit cb4bfb8

Please sign in to comment.