Skip to content

Commit

Permalink
Merge pull request #268 from vshkl/fix/267/alert-may-has-extra-bottom…
Browse files Browse the repository at this point in the history
…-padding-when-displayed-with-gravity-bottom

Fix. Extra bottom margin when displayed with Gravity.BOTTOM
  • Loading branch information
kpmmmurphy committed Jul 27, 2021
2 parents d47a334 + ec6c8e3 commit 86ed4ef
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions alerter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -112,4 +112,4 @@ dependencies {
dokka {
outputFormat = 'javadoc'
outputDirectory = "$buildDir/javadoc"
}
}
33 changes: 31 additions & 2 deletions alerter/src/main/java/com/tapadoo/alerter/Alert.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ 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
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
Expand Down Expand Up @@ -118,9 +120,36 @@ class Alert @JvmOverloads constructor(context: Context,

val layoutContainer: View? by lazy { findViewById<View>(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 physicalScreenHeight: Int
get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
DisplayMetrics().also { currentDisplay?.getRealMetrics(it) }.heightPixels
} else {
usableScreenHeight
}

private val usableScreenHeight: Int
get() = Resources.getSystem().displayMetrics.heightPixels

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 {
Expand Down

0 comments on commit 86ed4ef

Please sign in to comment.