diff options
| author | Andrey Kulikov <andreykulikov@google.com> | 2018-10-31 14:57:22 +0000 |
|---|---|---|
| committer | Andrey Kulikov <andreykulikov@google.com> | 2018-11-01 12:33:53 +0000 |
| commit | a4ae81857a7eb84d019ea7855b24ba9fe69fbf50 (patch) | |
| tree | 7333b9768e017821899c61b0dfe72a25064eebe9 /core/java/android/transition/Scene.java | |
| parent | d33b50a66acde10cf35fecfb63ae194a62483c0e (diff) | |
Make transitions Scene.getCurrentScene() public
I pretty sure the getter method Scene.getCurrentScene() should be promoted to be public. This method is the only option for developers to understand is the sceneRoot already in the scene they need. Otherwise they have to introduce their own states and sync it with all scene changes which is more error-prone. To make it simpler to developers we can just make the method public. As an example of usage:
void displayMessages(List<Message> messages) {
if (!messages.isEmpty()) {
if (Scene.getCurrentScene(root) != messagesScene) {
TransitionManager.go(messagesScene);
MyAnalytics.trackDisplayMessages();
(... more initialization ... )
}
messagesView.display(messages);
}
}
Test: added a cts test for getCurrentScene
Change in AndroidX: aosp/807055
Bug: 118720709
Change-Id: Ic90e3576a82b5ab9a88e38e396efd49875968011
Diffstat (limited to 'core/java/android/transition/Scene.java')
| -rw-r--r-- | core/java/android/transition/Scene.java | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/core/java/android/transition/Scene.java b/core/java/android/transition/Scene.java index 1bdcff98ff17..7e499f29122a 100644 --- a/core/java/android/transition/Scene.java +++ b/core/java/android/transition/Scene.java @@ -16,6 +16,8 @@ package android.transition; +import android.annotation.NonNull; +import android.annotation.Nullable; import android.annotation.UnsupportedAppUsage; import android.content.Context; import android.util.SparseArray; @@ -196,22 +198,24 @@ public final class Scene { * information is used by Scene to determine whether there is a previous * scene which should be exited before the new scene is entered. * - * @param view The view on which the current scene is being set + * @param sceneRoot The view on which the current scene is being set */ @UnsupportedAppUsage - static void setCurrentScene(View view, Scene scene) { - view.setTagInternal(com.android.internal.R.id.current_scene, scene); + static void setCurrentScene(@NonNull View sceneRoot, @Nullable Scene scene) { + sceneRoot.setTagInternal(com.android.internal.R.id.current_scene, scene); } /** * Gets the current {@link Scene} set on the given view. A scene is set on a view * only if that view is the scene root. * + * @param sceneRoot The view on which the current scene will be returned * @return The current Scene set on this view. A value of null indicates that * no Scene is currently set. */ - static Scene getCurrentScene(View view) { - return (Scene) view.getTag(com.android.internal.R.id.current_scene); + @Nullable + public static Scene getCurrentScene(@NonNull View sceneRoot) { + return (Scene) sceneRoot.getTag(com.android.internal.R.id.current_scene); } /** |
