Search in sources :

Example 26 with DrawerLayout

use of android.support.v4.widget.DrawerLayout in project cardslib by gabrielemariotti.

the class BaseActivity method setupNavDrawer.

//----------------------------------------------------------------------------
// Navigation Drawer
//----------------------------------------------------------------------------
/**
     * Sets up the navigation drawer as appropriate. Note that the nav drawer will be
     * different depending on whether the attendee indicated that they are attending the
     * event on-site vs. attending remotely.
     */
private void setupNavDrawer() {
    // What nav drawer item should be selected?
    int selfItem = getSelfNavDrawerItem();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (mDrawerLayout == null) {
        return;
    }
    mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.demo_colorPrimaryDark));
    if (selfItem == NAVDRAWER_ITEM_INVALID) {
        // do not show a nav drawer
        View navDrawer = mDrawerLayout.findViewById(R.id.navdrawer);
        if (navDrawer != null) {
            ((ViewGroup) navDrawer.getParent()).removeView(navDrawer);
        }
        mDrawerLayout = null;
        return;
    }
    if (mActionBarToolbar != null) {
        mActionBarToolbar.setNavigationIcon(R.drawable.ic_navigation_drawer);
        mActionBarToolbar.setNavigationOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                mDrawerLayout.openDrawer(Gravity.START);
            }
        });
    }
    mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {

        @Override
        public void onDrawerClosed(View drawerView) {
            // run deferred action, if we have one
            if (mDeferredOnDrawerClosedRunnable != null) {
                mDeferredOnDrawerClosedRunnable.run();
                mDeferredOnDrawerClosedRunnable = null;
            }
            //invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            //updateStatusBarForNavDrawerSlide(0f);
            onNavDrawerStateChanged(false, false);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            //invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            //updateStatusBarForNavDrawerSlide(1f);
            onNavDrawerStateChanged(true, false);
        }

        @Override
        public void onDrawerStateChanged(int newState) {
            //invalidateOptionsMenu();
            onNavDrawerStateChanged(isNavDrawerOpen(), newState != DrawerLayout.STATE_IDLE);
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            //updateStatusBarForNavDrawerSlide(slideOffset);
            onNavDrawerSlide(slideOffset);
        }
    });
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);
    //getActionBar().setDisplayHomeAsUpEnabled(true);
    //getActionBar().setHomeButtonEnabled(true);
    // populate the nav drawer with the correct items
    populateNavDrawer();
    // navigation drawer open. But just the first time.
    if (!PrefUtils.isWelcomeDone(this)) {
        // first run of the app starts with the nav drawer open
        PrefUtils.markWelcomeDone(this);
        mDrawerLayout.openDrawer(Gravity.START);
    }
}
Also used : ViewGroup(android.view.ViewGroup) DrawerLayout(android.support.v4.widget.DrawerLayout) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 27 with DrawerLayout

use of android.support.v4.widget.DrawerLayout in project fresco by facebook.

the class MainActivity method onNavigationItemSelected.

@Override
public boolean onNavigationItemSelected(MenuItem item) {
    handleNavigationItemClick(item.getItemId());
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
Also used : DrawerLayout(android.support.v4.widget.DrawerLayout)

Example 28 with DrawerLayout

use of android.support.v4.widget.DrawerLayout in project fresco by facebook.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    if (savedInstanceState == null) {
        int selectedItem = PreferenceManager.getDefaultSharedPreferences(this).getInt(KEY_SELECTED_NAVDRAWER_ITEM_ID, INITIAL_NAVDRAWER_ITEM_ID);
        handleNavigationItemClick(selectedItem);
        navigationView.setCheckedItem(selectedItem);
    }
}
Also used : NavigationView(android.support.design.widget.NavigationView) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) DrawerLayout(android.support.v4.widget.DrawerLayout) Toolbar(android.support.v7.widget.Toolbar)

Example 29 with DrawerLayout

use of android.support.v4.widget.DrawerLayout in project flexbox-layout by google.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initializeStringResources();
    mFlexboxLayout = (FlexboxLayout) findViewById(R.id.flexbox_layout);
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    if (drawer != null) {
        drawer.addDrawerListener(toggle);
    }
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    if (navigationView != null) {
        navigationView.setNavigationItemSelectedListener(this);
        Menu navigationMenu = navigationView.getMenu();
        initializeFlexDirectionSpinner(navigationMenu);
        initializeFlexWrapSpinner(navigationMenu);
        initializeJustifyContentSpinner(navigationMenu);
        initializeAlignItemsSpinner(navigationMenu);
        initializeAlignContentSpinner(navigationMenu);
    }
    if (savedInstanceState != null) {
        ArrayList<FlexItem> flexItems = savedInstanceState.getParcelableArrayList(FLEX_ITEMS_KEY);
        assert flexItems != null;
        mFlexboxLayout.removeAllViews();
        for (int i = 0; i < flexItems.size(); i++) {
            FlexItem flexItem = flexItems.get(i);
            FlexboxLayout.LayoutParams lp = flexItem.toLayoutParams(this);
            TextView textView = createBaseFlexItemTextView(i);
            ViewCompat.setPaddingRelative(textView, flexItem.paddingStart, flexItem.paddingTop, flexItem.paddingEnd, flexItem.paddingBottom);
            textView.setLayoutParams(lp);
            mFlexboxLayout.addView(textView);
        }
    }
    for (int i = 0; i < mFlexboxLayout.getChildCount(); i++) {
        mFlexboxLayout.getChildAt(i).setOnClickListener(new FlexItemClickListener(i));
    }
    FloatingActionButton addFab = (FloatingActionButton) findViewById(R.id.add_fab);
    if (addFab != null) {
        addFab.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                int viewIndex = mFlexboxLayout.getChildCount();
                // index starts from 0. New View's index is N if N views ([0, 1, 2, ... N-1])
                // exist.
                TextView textView = createBaseFlexItemTextView(viewIndex);
                textView.setLayoutParams(createDefaultLayoutParams());
                textView.setOnClickListener(new FlexItemClickListener(viewIndex));
                mFlexboxLayout.addView(textView);
            }
        });
    }
    FloatingActionButton removeFab = (FloatingActionButton) findViewById(R.id.remove_fab);
    if (removeFab != null) {
        removeFab.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (mFlexboxLayout.getChildCount() == 0) {
                    return;
                }
                mFlexboxLayout.removeViewAt(mFlexboxLayout.getChildCount() - 1);
            }
        });
    }
}
Also used : NavigationView(android.support.design.widget.NavigationView) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) NavigationView(android.support.design.widget.NavigationView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) FlexboxLayout(com.google.android.flexbox.FlexboxLayout) FloatingActionButton(android.support.design.widget.FloatingActionButton) TextView(android.widget.TextView) Menu(android.view.Menu) DrawerLayout(android.support.v4.widget.DrawerLayout) Toolbar(android.support.v7.widget.Toolbar)

Example 30 with DrawerLayout

use of android.support.v4.widget.DrawerLayout in project OkVolley by googolmo.

the class DrawerFragment method setUp.

/**
     * Users of this fragment must call this method to set up the navigation drawer interactions.
     *
     * @param fragmentId   The android:id of this fragment in its activity's layout.
     * @param drawerLayout The DrawerLayout containing this fragment's UI.
     */
public void setUp(int fragmentId, DrawerLayout drawerLayout) {
    mFragmentContainerView = getActivity().findViewById(fragmentId);
    mDrawerLayout = drawerLayout;
    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);
    // ActionBarDrawerToggle ties together the the proper interactions
    // between the navigation drawer and the action bar app icon.
    mDrawerToggle = new ActionBarDrawerToggle(getActivity(), /* host Activity */
    mDrawerLayout, /* DrawerLayout object */
    R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
    R.string.drawer_open, /* "open drawer" description for accessibility */
    R.string.drawer_close) {

        /* "close drawer" description for accessibility */
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (!isAdded()) {
                return;
            }
            // calls onPrepareOptionsMenu()
            getActivity().supportInvalidateOptionsMenu();
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (!isAdded()) {
                return;
            }
            // calls onPrepareOptionsMenu()
            getActivity().supportInvalidateOptionsMenu();
        }
    };
    // Defer code dependent on restoration of previous instance state.
    mDrawerLayout.post(new Runnable() {

        @Override
        public void run() {
            mDrawerToggle.syncState();
        }
    });
    mDrawerLayout.setDrawerListener(mDrawerToggle);
}
Also used : ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) View(android.view.View) AdapterView(android.widget.AdapterView) ActionBar(android.support.v7.app.ActionBar)

Aggregations

View (android.view.View)54 DrawerLayout (android.support.v4.widget.DrawerLayout)51 ActionBarDrawerToggle (android.support.v4.app.ActionBarDrawerToggle)33 AdapterView (android.widget.AdapterView)22 ListView (android.widget.ListView)21 NavigationView (android.support.design.widget.NavigationView)18 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)17 Intent (android.content.Intent)16 Toolbar (android.support.v7.widget.Toolbar)16 TextView (android.widget.TextView)14 ImageView (android.widget.ImageView)10 ActionBar (android.support.v7.app.ActionBar)9 SharedPreferences (android.content.SharedPreferences)8 FloatingActionButton (android.support.design.widget.FloatingActionButton)7 ViewPager (android.support.v4.view.ViewPager)6 ArrayList (java.util.ArrayList)5 SuppressLint (android.annotation.SuppressLint)4 ActionBar (android.app.ActionBar)4 TypedArray (android.content.res.TypedArray)4 Paint (android.graphics.Paint)4