diff --git a/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.kt b/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.kt index b230fa6ed4..79328df325 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.kt +++ b/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.kt @@ -36,8 +36,9 @@ import com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_SCALE import com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_TRANSLATE_X import com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_TRANSLATE_Y import com.android.launcher3.states.StateAnimationConfig.SKIP_OVERVIEW -import com.android.launcher3.util.MultiPropertyFactory.MULTI_PROPERTY_VALUE import com.android.quickstep.util.AnimUtils +import com.android.quickstep.views.AddDesktopButton +import com.android.quickstep.views.ClearAllButton import com.android.quickstep.views.RecentsView import com.android.quickstep.views.RecentsView.ADJACENT_PAGE_HORIZONTAL_OFFSET import com.android.quickstep.views.RecentsView.CONTENT_ALPHA @@ -287,8 +288,8 @@ class RecentsViewStateController(private val launcher: QuickstepLauncher) : val clearAllButtonAlpha = if (state.areElementsVisible(launcher, LauncherState.CLEAR_ALL_BUTTON)) 1f else 0f propertySetter.setFloat( - recentsView.clearAllButton.visibilityAlphaProperty, - MULTI_PROPERTY_VALUE, + recentsView.clearAllButton, + ClearAllButton.VISIBILITY_ALPHA, clearAllButtonAlpha, LINEAR, ) @@ -302,8 +303,8 @@ class RecentsViewStateController(private val launcher: QuickstepLauncher) : ) recentsView.addDeskButton?.let { propertySetter.setFloat( - it.visibilityAlphaProperty, - MULTI_PROPERTY_VALUE, + it, + AddDesktopButton.VISIBILITY_ALPHA, if (state.areElementsVisible(launcher, LauncherState.ADD_DESK_BUTTON)) 1f else 0f, LINEAR, ) diff --git a/quickstep/src/com/android/quickstep/fallback/FallbackRecentsStateController.java b/quickstep/src/com/android/quickstep/fallback/FallbackRecentsStateController.java index 51f2a33529..2631efea1c 100644 --- a/quickstep/src/com/android/quickstep/fallback/FallbackRecentsStateController.java +++ b/quickstep/src/com/android/quickstep/fallback/FallbackRecentsStateController.java @@ -26,7 +26,6 @@ import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_TR import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_TRANSLATE_Y; import static com.android.launcher3.states.StateAnimationConfig.ANIM_SCRIM_FADE; import static com.android.launcher3.states.StateAnimationConfig.SKIP_OVERVIEW; -import static com.android.launcher3.util.MultiPropertyFactory.MULTI_PROPERTY_VALUE; import static com.android.quickstep.fallback.RecentsState.OVERVIEW_SPLIT_SELECT; import static com.android.quickstep.views.RecentsView.ADJACENT_PAGE_HORIZONTAL_OFFSET; import static com.android.quickstep.views.RecentsView.DESKTOP_CAROUSEL_DETACH_PROGRESS; @@ -52,6 +51,8 @@ import com.android.launcher3.anim.PendingAnimation; import com.android.launcher3.anim.PropertySetter; import com.android.launcher3.statemanager.StateManager.StateHandler; import com.android.launcher3.states.StateAnimationConfig; +import com.android.quickstep.views.AddDesktopButton; +import com.android.quickstep.views.ClearAllButton; import com.android.quickstep.views.RecentsView; import com.android.quickstep.views.RecentsViewContainer; @@ -97,12 +98,12 @@ public class FallbackRecentsStateController implements StateHandler.MultiProperty - get() = addDeskButtonAlpha.get(Alpha.VISIBILITY.ordinal) - - private enum class TranslationX { - GRID, - OFFSET, - } + var contentAlpha by MultiPropertyDelegate(addDeskButtonAlpha, Alpha.CONTENT) + var visibilityAlpha by MultiPropertyDelegate(addDeskButtonAlpha, Alpha.VISIBILITY) private val multiTranslationX = MultiPropertyFactory(this, VIEW_TRANSLATE_X, TranslationX.entries.size) { a: Float, b: Float -> a + b } - - var gridTranslationX - get() = multiTranslationX[TranslationX.GRID.ordinal].value - set(value) { - multiTranslationX[TranslationX.GRID.ordinal].value = value - } - - var offsetTranslationX - get() = multiTranslationX[TranslationX.OFFSET.ordinal].value - set(value) { - multiTranslationX[TranslationX.OFFSET.ordinal].value = value - } + var gridTranslationX by MultiPropertyDelegate(multiTranslationX, TranslationX.GRID) + var offsetTranslationX by MultiPropertyDelegate(multiTranslationX, TranslationX.OFFSET) private val focusBorderAnimator: BorderAnimator = createSimpleBorderAnimator( @@ -109,7 +84,7 @@ class AddDesktopButton @JvmOverloads constructor(context: Context, attrs: Attrib } } - protected fun getScrollAdjustment(showAsGrid: Boolean): Int = + fun getScrollAdjustment(showAsGrid: Boolean): Int = if (showAsGrid) gridTranslationX.toInt() else 0 private fun getBorderBounds(bounds: Rect) { @@ -123,4 +98,20 @@ class AddDesktopButton @JvmOverloads constructor(context: Context, attrs: Attrib focusBorderAnimator.drawBorder(canvas) super.draw(canvas) } + + companion object { + private enum class Alpha { + CONTENT, + VISIBILITY, + } + + private enum class TranslationX { + GRID, + OFFSET, + } + + @JvmField + val VISIBILITY_ALPHA: FloatProperty = + KFloatProperty(AddDesktopButton::visibilityAlpha) + } } diff --git a/quickstep/src/com/android/quickstep/views/ClearAllButton.kt b/quickstep/src/com/android/quickstep/views/ClearAllButton.kt index 6420ece95c..69c85eeaeb 100644 --- a/quickstep/src/com/android/quickstep/views/ClearAllButton.kt +++ b/quickstep/src/com/android/quickstep/views/ClearAllButton.kt @@ -19,11 +19,12 @@ import android.content.Context import android.graphics.Canvas import android.graphics.Rect import android.util.AttributeSet -import android.view.View +import android.util.FloatProperty import android.widget.Button import com.android.launcher3.Flags.enableFocusOutline import com.android.launcher3.R -import com.android.launcher3.util.MultiPropertyFactory +import com.android.launcher3.util.KFloatProperty +import com.android.launcher3.util.MultiPropertyDelegate import com.android.launcher3.util.MultiValueAlpha import com.android.quickstep.util.BorderAnimator import com.android.quickstep.util.BorderAnimator.Companion.createSimpleBorderAnimator @@ -33,13 +34,6 @@ import kotlin.math.min class ClearAllButton @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : Button(context, attrs) { - private enum class Alpha { - SCROLL, - CONTENT, - VISIBILITY, - DISMISS, - } - private val clearAllButtonAlpha = object : MultiValueAlpha(this, Alpha.entries.size) { override fun apply(value: Float) { @@ -47,32 +41,10 @@ class ClearAllButton @JvmOverloads constructor(context: Context, attrs: Attribut isClickable = value >= 1f } } - - var scrollAlpha - set(value) { - clearAllButtonAlpha.get(Alpha.SCROLL.ordinal).value = value - } - get() = clearAllButtonAlpha.get(Alpha.SCROLL.ordinal).value - - var contentAlpha - set(value) { - clearAllButtonAlpha.get(Alpha.CONTENT.ordinal).value = value - } - get() = clearAllButtonAlpha.get(Alpha.CONTENT.ordinal).value - - @JvmField - val visibilityAlphaProperty: MultiPropertyFactory.MultiProperty = - clearAllButtonAlpha.get(Alpha.VISIBILITY.ordinal) - - var dismissAlpha - set(value) { - dismissAlphaProperty.value = value - } - get() = dismissAlphaProperty.value - - @JvmField - val dismissAlphaProperty: MultiPropertyFactory.MultiProperty = - clearAllButtonAlpha.get(Alpha.DISMISS.ordinal) + var scrollAlpha by MultiPropertyDelegate(clearAllButtonAlpha, Alpha.SCROLL) + var contentAlpha by MultiPropertyDelegate(clearAllButtonAlpha, Alpha.CONTENT) + var visibilityAlpha by MultiPropertyDelegate(clearAllButtonAlpha, Alpha.VISIBILITY) + var dismissAlpha by MultiPropertyDelegate(clearAllButtonAlpha, Alpha.DISMISS) var fullscreenProgress = 1f set(value) { @@ -257,4 +229,21 @@ class ClearAllButton @JvmOverloads constructor(context: Context, attrs: Attribut if (fullscreenProgress > 0) endTranslation else 0f private fun getGridTrans(endTranslation: Float) = if (gridProgress > 0) endTranslation else 0f + + companion object { + private enum class Alpha { + SCROLL, + CONTENT, + VISIBILITY, + DISMISS, + } + + @JvmField + val VISIBILITY_ALPHA: FloatProperty = + KFloatProperty(ClearAllButton::visibilityAlpha) + + @JvmField + val DISMISS_ALPHA: FloatProperty = + KFloatProperty(ClearAllButton::dismissAlpha) + } } diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index e1868384ef..44bf82c7b8 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -66,6 +66,7 @@ import static com.android.launcher3.util.SystemUiController.UI_STATE_FULLSCREEN_ import static com.android.quickstep.BaseContainerInterface.getTaskDimension; import static com.android.quickstep.TaskUtils.checkCurrentOrManagedUserId; import static com.android.quickstep.util.LogUtils.splitFailureMessage; +import static com.android.quickstep.views.ClearAllButton.DISMISS_ALPHA; import static com.android.quickstep.views.OverviewActionsView.HIDDEN_ACTIONS_IN_MENU; import static com.android.quickstep.views.OverviewActionsView.HIDDEN_DESKTOP; import static com.android.quickstep.views.OverviewActionsView.HIDDEN_NON_ZERO_ROTATION; @@ -73,6 +74,7 @@ import static com.android.quickstep.views.OverviewActionsView.HIDDEN_NO_RECENTS; import static com.android.quickstep.views.OverviewActionsView.HIDDEN_NO_TASKS; import static com.android.quickstep.views.OverviewActionsView.HIDDEN_SPLIT_SELECT_ACTIVE; import static com.android.quickstep.views.RecentsViewUtils.DESK_EXPLODE_PROGRESS; +import static com.android.quickstep.views.TaskView.SPLIT_ALPHA; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; @@ -3974,8 +3976,7 @@ public abstract class RecentsView< // Change alpha of clear all if translating grid to hide it if (isClearAllHidden) { - anim.setFloat(mClearAllButton.dismissAlphaProperty, MULTI_PROPERTY_VALUE, 0, - LINEAR); + anim.setFloat(mClearAllButton, DISMISS_ALPHA, 0, LINEAR); anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { @@ -5354,8 +5355,7 @@ public abstract class RecentsView< clampToProgress(timings.getDesktopTaskScaleInterpolator(), 0f, timings.getDesktopFadeSplitAnimationEndOffset())); } - builder.addFloat(taskView.getSplitAlphaProperty(), - MULTI_PROPERTY_VALUE, 1f, 0f, + builder.addFloat(taskView, SPLIT_ALPHA, 1f, 0f, clampToProgress(deskTopFadeInterPolator, 0f, timings.getDesktopFadeSplitAnimationEndOffset())); } diff --git a/quickstep/src/com/android/quickstep/views/RecentsViewUtils.kt b/quickstep/src/com/android/quickstep/views/RecentsViewUtils.kt index 67318acc74..31ae890d97 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsViewUtils.kt +++ b/quickstep/src/com/android/quickstep/views/RecentsViewUtils.kt @@ -28,6 +28,7 @@ import com.android.quickstep.util.isExternalDisplay import com.android.quickstep.views.RecentsView.RUNNING_TASK_ATTACH_ALPHA import com.android.systemui.shared.recents.model.ThumbnailData import java.util.function.BiConsumer +import kotlin.reflect.KMutableProperty1 /** * Helper class for [RecentsView]. This util class contains refactored and extracted functions from @@ -305,16 +306,19 @@ class RecentsViewUtils(private val recentsView: RecentsView<*, *>) { } companion object { - @JvmField - val DESK_EXPLODE_PROGRESS = - object : FloatProperty>("deskExplodeProgress") { - override fun setValue(recentsView: RecentsView<*, *>, value: Float) { - recentsView.mUtils.deskExplodeProgress = value - } + class RecentsViewFloatProperty( + private val utilsProperty: KMutableProperty1 + ) : FloatProperty>(utilsProperty.name) { + override fun get(recentsView: RecentsView<*, *>): Float = + utilsProperty.get(recentsView.mUtils) - override fun get(recentsView: RecentsView<*, *>) = - recentsView.mUtils.deskExplodeProgress + override fun setValue(recentsView: RecentsView<*, *>, value: Float) { + utilsProperty.set(recentsView.mUtils, value) } + } + + @JvmField + val DESK_EXPLODE_PROGRESS = RecentsViewFloatProperty(RecentsViewUtils::deskExplodeProgress) val TEMP_RECT = Rect() } diff --git a/quickstep/src/com/android/quickstep/views/TaskView.kt b/quickstep/src/com/android/quickstep/views/TaskView.kt index ad60329814..276318c2db 100644 --- a/quickstep/src/com/android/quickstep/views/TaskView.kt +++ b/quickstep/src/com/android/quickstep/views/TaskView.kt @@ -61,8 +61,9 @@ import com.android.launcher3.testing.TestLogging import com.android.launcher3.testing.shared.TestProtocol import com.android.launcher3.util.CancellableTask import com.android.launcher3.util.Executors +import com.android.launcher3.util.KFloatProperty +import com.android.launcher3.util.MultiPropertyDelegate import com.android.launcher3.util.MultiPropertyFactory -import com.android.launcher3.util.MultiPropertyFactory.MULTI_PROPERTY_VALUE import com.android.launcher3.util.MultiValueAlpha import com.android.launcher3.util.RunnableList import com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITION_UNDEFINED @@ -440,28 +441,10 @@ constructor( applyTranslationX() } - private val taskViewAlpha = MultiValueAlpha(this, NUM_ALPHA_CHANNELS) - - protected var stableAlpha - set(value) { - taskViewAlpha.get(ALPHA_INDEX_STABLE).value = value - } - get() = taskViewAlpha.get(ALPHA_INDEX_STABLE).value - - var attachAlpha - set(value) { - taskViewAlpha.get(ALPHA_INDEX_ATTACH).value = value - } - get() = taskViewAlpha.get(ALPHA_INDEX_ATTACH).value - - var splitAlpha - set(value) { - splitAlphaProperty.value = value - } - get() = splitAlphaProperty.value - - val splitAlphaProperty: MultiPropertyFactory.MultiProperty - get() = taskViewAlpha.get(ALPHA_INDEX_SPLIT) + private val taskViewAlpha = MultiValueAlpha(this, Alpha.entries.size) + protected var stableAlpha by MultiPropertyDelegate(taskViewAlpha, Alpha.STABLE) + var attachAlpha by MultiPropertyDelegate(taskViewAlpha, Alpha.ATTACH) + var splitAlpha by MultiPropertyDelegate(taskViewAlpha, Alpha.SPLIT) protected var shouldShowScreenshot = false get() = !isRunningTask || field @@ -515,16 +498,16 @@ constructor( MultiPropertyFactory( this, SETTLED_PROGRESS, - SETTLED_PROGRESS_INDEX_COUNT, + SettledProgress.entries.size, { x: Float, y: Float -> x * y }, 1f, ) - private val settledProgressFullscreen = - settledProgressPropertyFactory.get(SETTLED_PROGRESS_INDEX_FULLSCREEN) - private val settledProgressGesture = - settledProgressPropertyFactory.get(SETTLED_PROGRESS_INDEX_GESTURE) - private val settledProgressDismiss = - settledProgressPropertyFactory.get(SETTLED_PROGRESS_INDEX_DISMISS) + private var settledProgressFullscreen by + MultiPropertyDelegate(settledProgressPropertyFactory, SettledProgress.Fullscreen) + private var settledProgressGesture by + MultiPropertyDelegate(settledProgressPropertyFactory, SettledProgress.Gesture) + private var settledProgressDismiss by + MultiPropertyDelegate(settledProgressPropertyFactory, SettledProgress.Dismiss) private var viewModel: TaskViewModel? = null private val dispatcherProvider: DispatcherProvider by RecentsDependencies.inject() @@ -536,7 +519,7 @@ constructor( * interpolator. */ fun getDismissIconFadeInAnimator(): ObjectAnimator = - ObjectAnimator.ofFloat(settledProgressDismiss, MULTI_PROPERTY_VALUE, 1f).apply { + ObjectAnimator.ofFloat(this, SETTLED_PROGRESS_DISMISS, 1f).apply { duration = FADE_IN_ICON_DURATION interpolator = FADE_IN_ICON_INTERPOLATOR } @@ -548,8 +531,7 @@ constructor( */ fun getDismissIconFadeOutAnimator(): ObjectAnimator = AnimatedFloat { v -> - settledProgressDismiss.value = - SETTLED_PROGRESS_FAST_OUT_INTERPOLATOR.getInterpolation(v) + settledProgressDismiss = SETTLED_PROGRESS_FAST_OUT_INTERPOLATOR.getInterpolation(v) } .animateToValue(1f, 0f) @@ -1603,7 +1585,7 @@ constructor( fun startIconFadeInOnGestureComplete() { iconFadeInOnGestureCompleteAnimator?.cancel() iconFadeInOnGestureCompleteAnimator = - ObjectAnimator.ofFloat(settledProgressGesture, MULTI_PROPERTY_VALUE, 1f).apply { + ObjectAnimator.ofFloat(this, SETTLED_PROGRESS_GESTURE, 1f).apply { duration = FADE_IN_ICON_DURATION interpolator = Interpolators.LINEAR addListener( @@ -1619,7 +1601,7 @@ constructor( fun setIconVisibleForGesture(isVisible: Boolean) { iconFadeInOnGestureCompleteAnimator?.cancel() - settledProgressGesture.value = if (isVisible) 1f else 0f + settledProgressGesture = if (isVisible) 1f else 0f } /** Set a color tint on the snapshot and supporting views. */ @@ -1708,7 +1690,7 @@ constructor( it.iconView.setVisibility(if (fullscreenProgress < 1) VISIBLE else INVISIBLE) it.overlay.setFullscreenProgress(fullscreenProgress) } - settledProgressFullscreen.value = + settledProgressFullscreen = SETTLED_PROGRESS_FAST_OUT_INTERPOLATOR.getInterpolation(1 - fullscreenProgress) updateFullscreenParams() } @@ -1766,7 +1748,7 @@ constructor( dismissScale = 1f translationZ = 0f setIconVisibleForGesture(true) - settledProgressDismiss.value = 1f + settledProgressDismiss = 1f setColorTint(0f, 0) } @@ -1788,23 +1770,25 @@ constructor( companion object { private const val TAG = "TaskView" + + private enum class Alpha { + STABLE, + ATTACH, + SPLIT, + } + + private enum class SettledProgress { + Fullscreen, + Gesture, + Dismiss, + } + const val FLAG_UPDATE_ICON = 1 const val FLAG_UPDATE_THUMBNAIL = FLAG_UPDATE_ICON shl 1 const val FLAG_UPDATE_CORNER_RADIUS = FLAG_UPDATE_THUMBNAIL shl 1 const val FLAG_UPDATE_ALL = (FLAG_UPDATE_ICON or FLAG_UPDATE_THUMBNAIL or FLAG_UPDATE_CORNER_RADIUS) - const val SETTLED_PROGRESS_INDEX_FULLSCREEN = 0 - const val SETTLED_PROGRESS_INDEX_GESTURE = 1 - const val SETTLED_PROGRESS_INDEX_DISMISS = 2 - const val SETTLED_PROGRESS_INDEX_COUNT = 3 - - private const val ALPHA_INDEX_STABLE = 0 - private const val ALPHA_INDEX_ATTACH = 1 - private const val ALPHA_INDEX_SPLIT = 2 - - private const val NUM_ALPHA_CHANNELS = 3 - /** The maximum amount that a task view can be scrimmed, dimmed or tinted. */ const val MAX_PAGE_SCRIM_ALPHA = 0.4f const val FADE_IN_ICON_DURATION: Long = 120 @@ -1821,104 +1805,45 @@ constructor( private val SYSTEM_GESTURE_EXCLUSION_RECT = listOf(Rect()) private val SETTLED_PROGRESS: FloatProperty = - object : FloatProperty("settleTransition") { - override fun setValue(taskView: TaskView, v: Float) { - taskView.settledProgress = v - } + KFloatProperty(TaskView::settledProgress) - override fun get(taskView: TaskView) = taskView.settledProgress - } + private val SETTLED_PROGRESS_GESTURE: FloatProperty = + KFloatProperty(TaskView::settledProgressGesture) + + private val SETTLED_PROGRESS_DISMISS: FloatProperty = + KFloatProperty(TaskView::settledProgressDismiss) private val SPLIT_SELECT_TRANSLATION_X: FloatProperty = - object : FloatProperty("splitSelectTranslationX") { - override fun setValue(taskView: TaskView, v: Float) { - taskView.splitSelectTranslationX = v - } - - override fun get(taskView: TaskView) = taskView.splitSelectTranslationX - } + KFloatProperty(TaskView::splitSelectTranslationX) private val SPLIT_SELECT_TRANSLATION_Y: FloatProperty = - object : FloatProperty("splitSelectTranslationY") { - override fun setValue(taskView: TaskView, v: Float) { - taskView.splitSelectTranslationY = v - } - - override fun get(taskView: TaskView) = taskView.splitSelectTranslationY - } + KFloatProperty(TaskView::splitSelectTranslationY) private val DISMISS_TRANSLATION_X: FloatProperty = - object : FloatProperty("dismissTranslationX") { - override fun setValue(taskView: TaskView, v: Float) { - taskView.dismissTranslationX = v - } - - override fun get(taskView: TaskView) = taskView.dismissTranslationX - } + KFloatProperty(TaskView::dismissTranslationX) private val DISMISS_TRANSLATION_Y: FloatProperty = - object : FloatProperty("dismissTranslationY") { - override fun setValue(taskView: TaskView, v: Float) { - taskView.dismissTranslationY = v - } - - override fun get(taskView: TaskView) = taskView.dismissTranslationY - } + KFloatProperty(TaskView::dismissTranslationY) private val TASK_OFFSET_TRANSLATION_X: FloatProperty = - object : FloatProperty("taskOffsetTranslationX") { - override fun setValue(taskView: TaskView, v: Float) { - taskView.taskOffsetTranslationX = v - } - - override fun get(taskView: TaskView) = taskView.taskOffsetTranslationX - } + KFloatProperty(TaskView::taskOffsetTranslationX) private val TASK_OFFSET_TRANSLATION_Y: FloatProperty = - object : FloatProperty("taskOffsetTranslationY") { - override fun setValue(taskView: TaskView, v: Float) { - taskView.taskOffsetTranslationY = v - } - - override fun get(taskView: TaskView) = taskView.taskOffsetTranslationY - } + KFloatProperty(TaskView::taskOffsetTranslationY) private val TASK_RESISTANCE_TRANSLATION_X: FloatProperty = - object : FloatProperty("taskResistanceTranslationX") { - override fun setValue(taskView: TaskView, v: Float) { - taskView.taskResistanceTranslationX = v - } - - override fun get(taskView: TaskView) = taskView.taskResistanceTranslationX - } + KFloatProperty(TaskView::taskResistanceTranslationX) private val TASK_RESISTANCE_TRANSLATION_Y: FloatProperty = - object : FloatProperty("taskResistanceTranslationY") { - override fun setValue(taskView: TaskView, v: Float) { - taskView.taskResistanceTranslationY = v - } - - override fun get(taskView: TaskView) = taskView.taskResistanceTranslationY - } + KFloatProperty(TaskView::taskResistanceTranslationY) @JvmField val GRID_END_TRANSLATION_X: FloatProperty = - object : FloatProperty("gridEndTranslationX") { - override fun setValue(taskView: TaskView, v: Float) { - taskView.gridEndTranslationX = v - } - - override fun get(taskView: TaskView) = taskView.gridEndTranslationX - } + KFloatProperty(TaskView::gridEndTranslationX) @JvmField - val DISMISS_SCALE: FloatProperty = - object : FloatProperty("dismissScale") { - override fun setValue(taskView: TaskView, v: Float) { - taskView.dismissScale = v - } + val DISMISS_SCALE: FloatProperty = KFloatProperty(TaskView::dismissScale) - override fun get(taskView: TaskView) = taskView.dismissScale - } + @JvmField val SPLIT_ALPHA: FloatProperty = KFloatProperty(TaskView::splitAlpha) } } diff --git a/src/com/android/launcher3/util/KFloatProperty.kt b/src/com/android/launcher3/util/KFloatProperty.kt new file mode 100644 index 0000000000..55792415f7 --- /dev/null +++ b/src/com/android/launcher3/util/KFloatProperty.kt @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2025 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.util + +import android.util.FloatProperty +import kotlin.reflect.KMutableProperty1 + +/** Maps any Kotlin mutable property (var) to [FloatProperty]. */ +class KFloatProperty(private val kProperty: KMutableProperty1) : + FloatProperty(kProperty.name) { + override fun get(target: T) = kProperty.get(target) + + override fun setValue(target: T, value: Float) { + kProperty.set(target, value) + } +} diff --git a/src/com/android/launcher3/util/MultiPropertyDelegate.kt b/src/com/android/launcher3/util/MultiPropertyDelegate.kt new file mode 100644 index 0000000000..837a586045 --- /dev/null +++ b/src/com/android/launcher3/util/MultiPropertyDelegate.kt @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2025 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.util + +import kotlin.reflect.KProperty + +/** Delegate Kotlin mutable property (var) to a property in [MultiPropertyFactory] */ +class MultiPropertyDelegate(private val property: MultiPropertyFactory<*>.MultiProperty) { + constructor(factory: MultiPropertyFactory<*>, enum: Enum<*>) : this(factory[enum.ordinal]) + + operator fun getValue(thisRef: Any?, kProperty: KProperty<*>): Float = property.value + + operator fun setValue(thisRef: Any?, kProperty: KProperty<*>, value: Float) { + property.value = value + } +}