Search in sources :

Example 1 with Path

use of flow.path.Path 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)

Example 2 with Path

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

the class MortarDemoActivity method dispatch.

@Override
public void dispatch(Flow.Traversal traversal, Flow.TraversalCallback callback) {
    Path newScreen = traversal.destination.top();
    String title = newScreen.getClass().getSimpleName();
    ActionBarOwner.MenuAction menu = new ActionBarOwner.MenuAction("Friends", new Action0() {

        @Override
        public void call() {
            Flow.get(MortarDemoActivity.this).set(new FriendListScreen());
        }
    });
    actionBarOwner.setConfig(new ActionBarOwner.Config(false, !(newScreen instanceof ChatListScreen), title, menu));
    container.dispatch(traversal, callback);
}
Also used : Path(flow.path.Path) Action0(rx.functions.Action0) FriendListScreen(com.example.mortar.screen.FriendListScreen) ChatListScreen(com.example.mortar.screen.ChatListScreen) ActionBarOwner(com.example.mortar.android.ActionBarOwner)

Aggregations

Path (flow.path.Path)2 View (android.view.View)1 ActionBarOwner (com.example.mortar.android.ActionBarOwner)1 ChatListScreen (com.example.mortar.screen.ChatListScreen)1 FriendListScreen (com.example.mortar.screen.FriendListScreen)1 PathContext (flow.path.PathContext)1 Action0 (rx.functions.Action0)1