Fix navbar detection

This commit is contained in:
kubasz 2019-08-24 20:36:17 +02:00
parent 2032d7510e
commit ab5bb48e61
2 changed files with 44 additions and 8 deletions

View File

@ -7,13 +7,16 @@ import android.graphics.Color
import android.os.Build.VERSION.SDK_INT import android.os.Build.VERSION.SDK_INT
import android.os.Build.VERSION_CODES.* import android.os.Build.VERSION_CODES.*
import android.util.Log import android.util.Log
import android.view.* import android.view.View
import android.view.View.* import android.view.View.*
import android.view.Window
import android.view.WindowManager
import androidx.core.graphics.ColorUtils import androidx.core.graphics.ColorUtils
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import com.mikepenz.materialize.util.KeyboardUtil import com.mikepenz.materialize.util.KeyboardUtil
class SystemBarsUtil(val activity: Activity) {
class SystemBarsUtil(private val activity: Activity) {
companion object { companion object {
private const val COLOR_TRANSPARENT = Color.TRANSPARENT private const val COLOR_TRANSPARENT = Color.TRANSPARENT
/** /**
@ -310,9 +313,7 @@ class SystemBarsUtil(val activity: Activity) {
var navigationBarSize = 0 var navigationBarSize = 0
val hasMenuKey = ViewConfiguration.get(activity).hasPermanentMenuKey() if (hasNavigationBar(resources) && targetAppFullscreen) {
val hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK)
if (!hasMenuKey && !hasBackKey && targetAppFullscreen) {
val orientation = resources.configuration.orientation val orientation = resources.configuration.orientation
val navigationBarRes = when { val navigationBarRes = when {

View File

@ -3,13 +3,17 @@ package pl.szczodrzynski.navlib
import android.app.Activity import android.app.Activity
import android.content.Context import android.content.Context
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Color import android.content.res.Resources
import android.graphics.drawable.Drawable
import android.os.Build import android.os.Build
import android.util.TypedValue import android.util.TypedValue
import android.view.View import android.view.View
import androidx.annotation.AttrRes import androidx.annotation.AttrRes
import androidx.annotation.ColorInt import androidx.annotation.DrawableRes
import androidx.core.graphics.ColorUtils import com.google.android.material.elevation.ElevationOverlayProvider
import com.mikepenz.iconics.IconicsColor
import com.mikepenz.iconics.IconicsDrawable
/*private val displayMetrics by lazy { /*private val displayMetrics by lazy {
context.resources.displayMetrics context.resources.displayMetrics
@ -76,6 +80,37 @@ fun blendColors(background: Int, foreground: Int): Int {
return (0xff000000 or (red.toLong() shl 16) or (green.toLong() shl 8) or (blue.toLong())).toInt() return (0xff000000 or (red.toLong() shl 16) or (green.toLong() shl 8) or (blue.toLong())).toInt()
} }
fun elevateSurface(context: Context, dp: Int): Int {
ElevationOverlayProvider(context).apply {
return compositeOverlay(themeSurfaceColor, dp * context.resources.displayMetrics.density)
}
}
fun isTablet(c: Context): Boolean { fun isTablet(c: Context): Boolean {
return (c.resources.configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE return (c.resources.configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE
}
fun hasNavigationBar(resources: Resources): Boolean {
val id = resources.getIdentifier("config_showNavigationBar", "bool", "android")
var hasNavigationBar = id > 0 && resources.getBoolean(id)
// Allow a system property to override this. Used by the emulator.
// See also hasNavigationBar().
val navBarOverride = System.getProperty("qemu.hw.mainkeys")
if (navBarOverride == "1")
hasNavigationBar = true
else if (navBarOverride == "0") hasNavigationBar = false
return hasNavigationBar
}
fun IconicsDrawable.colorAttr(context: Context, @AttrRes attrRes: Int) = color(IconicsColor.colorInt(getColorFromAttr(context, attrRes)))
fun Context.getDrawableFromRes(@DrawableRes id: Int): Drawable {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
resources.getDrawable(id, theme)
}
else {
resources.getDrawable(id)
}
} }