pull/1222/head
gedoor 3 years ago
parent 4be6a5f67e
commit 62901356c5
  1. 7
      app/src/main/java/io/legado/app/data/entities/rule/LogInRule.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  3. 30
      app/src/main/java/io/legado/app/utils/ActivityExtensions.kt
  4. 29
      app/src/main/java/io/legado/app/utils/SystemUtils.kt

@ -0,0 +1,7 @@
package io.legado.app.data.entities.rule
data class LogInRule(
val ui: HashMap<String, String>,
val logInUrl: String,
val checkJs: String
)

@ -84,7 +84,9 @@ class PageView(context: Context) : FrameLayout(context) {
vwTopDivider.visible(it.showHeaderLine)
vwBottomDivider.visible(it.showFooterLine)
pageNvBar.layoutParams = pageNvBar.layoutParams.apply {
height = if (it.hideNavigationBar) 0 else activity?.navigationBarHeight ?: 0
height =
if (it.hideNavigationBar) 0
else activity?.navigationBarHeight ?: 0
}
}
contentTextView.upVisibleRect()

@ -3,6 +3,8 @@ package io.legado.app.utils
import android.app.Activity
import android.os.Build
import android.util.DisplayMetrics
import android.view.View
import android.view.ViewGroup
import android.view.WindowInsets
import android.view.WindowMetrics
@ -22,13 +24,39 @@ val Activity.windowSize: DisplayMetrics
return displayMetrics
}
/**
* 返回NavigationBar是否存在
* 该方法需要在View完全被绘制出来之后调用否则判断不了
* 在比如 onWindowFocusChanged方法中可以得到正确的结果
*/
val Activity.isNavigationBarExist: Boolean
get() {
val viewGroup = window.decorView as? ViewGroup
if (viewGroup != null) {
for (i in 0 until viewGroup.childCount) {
viewGroup.getChildAt(i).context.packageName
if (viewGroup.getChildAt(i).id != View.NO_ID
&& "navigationBarBackground" == resources.getResourceEntryName(
viewGroup.getChildAt(
i
).id
)
) {
return true
}
}
}
return false
}
/**
* 该方法需要在View完全被绘制出来之后调用否则判断不了
* 在比如 onWindowFocusChanged方法中可以得到正确的结果
*/
val Activity.navigationBarHeight: Int
get() {
if (SystemUtils.isNavigationBarExist(this)) {
if (isNavigationBarExist) {
val resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android")
return resources.getDimensionPixelSize(resourceId)
}

@ -8,15 +8,11 @@ import android.content.Intent
import android.net.Uri
import android.os.PowerManager
import android.provider.Settings
import android.view.View
import android.view.ViewGroup
@Suppress("unused")
object SystemUtils {
private const val NAVIGATION = "navigationBarBackground"
fun getScreenOffTime(context: Context): Int {
var screenOffTime = 0
kotlin.runCatching {
@ -49,29 +45,4 @@ object SystemUtils {
}
}
/**
* 返回NavigationBar是否存在
* 该方法需要在View完全被绘制出来之后调用否则判断不了
* 在比如 onWindowFocusChanged方法中可以得到正确的结果
*/
fun isNavigationBarExist(activity: Activity?): Boolean {
activity?.let {
val viewGroup = it.window.decorView as? ViewGroup
if (viewGroup != null) {
for (i in 0 until viewGroup.childCount) {
viewGroup.getChildAt(i).context.packageName
if (viewGroup.getChildAt(i).id != View.NO_ID
&& NAVIGATION == activity.resources.getResourceEntryName(
viewGroup.getChildAt(
i
).id
)
) {
return true
}
}
}
}
return false
}
}

Loading…
Cancel
Save