From 802789d1daa66571aefaa3e108ec00670b9a5588 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 4 Dec 2016 15:20:48 +0100 Subject: [PATCH] move hasNavBar into an activity extension --- .../com/simplemobiletools/gallery/Utils.kt | 30 ------------------- .../gallery/extensions/activity.kt | 29 ++++++++++++++++++ .../gallery/fragments/VideoFragment.kt | 3 +- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/Utils.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/Utils.kt index 0c3ca09d0..5c1b44e9c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/Utils.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/Utils.kt @@ -1,14 +1,8 @@ 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 class Utils { companion object { @@ -36,29 +30,5 @@ class Utils { } 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 - } - } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt index 5352d2453..2ade2863a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt @@ -3,6 +3,11 @@ package com.simplemobiletools.gallery.extensions import android.app.Activity import android.content.Intent 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.gallery.R import com.simplemobiletools.gallery.REQUEST_SET_WALLPAPER @@ -61,3 +66,27 @@ fun Activity.openWith(file: File) { 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 + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt index 135062bcf..a6eb781a4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -17,6 +17,7 @@ import com.simplemobiletools.gallery.Config import com.simplemobiletools.gallery.MEDIUM import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.Utils +import com.simplemobiletools.gallery.extensions.hasNavBar import com.simplemobiletools.gallery.models.Medium import kotlinx.android.synthetic.main.pager_video_item.view.* 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 bottom = 0 - if (Utils.hasNavBar(activity)) { + if (activity.hasNavBar()) { if (res.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) { bottom += height } else {