ECode EnterTransitionCoordinator::TriggerViewsReady(
    /* [in] */ IArrayMap* sharedElements) //ArrayMap<String, View>
{
    if (mAreViewsReady) {
        return NOERROR;
    }

    mAreViewsReady = TRUE;
    // Ensure the views have been laid out before capturing the views -- we need the epicenter.
    Boolean isEmpty;
    sharedElements->IsEmpty(&isEmpty);
    if (isEmpty) {
        ViewsReady(sharedElements);
        return NOERROR;
    }

    AutoPtr<IInterface> obj;
    sharedElements->Get(0, (IInterface**)&obj);
    IView* sharedElement = IView::Probe(obj);
    Boolean requested;
    sharedElement->IsLayoutRequested(&requested);

    if (!requested) {
        ViewsReady(sharedElements);
    }
    else {
        AutoPtr<IOnPreDrawListener> listener = new SharedElementOnPreDrawListener(
            this, sharedElements, sharedElement);
        AutoPtr<IViewTreeObserver> vto;
        sharedElement->GetViewTreeObserver((IViewTreeObserver**)&vto);
        vto->AddOnPreDrawListener(listener);
    }

    return NOERROR;
}
ECode EnterTransitionCoordinator::constructor(
    /* [in] */ IActivity* activity,
    /* [in] */ IResultReceiver* resultReceiver,
    /* [in] */ IArrayList* sharedElementNames,
    /* [in] */ Boolean isReturning)
{
    AutoPtr<IWindow> window;
    activity->GetWindow((IWindow**)&window);

    FAIL_RETURN(ActivityTransitionCoordinator::constructor(
        window, sharedElementNames, GetListener(activity, isReturning), isReturning))
    mActivity = activity;
    SetResultReceiver(resultReceiver);
    PrepareEnter();
    AutoPtr<IBundle> resultReceiverBundle;
    CBundle::New((IBundle**)&resultReceiverBundle);
    resultReceiverBundle->PutParcelable(
        ActivityTransitionCoordinator::KEY_REMOTE_RECEIVER, this);

    mResultReceiver->Send(
        IActivityTransitionCoordinator::MSG_SET_REMOTE_RECEIVER, resultReceiverBundle);

    AutoPtr<IViewGroup> vg;
    GetDecor((IViewGroup**)&vg);
    IView* decorView = IView::Probe(vg);
    if (decorView != NULL) {
        AutoPtr<IViewTreeObserver> vto;
        decorView->GetViewTreeObserver((IViewTreeObserver**)&vto);
        AutoPtr<IOnPreDrawListener> listener = new DecorViewOnPreDrawListener(this, decorView);
        vto->AddOnPreDrawListener(listener);
    }
    return NOERROR;
}
void EnterTransitionCoordinator::SendSharedElementDestination()
{
    Boolean allReady, bval;
    AutoPtr<IViewGroup> vg;
    GetDecor((IViewGroup**)&vg);
    IView* decorView = IView::Probe(vg);
    AutoPtr<ITransition> evt;
    GetEnterViewsTransition((ITransition**)&evt);
    if (AllowOverlappingTransitions() && evt != NULL) {
        allReady = FALSE;
    }
    else if (decorView == NULL) {
        allReady = TRUE;
    }
    else {
        decorView->IsLayoutRequested(&allReady);
        allReady = !allReady;
        if (allReady) {
            Int32 size;
            mSharedElements->GetSize(&size);
            IView* view;
            for (Int32 i = 0; i < size; i++) {
                AutoPtr<IInterface> obj;
                mSharedElements->Get(i, (IInterface**)&obj);
                view = IView::Probe(obj);
                view->IsLayoutRequested(&bval);
                if (bval) {
                    allReady = FALSE;
                    break;
                }
            }
        }
    }

    if (allReady) {
        AutoPtr<IBundle> state = CaptureSharedElementState();
        SetSharedElementMatrices();
        MoveSharedElementsToOverlay();
        mResultReceiver->Send(
            IActivityTransitionCoordinator::MSG_SHARED_ELEMENT_DESTINATION, state);
    }
    else if (decorView != NULL) {
        AutoPtr<IViewTreeObserver> vto;
        decorView->GetViewTreeObserver((IViewTreeObserver**)&vto);
        AutoPtr<IOnPreDrawListener> listener = new DestinationDecorViewOnPreDrawListener(this, decorView);
        vto->AddOnPreDrawListener(listener);
    }
    if (AllowOverlappingTransitions()) {
        StartEnterTransitionOnly();
    }
}
void EnterTransitionCoordinator::OnTakeSharedElements()
{
    if (!mIsReadyForTransition || mSharedElementsBundle == NULL) {
        return;
    }
    AutoPtr<IBundle> sharedElementState = mSharedElementsBundle;
    mSharedElementsBundle = NULL;
    AutoPtr<IViewGroup> vg;
    GetDecor((IViewGroup**)&vg);
    IView* decorView = IView::Probe(vg);
    if (decorView != NULL) {
        AutoPtr<IViewTreeObserver> vto;
        decorView->GetViewTreeObserver((IViewTreeObserver**)&vto);
        AutoPtr<IOnPreDrawListener> listener = new TakeSharedElementsOnPreDrawListener(
            this, decorView, sharedElementState);
        vto->AddOnPreDrawListener(listener);
        decorView->Invalidate();
    }
}