content: package androidx.transition;
  
  import android.view.View;
  import android.view.ViewGroup;
  import android.view.ViewTreeObserver;
  import androidx.collection.ArrayMap;
  import androidx.core.view.ViewCompat;
  import java.lang.ref.WeakReference;
  import java.util.ArrayList;
  import java.util.Iterator;
  
  public class TransitionManager {
      private static final String LOG_TAG = "TransitionManager";
      private static Transition sDefaultTransition = new AutoTransition();
      static ArrayList<ViewGroup> sPendingTransitions = new ArrayList<>();
      private static ThreadLocal<WeakReference<ArrayMap<ViewGroup, ArrayList<Transition>>>> sRunningTransitions = new ThreadLocal<>();
      private ArrayMap<Scene, ArrayMap<Scene, Transition>> mScenePairTransitions = new ArrayMap<>();
      private ArrayMap<Scene, Transition> mSceneTransitions = new ArrayMap<>();
  
      private static class MultiListener implements ViewTreeObserver.OnPreDrawListener, View.OnAttachStateChangeListener {
          ViewGroup mSceneRoot;
          Transition mTransition;
  
          MultiListener(Transition transition, ViewGroup sceneRoot) {
              this.mTransition = transition;
              this.mSceneRoot = sceneRoot;
          }
  
          private void removeListeners() {
              this.mSceneRoot.getViewTreeObserver().removeOnPreDrawListener(this);
              this.mSceneRoot.removeOnAttachStateChangeListener(this);
          }
  
          public boolean onPreDraw() {
              removeListeners();
              if (!TransitionManager.sPendingTransitions.remove(this.mSceneRoot)) {
                  return true;
              }
              final ArrayMap<ViewGroup, ArrayList<Transition>> runningTransitions = TransitionManager.getRunningTransitions();
              ArrayList arrayList = runningTransitions.get(this.mSceneRoot);
              ArrayList arrayList2 = null;
              if (arrayList == null) {
                  arrayList = new ArrayList();
                  runningTransitions.put(this.mSceneRoot, arrayList);
              } else if (arrayList.size() > 0) {
                  arrayList2 = new ArrayList(arrayList);
              }
              arrayList.add(this.mTransition);
              this.mTransition.addListener(new TransitionListenerAdapter() {
                  public void onTransitionEnd(Transition transition) {
                      ((ArrayList) runningTransitions.get(MultiListener.this.mSceneRoot)).remove(transition);
                      transition.removeListener(this);
                  }
              });
              this.mTransition.captureValues(this.mSceneRoot, false);
              if (arrayList2 != null) {
                  Iterator it = arrayList2.iterator();
                  while (it.hasNext()) {
                      ((Transition) it.next()).resume(this.mSceneRoot);
                  }
              }
              this.mTransition.playTransition(this.mSceneRoot);
              return true;
          }
  
          public void onViewAttachedToWindow(View v) {
          }
  
          public void onViewDetachedFromWindow(View v) {
              removeListeners();
              TransitionManager.sPendingTransitions.remove(this.mSceneRoot);
              ArrayList arrayList = TransitionManager.getRunningTransitions().get(this.mSceneRoot);
              if (arrayList != null && arrayList.size() > 0) {
                  Iterator it = arrayList.iterator();
                  while (it.hasNext()) {
                      ((Transition) it.next()).resume(this.mSceneRoot);
                  }
              }
              this.mTransition.clearValues(true);
          }
      }
  
      public static void beginDelayedTransition(ViewGroup sceneRoot) {
          beginDelayedTransition(sceneRoot, (Transition) null);
      }
  
      public static void beginDelayedTransition(ViewGroup sceneRoot, Transition transition) {
          if (!sPendingTransitions.contains(sceneRoot) && ViewCompat.isLaidOut(sceneRoot)) {
              sPendingTransitions.add(sceneRoot);
              if (transition == null) {
                  transition = sDefaultTransition;
              }
              Transition clone = transition.clone();
              sceneChangeSetup(sceneRoot, clone);
              Scene.setCurrentScene(sceneRoot, (Scene) null);
              sceneChangeRunTransition(sceneRoot, clone);
          }
      }
  
      private static void changeScene(Scene scene, Transition transition) {
          ViewGroup sceneRoot = scene.getSceneRoot();
          if (!sPendingTransitions.contains(sceneRoot)) {
              Scene currentScene = Scene.getCurrentScene(sceneRoot);
              if (transition == null) {
                  if (currentScene != null) {
                      currentScene.exit();
                  }
                  scene.enter();
                  return;
              }
              sPendingTransitions.add(sceneRoot);
              Transition clone = transition.clone();
              clone.setSceneRoot(sceneRoot);
              if (currentScene != null && currentScene.isCreatedFromLayoutResource()) {
                  clone.setCanRemoveViews(true);
              }
              sceneChangeSetup(sceneRoot, clone);
              scene.enter();
              sceneChangeRunTransition(sceneRoot, clone);
          }
      }
  
      public static void endTransitions(ViewGroup sceneRoot) {
          sPendingTransitions.remove(sceneRoot);
          ArrayList arrayList = getRunningTransitions().get(sceneRoot);
          if (arrayList != null && !arrayList.isEmpty()) {
              ArrayList arrayList2 = new ArrayList(arrayList);
              for (int size = arrayList2.size() - 1; size >= 0; size--) {
                  ((Transition) arrayList2.get(size)).forceToEnd(sceneRoot);
              }
          }
      }
  
      static ArrayMap<ViewGroup, ArrayList<Transition>> getRunningTransitions() {
          ArrayMap<ViewGroup, ArrayList<Transition>> arrayMap;
          WeakReference weakReference = sRunningTransitions.get();
          if (weakReference != null && (arrayMap = (ArrayMap) weakReference.get()) != null) {
              return arrayMap;
          }
          ArrayMap<ViewGroup, ArrayList<Transition>> arrayMap2 = new ArrayMap<>();
          sRunningTransitions.set(new WeakReference(arrayMap2));
          return arrayMap2;
      }
  
      private Transition getTransition(Scene scene) {
          Scene currentScene;
          ArrayMap arrayMap;
          Transition transition;
          ViewGroup sceneRoot = scene.getSceneRoot();
          if (sceneRoot != null && (currentScene = Scene.getCurrentScene(sceneRoot)) != null && (arrayMap = this.mScenePairTransitions.get(scene)) != null && (transition = (Transition) arrayMap.get(currentScene)) != null) {
              return transition;
          }
          Transition transition2 = this.mSceneTransitions.get(scene);
          return transition2 != null ? transition2 : sDefaultTransition;
      }
  
      public static void go(Scene scene) {
          changeScene(scene, sDefaultTransition);
      }
  
      public static void go(Scene scene, Transition transition) {
          changeScene(scene, transition);
      }
  
      private static void sceneChangeRunTransition(ViewGroup sceneRoot, Transition transition) {
          if (transition != null && sceneRoot != null) {
              MultiListener multiListener = new MultiListener(transition, sceneRoot);
              sceneRoot.addOnAttachStateChangeListener(multiListener);
              sceneRoot.getViewTreeObserver().addOnPreDrawListener(multiListener);
          }
      }
  
      private static void sceneChangeSetup(ViewGroup sceneRoot, Transition transition) {
          ArrayList arrayList = getRunningTransitions().get(sceneRoot);
          if (arrayList != null && arrayList.size() > 0) {
              Iterator it = arrayList.iterator();
              while (it.hasNext()) {
                  ((Transition) it.next()).pause(sceneRoot);
              }
          }
          if (transition != null) {
              transition.captureValues(sceneRoot, true);
          }
          Scene currentScene = Scene.getCurrentScene(sceneRoot);
          if (currentScene != null) {
              currentScene.exit();
          }
      }
  
      public void setTransition(Scene fromScene, Scene toScene, Transition transition) {
          ArrayMap arrayMap = this.mScenePairTransitions.get(toScene);
          if (arrayMap == null) {
              arrayMap = new ArrayMap();
              this.mScenePairTransitions.put(toScene, arrayMap);
          }
          arrayMap.put(fromScene, transition);
      }
  
      public void setTransition(Scene scene, Transition transition) {
          this.mSceneTransitions.put(scene, transition);
      }
  
      public void transitionTo(Scene scene) {
          changeScene(scene, getTransition(scene));
      }
  }
  