Improve keyboard animation

hh
Laurent 6 years ago
parent d4dd65a09d
commit 61e77a55c6
  1. 73
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  2. 3
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt
  3. 36
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/KeyboardContainer.kt
  4. 19
      app/src/main/res/layout/fragment_hand_history.xml
  5. 2
      app/src/main/res/layout/view_hand_keyboard_action.xml
  6. 2
      app/src/main/res/layout/view_hand_keyboard_amount.xml
  7. 2
      app/src/main/res/layout/view_hand_keyboard_card.xml

@ -1,7 +1,10 @@
package net.pokeranalytics.android.ui.modules.handhistory
import android.animation.ValueAnimator
import android.os.Bundle
import android.view.*
import android.view.animation.AccelerateDecelerateInterpolator
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import kotlinx.android.synthetic.main.fragment_hand_history.*
@ -14,6 +17,7 @@ import net.pokeranalytics.android.model.realm.handhistory.Action
import net.pokeranalytics.android.model.realm.handhistory.Card
import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.extensions.px
import net.pokeranalytics.android.ui.fragment.components.RealmFragment
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
@ -125,13 +129,15 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
}
keyboard?.let {
this.keyboard.show(it)
// this.animateKeyboard(true)
this.showKeyboard(it)
// this.keyboard.show(it)
} ?: run {
this.keyboard.hide()
this.animateKeyboard(false)
}
} ?: run {
this.keyboard.hide()
this.animateKeyboard(false)
}
}
@ -152,6 +158,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
}
}
initKeyboard()
this.keyboard.keyboardListener = this
this.keyboard.setCardCentralizer(this.model)
}
@ -206,30 +213,15 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.findNextActionToEdit(0)
}
private fun closeEdition() {
this.model.isEdited = false
}
private fun findNextActionToEdit(index: Int? = null, userInitiated: Boolean = false) {
val startIndex = index ?: this.model.currentSelection.index
val minTag = if (index != null) null else this.model.currentSelection.tag
this.model.findSelectionForEdition(startIndex, minTag, userInitiated)?.let { selection ->
this.scrollToPosition(selection.index)
// this.model.currentKeyboard?.let { keyboard ->
// when (keyboard) {
// HHKeyboard.ACTION -> {
// configureActionKeyboard()
// } else -> {}
// }
// this.keyboard.show(keyboard)
// }
} ?: run {
this.keyboard.hide()
this.animateKeyboard(false)
}
// The whole data set is refreshed because of a weird EditText bug where
@ -249,7 +241,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
return
}
when (row.bottomSheetType) {
when (row.bottomSheetType) { // Comment, number of players
BottomSheetType.NONE -> {}
else -> {
val editDescriptors = listOf(RowRepresentableEditDescriptor(this.model.handHistory.comment, R.string.comment))
@ -404,7 +396,8 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
val currentIndex = this.model.currentSelection.index
this.model.selectionLiveData.value = null
this.handHistoryAdapter.notifyItemChanged(currentIndex)
this.keyboard?.hide()
this.animateKeyboard(false)
// this.hideKeyboard()
}
override fun positionSelected(position: Position) {
@ -443,4 +436,42 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
}
}
private fun showKeyboard(keyboard: HHKeyboard) {
val lp = this.kbTopGuideline.layoutParams as ConstraintLayout.LayoutParams
if (lp.guideEnd == 0) {
this.animateKeyboard(true)
}
this.keyboard.show(keyboard)
}
private fun animateKeyboard(show: Boolean) {
val height = 300.0f.px
val start = if (show) 0.0f else height
val end = if (show) height else 0.0f
// val end = (this.kbTopGuideline.layoutParams as ConstraintLayout.LayoutParams).guideEnd
val valueAnimator = ValueAnimator.ofFloat(start, end)
valueAnimator.duration = 150L
// set duration
valueAnimator.interpolator = AccelerateDecelerateInterpolator()
// set interpolator and updateListener to get the animated value
valueAnimator.addUpdateListener {
val lp = this.kbTopGuideline.layoutParams as ConstraintLayout.LayoutParams
// get the float value
lp.guideEnd = (it.animatedValue as Float).toInt()
// update layout params
this.kbTopGuideline.layoutParams = lp
}
valueAnimator.start()
}
private fun initKeyboard() {
val lp = this.kbTopGuideline.layoutParams as ConstraintLayout.LayoutParams
lp.guideEnd = 0
}
}

@ -56,6 +56,9 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
set(value) {
field = value
createRowRepresentation()
if (!value) {
this.selectionLiveData.value = null
}
}
/***

@ -5,7 +5,6 @@ import android.util.AttributeSet
import android.view.View
import android.widget.EditText
import android.widget.FrameLayout
import androidx.core.view.isVisible
import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.handhistory.Position
@ -31,7 +30,13 @@ interface PositionSelectionListener {
fun positionSelected(position: Position)
}
class KeyboardContainer(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) {
class KeyboardContainer : FrameLayout {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
private val keyboards = HashMap<HHKeyboard, AbstractKeyboardView>()
@ -67,24 +72,10 @@ class KeyboardContainer(context: Context, attrs: AttributeSet?) : FrameLayout(co
}
}
private fun show() {
if (!this.isVisible) {
val height = this.height.toFloat()
this.translationY = height
this.visibility = View.VISIBLE
this.animate().translationY(0.0f).setDuration(250).start()
}
}
fun hide() {
// animate
this.visibility = View.GONE
}
fun show(type: HHKeyboard) {
// Timber.d("show keyboard : $type")
show()
// showAnimated()
this.keyboards[type]?.let {
show(it)
@ -119,15 +110,4 @@ class KeyboardContainer(context: Context, attrs: AttributeSet?) : FrameLayout(co
cardKeyboard.setCardCentralizer(centralizer)
}
// private fun loadView(layoutId: Int) {
// val layoutInflater = LayoutInflater.from(context)
// constraintLayout = layoutInflater.inflate(layoutId, this, false) as ConstraintLayout
// val layoutParams = LayoutParams(
// LayoutParams.MATCH_PARENT,
// LayoutParams.MATCH_PARENT
// )
// addView(constraintLayout, layoutParams)
//
// }
}

@ -29,18 +29,27 @@
android:id="@+id/recyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/keyboard"
app:layout_constraintBottom_toTopOf="@id/kbTopGuideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/appBar" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/kbTopGuideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_end="300dp" />
<net.pokeranalytics.android.ui.modules.handhistory.views.KeyboardContainer
android:id="@+id/keyboard"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
android:layout_height="0dp"
android:visibility="visible"
app:layout_constraintTop_toBottomOf="@id/kbTopGuideline"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -2,7 +2,7 @@
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout

Loading…
Cancel
Save