summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Adam Powell <adamp@google.com> 2013-10-23 13:26:03 -0700
committer Adam Powell <adamp@google.com> 2013-10-23 14:26:57 -0700
commit40a67888f91c2bb94c8654fbfe402f84795d17cf (patch)
tree7bbbfdf115bfdd90ad99db48f6e39fee65bd4538
parent3e1a9eaca6b5e1c699c9962e3932298751829660 (diff)
Cache Scene objects by layout ID on the scene root
The current tracking of scene objects in a static ThreadLocal is problematic as it leaks the Context associated with the SceneRoot and returns the wrong Scene object if the same layout ID is used across different scene roots. Track Scene objects on the scene root view instead to avoid these issues. Change-Id: I891986897f757f2666897c937b5ebb0ed1d531c1
-rw-r--r--core/java/android/transition/Scene.java17
-rw-r--r--core/res/res/values/ids.xml1
-rw-r--r--core/res/res/values/symbols.xml1
3 files changed, 11 insertions, 8 deletions
diff --git a/core/java/android/transition/Scene.java b/core/java/android/transition/Scene.java
index d798abec5a33..5800bd586bd0 100644
--- a/core/java/android/transition/Scene.java
+++ b/core/java/android/transition/Scene.java
@@ -36,27 +36,28 @@ public final class Scene {
private ViewGroup mSceneRoot;
private ViewGroup mLayout; // alternative to layoutId
Runnable mEnterAction, mExitAction;
- private static ThreadLocal<SparseArray<Scene>> sScenes = new ThreadLocal<SparseArray<Scene>>();
/**
* Returns a Scene described by the resource file associated with the given
- * <code>layoutId</code> parameter. If such a Scene has already been created,
- * that same Scene will be returned. This caching of layoutId-based scenes enables
- * sharing of common scenes between those created in code and those referenced
- * by {@link TransitionManager} XML resource files.
+ * <code>layoutId</code> parameter. If such a Scene has already been created for
+ * the given <code>sceneRoot</code>, that same Scene will be returned.
+ * This caching of layoutId-based scenes enables sharing of common scenes
+ * between those created in code and those referenced by {@link TransitionManager}
+ * XML resource files.
*
* @param sceneRoot The root of the hierarchy in which scene changes
* and transitions will take place.
* @param layoutId The id of a standard layout resource file.
* @param context The context used in the process of inflating
* the layout resource.
- * @return
+ * @return The scene for the given root and layout id
*/
public static Scene getSceneForLayout(ViewGroup sceneRoot, int layoutId, Context context) {
- SparseArray<Scene> scenes = sScenes.get();
+ SparseArray<Scene> scenes = (SparseArray<Scene>) sceneRoot.getTag(
+ com.android.internal.R.id.scene_layoutid_cache);
if (scenes == null) {
scenes = new SparseArray<Scene>();
- sScenes.set(scenes);
+ sceneRoot.setTag(com.android.internal.R.id.scene_layoutid_cache, scenes);
}
Scene scene = scenes.get(layoutId);
if (scene != null) {
diff --git a/core/res/res/values/ids.xml b/core/res/res/values/ids.xml
index 15df295e5784..5c0baaa4998f 100644
--- a/core/res/res/values/ids.xml
+++ b/core/res/res/values/ids.xml
@@ -81,4 +81,5 @@
<item type="id" name="popup_submenu_presenter" />
<item type="id" name="action_bar_spinner" />
<item type="id" name="current_scene" />
+ <item type="id" name="scene_layoutid_cache" />
</resources>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index e17b650ff969..dc0841ab1041 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -55,6 +55,7 @@
<java-symbol type="id" name="clearDefaultHint" />
<java-symbol type="id" name="contentPanel" />
<java-symbol type="id" name="current_scene" />
+ <java-symbol type="id" name="scene_layoutid_cache" />
<java-symbol type="id" name="customPanel" />
<java-symbol type="id" name="datePicker" />
<java-symbol type="id" name="day" />