Android Open Source - screenplay Navigation Menu View






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.view;
/*from  w w w .  j a  va  2  s .  c  o  m*/
import android.content.Context;
import android.os.Handler;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.davidstemmer.screenplay.sample.simple.DrawerHelper;
import com.davidstemmer.screenplay.sample.simple.SampleApplication;
import com.davidstemmer.screenplay.sample.simple.scene.StackedScene;
import com.davidstemmer.screenplay.sample.simple.scene.PagedScene1;
import com.davidstemmer.screenplay.sample.simple.scene.WelcomeScene;
import com.davidstemmer.screenplay.scene.Scene;
import com.example.weefbellington.screenplay.sample.simple.R;

import flow.Flow;

/**
 * Created by weefbellington on 10/17/14.
 */
public class NavigationMenuView extends LinearLayout {

    private final Flow flow;
    private final DrawerHelper drawerHelper;
    private final WelcomeScene welcomeScene;
    private final PagedScene1 pagedScene;
    private final StackedScene stackedScene;

    public NavigationMenuView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.flow = SampleApplication.getMainFlow();
        this.drawerHelper = SampleApplication.getDrawerHelper();
        this.welcomeScene = new WelcomeScene();
        this.pagedScene = new PagedScene1();
        this.stackedScene = new StackedScene();
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        findViewById(R.id.nav_item_simple_scene).setOnClickListener(new WelcomeSceneListener());
        findViewById(R.id.nav_item_paged_scenes).setOnClickListener(new PagedSceneListener());
        findViewById(R.id.nav_item_modal_scenes).setOnClickListener(new ModalSceneListener());
    }

    private int selected = R.id.nav_item_simple_scene;

    private class WelcomeSceneListener implements OnClickListener {
        @Override
        public void onClick(View v) {
            setSelected(v);
            showNextSceneAfterDelay(welcomeScene);
            drawerHelper.close();
        }
    }


    private class PagedSceneListener implements OnClickListener {
        @Override
        public void onClick(View v) {
            setSelected(v);
            showNextSceneAfterDelay(pagedScene);
            drawerHelper.close();
        }
    }

    private class ModalSceneListener implements OnClickListener {
        @Override
        public void onClick(View v) {
            setSelected(v);
            showNextSceneAfterDelay(stackedScene);
            drawerHelper.close();
        }
    }


    private void setSelected(View selectedView) {
        setSelected(selectedView.getId());
    }

    private void setSelected(int id) {
        selected = id;
        for (int i = 0; i < getChildCount(); i++) {
            TextView child = (TextView) getChildAt(i);
            if (id == child.getId()) {
                child.setSelected(true);
            } else {
                child.setSelected(false);
            }
        }
    }

    private final Handler mDrawerHandler = new Handler();
    private void showNextSceneAfterDelay(final Scene nextScene) {
        // Clears any previously posted runnables, for double clicks
        mDrawerHandler.removeCallbacksAndMessages(null);
        mDrawerHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                flow.replaceTo(nextScene);
            }
        }, 250);
        // The millisecond delay is arbitrary and was arrived at through trial and error
        drawerHelper.close();
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        setSelected(selected);
    }

    @Override
    protected Parcelable onSaveInstanceState() {
        Parcelable superState = super.onSaveInstanceState();
        SavedState savedState = new SavedState(superState);

        savedState.selected = this.selected;
        return savedState;
    }

    @Override
    public void onRestoreInstanceState(Parcelable state) {
        if(!(state instanceof SavedState)) {
            super.onRestoreInstanceState(state);
            return;
        }

        SavedState savedState = (SavedState)state;
        super.onRestoreInstanceState(savedState.getSuperState());

        this.selected = savedState.selected;
    }


    private static class SavedState extends BaseSavedState {

        private int selected;

        public SavedState(Parcelable superState) {
            super(superState);
        }

        private SavedState(Parcel in) {
            super(in);
            this.selected = in.readInt();
        }

        @Override
        public void writeToParcel(Parcel out, int flags) {
            super.writeToParcel(out, flags);
            out.writeInt(this.selected);
        }

        public static final Parcelable.Creator<SavedState> CREATOR =
            new Parcelable.Creator<SavedState>() {
                public SavedState createFromParcel(Parcel in) {
                    return new SavedState(in);
                }
                public SavedState[] newArray(int size) {
                    return new SavedState[size];
                }
            };
    }
}




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