Android Open Source - screenplay Drawer Helper






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.simple;
// w  w  w.  j a v a2 s .c  o m
import android.content.res.Configuration;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBarDrawerToggle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;

import com.davidstemmer.screenplay.SimpleActivityDirector;
import com.example.weefbellington.screenplay.sample.simple.R;

/**
 * Created by weefbellington on 10/24/14.
 */
public class DrawerHelper {

    private final SimpleActivityDirector director;

    private ActionBarDrawerToggle drawerToggle;
    private DrawerLayout drawerLayout;

    public DrawerHelper(SimpleActivityDirector director) {
        this.director = director;
    }

    public void bind(DrawerLayout layout) {

        drawerLayout = layout;
        drawerToggle = createDrawerToggle();

        LayoutInflater inflater = director.getActivity().getLayoutInflater();
        inflater.inflate(R.layout.navigation_menu, getLayout());
        getLayout().setDrawerListener(drawerToggle);

        ActionBar actionBar = ((ActionBarActivity)director.getActivity()).getSupportActionBar();
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    public void unbind() {
        drawerToggle = null;
    }

    private ActionBarDrawerToggle createDrawerToggle() {

        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                director.getActivity(),
                getLayout(),
                R.string.drawer_open,
                R.string.drawer_close) {
            public void onDrawerClosed(View view) {
                super.onDrawerClosed(view);
                director.getActivity().invalidateOptionsMenu();
            }

            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                director.getActivity().invalidateOptionsMenu();
            }
        };
        toggle.setDrawerIndicatorEnabled(true);
        return toggle;
    }

    public void syncToggleState() {
        drawerToggle.syncState();
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        return drawerToggle.onOptionsItemSelected(item);
    }

    public void onConfigurationChanged(Configuration newConfig) {
        drawerToggle.onConfigurationChanged(newConfig);
    }

    public DrawerLayout getLayout() {
        return drawerLayout;
    }

    public void setLocked(boolean locked) {
        if (locked) {
            getLayout().setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        } else {
            getLayout().setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
        }
    }

    public boolean isLockedShut() {
        return getLayout().getDrawerLockMode(Gravity.LEFT) == DrawerLayout.LOCK_MODE_LOCKED_CLOSED;
    }

    public boolean isLockedOpen() {
        return getLayout().getDrawerLockMode(Gravity.LEFT) == DrawerLayout.LOCK_MODE_LOCKED_OPEN;
    }

    public boolean isDrawerVisible() {
        return getLayout().isDrawerVisible(Gravity.LEFT);
    }

    public void open() {
        getLayout().openDrawer(Gravity.LEFT);
    }

    public void close() {
        getLayout().closeDrawer(Gravity.LEFT);
    }
}




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