Skip to content

Commit

Permalink
优化全面屏兼容问题
Browse files Browse the repository at this point in the history
  • Loading branch information
princekin-f committed Nov 12, 2019
1 parent f915969 commit a965280
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ allprojects {
- **在应用模块的`build.gradle`添加:**
```
dependencies {
implementation 'com.github.princekin-f:EasyFloat:1.1.2'
implementation 'com.github.princekin-f:EasyFloat:1.1.3'
}
```

Expand Down
3 changes: 3 additions & 0 deletions UpdateDoc.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## 版本更新日志
#### v 1.1.3:
- 优化部分全面屏手机,系统浮窗不能拖到底部的问题。

#### v 1.1.2:
- 优化页面过滤和主动隐藏的逻辑。

Expand Down
61 changes: 34 additions & 27 deletions easyfloat/src/main/java/com/lzf/easyfloat/utils/DisplayUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Point
import android.os.Build
import android.provider.Settings
import android.util.Log
import android.view.*
import android.widget.FrameLayout

/**
* @author: liuzhenfeng
Expand Down Expand Up @@ -50,9 +50,11 @@ object DisplayUtils {
* 获取屏幕高度
*/
fun getScreenHeight(context: Context): Int {
val resources = context.resources
val dm = resources.displayMetrics
return dm.heightPixels
val display =
(context.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay
val point = Point()
display.getRealSize(point)
return point.y
}

/**
Expand Down Expand Up @@ -91,31 +93,36 @@ object DisplayUtils {
return result
}

@SuppressLint("ObsoleteSdkInt")
fun isNavigationBarShow(context: Context): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
val display =
(context.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay
val size = Point()
val realSize = Point()
display.getSize(size)
display.getRealSize(realSize)
realSize.y != size.y
} else {
val menu = ViewConfiguration.get(context).hasPermanentMenuKey()
val back = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK)
!(menu || back)
}
}

/**
* 设置相对于原点坐标的偏移量
* 判断虚拟导航栏是否显示
*
* @param context 上下文对象
* @return true(显示虚拟导航栏),false(不显示或不支持虚拟导航栏)
*/
fun setLayoutLocation(view: View, pair: Pair<Int, Int>) {
val margin = ViewGroup.MarginLayoutParams(view.layoutParams)
margin.setMargins(pair.first, pair.second, 0, 0)
val layoutParams = FrameLayout.LayoutParams(margin)
view.layoutParams = layoutParams
@SuppressLint("PrivateApi")
fun isNavigationBarShow(context: Context): Boolean {
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)
val navBarOverride = m.invoke(systemPropertiesClass, "qemu.hw.mainkeys") as String
// 判断是否隐藏了底部虚拟导航
val navigationBarIsMin = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Settings.System.getInt(context.contentResolver, "navigationbar_is_min", 0)
} else {
Settings.Global.getInt(context.contentResolver, "navigationbar_is_min", 0)
}
if ("1" == navBarOverride || 1 == navigationBarIsMin) {
hasNavigationBar = false
} else if ("0" == navBarOverride) {
hasNavigationBar = true
}
} catch (e: Exception) {
}
return hasNavigationBar
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ internal class TouchUtils(val context: Context, val config: FloatConfig) {
// x轴、y轴的最小距离值
private var minX = 0
private var minY = 0

private val location = IntArray(2)
// 屏幕可用高度 - 浮窗自身高度 的剩余高度
private var emptyHeight = 0
// 屏幕高度
private val screenHeight = DisplayUtils.getScreenHeight(context)
private val navigationBarHeight = DisplayUtils.getNavigationBarHeight(context)
// 虚拟导航栏高度
private val navigationBarHeight = DisplayUtils.getNavigationBarCurrentHeight(context)
// 是否包含状态栏
private var hasStatusBar = true

/**
Expand Down Expand Up @@ -67,10 +71,12 @@ internal class TouchUtils(val context: Context, val config: FloatConfig) {
lastY = event.rawY
windowManager.defaultDisplay.getRectSize(parentRect)
parentWidth = parentRect.width()
parentHeight = parentRect.height()
// 当前高度是否包含顶部状态栏
hasStatusBar =
parentHeight == screenHeight || parentHeight + navigationBarHeight == screenHeight
// 可用高度 = 屏幕高度 - 导航栏
parentHeight = screenHeight - navigationBarHeight
// 获取在整个屏幕内的绝对坐标
view.getLocationOnScreen(location)
// 通过绝对高度和相对高度比较,判断包含顶部状态栏
hasStatusBar = location[1] > params.y
emptyHeight = parentHeight - view.height
}

Expand Down
Binary file modified example/release/EasyFloat.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.Gravity
import android.view.MotionEvent
import android.view.View
import android.view.*
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import com.lzf.easyfloat.EasyFloat
Expand Down

0 comments on commit a965280

Please sign in to comment.