Android Open Source - screenplay Screenplay






From Project

Back to project page screenplay.

License

The source code is released under:

MIT License

If you think the Android project screenplay listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.davidstemmer.screenplay.flow;
/*from ww w  .  jav  a 2s  .c  o  m*/
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;

import com.davidstemmer.screenplay.SceneCut;
import com.davidstemmer.screenplay.SceneState;
import com.davidstemmer.screenplay.scene.Scene;

import java.util.Iterator;

import flow.Backstack;
import flow.Flow;

/**
 * @version 1.0.0
 * @author  David Stemmer
 * @since   1.0.0
 */
public class Screenplay implements Flow.Listener {

    private final Director director;

    private Scene outgoingScene;
    private SceneState screenState = SceneState.NORMAL;

    public Screenplay(Director director) {
        this.director = director;
    }

    @Override
    public void go(Backstack nextBackstack, Flow.Direction direction, Flow.Callback callback) {

        screenState = SceneState.TRANSITIONING;

        Scene incomingScene = (Scene) nextBackstack.current().getScreen();
        Scene.Rigger delegatedRigger;
        Scene.Transformer delegatedTransformer;

        SceneCut sceneCut = new SceneCut.Builder()
                .setDirection(direction)
                .setIncomingScene(incomingScene)
                .setOutgoingScene(outgoingScene)
                .setCallback(callback).build();

        if (incomingScene == outgoingScene) {
            callback.onComplete();
        }

        if (direction == Flow.Direction.BACKWARD && outgoingScene == null) {
            //Honestly, I have no idea how to reach this case. We might want to remove this line.
            callback.onComplete();
            return;
        }

        // Only call incomingScene.setUp if necessary. If we are exiting a modal scene, the View will
        // already exist.
        if (incomingScene.getView() == null) {
            incomingScene.setUp(director.getActivity(), director.getContainer());
        }

        if (direction == Flow.Direction.FORWARD || direction == Flow.Direction.REPLACE) {
            delegatedRigger = incomingScene.getRigger();
            delegatedTransformer = incomingScene.getTransformer();

        }
        else {
            delegatedRigger = outgoingScene.getRigger();
            delegatedTransformer = outgoingScene.getTransformer();
        }

        delegatedRigger.layoutIncoming(director.getContainer(), incomingScene.getView(), direction);
        delegatedTransformer.applyAnimations(sceneCut, this);

        outgoingScene = incomingScene;
    }


    /**
     * Called by the {@link com.davidstemmer.screenplay.scene.Scene.Transformer} after the scene
     * animation completes. Finishes pending layout operations and notifies the Flow.Callback.
     * @param cut contains the next and previous scene, and the flow direction
     */
    public void endCut(SceneCut cut) {

        if (cut.outgoingScene != null) {
            ViewGroup container = director.getContainer();
            View outgoingView = cut.outgoingScene.getView();
            Scene.Rigger delegatedRigger = cut.direction == Flow.Direction.BACKWARD ?
                    cut.outgoingScene.getRigger() :
                    cut.incomingScene.getRigger();
            boolean isViewDetached = delegatedRigger.layoutOutgoing(container, outgoingView, cut.direction);
            if (isViewDetached) {
                cut.outgoingScene.tearDown(director.getActivity(), container);
            }
        }

        cut.callback.onComplete();
        screenState = SceneState.NORMAL;
    }

    /**
     * @return TRANSITIONING if a transition is in process, NORMAL otherwise
     */
    public SceneState getScreenState() {
        return screenState;
    }

    /**
     * Initialize the screen using the current Flow.Backstack. This is expected to be called in
     * Activity.onCreate(). Supports configuration changes.
     * @param flow the current Flow
     */
    public void enter(Flow flow) {
        if (flow.getBackstack().size() == 0) {
            throw new IllegalStateException("Backstack is empty");
        }
        boolean isSceneAttached = false;
        Iterator<Backstack.Entry> iterator = flow.getBackstack().reverseIterator();
        while (iterator.hasNext()) {
            Scene nextScene = (Scene) iterator.next().getScreen();
            if (nextScene.getView() != null) {
                ViewGroup parent = (ViewGroup) nextScene.getView().getParent();
                parent.removeView(nextScene.getView());
                nextScene.getRigger().layoutIncoming(director.getContainer(), nextScene.getView(), Flow.Direction.FORWARD);
                isSceneAttached = true;
            }
        }
        if (!isSceneAttached) {
            flow.replaceTo(flow.getBackstack().current().getScreen());
        }
    }

    /**
     * @version 1.0.0
     * @author  David Stemmer
     * @since   1.0.0
     */
    public interface Director {
        /**
         * @return the current Activity. Should be re-initialized after configuration changes.
         */
        public Activity getActivity();
        /**
         * @return the container for the Flow. Should be re-initialized after configuration changes.
         */
        public ViewGroup getContainer();
    }
}




Java Source Code List

com.davidstemmer.screenplay.MortarActivityDirector.java
com.davidstemmer.screenplay.SceneCut.java
com.davidstemmer.screenplay.SceneState.java
com.davidstemmer.screenplay.SimpleActivityDirector.java
com.davidstemmer.screenplay.flow.LayoutCompat.java
com.davidstemmer.screenplay.flow.Screenplay.java
com.davidstemmer.screenplay.sample.ApplicationTest.java
com.davidstemmer.screenplay.sample.mortar.MainActivity.java
com.davidstemmer.screenplay.sample.mortar.SampleApplication.java
com.davidstemmer.screenplay.sample.mortar.component.DrawerLockingComponent.java
com.davidstemmer.screenplay.sample.mortar.module.ActivityModule.java
com.davidstemmer.screenplay.sample.mortar.module.ApplicationModule.java
com.davidstemmer.screenplay.sample.mortar.presenter.DrawerPresenter.java
com.davidstemmer.screenplay.sample.mortar.presenter.NavigationMenuPresenter.java
com.davidstemmer.screenplay.sample.mortar.scene.ActionDrawerScene.java
com.davidstemmer.screenplay.sample.mortar.scene.DialogScene.java
com.davidstemmer.screenplay.sample.mortar.scene.PagedScene1.java
com.davidstemmer.screenplay.sample.mortar.scene.PagedScene2.java
com.davidstemmer.screenplay.sample.mortar.scene.PagedScene3.java
com.davidstemmer.screenplay.sample.mortar.scene.StackedScene.java
com.davidstemmer.screenplay.sample.mortar.scene.WelcomeScene.java
com.davidstemmer.screenplay.sample.mortar.scene.transformer.ActionDrawerTransformer.java
com.davidstemmer.screenplay.sample.mortar.scene.transformer.CrossfadeTransformer.java
com.davidstemmer.screenplay.sample.mortar.scene.transformer.HorizontalSlideTransformer.java
com.davidstemmer.screenplay.sample.mortar.scene.transformer.NavigationDrawerTransformer.java
com.davidstemmer.screenplay.sample.mortar.scene.transformer.NoAnimationTransformer.java
com.davidstemmer.screenplay.sample.mortar.scene.transformer.PopupTransformer.java
com.davidstemmer.screenplay.sample.mortar.scene.transformer.VerticalSlideTransformer.java
com.davidstemmer.screenplay.sample.mortar.view.ActionDrawerView.java
com.davidstemmer.screenplay.sample.mortar.view.DialogSceneView.java
com.davidstemmer.screenplay.sample.mortar.view.ModalSceneView.java
com.davidstemmer.screenplay.sample.mortar.view.NavigationMenuView.java
com.davidstemmer.screenplay.sample.mortar.view.PagedView1.java
com.davidstemmer.screenplay.sample.mortar.view.PagedView2.java
com.davidstemmer.screenplay.sample.mortar.view.WelcomeView.java
com.davidstemmer.screenplay.sample.simple.DrawerHelper.java
com.davidstemmer.screenplay.sample.simple.MainActivity.java
com.davidstemmer.screenplay.sample.simple.SampleApplication.java
com.davidstemmer.screenplay.sample.simple.component.DrawerLockingComponent.java
com.davidstemmer.screenplay.sample.simple.scene.ActionDrawerResult.java
com.davidstemmer.screenplay.sample.simple.scene.ActionDrawerScene.java
com.davidstemmer.screenplay.sample.simple.scene.DialogScene.java
com.davidstemmer.screenplay.sample.simple.scene.IndexedScene.java
com.davidstemmer.screenplay.sample.simple.scene.PagedScene1.java
com.davidstemmer.screenplay.sample.simple.scene.PagedScene2.java
com.davidstemmer.screenplay.sample.simple.scene.PagedScene3.java
com.davidstemmer.screenplay.sample.simple.scene.StackedScene.java
com.davidstemmer.screenplay.sample.simple.scene.WelcomeScene.java
com.davidstemmer.screenplay.sample.simple.scene.transformer.ActionDrawerTransformer.java
com.davidstemmer.screenplay.sample.simple.scene.transformer.CrossfadeTransformer.java
com.davidstemmer.screenplay.sample.simple.scene.transformer.HorizontalSlideTransformer.java
com.davidstemmer.screenplay.sample.simple.scene.transformer.NavigationDrawerTransformer.java
com.davidstemmer.screenplay.sample.simple.scene.transformer.NoAnimationTransformer.java
com.davidstemmer.screenplay.sample.simple.scene.transformer.PopupTransformer.java
com.davidstemmer.screenplay.sample.simple.scene.transformer.VerticalSlideTransformer.java
com.davidstemmer.screenplay.sample.simple.view.ActionDrawerView.java
com.davidstemmer.screenplay.sample.simple.view.DialogSceneView.java
com.davidstemmer.screenplay.sample.simple.view.ModalSceneView.java
com.davidstemmer.screenplay.sample.simple.view.NavigationMenuView.java
com.davidstemmer.screenplay.sample.simple.view.PagedView1.java
com.davidstemmer.screenplay.sample.simple.view.PagedView2.java
com.davidstemmer.screenplay.scene.Scene.java
com.davidstemmer.screenplay.scene.ScopedScene.java
com.davidstemmer.screenplay.scene.StandardScene.java
com.davidstemmer.screenplay.scene.component.CallbackComponent.java
com.davidstemmer.screenplay.scene.component.PresenterComponent.java
com.davidstemmer.screenplay.scene.component.ResultHandler.java
com.davidstemmer.screenplay.scene.component.SceneCallback.java
com.davidstemmer.screenplay.scene.rigger.PageRigger.java
com.davidstemmer.screenplay.scene.rigger.StackRigger.java
com.davidstemmer.screenplay.scene.transformer.AnimatorTransformer.java
com.davidstemmer.screenplay.scene.transformer.TweenAnimationListener.java
com.davidstemmer.screenplay.scene.transformer.TweenTransformer.java
com.example.weefbellington.screenplay.ApplicationTest.java