mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-24 21:47:59 +01:00
73 lines
2.5 KiB
Kotlin
73 lines
2.5 KiB
Kotlin
package com.simplemobiletools.gallery
|
|
|
|
import android.app.Activity
|
|
import android.content.Context
|
|
import android.content.res.Resources
|
|
import android.os.Build
|
|
import android.util.DisplayMetrics
|
|
import android.util.TypedValue
|
|
import android.view.KeyCharacterMap
|
|
import android.view.KeyEvent
|
|
import android.view.ViewConfiguration
|
|
import android.webkit.MimeTypeMap
|
|
|
|
class Utils {
|
|
companion object {
|
|
fun getActionBarHeight(context: Context, res: Resources): Int {
|
|
val tv = TypedValue()
|
|
var height = 0
|
|
if (context.theme.resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
|
|
height = TypedValue.complexToDimensionPixelSize(tv.data, res.displayMetrics)
|
|
}
|
|
return height
|
|
}
|
|
|
|
fun getStatusBarHeight(res: Resources): Int {
|
|
val id = res.getIdentifier("status_bar_height", "dimen", "android")
|
|
return if (id > 0) {
|
|
res.getDimensionPixelSize(id)
|
|
} else
|
|
0
|
|
}
|
|
|
|
fun getNavBarHeight(res: Resources): Int {
|
|
val id = res.getIdentifier("navigation_bar_height", "dimen", "android")
|
|
return if (id > 0) {
|
|
res.getDimensionPixelSize(id)
|
|
} else
|
|
0
|
|
}
|
|
|
|
fun hasNavBar(act: Activity): Boolean {
|
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
|
val display = act.windowManager.defaultDisplay
|
|
|
|
val realDisplayMetrics = DisplayMetrics()
|
|
display.getRealMetrics(realDisplayMetrics)
|
|
|
|
val realHeight = realDisplayMetrics.heightPixels
|
|
val realWidth = realDisplayMetrics.widthPixels
|
|
|
|
val displayMetrics = DisplayMetrics()
|
|
display.getMetrics(displayMetrics)
|
|
|
|
val displayHeight = displayMetrics.heightPixels
|
|
val displayWidth = displayMetrics.widthPixels
|
|
|
|
realWidth - displayWidth > 0 || realHeight - displayHeight > 0
|
|
} else {
|
|
val hasMenuKey = ViewConfiguration.get(act).hasPermanentMenuKey()
|
|
val hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK)
|
|
!hasMenuKey && !hasBackKey
|
|
}
|
|
}
|
|
|
|
fun getMimeType(url: String): String? {
|
|
val extension = MimeTypeMap.getFileExtensionFromUrl(url)
|
|
return if (extension != null) {
|
|
MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)
|
|
} else
|
|
""
|
|
}
|
|
}
|
|
}
|