From c547cb38905ea896311362bf70c28fa563455add Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 2 Oct 2018 16:13:54 +0200 Subject: [PATCH] moving some activity extensions to context --- .../gallery/activities/ViewPagerActivity.kt | 2 +- .../gallery/extensions/Activity.kt | 16 ---------------- .../gallery/extensions/Context.kt | 19 +++++++++++++++++++ 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 582cc0789..f35a6012f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -83,7 +83,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View super.onCreate(savedInstanceState) setContentView(R.layout.activity_medium) - top_shadow.layoutParams.height = getStatusBarHeight() + getActionBarHeight() + top_shadow.layoutParams.height = statusBarHeight + actionBarHeight if (isOreoPlus()) { window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) 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 639cefbf1..380aaa184 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt @@ -278,19 +278,3 @@ fun BaseSimpleActivity.showRecycleBinEmptyingDialog(callback: () -> Unit) { callback() } } - -fun BaseSimpleActivity.getStatusBarHeight(): Int { - var statusBarHeight = 0 - val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android") - if (resourceId > 0) { - statusBarHeight = resources.getDimensionPixelSize(resourceId) - } - return statusBarHeight -} - -fun BaseSimpleActivity.getActionBarHeight(): Int { - val styledAttributes = theme.obtainStyledAttributes(intArrayOf(android.R.attr.actionBarSize)) - val actionBarHeight = styledAttributes.getDimension(0, 0f) - styledAttributes.recycle() - return actionBarHeight.toInt() -} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt index eb41408b1..e1a0ab954 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -49,6 +49,25 @@ internal val Context.navigationBarSize: Point else -> Point() } +internal val Context.statusBarHeight: Int + get() { + var statusBarHeight = 0 + val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android") + if (resourceId > 0) { + statusBarHeight = resources.getDimensionPixelSize(resourceId) + } + return statusBarHeight + } + +internal val Context.actionBarHeight: Int + get() { + val styledAttributes = theme.obtainStyledAttributes(intArrayOf(android.R.attr.actionBarSize)) + val actionBarHeight = styledAttributes.getDimension(0, 0f) + styledAttributes.recycle() + return actionBarHeight.toInt() + } + + val Context.usableScreenSize: Point get() { val size = Point()