From ff7671c7b1b101c070cb018d1d70f98092a49943 Mon Sep 17 00:00:00 2001 From: sictiru Date: Wed, 8 May 2024 18:12:33 -0700 Subject: [PATCH] #1857 Override activity transition API 34+ --- .../java/com/newsblur/activity/ItemsList.java | 11 +-- .../newsblur/util/PendingTransitionUtils.kt | 68 +++++++++++++++++++ .../main/java/com/newsblur/util/UIUtils.java | 4 +- 3 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 clients/android/NewsBlur/app/src/main/java/com/newsblur/util/PendingTransitionUtils.kt diff --git a/clients/android/NewsBlur/app/src/main/java/com/newsblur/activity/ItemsList.java b/clients/android/NewsBlur/app/src/main/java/com/newsblur/activity/ItemsList.java index fc4f4bde2e..275d29acbe 100644 --- a/clients/android/NewsBlur/app/src/main/java/com/newsblur/activity/ItemsList.java +++ b/clients/android/NewsBlur/app/src/main/java/com/newsblur/activity/ItemsList.java @@ -35,6 +35,7 @@ import com.newsblur.util.FeedSet; import com.newsblur.util.FeedUtils; import com.newsblur.util.Log; +import com.newsblur.util.PendingTransitionUtils; import com.newsblur.util.ReadingActionListener; import com.newsblur.util.PrefsUtils; import com.newsblur.util.Session; @@ -82,7 +83,7 @@ protected void onCreate(Bundle bundle) { Trace.beginSection("ItemsListOnCreate"); super.onCreate(bundle); - overridePendingTransition(R.anim.slide_in_from_right, R.anim.slide_out_to_left); + PendingTransitionUtils.overrideEnterTransition(this); contextMenuDelegate = new ItemListContextMenuDelegateImpl(this, feedUtils); viewModel = new ViewModelProvider(this).get(ItemListViewModel.class); @@ -313,13 +314,7 @@ private void handleReadingActivityResult(ActivityResult result) { @Override public void finish() { super.finish(); - /* - * Animate out the list by sliding it to the right and the Main activity in from - * the left. Do this when going back to Main as a subtle hint to the swipe gesture, - * to make the gesture feel more natural, and to override the really ugly transition - * used in some of the newer platforms. - */ - overridePendingTransition(R.anim.slide_in_from_left, R.anim.slide_out_to_right); + PendingTransitionUtils.overrideExitTransition(this); } abstract String getSaveSearchFeedId(); diff --git a/clients/android/NewsBlur/app/src/main/java/com/newsblur/util/PendingTransitionUtils.kt b/clients/android/NewsBlur/app/src/main/java/com/newsblur/util/PendingTransitionUtils.kt new file mode 100644 index 0000000000..60cddb30d8 --- /dev/null +++ b/clients/android/NewsBlur/app/src/main/java/com/newsblur/util/PendingTransitionUtils.kt @@ -0,0 +1,68 @@ +@file:Suppress("DEPRECATION") + +package com.newsblur.util + +import android.app.Activity +import android.os.Build +import com.newsblur.R + +object PendingTransitionUtils { + + @JvmStatic + fun overrideEnterTransition(activity: Activity) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + activity.overrideActivityTransition( + Activity.OVERRIDE_TRANSITION_OPEN, + R.anim.slide_in_from_right, + R.anim.slide_out_to_left, + ) + } else { + activity.overridePendingTransition( + R.anim.slide_in_from_right, + R.anim.slide_out_to_left, + ) + } + } + + @JvmStatic + fun overrideNoEnterTransition(activity: Activity) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + activity.overrideActivityTransition( + Activity.OVERRIDE_TRANSITION_OPEN, + 0, + 0, + ) + } else { + activity.overridePendingTransition( + 0, + 0, + ) + } + } + + @JvmStatic + fun overrideExitTransition(activity: Activity) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + activity.overrideActivityTransition( + Activity.OVERRIDE_TRANSITION_CLOSE, + R.anim.slide_in_from_left, + R.anim.slide_out_to_right, + ) + } else { + activity.overridePendingTransition(R.anim.slide_in_from_left, R.anim.slide_out_to_right) + } + } + + @JvmStatic + fun overrideNoExitTransition(activity: Activity) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + activity.overrideActivityTransition( + Activity.OVERRIDE_TRANSITION_CLOSE, + 0, + 0, + ) + } else { + activity.overridePendingTransition(0, 0) + } + } +} \ No newline at end of file diff --git a/clients/android/NewsBlur/app/src/main/java/com/newsblur/util/UIUtils.java b/clients/android/NewsBlur/app/src/main/java/com/newsblur/util/UIUtils.java index 1c343747ca..ff98ee055c 100644 --- a/clients/android/NewsBlur/app/src/main/java/com/newsblur/util/UIUtils.java +++ b/clients/android/NewsBlur/app/src/main/java/com/newsblur/util/UIUtils.java @@ -232,10 +232,10 @@ public static void restartActivity(final Activity activity) { public void run() { Intent intent = activity.getIntent(); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION); - activity.overridePendingTransition(0, 0); + PendingTransitionUtils.overrideNoExitTransition(activity); activity.finish(); - activity.overridePendingTransition(0, 0); + PendingTransitionUtils.overrideNoEnterTransition(activity); activity.startActivity(intent); } });