summaryrefslogtreecommitdiff
path: root/quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt
diff options
context:
space:
mode:
Diffstat (limited to 'quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt')
-rw-r--r--quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt113
1 files changed, 97 insertions, 16 deletions
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt b/quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt
index e215bc9d46..3f9b66a717 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt
@@ -15,22 +15,29 @@
*/
package com.android.launcher3.taskbar
+import android.animation.Animator
+import android.animation.AnimatorListenerAdapter
+import android.animation.AnimatorSet
+import android.animation.ObjectAnimator
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Rect
import android.graphics.drawable.GradientDrawable
import android.util.AttributeSet
+import android.util.Property
import android.view.Gravity
import android.view.MotionEvent
import android.view.View
import android.widget.LinearLayout
import android.widget.Switch
import androidx.core.view.postDelayed
+import com.android.app.animation.Interpolators.EMPHASIZED_ACCELERATE
import com.android.launcher3.R
import com.android.launcher3.popup.ArrowPopup
import com.android.launcher3.popup.RoundedArrowDrawable
import com.android.launcher3.util.DisplayController
import com.android.launcher3.util.Themes
+import com.android.launcher3.views.ActivityContext
/** Popup view with arrow for taskbar pinning */
class TaskbarDividerPopupView<T : TaskbarActivityContext>
@@ -42,7 +49,8 @@ constructor(
) : ArrowPopup<T>(context, attrs, defStyleAttr) {
companion object {
private const val TAG = "TaskbarDividerPopupView"
- private const val DIVIDER_POPUP_CLOSING_DELAY = 500L
+ private const val DIVIDER_POPUP_CLOSING_DELAY = 333L
+ private const val DIVIDER_POPUP_CLOSING_ANIMATION_DURATION = 83L
@JvmStatic
fun createAndPopulate(
@@ -59,10 +67,11 @@ constructor(
return taskMenuViewWithArrow.populateForView(view)
}
}
+
private lateinit var dividerView: View
private val menuWidth =
- context.resources.getDimensionPixelSize(R.dimen.taskbar_pinning_popup_menu_width)
+ resources.getDimensionPixelSize(R.dimen.taskbar_pinning_popup_menu_width)
private val popupCornerRadius = Themes.getDialogCornerRadius(context)
private val arrowWidth = resources.getDimension(R.dimen.popup_arrow_width)
private val arrowHeight = resources.getDimension(R.dimen.popup_arrow_height)
@@ -70,16 +79,12 @@ constructor(
private var alwaysShowTaskbarOn = !DisplayController.isTransientTaskbar(context)
private var didPreferenceChange = false
+ private var verticalOffsetForPopupView =
+ resources.getDimensionPixelSize(R.dimen.taskbar_pinning_popup_menu_vertical_margin)
/** Callback invoked when the pinning popup view is closing. */
var onCloseCallback: (preferenceChanged: Boolean) -> Unit = {}
- /**
- * Callback invoked when the user preference changes in popup view. Preference change will be
- * based upon current value stored in [LauncherPrefs] for `TASKBAR_PINNING`
- */
- var changePreference: () -> Unit = {}
-
init {
// This synchronizes the arrow and menu to open at the same time
mOpenChildFadeStartDelay = mOpenFadeStartDelay
@@ -99,11 +104,22 @@ constructor(
super.onFinishInflate()
val taskbarSwitchOption = requireViewById<LinearLayout>(R.id.taskbar_switch_option)
val alwaysShowTaskbarSwitch = requireViewById<Switch>(R.id.taskbar_pinning_switch)
+ val taskbarVisibilityIcon = requireViewById<View>(R.id.taskbar_pinning_visibility_icon)
alwaysShowTaskbarSwitch.isChecked = alwaysShowTaskbarOn
- taskbarSwitchOption.setOnClickListener {
- alwaysShowTaskbarSwitch.isClickable = true
- alwaysShowTaskbarSwitch.isChecked = !alwaysShowTaskbarOn
- onClickAlwaysShowTaskbarSwitchOption()
+ if (ActivityContext.lookupContext<TaskbarActivityContext>(context).isGestureNav) {
+ taskbarSwitchOption.setOnClickListener {
+ alwaysShowTaskbarSwitch.isClickable = true
+ alwaysShowTaskbarSwitch.isChecked = !alwaysShowTaskbarOn
+ onClickAlwaysShowTaskbarSwitchOption()
+ }
+ } else {
+ alwaysShowTaskbarSwitch.isEnabled = false
+ }
+
+ if (!alwaysShowTaskbarSwitch.isEnabled) {
+ taskbarVisibilityIcon.background.setTint(
+ resources.getColor(android.R.color.system_neutral2_500, context.theme)
+ )
}
}
@@ -176,15 +192,80 @@ constructor(
}
}
- override fun closeComplete() {
+ override fun getExtraVerticalOffset(): Int {
+ return (mActivityContext.deviceProfile.taskbarHeight -
+ mActivityContext.deviceProfile.taskbarIconSize) / 2 + verticalOffsetForPopupView
+ }
+
+ override fun animateClose() {
+ if (!mIsOpen) {
+ return
+ }
+ if (mOpenCloseAnimator != null) {
+ mOpenCloseAnimator.cancel()
+ }
+ mIsOpen = false
+
+ mOpenCloseAnimator = getCloseAnimator()
+
+ mOpenCloseAnimator.addListener(
+ object : AnimatorListenerAdapter() {
+ override fun onAnimationEnd(animation: Animator) {
+ mOpenCloseAnimator = null
+ if (mDeferContainerRemoval) {
+ setVisibility(INVISIBLE)
+ } else {
+ closeComplete()
+ }
+ }
+ }
+ )
onCloseCallback(didPreferenceChange)
- super.closeComplete()
+ onCloseCallback = {}
+ mOpenCloseAnimator.start()
+ }
+
+ private fun getCloseAnimator(): AnimatorSet {
+ val alphaValues = floatArrayOf(1f, 0f)
+ val translateYValue =
+ if (!alwaysShowTaskbarOn) verticalOffsetForPopupView else -verticalOffsetForPopupView
+ val alpha = getAnimatorOfFloat(this, ALPHA, *alphaValues)
+ val arrowAlpha = getAnimatorOfFloat(mArrow, ALPHA, *alphaValues)
+ val translateY =
+ ObjectAnimator.ofFloat(
+ this,
+ TRANSLATION_Y,
+ *floatArrayOf(this.translationY, this.translationY + translateYValue)
+ )
+ val arrowTranslateY =
+ ObjectAnimator.ofFloat(
+ mArrow,
+ TRANSLATION_Y,
+ *floatArrayOf(mArrow.translationY, mArrow.translationY + translateYValue)
+ )
+ val animatorSet = AnimatorSet()
+ animatorSet.playTogether(alpha, arrowAlpha, translateY, arrowTranslateY)
+ return animatorSet
+ }
+
+ private fun getAnimatorOfFloat(
+ view: View,
+ property: Property<View, Float>,
+ vararg values: Float
+ ): Animator {
+ val animator: Animator = ObjectAnimator.ofFloat(view, property, *values)
+ animator.setDuration(DIVIDER_POPUP_CLOSING_ANIMATION_DURATION)
+ animator.interpolator = EMPHASIZED_ACCELERATE
+ return animator
}
private fun onClickAlwaysShowTaskbarSwitchOption() {
didPreferenceChange = true
- changePreference()
// Allow switch animation to finish and then close the popup.
- postDelayed(DIVIDER_POPUP_CLOSING_DELAY) { close(true) }
+ postDelayed(DIVIDER_POPUP_CLOSING_DELAY) {
+ if (isOpen) {
+ close(true)
+ }
+ }
}
}