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();
}
Aggregations