Android Open Source - screenplay Main Activity






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.sample.mortar;
/*from w  w  w  .  jav a  2s . c  o  m*/
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.view.MenuItem;

import com.davidstemmer.screenplay.MortarActivityDirector;
import com.davidstemmer.screenplay.flow.Screenplay;
import com.davidstemmer.screenplay.sample.mortar.R;
import com.davidstemmer.screenplay.sample.mortar.module.ActivityModule;
import com.davidstemmer.screenplay.sample.mortar.presenter.DrawerPresenter;

import javax.inject.Inject;

import butterknife.ButterKnife;
import flow.Flow;
import mortar.Blueprint;
import mortar.Mortar;
import mortar.MortarActivityScope;
import mortar.MortarScope;

public class MainActivity extends ActionBarActivity implements Blueprint {

    @Inject Flow flow;
    @Inject Screenplay screenplay;
    @Inject MortarActivityDirector activityDirector;
    @Inject DrawerPresenter drawerPresenter;

    private DrawerLayout navigationDrawer;

    private MortarActivityScope activityScope;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        MortarScope parentScope = Mortar.getScope(getApplication());
        activityScope = Mortar.requireActivityScope(parentScope, this);
        activityScope.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        Mortar.inject(this, this);

        ButterKnife.inject(this, this);

        navigationDrawer = (DrawerLayout) findViewById(R.id.drawer_parent);
        activityDirector.takeView(this);
        drawerPresenter.takeView(navigationDrawer);

        screenplay.enter(flow);
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        drawerPresenter.syncToggleState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        drawerPresenter.onConfigurationChanged(newConfig);
    }

    @Override public void onBackPressed() {
        if (!flow.goBack()) {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        if (item.getItemId() == android.R.id.home) {
            if (drawerPresenter.isLockedOpen() || drawerPresenter.isLockedShut()) {
               return true;
            }
            else if (drawerPresenter.onOptionsItemSelected(item)) {
               return true;
            }
        }
        return super.onOptionsItemSelected(item);
    }

    @Override public Object getSystemService(String name) {
        if (Mortar.isScopeSystemService(name)) {
            return activityScope;
        }
        return super.getSystemService(name);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        activityScope.onSaveInstanceState(outState);
        super.onSaveInstanceState(outState);
    }

    @Override public void onDestroy() {
        super.onDestroy();
        // Drop the activity and drawer presenter every time the Activity is destroyed.
        // This allows them to release references to the Activity that is about to be destroyed.
        activityDirector.dropView(this);
        drawerPresenter.dropView(navigationDrawer);

        if (isFinishing()) {
            // Destroy the Activity scope only if the Activity is finishing (back button press).
            // This is so singletons, such as Scenes, can survive configuration changes.
            MortarScope parentScope = Mortar.getScope(getApplication());
            parentScope.destroyChild(activityScope);
            activityScope = null;
        }
    }

    @Override
    public String getMortarScopeName() {
        return getClass().getName();
    }

    @Override
    public Object getDaggerModule() {
        return new ActivityModule();
    }


}




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