diff --git a/CHANGELOG.md b/CHANGELOG.md index 03af90a..f0c0e95 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. +## 6.2.0 - 03/09/2020 +* Added the ability to enable\disable click animation + ## 6.1.0 - 27/06/2020 * Readded getters for title & text TextView diff --git a/alerter/build.gradle b/alerter/build.gradle index 430be2a..621cca8 100644 --- a/alerter/build.gradle +++ b/alerter/build.gradle @@ -14,7 +14,7 @@ apply from: rootProject.file('quality.gradle') final String GROUP_ID = "com.tapadoo.android" -final String VERSION = "6.1.0" +final String VERSION = "6.2.0" final String DESCRIPTION = "An Android Alerting Library" final String GITHUB_URL = "https://github.com/Tapadoo/Alerter" diff --git a/alerter/src/main/java/com/tapadoo/alerter/Alert.kt b/alerter/src/main/java/com/tapadoo/alerter/Alert.kt index 9cbb80d..6830504 100644 --- a/alerter/src/main/java/com/tapadoo/alerter/Alert.kt +++ b/alerter/src/main/java/com/tapadoo/alerter/Alert.kt @@ -25,6 +25,7 @@ import androidx.core.content.ContextCompat import androidx.core.view.ViewCompat import androidx.core.widget.TextViewCompat import com.tapadoo.alerter.utils.getDimenPixelSize +import com.tapadoo.alerter.utils.getRippleDrawable import com.tapadoo.alerter.utils.notchHeight import kotlinx.android.synthetic.main.alerter_alert_default_layout.view.* import kotlinx.android.synthetic.main.alerter_alert_view.view.* @@ -56,6 +57,7 @@ class Alert @JvmOverloads constructor(context: Context, private var enableProgress: Boolean = false private var showRightIcon: Boolean = false + private var enableClickAnimation: Boolean = true private var enableRightIconPurse = true private var runningAnimation: Runnable? = null @@ -133,6 +135,13 @@ class Alert @JvmOverloads constructor(context: Context, super.onAttachedToWindow() llAlertBackground.apply { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + foreground = if (enableClickAnimation.not()) { + null + } else { + context.getRippleDrawable() + } + } (layoutParams as LayoutParams).gravity = layoutGravity @@ -625,6 +634,15 @@ class Alert @JvmOverloads constructor(context: Context, this.showRightIcon = showRightIcon } + /** + * Set whether to show the animation on focus/pressed states + * + * @param enabled True to show the animation, false otherwise + */ + fun enableClickAnimation(enabled: Boolean) { + this.enableClickAnimation = enabled + } + /** * Set right icon position * diff --git a/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt b/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt index 6585f25..6d85787 100644 --- a/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt +++ b/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt @@ -524,6 +524,17 @@ class Alerter private constructor() { return this } + /** + * Set whether to show the animation on focus/pressed states + * + * @param enabled True to show the animation, false otherwise + */ + fun enableClickAnimation(enabled: Boolean): Alerter { + alert?.enableClickAnimation(enabled) + + return this + } + /** * Enable or disable infinite duration of the alert * diff --git a/alerter/src/main/java/com/tapadoo/alerter/utils/ExAlert.kt b/alerter/src/main/java/com/tapadoo/alerter/utils/ExAlert.kt index af8e900..5ffdca6 100644 --- a/alerter/src/main/java/com/tapadoo/alerter/utils/ExAlert.kt +++ b/alerter/src/main/java/com/tapadoo/alerter/utils/ExAlert.kt @@ -1,13 +1,25 @@ package com.tapadoo.alerter.utils import android.app.Activity +import android.content.Context +import android.graphics.drawable.Drawable import android.os.Build +import android.util.TypedValue import androidx.annotation.DimenRes import androidx.annotation.RequiresApi +import androidx.core.content.ContextCompat import com.tapadoo.alerter.Alert +import com.tapadoo.alerter.R fun Alert.getDimenPixelSize(@DimenRes id: Int) = resources.getDimensionPixelSize(id) @RequiresApi(Build.VERSION_CODES.P) fun Alert.notchHeight() = (context as? Activity)?.window?.decorView?.rootWindowInsets?.displayCutout?.safeInsetTop - ?: 0 \ No newline at end of file + ?: 0 + +fun Context.getRippleDrawable(): Drawable? { + val typedValue = TypedValue() + theme.resolveAttribute(R.attr.selectableItemBackground, typedValue, true) + val imageResId = typedValue.resourceId + return ContextCompat.getDrawable(this, imageResId) +} \ No newline at end of file