Add spring animation for newly created desktop
spring into place from 40 dp offscreen:
expressive default spatial spring
damping: 0.8,
stiffness: 380
Bug: 399642211
Flag: com.android.window.flags.enable_multiple_desktops_frontend
Flag: com.android.window.flags.enable_multiple_desktops_backend
Test: create desktop and check animation
Change-Id: Ie15b4f58d394590ea24d72036a587111f1e6cf3b
This commit is contained in:
@@ -5045,7 +5045,8 @@ public abstract class RecentsView<
|
||||
*
|
||||
* @param offsetProgress From 0 to 1 where 0 means no offset and 1 means offset offscreen.
|
||||
*/
|
||||
private float getHorizontalOffsetSize(int childIndex, int midpointIndex, float offsetProgress) {
|
||||
protected float getHorizontalOffsetSize(int childIndex, int midpointIndex,
|
||||
float offsetProgress) {
|
||||
if (offsetProgress == 0) {
|
||||
// Don't bother calculating everything below if we won't offset anyway.
|
||||
return 0;
|
||||
|
||||
@@ -29,11 +29,16 @@ import android.view.View.LAYOUT_DIRECTION_LTR
|
||||
import android.view.View.LAYOUT_DIRECTION_RTL
|
||||
import androidx.core.view.children
|
||||
import androidx.core.view.isInvisible
|
||||
import androidx.dynamicanimation.animation.FloatPropertyCompat
|
||||
import androidx.dynamicanimation.animation.SpringAnimation
|
||||
import androidx.dynamicanimation.animation.SpringForce
|
||||
import com.android.launcher3.AbstractFloatingView.TYPE_TASK_MENU
|
||||
import com.android.launcher3.AbstractFloatingView.getTopOpenViewWithType
|
||||
import com.android.launcher3.Flags.enableDesktopExplodedView
|
||||
import com.android.launcher3.Flags.enableLargeDesktopWindowingTile
|
||||
import com.android.launcher3.Flags.enableOverviewOnConnectedDisplays
|
||||
import com.android.launcher3.PagedView.INVALID_PAGE
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.Utilities.getPivotsForScalingRectToRect
|
||||
import com.android.launcher3.statehandlers.DesktopVisibilityController
|
||||
import com.android.launcher3.statehandlers.DesktopVisibilityController.Companion.INACTIVE_DESK_ID
|
||||
@@ -256,6 +261,44 @@ class RecentsViewUtils(private val recentsView: RecentsView<*, *>) : DesktopVisi
|
||||
recentsView.addDeskButton?.isInvisible = !canCreateDesks
|
||||
}
|
||||
|
||||
private fun animateDesktopTaskViewSpringIn(desktopTaskView: DesktopTaskView) {
|
||||
val taskDismissFloatProperty =
|
||||
FloatPropertyCompat.createFloatPropertyCompat(
|
||||
desktopTaskView.primaryDismissTranslationProperty
|
||||
)
|
||||
|
||||
with(recentsView) {
|
||||
// Calculate initial translation to bring it offscreen.
|
||||
val desktopTaskViewIndex = indexOfChild(desktopTaskView)
|
||||
val midpointIndex =
|
||||
if (getTaskViewAt(desktopTaskViewIndex + 1) != null) desktopTaskViewIndex + 1
|
||||
else INVALID_PAGE
|
||||
var offscreenTranslationX =
|
||||
getHorizontalOffsetSize(desktopTaskViewIndex, midpointIndex, 1f)
|
||||
|
||||
// Add 40dp to the offscreen translation.
|
||||
val additionalOffsetPx =
|
||||
context.resources.getDimensionPixelSize(
|
||||
R.dimen.newly_created_desktop_offscreen_position
|
||||
)
|
||||
offscreenTranslationX += if (isRtl) additionalOffsetPx else -additionalOffsetPx
|
||||
desktopTaskView.primaryDismissTranslationProperty.set(
|
||||
desktopTaskView,
|
||||
offscreenTranslationX,
|
||||
)
|
||||
desktopTaskView.isInvisible = false
|
||||
|
||||
val dampingRatio =
|
||||
context.resources.getFloat(R.dimen.newly_created_desktop_spring_damping_ratio)
|
||||
val stiffness =
|
||||
context.resources.getFloat(R.dimen.newly_created_desktop_spring_stiffness)
|
||||
|
||||
SpringAnimation(desktopTaskView, taskDismissFloatProperty)
|
||||
.setSpring(SpringForce(0f).setDampingRatio(dampingRatio).setStiffness(stiffness))
|
||||
.start()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDeskAdded(displayId: Int, deskId: Int) {
|
||||
with(recentsView) {
|
||||
// Ignore desk changes that don't belong to this display.
|
||||
@@ -278,12 +321,14 @@ class RecentsViewUtils(private val recentsView: RecentsView<*, *>) : DesktopVisi
|
||||
pagedViewOrientedState,
|
||||
taskOverlayFactory,
|
||||
)
|
||||
desktopTaskView.isInvisible = true
|
||||
|
||||
val insertionIndex = 1 + indexOfChild(addDeskButton!!)
|
||||
addView(desktopTaskView, insertionIndex)
|
||||
updateTaskSize()
|
||||
updateChildTaskOrientations()
|
||||
updateScrollSynchronously()
|
||||
animateDesktopTaskViewSpringIn(desktopTaskView)
|
||||
|
||||
// Set Current Page based on the stored TaskView.
|
||||
currentTaskView?.let { setCurrentPage(indexOfChild(it)) }
|
||||
|
||||
Reference in New Issue
Block a user