mirror of
https://github.com/kuba2k2/NavLib.git
synced 2025-01-18 06:16:43 -06:00
Fix navbar detection
This commit is contained in:
parent
2032d7510e
commit
ab5bb48e61
@ -7,13 +7,16 @@ import android.graphics.Color
|
||||
import android.os.Build.VERSION.SDK_INT
|
||||
import android.os.Build.VERSION_CODES.*
|
||||
import android.util.Log
|
||||
import android.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.view.ViewCompat
|
||||
import com.mikepenz.materialize.util.KeyboardUtil
|
||||
|
||||
class SystemBarsUtil(val activity: Activity) {
|
||||
|
||||
class SystemBarsUtil(private val activity: Activity) {
|
||||
companion object {
|
||||
private const val COLOR_TRANSPARENT = Color.TRANSPARENT
|
||||
/**
|
||||
@ -310,9 +313,7 @@ class SystemBarsUtil(val activity: Activity) {
|
||||
|
||||
|
||||
var navigationBarSize = 0
|
||||
val hasMenuKey = ViewConfiguration.get(activity).hasPermanentMenuKey()
|
||||
val hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK)
|
||||
if (!hasMenuKey && !hasBackKey && targetAppFullscreen) {
|
||||
if (hasNavigationBar(resources) && targetAppFullscreen) {
|
||||
val orientation = resources.configuration.orientation
|
||||
|
||||
val navigationBarRes = when {
|
||||
|
@ -3,13 +3,17 @@ package pl.szczodrzynski.navlib
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
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.util.TypedValue
|
||||
import android.view.View
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.annotation.DrawableRes
|
||||
import com.google.android.material.elevation.ElevationOverlayProvider
|
||||
import com.mikepenz.iconics.IconicsColor
|
||||
import com.mikepenz.iconics.IconicsDrawable
|
||||
|
||||
|
||||
/*private val displayMetrics by lazy {
|
||||
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()
|
||||
}
|
||||
|
||||
fun elevateSurface(context: Context, dp: Int): Int {
|
||||
ElevationOverlayProvider(context).apply {
|
||||
return compositeOverlay(themeSurfaceColor, dp * context.resources.displayMetrics.density)
|
||||
}
|
||||
}
|
||||
|
||||
fun isTablet(c: Context): Boolean {
|
||||
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)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user