Search in sources :

Example 11 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 12 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 13 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 14 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 15 with DrawerLayout

use of android.support.v4.widget.DrawerLayout in project carat by amplab.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    CaratApplication.setMain(this);
    tracker = Tracker.getInstance();
    // track user clicks (taps)
    tracker.trackUser("caratstarted");
    if (!CaratApplication.isInternetAvailable()) {
        EnableInternetDialogFragment dialog = new EnableInternetDialogFragment();
        dialog.show(getSupportFragmentManager(), "dialog");
    }
    /*
		 * Activity.getWindow.requestFeature() should get invoked only before
		 * setContentView(), otherwise it will cause an app crash The progress
		 * bar doesn't get displayed when there is no update in progress
		 */
    getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    getWindow().requestFeature(Window.FEATURE_PROGRESS);
    // Log.d(TAG, "about to set the layout");
    setContentView(R.layout.activity_main);
    ActionBar actionBar = getSupportActionBar();
    setTitleNormal();
    // read and load the preferences specified in our xml preference file
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    // Log.d(TAG, "about to initialize fragments");
    preInittializeFragments();
    // Log.d(TAG, "done with fragment initialization");
    /*
		 * Before using the field "fullVersion", first invoke setTitleNormal()
		 * or setFullVersion() to set this field
		 */
    mDrawerItems = getResources().getStringArray(R.array.drawer_items);
    List<Item> items = new ArrayList<Item>();
    //		items.add(new NavDrawerListHeader("Main"));
    items.add(new ListItem(mDrawerItems[0]));
    items.add(new ListItem(mDrawerItems[1]));
    items.add(new ListItem(mDrawerItems[2]));
    items.add(new ListItem(mDrawerItems[3]));
    items.add(new ListItem(mDrawerItems[4]));
    items.add(new NavDrawerListHeader(""));
    items.add(new ListItem(mDrawerItems[5]));
    items.add(new ListItem(mDrawerItems[6]));
    TextArrayAdapter adapter = new TextArrayAdapter(this, items);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    // 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
    mDrawerList.setAdapter(adapter);
    //		mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mDrawerItems));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* 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 */
        public void onDrawerClosed(View view) {
        //getSupportActionBar().setTitle(mTitle);
        }

        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mTitle);
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    // Enable ActionBar app icon to behave as action to toggle navigation drawer
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);
    if (savedInstanceState == null) {
        selectItem(0);
    }
    setTitleNormal();
// Uncomment the following to enable listening on local port 8080:
/*
		 * try {
		 *  HelloServer h = new HelloServer();
		 * } catch (IOException e) {
		 *  e.printStackTrace(); 
		 * }
		 */
}
Also used : MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) EnableInternetDialogFragment(edu.berkeley.cs.amplab.carat.android.fragments.EnableInternetDialogFragment) ActionBar(android.support.v7.app.ActionBar)

Aggregations

DrawerLayout (android.support.v4.widget.DrawerLayout)63 View (android.view.View)59 ActionBarDrawerToggle (android.support.v4.app.ActionBarDrawerToggle)33 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)22 AdapterView (android.widget.AdapterView)22 NavigationView (android.support.design.widget.NavigationView)21 ListView (android.widget.ListView)21 Intent (android.content.Intent)19 Toolbar (android.support.v7.widget.Toolbar)19 TextView (android.widget.TextView)15 ImageView (android.widget.ImageView)12 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 SuppressLint (android.annotation.SuppressLint)5 TabLayout (android.support.design.widget.TabLayout)5 ArrayList (java.util.ArrayList)5 ActionBar (android.app.ActionBar)4 TypedArray (android.content.res.TypedArray)4