More animation

This commit is contained in:
Niels Andriesse 2021-06-17 16:29:57 +10:00
parent b5376cd60e
commit f4621a4fee
4 changed files with 37 additions and 11 deletions

View File

@ -42,6 +42,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
private var threadID: Long = -1
private var actionMode: ActionMode? = null
private var isLockViewExpanded = false
private var isShowingAttachmentOptions = false
// TODO: Selected message background color
// TODO: Overflow menu background + text color
@ -155,6 +156,22 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
conversationRecyclerView.layoutParams = recyclerViewLayoutParams
}
override fun toggleAttachmentOptions() {
val targetAlpha = if (isShowingAttachmentOptions) 0.0f else 1.0f
val allButtons = listOf( cameraButtonContainer, libraryButtonContainer, documentButtonContainer, gifButtonContainer)
allButtons.indices.forEach { index ->
val view = allButtons[index]
val animation = ValueAnimator.ofObject(FloatEvaluator(), view.alpha, targetAlpha)
animation.duration = 250L
animation.startDelay = 50L * index.toLong()
animation.addUpdateListener { animator ->
view.alpha = animator.animatedValue as Float
}
animation.start()
}
isShowingAttachmentOptions = !isShowingAttachmentOptions
}
override fun showVoiceMessageUI() {
inputBarRecordingView.show()
inputBar.alpha = 0.0f
@ -167,7 +184,6 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
}
override fun handleInputBarRecordingViewHidden() {
Log.d("Test", "Here")
inputBar.alpha = 1.0f
val animation = ValueAnimator.ofObject(FloatEvaluator(), 0.0f, 1.0f)
animation.duration = 250L

View File

@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.conversation.v2.input_bar
import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.view.LayoutInflater
import android.view.MotionEvent
import android.widget.RelativeLayout
@ -29,12 +30,11 @@ class InputBar : RelativeLayout, InputBarEditTextDelegate {
// Attachments button
attachmentsButtonContainer.addView(attachmentsButton)
attachmentsButton.layoutParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)
attachmentsButton.onPress = { toggleAttachmentOptions() }
// Microphone button
microphoneOrSendButtonContainer.addView(microphoneButton)
microphoneButton.layoutParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)
microphoneButton.onLongPress = {
showVoiceMessageUI()
}
microphoneButton.onLongPress = { showVoiceMessageUI() }
microphoneButton.onMove = { delegate?.onMicrophoneButtonMove(it) }
microphoneButton.onCancel = { delegate?.onMicrophoneButtonCancel(it) }
microphoneButton.onUp = { delegate?.onMicrophoneButtonUp(it) }
@ -63,6 +63,10 @@ class InputBar : RelativeLayout, InputBarEditTextDelegate {
delegate?.inputBarHeightChanged(newHeight)
}
private fun toggleAttachmentOptions() {
delegate?.toggleAttachmentOptions()
}
private fun showVoiceMessageUI() {
delegate?.showVoiceMessageUI()
}
@ -72,6 +76,7 @@ class InputBar : RelativeLayout, InputBarEditTextDelegate {
interface InputBarDelegate {
fun inputBarHeightChanged(newValue: Int)
fun toggleAttachmentOptions()
fun showVoiceMessageUI()
fun onMicrophoneButtonMove(event: MotionEvent)
fun onMicrophoneButtonCancel(event: MotionEvent)

View File

@ -40,7 +40,8 @@ class InputBarButton : RelativeLayout {
var onLongPress: (() -> Unit)? = null
companion object {
val animationDuration = 250.toLong()
const val animationDuration = 250.toLong()
const val longPressDurationThreshold = 250L // ms
}
private val expandedImageViewPosition by lazy { PointF(0.0f, 0.0f) }
@ -148,7 +149,7 @@ class InputBarButton : RelativeLayout {
longPressCallback?.let { gestureHandler.removeCallbacks(it) }
val newLongPressCallback = Runnable { onLongPress?.invoke() }
this.longPressCallback = newLongPressCallback
gestureHandler.postDelayed(newLongPressCallback, VisibleMessageView.longPressDurationThreshold)
gestureHandler.postDelayed(newLongPressCallback, InputBarButton.longPressDurationThreshold)
onDownTimestamp = Date().time
}
@ -165,7 +166,7 @@ class InputBarButton : RelativeLayout {
private fun onUp(event: MotionEvent) {
onUp?.invoke(event)
collapse()
if ((Date().time - onDownTimestamp) < VisibleMessageView.longPressDurationThreshold) {
if ((Date().time - onDownTimestamp) < InputBarButton.longPressDurationThreshold) {
longPressCallback?.let { gestureHandler.removeCallbacks(it) }
onPress?.invoke()
}

View File

@ -24,25 +24,29 @@
<RelativeLayout
android:id="@+id/gifButtonContainer"
android:layout_width="@dimen/input_bar_button_expanded_size"
android:layout_height="@dimen/input_bar_button_expanded_size" />
android:layout_height="@dimen/input_bar_button_expanded_size"
android:alpha="0" />
<RelativeLayout
android:id="@+id/documentButtonContainer"
android:layout_marginTop="8dp"
android:layout_width="@dimen/input_bar_button_expanded_size"
android:layout_height="@dimen/input_bar_button_expanded_size" />
android:layout_height="@dimen/input_bar_button_expanded_size"
android:alpha="0" />
<RelativeLayout
android:id="@+id/libraryButtonContainer"
android:layout_marginTop="8dp"
android:layout_width="@dimen/input_bar_button_expanded_size"
android:layout_height="@dimen/input_bar_button_expanded_size" />
android:layout_height="@dimen/input_bar_button_expanded_size"
android:alpha="0" />
<RelativeLayout
android:id="@+id/cameraButtonContainer"
android:layout_marginTop="8dp"
android:layout_width="@dimen/input_bar_button_expanded_size"
android:layout_height="@dimen/input_bar_button_expanded_size" />
android:layout_height="@dimen/input_bar_button_expanded_size"
android:alpha="0" />
</LinearLayout>