From bdc5a0e5d902bfeabd58092f8e30635fdff0ded3 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Wed, 16 Jun 2021 15:49:39 +1000 Subject: [PATCH] Add animation --- .../conversation/v2/ConversationActivityV2.kt | 5 +- .../v2/input_bar/InputBarRecordingView.kt | 34 ++++ .../securesms/loki/utilities/ViewUtilities.kt | 6 +- .../res/layout/view_input_bar_recording.xml | 148 +++++++++++------- 4 files changed, 132 insertions(+), 61 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt index 13cad79ae6..d7e845d858 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt @@ -1,5 +1,7 @@ package org.thoughtcrime.securesms.conversation.v2 +import android.animation.FloatEvaluator +import android.animation.ValueAnimator import android.database.Cursor import android.os.Bundle import android.view.ActionMode @@ -20,6 +22,7 @@ import org.thoughtcrime.securesms.conversation.v2.menus.ConversationActionModeCa import org.thoughtcrime.securesms.conversation.v2.menus.ConversationMenuHelper import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.database.model.MessageRecord +import org.thoughtcrime.securesms.loki.views.NewConversationButtonSetView import org.thoughtcrime.securesms.mms.GlideApp class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDelegate { @@ -115,7 +118,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe } override fun showVoiceMessageUI() { - inputBarRecordingView.isVisible = true + inputBarRecordingView.show() } // endregion diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBarRecordingView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBarRecordingView.kt index ffcb403ab7..b1da2ec48a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBarRecordingView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBarRecordingView.kt @@ -1,10 +1,19 @@ package org.thoughtcrime.securesms.conversation.v2.input_bar +import android.animation.Animator +import android.animation.FloatEvaluator +import android.animation.ValueAnimator import android.content.Context import android.util.AttributeSet +import android.util.Log import android.view.LayoutInflater import android.widget.RelativeLayout +import androidx.core.view.isVisible +import kotlinx.android.synthetic.main.view_input_bar_recording.view.* import network.loki.messenger.R +import org.thoughtcrime.securesms.loki.utilities.animateSizeChange +import org.thoughtcrime.securesms.loki.utilities.toPx +import kotlin.math.roundToInt class InputBarRecordingView : RelativeLayout { @@ -15,4 +24,29 @@ class InputBarRecordingView : RelativeLayout { private fun initialize() { LayoutInflater.from(context).inflate(R.layout.view_input_bar_recording, this) } + + fun show() { + isVisible = true + alpha = 0.0f + val animation = ValueAnimator.ofObject(FloatEvaluator(), 0.0f, 1.0f) + animation.duration = 250L + animation.addUpdateListener { animator -> + alpha = animator.animatedValue as Float + } + animation.start() + pulse() + } + + private fun pulse() { + val collapsedSize = toPx(80.0f, resources) + val expandedSize = toPx(104.0f, resources) + pulseView.animateSizeChange(collapsedSize, expandedSize, 1000) + val animation = ValueAnimator.ofObject(FloatEvaluator(), 0.5, 0.0f) + animation.duration = 1000L + animation.addUpdateListener { animator -> + pulseView.alpha = animator.animatedValue as Float + if (animator.animatedFraction == 1.0f) { pulse() } + } + animation.start() + } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/ViewUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/ViewUtilities.kt index c9d135ba24..67a137bc48 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/ViewUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/ViewUtilities.kt @@ -21,9 +21,13 @@ val View.hitRect: Rect } fun View.animateSizeChange(@DimenRes startSizeID: Int, @DimenRes endSizeID: Int, animationDuration: Long = 250) { - val layoutParams = this.layoutParams val startSize = resources.getDimension(startSizeID) val endSize = resources.getDimension(endSizeID) + animateSizeChange(startSize, endSize) +} + +fun View.animateSizeChange(startSize: Float, endSize: Float, animationDuration: Long = 250) { + val layoutParams = this.layoutParams val animation = ValueAnimator.ofObject(FloatEvaluator(), startSize, endSize) animation.duration = animationDuration animation.addUpdateListener { animator -> diff --git a/app/src/main/res/layout/view_input_bar_recording.xml b/app/src/main/res/layout/view_input_bar_recording.xml index f0e10cf7c2..1ea62d3371 100644 --- a/app/src/main/res/layout/view_input_bar_recording.xml +++ b/app/src/main/res/layout/view_input_bar_recording.xml @@ -3,93 +3,123 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" - android:layout_height="80dp"> + android:layout_height="92dp"> - + - - - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - +