Search in sources :

Example 1 with PathContext

use of flow.path.PathContext in project mortar by square.

the class SimplePathContainer method performTraversal.

@Override
protected void performTraversal(final ViewGroup containerView, final TraversalState traversalState, final Flow.Direction direction, final Flow.TraversalCallback callback) {
    final PathContext context;
    final PathContext oldPath;
    if (containerView.getChildCount() > 0) {
        oldPath = PathContext.get(containerView.getChildAt(0).getContext());
    } else {
        oldPath = PathContext.root(containerView.getContext());
    }
    Path to = traversalState.toPath();
    View newView;
    context = PathContext.create(oldPath, to, contextFactory);
    int layout = getLayout(to);
    newView = LayoutInflater.from(context).cloneInContext(context).inflate(layout, containerView, false);
    View fromView = null;
    if (traversalState.fromPath() != null) {
        fromView = containerView.getChildAt(0);
        traversalState.saveViewState(fromView);
    }
    traversalState.restoreViewState(newView);
    if (fromView == null || direction == REPLACE) {
        containerView.removeAllViews();
        containerView.addView(newView);
        oldPath.destroyNotIn(context, contextFactory);
        callback.onTraversalCompleted();
    } else {
        containerView.addView(newView);
        final View finalFromView = fromView;
        Utils.waitForMeasure(newView, new Utils.OnMeasuredCallback() {

            @Override
            public void onMeasured(View view, int width, int height) {
                runAnimation(containerView, finalFromView, view, direction, new Flow.TraversalCallback() {

                    @Override
                    public void onTraversalCompleted() {
                        containerView.removeView(finalFromView);
                        oldPath.destroyNotIn(context, contextFactory);
                        callback.onTraversalCompleted();
                    }
                });
            }
        });
    }
}
Also used : Path(flow.path.Path) PathContext(flow.path.PathContext) View(android.view.View)

Aggregations

View (android.view.View)1 Path (flow.path.Path)1 PathContext (flow.path.PathContext)1