1c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki/* 2c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * Copyright (C) 2016 The Android Open Source Project 3c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * 4c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * Licensed under the Apache License, Version 2.0 (the "License"); 5c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * you may not use this file except in compliance with the License. 6c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * You may obtain a copy of the License at 7c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * 8c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * http://www.apache.org/licenses/LICENSE-2.0 9c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * 10c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * Unless required by applicable law or agreed to in writing, software 11c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * distributed under the License is distributed on an "AS IS" BASIS, 12c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * See the License for the specific language governing permissions and 14c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * limitations under the License. 15c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki */ 16c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki 17c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Arakipackage android.support.transition; 18c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki 19c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Arakiimport android.content.Context; 20cbba0a52f7d7b593dbb13a138515f066f75cce80Yuichi Arakiimport android.support.annotation.LayoutRes; 21cbba0a52f7d7b593dbb13a138515f066f75cce80Yuichi Arakiimport android.support.annotation.NonNull; 22cbba0a52f7d7b593dbb13a138515f066f75cce80Yuichi Arakiimport android.support.annotation.Nullable; 23c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Arakiimport android.util.SparseArray; 244e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Arakiimport android.view.LayoutInflater; 25c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Arakiimport android.view.View; 26c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Arakiimport android.view.ViewGroup; 27c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki 28c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki/** 29c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * A scene represents the collection of values that various properties in the 30c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * View hierarchy will have when the scene is applied. A Scene can be 31c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * configured to automatically run a Transition when it is applied, which will 32c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * animate the various property changes that take place during the 33c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * scene change. 34c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki */ 35c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Arakipublic class Scene { 36c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki 374e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki private Context mContext; 384e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki private int mLayoutId = -1; 394e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki private ViewGroup mSceneRoot; 404e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki private View mLayout; // alternative to layoutId 414e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki private Runnable mEnterAction, mExitAction; 42c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki 43c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki /** 44c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * Returns a Scene described by the resource file associated with the given 45c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * <code>layoutId</code> parameter. If such a Scene has already been created for 46c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * the given <code>sceneRoot</code>, that same Scene will be returned. 47c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * This caching of layoutId-based scenes enables sharing of common scenes 48c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * between those created in code and those referenced by {@link TransitionManager} 49c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * XML resource files. 50c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * 51c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * @param sceneRoot The root of the hierarchy in which scene changes 52c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * and transitions will take place. 53c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * @param layoutId The id of a standard layout resource file. 54c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * @param context The context used in the process of inflating 55c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * the layout resource. 56c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * @return The scene for the given root and layout id 57c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki */ 58cbba0a52f7d7b593dbb13a138515f066f75cce80Yuichi Araki @NonNull 59cbba0a52f7d7b593dbb13a138515f066f75cce80Yuichi Araki public static Scene getSceneForLayout(@NonNull ViewGroup sceneRoot, @LayoutRes int layoutId, 60cbba0a52f7d7b593dbb13a138515f066f75cce80Yuichi Araki @NonNull Context context) { 61c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki @SuppressWarnings("unchecked") 62c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki SparseArray<Scene> scenes = 63c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki (SparseArray<Scene>) sceneRoot.getTag(R.id.transition_scene_layoutid_cache); 64c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki if (scenes == null) { 65c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki scenes = new SparseArray<>(); 66c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki sceneRoot.setTag(R.id.transition_scene_layoutid_cache, scenes); 67c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki } 68c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki Scene scene = scenes.get(layoutId); 69c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki if (scene != null) { 70c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki return scene; 71c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki } else { 724e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki scene = new Scene(sceneRoot, layoutId, context); 73c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki scenes.put(layoutId, scene); 74c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki return scene; 75c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki } 76c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki } 77c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki 784e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki /** 794e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * Constructs a Scene with no information about how values will change 804e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * when this scene is applied. This constructor might be used when 814e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * a Scene is created with the intention of being dynamically configured, 824e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * through setting {@link #setEnterAction(Runnable)} and possibly 834e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * {@link #setExitAction(Runnable)}. 844e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * 854e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * @param sceneRoot The root of the hierarchy in which scene changes 864e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * and transitions will take place. 874e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki */ 884e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki public Scene(@NonNull ViewGroup sceneRoot) { 894e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki mSceneRoot = sceneRoot; 904e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki } 914e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki 924e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki /** 934e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * Constructs a Scene which, when entered, will remove any 944e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * children from the sceneRoot container and will inflate and add 954e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * the hierarchy specified by the layoutId resource file. 964e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * 974e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * <p>This method is hidden because layoutId-based scenes should be 984e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * created by the caching factory method {@link Scene#getCurrentScene(View)}.</p> 994e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * 1004e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * @param sceneRoot The root of the hierarchy in which scene changes 1014e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * and transitions will take place. 1024e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * @param layoutId The id of a resource file that defines the view 1034e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * hierarchy of this scene. 1044e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * @param context The context used in the process of inflating 1054e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * the layout resource. 1064e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki */ 1074e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki private Scene(ViewGroup sceneRoot, int layoutId, Context context) { 1084e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki mContext = context; 1094e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki mSceneRoot = sceneRoot; 1104e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki mLayoutId = layoutId; 1114e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki } 1124e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki 1134e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki /** 1144e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * Constructs a Scene which, when entered, will remove any 1154e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * children from the sceneRoot container and add the layout 1164e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * object as a new child of that container. 1174e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * 1184e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * @param sceneRoot The root of the hierarchy in which scene changes 1194e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * and transitions will take place. 1204e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * @param layout The view hierarchy of this scene, added as a child 1214e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * of sceneRoot when this scene is entered. 1224e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki */ 1234e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki public Scene(@NonNull ViewGroup sceneRoot, @NonNull View layout) { 1244e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki mSceneRoot = sceneRoot; 1254e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki mLayout = layout; 126c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki } 127c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki 128c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki /** 129c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * Gets the root of the scene, which is the root of the view hierarchy 130c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * affected by changes due to this scene, and which will be animated 131c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * when this scene is entered. 132c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * 133c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * @return The root of the view hierarchy affected by this scene. 134c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki */ 135cbba0a52f7d7b593dbb13a138515f066f75cce80Yuichi Araki @NonNull 136c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki public ViewGroup getSceneRoot() { 1374e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki return mSceneRoot; 138c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki } 139c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki 140c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki /** 141c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * Exits this scene, if it is the current scene 142c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * on the scene's {@link #getSceneRoot() scene root}. The current scene is 143c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * set when {@link #enter() entering} a scene. 144c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * Exiting a scene runs the {@link #setExitAction(Runnable) exit action} 145c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * if there is one. 146c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki */ 147c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki public void exit() { 1484e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki if (getCurrentScene(mSceneRoot) == this) { 1494e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki if (mExitAction != null) { 1504e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki mExitAction.run(); 1514e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki } 1524e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki } 153c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki } 154c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki 155c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki /** 156c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * Enters this scene, which entails changing all values that 157c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * are specified by this scene. These may be values associated 158c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * with a layout view group or layout resource file which will 159c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * now be added to the scene root, or it may be values changed by 160c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * an {@link #setEnterAction(Runnable)} enter action}, or a 161c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * combination of the these. No transition will be run when the 162c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * scene is entered. To get transition behavior in scene changes, 163c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * use one of the methods in {@link android.support.transition.TransitionManager} instead. 164c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki */ 165c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki public void enter() { 1664e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki // Apply layout change, if any 1674e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki if (mLayoutId > 0 || mLayout != null) { 1684e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki // empty out parent container before adding to it 1694e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki getSceneRoot().removeAllViews(); 1704e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki 1714e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki if (mLayoutId > 0) { 1724e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki LayoutInflater.from(mContext).inflate(mLayoutId, mSceneRoot); 1734e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki } else { 1744e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki mSceneRoot.addView(mLayout); 1754e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki } 1764e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki } 1774e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki 1784e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki // Notify next scene that it is entering. Subclasses may override to configure scene. 1794e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki if (mEnterAction != null) { 1804e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki mEnterAction.run(); 1814e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki } 1824e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki 1834e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki setCurrentScene(mSceneRoot, this); 1844e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki } 1854e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki 1864e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki /** 1874e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * Set the scene that the given view is in. The current scene is set only 1884e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * on the root view of a scene, not for every view in that hierarchy. This 1894e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * information is used by Scene to determine whether there is a previous 1904e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * scene which should be exited before the new scene is entered. 1914e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * 1924e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * @param view The view on which the current scene is being set 1934e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki */ 1944e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki static void setCurrentScene(View view, Scene scene) { 1954e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki view.setTag(R.id.transition_current_scene, scene); 1964e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki } 1974e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki 1984e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki /** 1994e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * Gets the current {@link Scene} set on the given view. A scene is set on a view 2004e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * only if that view is the scene root. 2014e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * 2024e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * @return The current Scene set on this view. A value of null indicates that 2034e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * no Scene is currently set. 2044e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki */ 2054e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki static Scene getCurrentScene(View view) { 2064e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki return (Scene) view.getTag(R.id.transition_current_scene); 207c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki } 208c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki 209c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki /** 210c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * Scenes that are not defined with layout resources or 211c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * hierarchies, or which need to perform additional steps 212c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * after those hierarchies are changed to, should set an enter 213c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * action, and possibly an exit action as well. An enter action 214c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * will cause Scene to call back into application code to do 215c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * anything else the application needs after transitions have 216c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * captured pre-change values and after any other scene changes 217c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * have been applied, such as the layout (if any) being added to 218c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * the view hierarchy. After this method is called, Transitions will 219c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * be played. 220c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * 221c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * @param action The runnable whose {@link Runnable#run() run()} method will 222c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * be called when this scene is entered 223c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * @see #setExitAction(Runnable) 224c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * @see android.support.transition.Scene(android.view.ViewGroup, android.view.ViewGroup) 225c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki */ 226cbba0a52f7d7b593dbb13a138515f066f75cce80Yuichi Araki public void setEnterAction(@Nullable Runnable action) { 2274e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki mEnterAction = action; 228c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki } 229c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki 230c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki /** 231c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * Scenes that are not defined with layout resources or 232c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * hierarchies, or which need to perform additional steps 233c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * after those hierarchies are changed to, should set an enter 234c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * action, and possibly an exit action as well. An exit action 235c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * will cause Scene to call back into application code to do 236c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * anything the application needs to do after applicable transitions have 237c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * captured pre-change values, but before any other scene changes 238c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * have been applied, such as the new layout (if any) being added to 239c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * the view hierarchy. After this method is called, the next scene 240c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * will be entered, including a call to {@link #setEnterAction(Runnable)} 241c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * if an enter action is set. 242c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * 243c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * @see #setEnterAction(Runnable) 244c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki * @see android.support.transition.Scene(android.view.ViewGroup, android.view.ViewGroup) 245c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki */ 246cbba0a52f7d7b593dbb13a138515f066f75cce80Yuichi Araki public void setExitAction(@Nullable Runnable action) { 2474e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki mExitAction = action; 2484e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki } 2494e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki 2504e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki /** 2514e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * Returns whether this Scene was created by a layout resource file, determined 2524e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * by the layoutId passed into 2534e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki * {@link #getSceneForLayout(ViewGroup, int, Context)}. 2544e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki */ 2554e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki boolean isCreatedFromLayoutResource() { 2564e5a72756eb66c31baf1a3054c66520f1c3f5b8cYuichi Araki return (mLayoutId > 0); 257c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki } 258c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki 259c876cd8f9334e2423de00836009f3fd7a9566938Yuichi Araki} 260