Search in sources :

Example 1 with DrawerNavigationView

use of com.orgzly.android.ui.drawer.DrawerNavigationView in project orgzly-android by orgzly.

the class MainActivity method setupDrawer.

private void setupDrawer() {
    if (BuildConfig.LOG_DEBUG)
        LogUtils.d(TAG);
    mDrawerLayout = findViewById(R.id.drawer_layout);
    NavigationView navigationView = mDrawerLayout.findViewById(R.id.drawer_navigation_view);
    navigationView.setNavigationItemSelectedListener(item -> {
        Intent intent = item.getIntent();
        if (intent != null) {
            mDrawerLayout.closeDrawer(GravityCompat.START);
            // Avoid jerky drawer close by displaying new fragment with a delay
            new Handler().postDelayed(() -> broadcastManager.sendBroadcast(intent), 200);
        }
        if (BuildConfig.LOG_DEBUG)
            LogUtils.d(TAG, item, intent);
        return true;
    });
    drawerNavigationView = new DrawerNavigationView(this, navigationView);
    if (mDrawerLayout != null) {
        // Set the drawer toggle as the DrawerListener
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) {

            private int state = -1;

            /*
                 * onDrawerOpened and onDrawerClosed are not called fast enough.
                 * So state is determined using onDrawerSlide callback and checking the slide offset.
                 */
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                super.onDrawerSlide(drawerView, slideOffset);
                switch(state) {
                    case // Unknown
                    -1:
                        if (slideOffset == 0) {
                            state = 0;
                            drawerClosed();
                        } else if (slideOffset > 0) {
                            state = 1;
                            drawerOpened();
                        }
                        break;
                    case // Starting to open the drawer
                    0:
                        if (slideOffset > 0) {
                            state = 1;
                            drawerOpened();
                        }
                        break;
                    case // Starting to close the drawer
                    1:
                        if (slideOffset == 0) {
                            state = 0;
                            drawerClosed();
                        }
                        break;
                }
            }
        };
        // No flipping burgers
        mDrawerToggle.setDrawerSlideAnimationEnabled(false);
        mDrawerLayout.addDrawerListener(mDrawerToggle);
    }
    mSyncFragment = addSyncFragment();
}
Also used : NavigationView(android.support.design.widget.NavigationView) DrawerNavigationView(com.orgzly.android.ui.drawer.DrawerNavigationView) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) Handler(android.os.Handler) Intent(android.content.Intent) AppIntent(com.orgzly.android.AppIntent) NavigationView(android.support.design.widget.NavigationView) SearchView(android.support.v7.widget.SearchView) View(android.view.View) DrawerNavigationView(com.orgzly.android.ui.drawer.DrawerNavigationView) TextView(android.widget.TextView) DrawerNavigationView(com.orgzly.android.ui.drawer.DrawerNavigationView)

Aggregations

Intent (android.content.Intent)1 Handler (android.os.Handler)1 NavigationView (android.support.design.widget.NavigationView)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 SearchView (android.support.v7.widget.SearchView)1 View (android.view.View)1 TextView (android.widget.TextView)1 AppIntent (com.orgzly.android.AppIntent)1 DrawerNavigationView (com.orgzly.android.ui.drawer.DrawerNavigationView)1