Search in sources :

Example 1 with ClosableDrawerLayout

use of androidx.drawerlayout.widget.ClosableDrawerLayout in project Anki-Android by ankidroid.

the class NavigationDrawerActivity method setContentView.

@Override
public void setContentView(@LayoutRes int layoutResID) {
    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
    // Using ClosableDrawerLayout as a parent view.
    ClosableDrawerLayout closableDrawerLayout = (ClosableDrawerLayout) LayoutInflater.from(this).inflate(getNavigationDrawerLayout(), null, false);
    // Get CoordinatorLayout using resource ID
    CoordinatorLayout coordinatorLayout = (CoordinatorLayout) LayoutInflater.from(this).inflate(layoutResID, closableDrawerLayout, false);
    if (preferences.getBoolean(FULL_SCREEN_NAVIGATION_DRAWER, false)) {
        // If full screen navigation drawer is needed, then add FullDraggableContainer as a child view of closableDrawerLayout.
        // Then add coordinatorLayout as a child view of fullDraggableContainer.
        FullDraggableContainer fullDraggableContainer = new FullDraggableContainer(this);
        fullDraggableContainer.addView(coordinatorLayout);
        closableDrawerLayout.addView(fullDraggableContainer, 0);
    } else {
        // If full screen navigation drawer is not needed, then directly add coordinatorLayout as the child view.
        closableDrawerLayout.addView(coordinatorLayout, 0);
    }
    setContentView(closableDrawerLayout);
}
Also used : CoordinatorLayout(androidx.coordinatorlayout.widget.CoordinatorLayout) SharedPreferences(android.content.SharedPreferences) ClosableDrawerLayout(androidx.drawerlayout.widget.ClosableDrawerLayout) FullDraggableContainer(com.drakeet.drawer.FullDraggableContainer)

Example 2 with ClosableDrawerLayout

use of androidx.drawerlayout.widget.ClosableDrawerLayout in project Anki-Android by ankidroid.

the class NavigationDrawerActivity method initNavigationDrawer.

// Navigation drawer initialisation
protected void initNavigationDrawer(View mainView) {
    // Create inherited navigation drawer layout here so that it can be used by parent class
    mDrawerLayout = mainView.findViewById(R.id.drawer_layout);
    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // Force transparent status bar with primary dark color underlayed so that the drawer displays under status bar
    getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.transparent));
    mDrawerLayout.setStatusBarBackgroundColor(Themes.getColorFromAttr(this, R.attr.colorPrimaryDark));
    // Setup toolbar and hamburger
    mNavigationView = mDrawerLayout.findViewById(R.id.navdrawer_items_container);
    mNavigationView.setNavigationItemSelectedListener(this);
    Toolbar toolbar = mainView.findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
        // enable ActionBar app icon to behave as action to toggle nav drawer
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        // Decide which action to take when the navigation button is tapped.
        toolbar.setNavigationOnClickListener(v -> onNavigationPressed());
    }
    // Configure night-mode switch
    final SharedPreferences preferences = getPreferences();
    View actionLayout = mNavigationView.getMenu().findItem(R.id.nav_night_mode).getActionView();
    mNightModeSwitch = actionLayout.findViewById(R.id.switch_compat);
    mNightModeSwitch.setChecked(preferences.getBoolean(NIGHT_MODE_PREFERENCE, false));
    mNightModeSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> applyNightMode(isChecked));
    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, 0, 0) {

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            supportInvalidateOptionsMenu();
            // If animations are disabled, this is executed before onNavigationItemSelected is called
            // PERF: May be able to reduce this delay
            HandlerUtils.postDelayedOnNewHandler(() -> {
                if (mPendingRunnable != null) {
                    // TODO: See if we can use the same handler here
                    HandlerUtils.postOnNewHandler(mPendingRunnable);
                    mPendingRunnable = null;
                }
            }, 100);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            supportInvalidateOptionsMenu();
        }
    };
    if (mDrawerLayout instanceof ClosableDrawerLayout) {
        ((ClosableDrawerLayout) mDrawerLayout).setAnimationEnabled(animationEnabled());
    } else {
        Timber.w("Unexpected Drawer layout - could not modify navigation animation");
    }
    mDrawerToggle.setDrawerSlideAnimationEnabled(animationEnabled());
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    enablePostShortcut(this);
}
Also used : SharedPreferences(android.content.SharedPreferences) ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle) ClosableDrawerLayout(androidx.drawerlayout.widget.ClosableDrawerLayout) NavigationView(com.google.android.material.navigation.NavigationView) View(android.view.View) Toolbar(androidx.appcompat.widget.Toolbar)

Aggregations

SharedPreferences (android.content.SharedPreferences)2 ClosableDrawerLayout (androidx.drawerlayout.widget.ClosableDrawerLayout)2 View (android.view.View)1 ActionBarDrawerToggle (androidx.appcompat.app.ActionBarDrawerToggle)1 Toolbar (androidx.appcompat.widget.Toolbar)1 CoordinatorLayout (androidx.coordinatorlayout.widget.CoordinatorLayout)1 FullDraggableContainer (com.drakeet.drawer.FullDraggableContainer)1 NavigationView (com.google.android.material.navigation.NavigationView)1