-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix ActivityUtils.overrideActivityTransition() to be able to be calle…
…d from Activity.onCreate()
- Loading branch information
Showing
3 changed files
with
28 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 16 additions & 3 deletions
19
app/src/main/java/be/digitalia/fosdem/utils/ActivityUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,37 @@ | ||
package be.digitalia.fosdem.utils | ||
|
||
import android.app.Activity | ||
import android.os.Build | ||
import androidx.activity.ComponentActivity | ||
import androidx.annotation.AnimRes | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.LifecycleEventObserver | ||
|
||
object ActivityUtils { | ||
const val OVERRIDE_TRANSITION_OPEN = 0 | ||
const val OVERRIDE_TRANSITION_CLOSE = 1 | ||
|
||
/** | ||
* Call this method in Activity.onCreate() to configure the open or close transitions. | ||
*/ | ||
@Suppress("DEPRECATION") | ||
fun overrideActivityTransition( | ||
activity: Activity, | ||
activity: ComponentActivity, | ||
overrideType: Int, | ||
@AnimRes enterAnim: Int, | ||
@AnimRes exitAnim: Int | ||
) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { | ||
activity.overrideActivityTransition(overrideType, enterAnim, exitAnim) | ||
} else { | ||
activity.overridePendingTransition(enterAnim, exitAnim) | ||
if (overrideType == OVERRIDE_TRANSITION_OPEN) { | ||
activity.overridePendingTransition(enterAnim, exitAnim) | ||
} else { | ||
activity.lifecycle.addObserver(LifecycleEventObserver { _, event -> | ||
if (event == Lifecycle.Event.ON_PAUSE && activity.isFinishing) { | ||
activity.overridePendingTransition(enterAnim, exitAnim) | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
} |