[go: nahoru, domu]

Replace BuildCompat.isAtLeastU and prerelease checks

Now that we are back on main, we can reference the Build number of U
instead of using the compat function.

Replacing the calls to this API with Build.VERSION.SDK_INT >= 34 in
Activity and Fragment.

Test: all existings tests pass
Change-Id: I8e7f6afd4e3e48dbf1c0211fc2de8245ccf52d92
diff --git a/activity/activity/src/main/java/androidx/activity/BackEventCompat.kt b/activity/activity/src/main/java/androidx/activity/BackEventCompat.kt
index d500470..cbc3521 100644
--- a/activity/activity/src/main/java/androidx/activity/BackEventCompat.kt
+++ b/activity/activity/src/main/java/androidx/activity/BackEventCompat.kt
@@ -16,6 +16,7 @@
 
 package androidx.activity
 
+import android.os.Build
 import android.window.BackEvent
 import androidx.annotation.DoNotInline
 import androidx.annotation.IntDef
@@ -75,7 +76,7 @@
     @OptIn(BuildCompat.PrereleaseSdkCheck::class)
     @Suppress("PrereleaseSdkCoreDependency")
     fun toBackEvent(): BackEvent {
-        if (BuildCompat.isAtLeastU()) {
+        if (Build.VERSION.SDK_INT >= 34) {
             return Api34Impl.createOnBackEvent(touchX, touchY, progress, swipeEdge)
         } else {
             throw UnsupportedOperationException("This method is only supported on API level 34+")
diff --git a/activity/activity/src/main/java/androidx/activity/OnBackPressedDispatcher.kt b/activity/activity/src/main/java/androidx/activity/OnBackPressedDispatcher.kt
index e50f19a..ef664f3 100644
--- a/activity/activity/src/main/java/androidx/activity/OnBackPressedDispatcher.kt
+++ b/activity/activity/src/main/java/androidx/activity/OnBackPressedDispatcher.kt
@@ -22,11 +22,8 @@
 import android.window.OnBackInvokedDispatcher
 import androidx.annotation.DoNotInline
 import androidx.annotation.MainThread
-import androidx.annotation.OptIn
 import androidx.annotation.RequiresApi
 import androidx.annotation.VisibleForTesting
-import androidx.core.os.BuildCompat
-import androidx.core.os.BuildCompat.PrereleaseSdkCheck
 import androidx.core.util.Consumer
 import androidx.lifecycle.Lifecycle
 import androidx.lifecycle.LifecycleEventObserver
@@ -63,7 +60,6 @@
 // fallbackOnBackPressed. To avoid silently breaking source compatibility the new
 // primary constructor has no optional parameters to avoid ambiguity/wrong overload resolution
 // when a single parameter is provided as a trailing lambda.
-@OptIn(PrereleaseSdkCheck::class)
 class OnBackPressedDispatcher constructor(
     private val fallbackOnBackPressed: Runnable?,
     private val onHasEnabledCallbacksChanged: Consumer<Boolean>?
@@ -126,7 +122,7 @@
 
     init {
         if (Build.VERSION.SDK_INT >= 33) {
-             (BuildCompat.isAtLeastU()) {
+             (Build.VERSION.SDK_INT >= 34) {
                 Api34Impl.createOnBackAnimationCallback(
                     { backEvent -> onBackStarted(backEvent) },
                     { backEvent -> onBackProgressed(backEvent) },
diff --git a/fragment/fragment/src/main/java/androidx/fragment/app/DefaultSpecialEffectsController.kt b/fragment/fragment/src/main/java/androidx/fragment/app/DefaultSpecialEffectsController.kt
index 94ccdc1..15a7b33 100644
--- a/fragment/fragment/src/main/java/androidx/fragment/app/DefaultSpecialEffectsController.kt
+++ b/fragment/fragment/src/main/java/androidx/fragment/app/DefaultSpecialEffectsController.kt
@@ -27,10 +27,8 @@
 import android.view.ViewGroup
 import android.view.animation.Animation
 import androidx.annotation.DoNotInline
-import androidx.annotation.OptIn
 import androidx.annotation.RequiresApi
 import androidx.collection.ArrayMap
-import androidx.core.os.BuildCompat
 import androidx.core.os.CancellationSignal
 import androidx.core.view.OneShotPreDrawListener
 import androidx.core.view.ViewCompat
@@ -134,7 +132,6 @@
         }
     }
 
-    @OptIn(BuildCompat.PrereleaseSdkCheck::class)
     @SuppressLint("NewApi", "PrereleaseSdkCoreDependency")
     private fun startAnimations(
         animationInfos: List<AnimationInfo>,
@@ -207,25 +204,21 @@
                 }
             })
             animator.setTarget(viewToAnimate)
-            if (BuildCompat.isAtLeastU() && operation.fragment.mTransitioning) {
+            if (Build.VERSION.SDK_INT >= 34 && operation.fragment.mTransitioning) {
                 val animatorSet = animationInfo.getAnimation(container.context)?.animator
                 operation.addBackProgressCallbacks({ backEvent ->
-                    if (!BuildCompat.isAtLeastU()) {
-                        animatorSet?.start()
-                    } else {
-                        if (animatorSet != null) {
-                            val totalDuration = Api24Impl.totalDuration(animatorSet)
-                            var time = (backEvent.progress * totalDuration).toLong()
-                            // We cannot let the time get to 0 or the totalDuration to avoid
-                            // completing the operation accidentally.
-                            if (time == 0L) {
-                                time = 1L
-                            }
-                            if (time == totalDuration) {
-                                time = totalDuration - 1
-                            }
-                            Api26Impl.setCurrentPlayTime(animatorSet, time)
+                    if (animatorSet != null) {
+                        val totalDuration = Api24Impl.totalDuration(animatorSet)
+                        var time = (backEvent.progress * totalDuration).toLong()
+                        // We cannot let the time get to 0 or the totalDuration to avoid
+                        // completing the operation accidentally.
+                        if (time == 0L) {
+                            time = 1L
                         }
+                        if (time == totalDuration) {
+                            time = totalDuration - 1
+                        }
+                        Api26Impl.setCurrentPlayTime(animatorSet, time)
                     }
                 }) { animatorSet?.start() }
             } else {