@Test public void testGetSceneForLayout_cache() { TransitionActivity activity = rule.getActivity(); ViewGroup root = activity.getRoot(); Scene scene = Scene.getSceneForLayout(root, R.layout.support_scene0, activity); assertThat("getSceneForLayout should return the same instance for subsequent calls", Scene.getSceneForLayout(root, R.layout.support_scene0, activity), is(sameInstance(scene))); }
@NonNull public static Scene getSceneForLayout(@NonNull ViewGroup sceneRoot, @LayoutRes int layoutId, @NonNull Context context) { @SuppressWarnings("unchecked") SparseArray<Scene> scenes = (SparseArray<Scene>) sceneRoot.getTag(R.id.transition_scene_layoutid_cache); if (scenes == null) { scenes = new SparseArray<>(); sceneRoot.setTag(R.id.transition_scene_layoutid_cache, scenes); } Scene scene = scenes.get(layoutId); if (scene != null) { return scene; } else { scene = new Scene(sceneRoot, layoutId, context); scenes.put(layoutId, scene); return scene; } }
Scene { @NonNull public static Scene getSceneForLayout(@NonNull ViewGroup sceneRoot, @LayoutRes int layoutId, @NonNull Context context) { @SuppressWarnings("unchecked") SparseArray<Scene> scenes = (SparseArray<Scene>) sceneRoot.getTag(R.id.transition_scene_layoutid_cache); if (scenes == null) { scenes = new SparseArray<>(); sceneRoot.setTag(R.id.transition_scene_layoutid_cache, scenes); } Scene scene = scenes.get(layoutId); if (scene != null) { return scene; } else { scene = new Scene(sceneRoot, layoutId, context); scenes.put(layoutId, scene); return scene; } } }
Scene { @NonNull public static Scene getSceneForLayout(@NonNull ViewGroup sceneRoot, @LayoutRes int layoutId, @NonNull Context context) { @SuppressWarnings("unchecked") SparseArray<Scene> scenes = (SparseArray<Scene>) sceneRoot.getTag(R.id.transition_scene_layoutid_cache); if (scenes == null) { scenes = new SparseArray<>(); sceneRoot.setTag(R.id.transition_scene_layoutid_cache, scenes); } Scene scene = scenes.get(layoutId); if (scene != null) { return scene; } else { scene = new Scene(sceneRoot, layoutId, context); scenes.put(layoutId, scene); return scene; } } Scene(@NonNull ViewGroup sceneRoot); private  Scene(ViewGroup sceneRoot, int layoutId, Context context);  Scene(@NonNull ViewGroup sceneRoot, @NonNull View layout); }
Scene { @NonNull public static Scene getSceneForLayout(@NonNull ViewGroup sceneRoot, @LayoutRes int layoutId, @NonNull Context context) { @SuppressWarnings("unchecked") SparseArray<Scene> scenes = (SparseArray<Scene>) sceneRoot.getTag(R.id.transition_scene_layoutid_cache); if (scenes == null) { scenes = new SparseArray<>(); sceneRoot.setTag(R.id.transition_scene_layoutid_cache, scenes); } Scene scene = scenes.get(layoutId); if (scene != null) { return scene; } else { scene = new Scene(sceneRoot, layoutId, context); scenes.put(layoutId, scene); return scene; } } Scene(@NonNull ViewGroup sceneRoot); private  Scene(ViewGroup sceneRoot, int layoutId, Context context);  Scene(@NonNull ViewGroup sceneRoot, @NonNull View layout); @NonNull static Scene getSceneForLayout(@NonNull ViewGroup sceneRoot, @LayoutRes int layoutId,
            @NonNull Context context); @NonNull ViewGroup getSceneRoot(); void exit(); void enter(); void setEnterAction(@Nullable Runnable action); void setExitAction(@Nullable Runnable action); }
Scene { @NonNull public static Scene getSceneForLayout(@NonNull ViewGroup sceneRoot, @LayoutRes int layoutId, @NonNull Context context) { @SuppressWarnings("unchecked") SparseArray<Scene> scenes = (SparseArray<Scene>) sceneRoot.getTag(R.id.transition_scene_layoutid_cache); if (scenes == null) { scenes = new SparseArray<>(); sceneRoot.setTag(R.id.transition_scene_layoutid_cache, scenes); } Scene scene = scenes.get(layoutId); if (scene != null) { return scene; } else { scene = new Scene(sceneRoot, layoutId, context); scenes.put(layoutId, scene); return scene; } } Scene(@NonNull ViewGroup sceneRoot); private  Scene(ViewGroup sceneRoot, int layoutId, Context context);  Scene(@NonNull ViewGroup sceneRoot, @NonNull View layout); @NonNull static Scene getSceneForLayout(@NonNull ViewGroup sceneRoot, @LayoutRes int layoutId,
            @NonNull Context context); @NonNull ViewGroup getSceneRoot(); void exit(); void enter(); void setEnterAction(@Nullable Runnable action); void setExitAction(@Nullable Runnable action);  }