Android Open Source - android-menudrawer Window Sample






From Project

Back to project page android-menudrawer.

License

The source code is released under:

Apache License

If you think the Android project android-menudrawer 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 net.simonvt.menudrawer.samples;
//from  w ww  .j  av  a  2s . c  o m
import net.simonvt.menudrawer.MenuDrawer;
import net.simonvt.menudrawer.Position;

import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

public class WindowSample extends Activity implements View.OnClickListener {

    private static final String STATE_MENUDRAWER = "net.simonvt.menudrawer.samples.WindowSample.menuDrawer";
    private static final String STATE_ACTIVE_VIEW_ID = "net.simonvt.menudrawer.samples.WindowSample.activeViewId";

    private MenuDrawer mMenuDrawer;
    private TextView mContentTextView;

    private int mActiveViewId;

    @Override
    public void onCreate(Bundle inState) {
        super.onCreate(inState);
        if (inState != null) {
            mActiveViewId = inState.getInt(STATE_ACTIVE_VIEW_ID);
        }

        mMenuDrawer = MenuDrawer.attach(this, MenuDrawer.Type.BEHIND, Position.LEFT, MenuDrawer.MENU_DRAG_WINDOW);
        mMenuDrawer.setContentView(R.layout.activity_windowsample);
        mMenuDrawer.setMenuView(R.layout.menu_scrollview);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            getActionBar().setDisplayHomeAsUpEnabled(true);
        }

        mContentTextView = (TextView) findViewById(R.id.contentText);

        findViewById(R.id.item1).setOnClickListener(this);
        findViewById(R.id.item2).setOnClickListener(this);
        findViewById(R.id.item3).setOnClickListener(this);
        findViewById(R.id.item4).setOnClickListener(this);
        findViewById(R.id.item5).setOnClickListener(this);
        findViewById(R.id.item6).setOnClickListener(this);

        TextView activeView = (TextView) findViewById(mActiveViewId);
        if (activeView != null) {
            mMenuDrawer.setActiveView(activeView);
            mContentTextView.setText("Active item: " + activeView.getText());
        }

        // This will animate the drawer open and closed until the user manually drags it. Usually this would only be
        // called on first launch.
        mMenuDrawer.peekDrawer();
    }

    @Override
    protected void onRestoreInstanceState(Bundle inState) {
        super.onRestoreInstanceState(inState);
        mMenuDrawer.restoreState(inState.getParcelable(STATE_MENUDRAWER));
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putParcelable(STATE_MENUDRAWER, mMenuDrawer.saveState());
        outState.putInt(STATE_ACTIVE_VIEW_ID, mActiveViewId);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                mMenuDrawer.toggleMenu();
                return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onBackPressed() {
        final int drawerState = mMenuDrawer.getDrawerState();
        if (drawerState == MenuDrawer.STATE_OPEN || drawerState == MenuDrawer.STATE_OPENING) {
            mMenuDrawer.closeMenu();
            return;
        }

        super.onBackPressed();
    }

    @Override
    public void onClick(View v) {
        mMenuDrawer.setActiveView(v);
        mContentTextView.setText("Active item: " + ((TextView) v).getText());
        mMenuDrawer.closeMenu();
        mActiveViewId = v.getId();
    }
}




Java Source Code List

net.simonvt.menudrawer.BuildLayerFrameLayout.java
net.simonvt.menudrawer.ColorDrawable.java
net.simonvt.menudrawer.DraggableDrawer.java
net.simonvt.menudrawer.FloatScroller.java
net.simonvt.menudrawer.MenuDrawer.java
net.simonvt.menudrawer.NoClickThroughFrameLayout.java
net.simonvt.menudrawer.OverlayDrawer.java
net.simonvt.menudrawer.PeekInterpolator.java
net.simonvt.menudrawer.Position.java
net.simonvt.menudrawer.Scroller.java
net.simonvt.menudrawer.SinusoidalInterpolator.java
net.simonvt.menudrawer.SlideDrawable.java
net.simonvt.menudrawer.SlidingDrawer.java
net.simonvt.menudrawer.SmoothInterpolator.java
net.simonvt.menudrawer.StaticDrawer.java
net.simonvt.menudrawer.ViewHelper.java
net.simonvt.menudrawer.compat.ActionBarHelperCompat.java
net.simonvt.menudrawer.compat.ActionBarHelperNative.java
net.simonvt.menudrawer.compat.ActionBarHelper.java
net.simonvt.menudrawer.samples.ActionBarSherlockSample.java
net.simonvt.menudrawer.samples.BaseListSample.java
net.simonvt.menudrawer.samples.BottomDrawerSample.java
net.simonvt.menudrawer.samples.BottomOverlaySample.java
net.simonvt.menudrawer.samples.Category.java
net.simonvt.menudrawer.samples.FragmentSample.java
net.simonvt.menudrawer.samples.Item.java
net.simonvt.menudrawer.samples.LayoutSample.java
net.simonvt.menudrawer.samples.LeftDrawerSample.java
net.simonvt.menudrawer.samples.LeftOverlaySample.java
net.simonvt.menudrawer.samples.ListActivitySample.java
net.simonvt.menudrawer.samples.MenuAdapter.java
net.simonvt.menudrawer.samples.RightDrawerSample.java
net.simonvt.menudrawer.samples.RightOverlaySample.java
net.simonvt.menudrawer.samples.SamplesActivity.java
net.simonvt.menudrawer.samples.StaticDrawerSample.java
net.simonvt.menudrawer.samples.TopDrawerSample.java
net.simonvt.menudrawer.samples.TopOverlaySample.java
net.simonvt.menudrawer.samples.ViewPagerSample.java
net.simonvt.menudrawer.samples.WindowSample.java