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

Adds animation to overlay #28

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.andrognito.flashbar

import android.animation.ArgbEvaluator
import android.app.Activity
import android.content.Context
import android.graphics.Rect
Expand All @@ -23,6 +24,9 @@ import com.andrognito.flashbar.util.afterMeasured
import com.andrognito.flashbar.util.getNavigationBarPosition
import com.andrognito.flashbar.util.getNavigationBarSizeInPx
import com.andrognito.flashbar.util.getRootView
import android.animation.ValueAnimator
import android.support.v4.content.ContextCompat


/**
* Container withView matching the height and width of the parent to hold a FlashbarView.
Expand All @@ -32,6 +36,8 @@ import com.andrognito.flashbar.util.getRootView
internal class FlashbarContainerView(context: Context)
: RelativeLayout(context), DismissCallbacks {

private val translucent = ContextCompat.getColor(context, R.color.translucent)

internal lateinit var parentFlashbar: Flashbar

private lateinit var flashbarView: FlashbarView
Expand All @@ -44,6 +50,7 @@ internal class FlashbarContainerView(context: Context)
private var onBarDismissListener: Flashbar.OnBarDismissListener? = null
private var onTapOutsideListener: Flashbar.OnTapListener? = null
private var overlayColor: Int? = null
private var overlayColorAnimator : ValueAnimator? = null
private var iconAnimBuilder: FlashAnimIconBuilder? = null

private var duration = DURATION_INDEFINITE
Expand Down Expand Up @@ -101,7 +108,11 @@ internal class FlashbarContainerView(context: Context)
isHapticFeedbackEnabled = true

if (showOverlay) {
setBackgroundColor(overlayColor!!)
overlayColorAnimator = ValueAnimator.ofObject(ArgbEvaluator(), translucent, overlayColor).also {
// Duration will only ever be used by setting currentPlayTime to a fraction of its value;
// we never start the animator
it.duration = 1000
}

if (overlayBlockable) {
isClickable = true
Expand Down Expand Up @@ -140,6 +151,8 @@ internal class FlashbarContainerView(context: Context)
// Only add the withView to the parent once
if (this.parent == null) activityRootView.addView(this)

overlayColorAnimator?.addUpdateListener { animator -> this.setBackgroundColor(animator.animatedValue as Int) }

activityRootView.afterMeasured {
val enterAnim = enterAnimBuilder.withView(flashbarView).build()
enterAnim.start(object : FlashAnim.InternalAnimListener {
Expand All @@ -150,6 +163,9 @@ internal class FlashbarContainerView(context: Context)

override fun onUpdate(progress: Float) {
onBarShowListener?.onShowProgress(parentFlashbar, progress)
overlayColorAnimator?.duration?.let { duration ->
overlayColorAnimator?.currentPlayTime = (duration * progress).toLong()
}
}

override fun onStop() {
Expand Down Expand Up @@ -250,6 +266,9 @@ internal class FlashbarContainerView(context: Context)

override fun onUpdate(progress: Float) {
onBarDismissListener?.onDismissProgress(parentFlashbar, progress)
overlayColorAnimator?.duration?.let { duration ->
overlayColorAnimator?.currentPlayTime = duration - (duration * progress).toLong()
}
}

override fun onStop() {
Expand All @@ -260,6 +279,8 @@ internal class FlashbarContainerView(context: Context)
performHapticFeedback(VIRTUAL_KEY)
}

overlayColorAnimator?.removeAllUpdateListeners()

onBarDismissListener?.onDismissed(parentFlashbar, event)

post { (parent as? ViewGroup)?.removeView(this@FlashbarContainerView) }
Expand Down
1 change: 1 addition & 0 deletions flashbar/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<color name="warm_grey">#8e8e8e</color>
<color name="white">#fff</color>
<color name="shadow_color">#94444444</color>
<color name="translucent">#0000</color>
<color name="translucent_black">#22000000</color>
<color name="modal">#80272727</color>
<color name="slate_black">#FF333333</color>
Expand Down