From 4c76a0ec8c26f57513b2e16b298cfd8c706a59ca Mon Sep 17 00:00:00 2001 From: Pavel Vashkel Date: Tue, 27 Jul 2021 12:03:21 +0200 Subject: [PATCH 1/4] Update navigationBarHeight calculation logic to handle different navigation bar states correctly --- .../main/java/com/tapadoo/alerter/Alert.kt | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/alerter/src/main/java/com/tapadoo/alerter/Alert.kt b/alerter/src/main/java/com/tapadoo/alerter/Alert.kt index 0815bf3..ace649b 100644 --- a/alerter/src/main/java/com/tapadoo/alerter/Alert.kt +++ b/alerter/src/main/java/com/tapadoo/alerter/Alert.kt @@ -3,6 +3,7 @@ package com.tapadoo.alerter import android.annotation.SuppressLint import android.annotation.TargetApi import android.content.Context +import android.content.res.Resources import android.graphics.* import android.graphics.drawable.Drawable import android.media.RingtoneManager @@ -10,6 +11,7 @@ import android.net.Uri import android.os.Build import android.text.TextUtils import android.util.AttributeSet +import android.util.DisplayMetrics import android.util.Log import android.view.* import android.view.animation.Animation @@ -118,9 +120,36 @@ class Alert @JvmOverloads constructor(context: Context, val layoutContainer: View? by lazy { findViewById(R.id.vAlertContentContainer) } + private val currentDisplay: Display? by lazy { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + context.display + } else { + @Suppress("DEPRECATION") + (context.applicationContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay + } + } + + private val usableScreenHeight: Int + get() = Resources.getSystem().displayMetrics.heightPixels + + private val physicalScreenHeight: Int + get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + DisplayMetrics().also { currentDisplay?.getRealMetrics(it) }.heightPixels + } else { + usableScreenHeight + } + + private val cutoutsHeight: Int + get() = when { + Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q -> + currentDisplay?.cutout?.run { safeInsetTop + safeInsetBottom } ?: 0 + Build.VERSION.SDK_INT >= Build.VERSION_CODES.P -> + rootWindowInsets?.displayCutout?.run { safeInsetTop + safeInsetBottom } ?: 0 + else -> 0 + } + private val navigationBarHeight by lazy { - val dimenId = resources.getIdentifier("navigation_bar_height", "dimen", "android") - resources.getDimensionPixelSize(dimenId) + physicalScreenHeight - usableScreenHeight - cutoutsHeight } init { From bc6390148d61f05a03e23e138e9b0675136fab59 Mon Sep 17 00:00:00 2001 From: Pavel Vashkel Date: Tue, 27 Jul 2021 12:42:08 +0200 Subject: [PATCH 2/4] Rearrange code --- alerter/src/main/java/com/tapadoo/alerter/Alert.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/alerter/src/main/java/com/tapadoo/alerter/Alert.kt b/alerter/src/main/java/com/tapadoo/alerter/Alert.kt index ace649b..4f27fd5 100644 --- a/alerter/src/main/java/com/tapadoo/alerter/Alert.kt +++ b/alerter/src/main/java/com/tapadoo/alerter/Alert.kt @@ -129,9 +129,6 @@ class Alert @JvmOverloads constructor(context: Context, } } - private val usableScreenHeight: Int - get() = Resources.getSystem().displayMetrics.heightPixels - private val physicalScreenHeight: Int get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { DisplayMetrics().also { currentDisplay?.getRealMetrics(it) }.heightPixels @@ -139,6 +136,9 @@ class Alert @JvmOverloads constructor(context: Context, usableScreenHeight } + private val usableScreenHeight: Int + get() = Resources.getSystem().displayMetrics.heightPixels + private val cutoutsHeight: Int get() = when { Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q -> From e86dafd3f2b5cf3ae234233f3659ae5e6ec9bc49 Mon Sep 17 00:00:00 2001 From: Pavel Vashkel Date: Tue, 27 Jul 2021 13:05:21 +0200 Subject: [PATCH 3/4] Upgrade library version to 7.2.1 --- alerter/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alerter/build.gradle b/alerter/build.gradle index fc374fb..4523834 100644 --- a/alerter/build.gradle +++ b/alerter/build.gradle @@ -9,7 +9,7 @@ apply from: rootProject.file('quality.gradle') final String GROUP_ID = "com.tapadoo.android" -final String VERSION = "7.2.0" +final String VERSION = "7.2.1" final String DESCRIPTION = "An Android Alerting Library" final String GITHUB_URL = "https://github.com/Tapadoo/Alerter" @@ -112,4 +112,4 @@ dependencies { dokka { outputFormat = 'javadoc' outputDirectory = "$buildDir/javadoc" -} \ No newline at end of file +} From ec6c8e32a2193beb42414f9ed9f219ad3f7c29e3 Mon Sep 17 00:00:00 2001 From: Pavel Vashkel Date: Tue, 27 Jul 2021 13:05:58 +0200 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54812ae..b546e40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Change Log All notable changes to this project will be documented in this file. +## 7.2.1 - 27/07/2021 +* Fixed alert may has extra bottom margin when displayed with Gravity.BOTTOM + ## 7.2.0 - 14/05/2021 * OnHideAlertListener added to hide() and clearCurrent() methods. @@ -80,7 +83,7 @@ All notable changes to this project will be documented in this file. * Updated build tools & support libs * Added methods to set icon tint -## 2.0.2 - 11/12/2017 +## 2.0.2 - 11/12/2017 * Added fixed for the Alert drawing under the status bar ## 2.0.1 - 18/09/2017 @@ -98,7 +101,7 @@ All notable changes to this project will be documented in this file. * Added setAlertBackgroundColor to allow the use of color ints ## 1.0.8 - 09/05/2017 -* Added disable vibration option +* Added disable vibration option * Updated Alert dismiss method * Added method to hide icon * Added method to disable outside touch