From 658977953bcf9970c393a6824e5f3f59ac950e96 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 21 Mar 2017 21:53:46 +0100 Subject: [PATCH] change the way we calculate the navigation bar height --- .../camera/activities/MainActivity.kt | 6 ++---- .../camera/extensions/context.kt | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt index f5401a4a..4138e759 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt @@ -22,6 +22,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy import com.simplemobiletools.camera.* import com.simplemobiletools.camera.Preview.PreviewListener import com.simplemobiletools.camera.extensions.config +import com.simplemobiletools.camera.extensions.navBarHeight import com.simplemobiletools.camera.views.FocusRectView import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.models.Release @@ -124,10 +125,7 @@ class MainActivity : SimpleActivity(), SensorEventListener, PreviewListener, Pho setContentView(R.layout.activity_main) initButtons() - if (mRes.hasNavBar() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - val lp = btn_holder.layoutParams as RelativeLayout.LayoutParams - lp.setMargins(0, 0, 0, lp.bottomMargin + mRes.getNavBarHeight()) - } + (btn_holder.layoutParams as RelativeLayout.LayoutParams).setMargins(0, 0, 0, navBarHeight) mCurrCameraId = config.lastUsedCamera mPreview = Preview(this, camera_view, this) diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/extensions/context.kt b/app/src/main/kotlin/com/simplemobiletools/camera/extensions/context.kt index 7c976391..4fa3626e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/extensions/context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/extensions/context.kt @@ -1,6 +1,8 @@ package com.simplemobiletools.camera.extensions import android.content.Context +import android.graphics.Point +import android.view.WindowManager import com.simplemobiletools.camera.Config import java.io.File import java.text.SimpleDateFormat @@ -8,6 +10,8 @@ import java.util.* val Context.config: Config get() = Config.newInstance(this) +internal val Context.windowManager: WindowManager get() = getSystemService(Context.WINDOW_SERVICE) as WindowManager + fun Context.getOutputMediaFile(isPhoto: Boolean): String { val mediaStorageDir = File(config.savePhotosFolder) @@ -24,3 +28,17 @@ fun Context.getOutputMediaFile(isPhoto: Boolean): String { "${mediaStorageDir.path}${File.separator}VID_$timestamp.mp4" } } + +val Context.usableScreenSize: Point get() { + val size = Point() + windowManager.defaultDisplay.getSize(size) + return size +} + +val Context.realScreenSize: Point get() { + val size = Point() + windowManager.defaultDisplay.getRealSize(size) + return size +} + +val Context.navBarHeight: Int get() = realScreenSize.y - usableScreenSize.y