mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-14 05:01:49 +00:00
Add animation
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 ->
|
||||
|
||||
Reference in New Issue
Block a user