move hasNavBar into an activity extension

This commit is contained in:
tibbi 2016-12-04 15:20:48 +01:00
parent 9ff47e6b6f
commit 802789d1da
3 changed files with 31 additions and 31 deletions

View file

@ -1,14 +1,8 @@
package com.simplemobiletools.gallery package com.simplemobiletools.gallery
import android.app.Activity
import android.content.Context import android.content.Context
import android.content.res.Resources import android.content.res.Resources
import android.os.Build
import android.util.DisplayMetrics
import android.util.TypedValue import android.util.TypedValue
import android.view.KeyCharacterMap
import android.view.KeyEvent
import android.view.ViewConfiguration
class Utils { class Utils {
companion object { companion object {
@ -36,29 +30,5 @@ class Utils {
} else } else
0 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
}
}
} }
} }

View file

@ -3,6 +3,11 @@ package com.simplemobiletools.gallery.extensions
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Build
import android.util.DisplayMetrics
import android.view.KeyCharacterMap
import android.view.KeyEvent
import android.view.ViewConfiguration
import com.simplemobiletools.filepicker.extensions.toast import com.simplemobiletools.filepicker.extensions.toast
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.REQUEST_SET_WALLPAPER import com.simplemobiletools.gallery.REQUEST_SET_WALLPAPER
@ -61,3 +66,27 @@ fun Activity.openWith(file: File) {
toast(R.string.no_app_found) toast(R.string.no_app_found)
} }
} }
fun Activity.hasNavBar(): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
val display = 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(this).hasPermanentMenuKey()
val hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK)
!hasMenuKey && !hasBackKey
}
}

View file

@ -17,6 +17,7 @@ import com.simplemobiletools.gallery.Config
import com.simplemobiletools.gallery.MEDIUM import com.simplemobiletools.gallery.MEDIUM
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.Utils import com.simplemobiletools.gallery.Utils
import com.simplemobiletools.gallery.extensions.hasNavBar
import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.Medium
import kotlinx.android.synthetic.main.pager_video_item.view.* import kotlinx.android.synthetic.main.pager_video_item.view.*
import java.io.IOException import java.io.IOException
@ -112,7 +113,7 @@ class VideoFragment : ViewPagerFragment(), View.OnClickListener, SurfaceHolder.C
var right = res.getDimension(R.dimen.timer_padding).toInt() var right = res.getDimension(R.dimen.timer_padding).toInt()
var bottom = 0 var bottom = 0
if (Utils.hasNavBar(activity)) { if (activity.hasNavBar()) {
if (res.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) { if (res.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
bottom += height bottom += height
} else { } else {