Scene.java revision 40a67888f91c2bb94c8654fbfe402f84795d17cf
1faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase/* 2faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * Copyright (C) 2013 The Android Open Source Project 3faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * 4faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * Licensed under the Apache License, Version 2.0 (the "License"); 5faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * you may not use this file except in compliance with the License. 6faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * You may obtain a copy of the License at 7faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * 8faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * http://www.apache.org/licenses/LICENSE-2.0 9faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * 10faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * Unless required by applicable law or agreed to in writing, software 11faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * distributed under the License is distributed on an "AS IS" BASIS, 12faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * See the License for the specific language governing permissions and 14faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * limitations under the License. 15faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase */ 166ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase 17d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haasepackage android.transition; 18faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase 19faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haaseimport android.content.Context; 20d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haaseimport android.util.SparseArray; 21faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haaseimport android.view.LayoutInflater; 22d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haaseimport android.view.View; 23faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haaseimport android.view.ViewGroup; 24faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase 25faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase/** 26faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * A scene represents the collection of values that various properties in the 27faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * View hierarchy will have when the scene is applied. A Scene can be 28faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * configured to automatically run a Transition when it is applied, which will 29faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * animate the various property changes that take place during the 30faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * scene change. 31faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase */ 32faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haasepublic final class Scene { 33faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase 34faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase private Context mContext; 35faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase private int mLayoutId = -1; 36faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase private ViewGroup mSceneRoot; 37faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase private ViewGroup mLayout; // alternative to layoutId 38faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase Runnable mEnterAction, mExitAction; 39d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase 40d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase /** 41d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * Returns a Scene described by the resource file associated with the given 4240a67888f91c2bb94c8654fbfe402f84795d17cfAdam Powell * <code>layoutId</code> parameter. If such a Scene has already been created for 4340a67888f91c2bb94c8654fbfe402f84795d17cfAdam Powell * the given <code>sceneRoot</code>, that same Scene will be returned. 4440a67888f91c2bb94c8654fbfe402f84795d17cfAdam Powell * This caching of layoutId-based scenes enables sharing of common scenes 4540a67888f91c2bb94c8654fbfe402f84795d17cfAdam Powell * between those created in code and those referenced by {@link TransitionManager} 4640a67888f91c2bb94c8654fbfe402f84795d17cfAdam Powell * XML resource files. 47d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * 48d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * @param sceneRoot The root of the hierarchy in which scene changes 49d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * and transitions will take place. 50d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * @param layoutId The id of a standard layout resource file. 51d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * @param context The context used in the process of inflating 52d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * the layout resource. 5340a67888f91c2bb94c8654fbfe402f84795d17cfAdam Powell * @return The scene for the given root and layout id 54d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase */ 55d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase public static Scene getSceneForLayout(ViewGroup sceneRoot, int layoutId, Context context) { 5640a67888f91c2bb94c8654fbfe402f84795d17cfAdam Powell SparseArray<Scene> scenes = (SparseArray<Scene>) sceneRoot.getTag( 5740a67888f91c2bb94c8654fbfe402f84795d17cfAdam Powell com.android.internal.R.id.scene_layoutid_cache); 58d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase if (scenes == null) { 59d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase scenes = new SparseArray<Scene>(); 6040a67888f91c2bb94c8654fbfe402f84795d17cfAdam Powell sceneRoot.setTag(com.android.internal.R.id.scene_layoutid_cache, scenes); 61d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase } 62d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase Scene scene = scenes.get(layoutId); 63d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase if (scene != null) { 64d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase return scene; 65d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase } else { 66d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase scene = new Scene(sceneRoot, layoutId, context); 67d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase scenes.put(layoutId, scene); 68d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase return scene; 69d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase } 70d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase } 71faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase 72faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase /** 73faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * Constructs a Scene with no information about how values will change 74faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * when this scene is applied. This constructor might be used when 75faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * a Scene is created with the intention of being dynamically configured, 76faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * through setting {@link #setEnterAction(Runnable)} and possibly 77faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * {@link #setExitAction(Runnable)}. 78faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * 79faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * @param sceneRoot The root of the hierarchy in which scene changes 80faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * and transitions will take place. 81faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase */ 82faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase public Scene(ViewGroup sceneRoot) { 83faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase mSceneRoot = sceneRoot; 84faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase } 85faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase 86faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase /** 87faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * Constructs a Scene which, when entered, will remove any 88faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * children from the sceneRoot container and will inflate and add 89faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * the hierarchy specified by the layoutId resource file. 90faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * 91d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * <p>This method is hidden because layoutId-based scenes should be 92d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * created by the caching factory method {@link Scene#getCurrentScene(View)}.</p> 93d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * 94faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * @param sceneRoot The root of the hierarchy in which scene changes 95faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * and transitions will take place. 96faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * @param layoutId The id of a resource file that defines the view 97faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * hierarchy of this scene. 98faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * @param context The context used in the process of inflating 99faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * the layout resource. 100faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase */ 101d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase private Scene(ViewGroup sceneRoot, int layoutId, Context context) { 102faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase mContext = context; 103faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase mSceneRoot = sceneRoot; 104faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase mLayoutId = layoutId; 105faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase } 106faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase 107faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase /** 108faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * Constructs a Scene which, when entered, will remove any 109faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * children from the sceneRoot container and add the layout 110faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * object as a new child of that container. 111faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * 112faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * @param sceneRoot The root of the hierarchy in which scene changes 113faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * and transitions will take place. 114d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * @param layout The view hierarchy of this scene, added as a child 115faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * of sceneRoot when this scene is entered. 116faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase */ 117faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase public Scene(ViewGroup sceneRoot, ViewGroup layout) { 118faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase mSceneRoot = sceneRoot; 119faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase mLayout = layout; 120faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase } 121faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase 122faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase /** 123faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * Gets the root of the scene, which is the root of the view hierarchy 124faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * affected by changes due to this scene, and which will be animated 125faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * when this scene is entered. 126faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * 127faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * @return The root of the view hierarchy affected by this scene. 128faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase */ 129faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase public ViewGroup getSceneRoot() { 130faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase return mSceneRoot; 131faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase } 132faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase 133faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase /** 134d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * Exits this scene, if it is the current scene 135d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * on the scene's {@link #getSceneRoot() scene root}. The current scene is 136d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * set when {@link #enter() entering} a scene. 137d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * Exiting a scene runs the {@link #setExitAction(Runnable) exit action} 138faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * if there is one. 139faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase */ 140faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase public void exit() { 141d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase if (getCurrentScene(mSceneRoot) == this) { 142faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase if (mExitAction != null) { 143faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase mExitAction.run(); 144faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase } 145faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase } 146faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase } 147faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase 148faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase /** 149faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * Enters this scene, which entails changing all values that 150faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * are specified by this scene. These may be values associated 151faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * with a layout view group or layout resource file which will 152faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * now be added to the scene root, or it may be values changed by 153faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * an {@link #setEnterAction(Runnable)} enter action}, or a 154faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * combination of the these. No transition will be run when the 155faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * scene is entered. To get transition behavior in scene changes, 156faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * use one of the methods in {@link TransitionManager} instead. 157faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase */ 158faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase public void enter() { 159faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase 160faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase // Apply layout change, if any 161b7a7fc9d233bad507ce893882352618b13647058Chet Haase if (mLayoutId > 0 || mLayout != null) { 162d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase // empty out parent container before adding to it 163faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase getSceneRoot().removeAllViews(); 164faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase 165b7a7fc9d233bad507ce893882352618b13647058Chet Haase if (mLayoutId > 0) { 166faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase LayoutInflater.from(mContext).inflate(mLayoutId, mSceneRoot); 167faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase } else { 168faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase mSceneRoot.addView(mLayout); 169faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase } 170faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase } 171faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase 172faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase // Notify next scene that it is entering. Subclasses may override to configure scene. 173faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase if (mEnterAction != null) { 174faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase mEnterAction.run(); 175faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase } 176faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase 177d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase setCurrentScene(mSceneRoot, this); 178d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase } 179d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase 180d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase /** 181d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * Set the scene that the given view is in. The current scene is set only 182d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * on the root view of a scene, not for every view in that hierarchy. This 183d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * information is used by Scene to determine whether there is a previous 184d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * scene which should be exited before the new scene is entered. 185d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * 186d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * @param view The view on which the current scene is being set 187d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase */ 188d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase static void setCurrentScene(View view, Scene scene) { 189d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase view.setTagInternal(com.android.internal.R.id.current_scene, scene); 190d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase } 191d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase 192d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase /** 193d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * Gets the current {@link Scene} set on the given view. A scene is set on a view 194d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * only if that view is the scene root. 195d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * 196d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * @return The current Scene set on this view. A value of null indicates that 197d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * no Scene is currently set. 198d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase */ 199d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase static Scene getCurrentScene(View view) { 200d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase return (Scene) view.getTag(com.android.internal.R.id.current_scene); 201faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase } 202faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase 203faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase /** 204faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * Scenes that are not defined with layout resources or 205faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * hierarchies, or which need to perform additional steps 206faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * after those hierarchies are changed to, should set an enter 207faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * action, and possibly an exit action as well. An enter action 208faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * will cause Scene to call back into application code to do 209faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * anything else the application needs after transitions have 210faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * captured pre-change values and after any other scene changes 211faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * have been applied, such as the layout (if any) being added to 212faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * the view hierarchy. After this method is called, Transitions will 213faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * be played. 214faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * 215faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * @param action The runnable whose {@link Runnable#run() run()} method will 216faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * be called when this scene is entered 217faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * @see #setExitAction(Runnable) 218faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * @see Scene#Scene(ViewGroup, int, Context) 219faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * @see Scene#Scene(ViewGroup, ViewGroup) 220faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase */ 221faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase public void setEnterAction(Runnable action) { 222faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase mEnterAction = action; 223faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase } 224faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase 225faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase /** 226faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * Scenes that are not defined with layout resources or 227faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * hierarchies, or which need to perform additional steps 228faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * after those hierarchies are changed to, should set an enter 229faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * action, and possibly an exit action as well. An exit action 230faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * will cause Scene to call back into application code to do 231faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * anything the application needs to do after applicable transitions have 232faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * captured pre-change values, but before any other scene changes 233faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * have been applied, such as the new layout (if any) being added to 234faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * the view hierarchy. After this method is called, the next scene 235faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * will be entered, including a call to {@link #setEnterAction(Runnable)} 236faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * if an enter action is set. 237faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * 238faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * @see #setEnterAction(Runnable) 239faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * @see Scene#Scene(ViewGroup, int, Context) 240faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * @see Scene#Scene(ViewGroup, ViewGroup) 241faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase */ 242faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase public void setExitAction(Runnable action) { 243faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase mExitAction = action; 244faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase } 245faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase 246b7a7fc9d233bad507ce893882352618b13647058Chet Haase 247b7a7fc9d233bad507ce893882352618b13647058Chet Haase /** 248b7a7fc9d233bad507ce893882352618b13647058Chet Haase * Returns whether this Scene was created by a layout resource file, determined 249b7a7fc9d233bad507ce893882352618b13647058Chet Haase * by the layoutId passed into 250b7a7fc9d233bad507ce893882352618b13647058Chet Haase * {@link #getSceneForLayout(android.view.ViewGroup, int, android.content.Context)}. 251b7a7fc9d233bad507ce893882352618b13647058Chet Haase * This is called by TransitionManager to determine whether it is safe for views from 252b7a7fc9d233bad507ce893882352618b13647058Chet Haase * this scene to be removed from their parents when the scene is exited, which is 253b7a7fc9d233bad507ce893882352618b13647058Chet Haase * used by {@link Fade} to fade these views out (the views must be removed from 254b7a7fc9d233bad507ce893882352618b13647058Chet Haase * their parent in order to add them to the overlay for fading purposes). If a 255b7a7fc9d233bad507ce893882352618b13647058Chet Haase * Scene is not based on a resource file, then the impact of removing views 256b7a7fc9d233bad507ce893882352618b13647058Chet Haase * arbitrarily is unknown and should be avoided. 257b7a7fc9d233bad507ce893882352618b13647058Chet Haase */ 258b7a7fc9d233bad507ce893882352618b13647058Chet Haase boolean isCreatedFromLayoutResource() { 259b7a7fc9d233bad507ce893882352618b13647058Chet Haase return (mLayoutId > 0); 260b7a7fc9d233bad507ce893882352618b13647058Chet Haase } 261faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase}