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; /* loaded from: classes2.dex */ public class TransitionManager { private static final String LOG_TAG = "TransitionManager"; private static Transition sDefaultTransition = new AutoTransition(); private static ThreadLocal>>> sRunningTransitions = new ThreadLocal<>(); static ArrayList sPendingTransitions = new ArrayList<>(); private ArrayMap mSceneTransitions = new ArrayMap<>(); private ArrayMap> mScenePairTransitions = new ArrayMap<>(); public void setTransition(Scene scene, Transition transition) { this.mSceneTransitions.put(scene, transition); } public void setTransition(Scene scene, Scene scene2, Transition transition) { ArrayMap arrayMap = this.mScenePairTransitions.get(scene2); if (arrayMap == null) { arrayMap = new ArrayMap<>(); this.mScenePairTransitions.put(scene2, arrayMap); } arrayMap.put(scene, transition); } 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 = arrayMap.get(currentScene)) != null) { return transition; } Transition transition2 = this.mSceneTransitions.get(scene); return transition2 != null ? transition2 : sDefaultTransition; } private static void changeScene(Scene scene, Transition transition) { ViewGroup sceneRoot = scene.getSceneRoot(); if (sPendingTransitions.contains(sceneRoot)) { return; } Scene currentScene = Scene.getCurrentScene(sceneRoot); if (transition == null) { if (currentScene != null) { currentScene.exit(); } scene.enter(); return; } sPendingTransitions.add(sceneRoot); Transition mo5320clone = transition.mo5320clone(); if (currentScene != null && currentScene.isCreatedFromLayoutResource()) { mo5320clone.setCanRemoveViews(true); } sceneChangeSetup(sceneRoot, mo5320clone); scene.enter(); sceneChangeRunTransition(sceneRoot, mo5320clone); } static ArrayMap> getRunningTransitions() { ArrayMap> arrayMap; WeakReference>> weakReference = sRunningTransitions.get(); if (weakReference != null && (arrayMap = weakReference.get()) != null) { return arrayMap; } ArrayMap> arrayMap2 = new ArrayMap<>(); sRunningTransitions.set(new WeakReference<>(arrayMap2)); return arrayMap2; } private static void sceneChangeRunTransition(ViewGroup viewGroup, Transition transition) { if (transition == null || viewGroup == null) { return; } MultiListener multiListener = new MultiListener(transition, viewGroup); viewGroup.addOnAttachStateChangeListener(multiListener); viewGroup.getViewTreeObserver().addOnPreDrawListener(multiListener); } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes2.dex */ public static class MultiListener implements ViewTreeObserver.OnPreDrawListener, View.OnAttachStateChangeListener { ViewGroup mSceneRoot; Transition mTransition; @Override // android.view.View.OnAttachStateChangeListener public void onViewAttachedToWindow(View view) { } MultiListener(Transition transition, ViewGroup viewGroup) { this.mTransition = transition; this.mSceneRoot = viewGroup; } private void removeListeners() { this.mSceneRoot.getViewTreeObserver().removeOnPreDrawListener(this); this.mSceneRoot.removeOnAttachStateChangeListener(this); } @Override // android.view.View.OnAttachStateChangeListener public void onViewDetachedFromWindow(View view) { 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()) { it.next().resume(this.mSceneRoot); } } this.mTransition.clearValues(true); } @Override // android.view.ViewTreeObserver.OnPreDrawListener public boolean onPreDraw() { removeListeners(); if (!TransitionManager.sPendingTransitions.remove(this.mSceneRoot)) { return true; } final ArrayMap> 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() { // from class: androidx.transition.TransitionManager.MultiListener.1 @Override // androidx.transition.TransitionListenerAdapter, androidx.transition.Transition.TransitionListener 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; } } private static void sceneChangeSetup(ViewGroup viewGroup, Transition transition) { ArrayList arrayList = getRunningTransitions().get(viewGroup); if (arrayList != null && arrayList.size() > 0) { Iterator it = arrayList.iterator(); while (it.hasNext()) { it.next().pause(viewGroup); } } if (transition != null) { transition.captureValues(viewGroup, true); } Scene currentScene = Scene.getCurrentScene(viewGroup); if (currentScene != null) { currentScene.exit(); } } public void transitionTo(Scene scene) { changeScene(scene, getTransition(scene)); } public static void go(Scene scene) { changeScene(scene, sDefaultTransition); } public static void go(Scene scene, Transition transition) { changeScene(scene, transition); } public static void beginDelayedTransition(ViewGroup viewGroup) { beginDelayedTransition(viewGroup, null); } public static void beginDelayedTransition(ViewGroup viewGroup, Transition transition) { if (sPendingTransitions.contains(viewGroup) || !ViewCompat.isLaidOut(viewGroup)) { return; } sPendingTransitions.add(viewGroup); if (transition == null) { transition = sDefaultTransition; } Transition mo5320clone = transition.mo5320clone(); sceneChangeSetup(viewGroup, mo5320clone); Scene.setCurrentScene(viewGroup, null); sceneChangeRunTransition(viewGroup, mo5320clone); } public static void endTransitions(ViewGroup viewGroup) { sPendingTransitions.remove(viewGroup); ArrayList arrayList = getRunningTransitions().get(viewGroup); if (arrayList == null || arrayList.isEmpty()) { return; } ArrayList arrayList2 = new ArrayList(arrayList); for (int size = arrayList2.size() - 1; size >= 0; size--) { ((Transition) arrayList2.get(size)).forceToEnd(viewGroup); } } }