diff --git a/easyfloat/build.gradle b/easyfloat/build.gradle index f4a6125..a869546 100644 --- a/easyfloat/build.gradle +++ b/easyfloat/build.gradle @@ -8,7 +8,7 @@ android { compileSdkVersion 28 defaultConfig { - minSdkVersion 19 + minSdkVersion 17 targetSdkVersion 28 versionCode 1 versionName "1.0" diff --git a/easyfloat/src/main/java/com/lzf/easyfloat/utils/DisplayUtils.kt b/easyfloat/src/main/java/com/lzf/easyfloat/utils/DisplayUtils.kt index f80edc2..27b319e 100644 --- a/easyfloat/src/main/java/com/lzf/easyfloat/utils/DisplayUtils.kt +++ b/easyfloat/src/main/java/com/lzf/easyfloat/utils/DisplayUtils.kt @@ -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 @@ -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) @@ -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 + } \ No newline at end of file diff --git a/easyfloat/src/main/java/com/lzf/easyfloat/widget/appfloat/TouchUtils.kt b/easyfloat/src/main/java/com/lzf/easyfloat/widget/appfloat/TouchUtils.kt index 94fe79a..fdbfff1 100644 --- a/easyfloat/src/main/java/com/lzf/easyfloat/widget/appfloat/TouchUtils.kt +++ b/easyfloat/src/main/java/com/lzf/easyfloat/widget/appfloat/TouchUtils.kt @@ -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 @@ -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 @@ -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) // 通过绝对高度和相对高度比较,判断包含顶部状态栏 diff --git a/example/release/EasyFloat.apk b/example/release/EasyFloat.apk index e97ecf1..9ae14e1 100644 Binary files a/example/release/EasyFloat.apk and b/example/release/EasyFloat.apk differ