Search in sources :

Example 1 with AccountSwitcherNavigationView

use of de.geeksfactory.opacclient.ui.AccountSwitcherNavigationView in project opacclient by opacapp.

the class OpacActivity method setupDrawer.

protected void setupDrawer() {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawerLayout != null) {
        hasDrawer = true;
        drawerLayout.setStatusBarBackground(R.color.primary_red_dark);
        drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.LEFT);
        drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) {

            /**
             * Called when a drawer has settled in a completely closed
             * state.
             */
            @Override
            public void onDrawerClosed(View view) {
                super.onDrawerClosed(view);
                getSupportActionBar().setTitle(title);
            }

            /**
             * Called when a drawer has settled in a completely open state.
             */
            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                getSupportActionBar().setTitle(app.getResources().getString(R.string.app_name));
                if (getCurrentFocus() != null) {
                    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
                }
            }
        };
        // Set the drawer toggle as the DrawerListener
        drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {

            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                drawerToggle.onDrawerSlide(drawerView, slideOffset);
            }

            @Override
            public void onDrawerOpened(final View drawerView) {
                drawerToggle.onDrawerOpened(drawerView);
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                drawerToggle.onDrawerClosed(drawerView);
                setAccountSwitcherVisible(false);
            }

            @Override
            public void onDrawerStateChanged(int newState) {
                drawerToggle.onDrawerStateChanged(newState);
            }
        });
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        drawer = (AccountSwitcherNavigationView) findViewById(R.id.navdrawer);
        drawer.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {

            @Override
            public boolean onNavigationItemSelected(MenuItem item) {
                selectItem(item);
                return true;
            }
        });
        if (!sp.getBoolean("version2.0.0-introduced", false) && app.getSlidingMenuEnabled()) {
            final Handler handler = new Handler();
            // Just show the menu to explain that is there if people start
            // version 2 for the first time.
            // We need a handler because if we just put this in onCreate
            // nothing
            // happens. I don't have any idea, why.
            handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(OpacActivity.this);
                    drawerLayout.openDrawer(drawer);
                    sp.edit().putBoolean("version2.0.0-introduced", true).apply();
                }
            }, 500);
        }
    }
}
Also used : NavigationView(android.support.design.widget.NavigationView) AccountSwitcherNavigationView(de.geeksfactory.opacclient.ui.AccountSwitcherNavigationView) SharedPreferences(android.content.SharedPreferences) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) Handler(android.os.Handler) InputMethodManager(android.view.inputmethod.InputMethodManager) MenuItem(android.view.MenuItem) NavigationView(android.support.design.widget.NavigationView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) AccountSwitcherNavigationView(de.geeksfactory.opacclient.ui.AccountSwitcherNavigationView) TextView(android.widget.TextView) ListView(android.widget.ListView) SuppressLint(android.annotation.SuppressLint) DrawerLayout(android.support.v4.widget.DrawerLayout)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 SharedPreferences (android.content.SharedPreferences)1 Handler (android.os.Handler)1 NavigationView (android.support.design.widget.NavigationView)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 AccountSwitcherNavigationView (de.geeksfactory.opacclient.ui.AccountSwitcherNavigationView)1