Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable\disable alert click animation #235

Merged
merged 3 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 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.

## 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

Expand Down
2 changes: 1 addition & 1 deletion alerter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 18 additions & 0 deletions alerter/src/main/java/com/tapadoo/alerter/Alert.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
*
Expand Down
11 changes: 11 additions & 0 deletions alerter/src/main/java/com/tapadoo/alerter/Alerter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
14 changes: 13 additions & 1 deletion alerter/src/main/java/com/tapadoo/alerter/utils/ExAlert.kt
Original file line number Diff line number Diff line change
@@ -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
?: 0

fun Context.getRippleDrawable(): Drawable? {
val typedValue = TypedValue()
theme.resolveAttribute(R.attr.selectableItemBackground, typedValue, true)
val imageResId = typedValue.resourceId
return ContextCompat.getDrawable(this, imageResId)
}