Merge "Seamless handoff between stashed handle and taskbar." into tm-qpr-dev
This commit is contained in:
@@ -55,6 +55,9 @@ class TaskbarBackgroundRenderer(context: TaskbarActivityContext) {
|
|||||||
private val stashedHandleWidth =
|
private val stashedHandleWidth =
|
||||||
context.resources.getDimensionPixelSize(R.dimen.taskbar_stashed_handle_width)
|
context.resources.getDimensionPixelSize(R.dimen.taskbar_stashed_handle_width)
|
||||||
|
|
||||||
|
private val stashedHandleHeight =
|
||||||
|
context.resources.getDimensionPixelSize(R.dimen.taskbar_stashed_handle_height)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
paint.color = context.getColor(R.color.taskbar_background)
|
paint.color = context.getColor(R.color.taskbar_background)
|
||||||
paint.flags = Paint.ANTI_ALIAS_FLAG
|
paint.flags = Paint.ANTI_ALIAS_FLAG
|
||||||
@@ -102,8 +105,8 @@ class TaskbarBackgroundRenderer(context: TaskbarActivityContext) {
|
|||||||
/** Draws the background with the given paint and height, on the provided canvas. */
|
/** Draws the background with the given paint and height, on the provided canvas. */
|
||||||
fun draw(canvas: Canvas) {
|
fun draw(canvas: Canvas) {
|
||||||
canvas.save()
|
canvas.save()
|
||||||
canvas.translate(0f, canvas.height - backgroundHeight - bottomMargin)
|
|
||||||
if (!isTransientTaskbar || transientBackgroundBounds.isEmpty) {
|
if (!isTransientTaskbar || transientBackgroundBounds.isEmpty) {
|
||||||
|
canvas.translate(0f, canvas.height - backgroundHeight - bottomMargin)
|
||||||
// Draw the background behind taskbar content.
|
// Draw the background behind taskbar content.
|
||||||
canvas.drawRect(0f, 0f, canvas.width.toFloat(), backgroundHeight, paint)
|
canvas.drawRect(0f, 0f, canvas.width.toFloat(), backgroundHeight, paint)
|
||||||
|
|
||||||
@@ -114,12 +117,21 @@ class TaskbarBackgroundRenderer(context: TaskbarActivityContext) {
|
|||||||
canvas.translate(canvas.width - rightCornerRadius, -rightCornerRadius)
|
canvas.translate(canvas.width - rightCornerRadius, -rightCornerRadius)
|
||||||
canvas.drawPath(invertedRightCornerPath, paint)
|
canvas.drawPath(invertedRightCornerPath, paint)
|
||||||
} else {
|
} else {
|
||||||
// Approximates the stash/unstash animation to transform the background.
|
// backgroundHeight is a value from [0...maxBackgroundHeight], so we can use it as a
|
||||||
|
// proxy to figure out the animation progress of the stash/unstash animation.
|
||||||
val progress = backgroundHeight / maxBackgroundHeight
|
val progress = backgroundHeight / maxBackgroundHeight
|
||||||
|
|
||||||
|
// At progress 0, we draw the background as the stashed handle.
|
||||||
|
// At progress 1, we draw the background as the full taskbar.
|
||||||
|
val newBackgroundHeight =
|
||||||
|
mapRange(progress, stashedHandleHeight.toFloat(), maxBackgroundHeight)
|
||||||
val fullWidth = transientBackgroundBounds.width()
|
val fullWidth = transientBackgroundBounds.width()
|
||||||
val newWidth = mapRange(progress, stashedHandleWidth.toFloat(), fullWidth.toFloat())
|
val newWidth = mapRange(progress, stashedHandleWidth.toFloat(), fullWidth.toFloat())
|
||||||
val delta = fullWidth - newWidth
|
val halfWidthDelta = (fullWidth - newWidth) / 2f
|
||||||
canvas.translate(0f, bottomMargin * ((1f - progress) / 2f))
|
val radius = newBackgroundHeight / 2f
|
||||||
|
val bottomMarginProgress = bottomMargin * ((1f - progress) / 2f)
|
||||||
|
|
||||||
|
canvas.translate(0f, canvas.height - bottomMargin + bottomMarginProgress)
|
||||||
|
|
||||||
// Draw shadow.
|
// Draw shadow.
|
||||||
val shadowAlpha =
|
val shadowAlpha =
|
||||||
@@ -131,20 +143,20 @@ class TaskbarBackgroundRenderer(context: TaskbarActivityContext) {
|
|||||||
setColorAlphaBound(Color.BLACK, Math.round(shadowAlpha))
|
setColorAlphaBound(Color.BLACK, Math.round(shadowAlpha))
|
||||||
)
|
)
|
||||||
|
|
||||||
// Draw background.
|
// Aligns the bottom with the bottom of the stashed handle.
|
||||||
val radius = backgroundHeight / 2f
|
val bottom =
|
||||||
|
(-mapRange(1f - progress, 0f, stashedHandleHeight / 2f) + translationYForSwipe)
|
||||||
|
|
||||||
canvas.drawRoundRect(
|
canvas.drawRoundRect(
|
||||||
transientBackgroundBounds.left + (delta / 2f),
|
transientBackgroundBounds.left + halfWidthDelta,
|
||||||
translationYForSwipe,
|
bottom - newBackgroundHeight,
|
||||||
transientBackgroundBounds.right - (delta / 2f),
|
transientBackgroundBounds.right - halfWidthDelta,
|
||||||
backgroundHeight + translationYForSwipe,
|
bottom,
|
||||||
radius,
|
radius,
|
||||||
radius,
|
radius,
|
||||||
paint
|
paint
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas.restore()
|
canvas.restore()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user