Skip to content
neokree edited this page Dec 19, 2014 · 1 revision

GoogleNavigationDrawer wiki

this is a simple wiki that show you all library functionality

Sections

A section is a simple element of your navigation drawer list. There are two type of section at this time:

  • Text Section
  • Text and Icon Section

Every section could have a notifications number.

There are two different lists where you can add your section:

  • Top list (default list)
  • Bottom List
    It is a list used exclusively for About, Settings or other things like this.
Create Section methods
    // only text section, it opens an activity
    public GSection newSection(String title,Intent target)
    
    // only text section, it opens a fragment
    public GSection newSection(String title,Fragment target)
    
    // icon bitmap and text section, it opens an activity
    public GSection newSection(String title, Bitmap icon,Intent target)
    
    // icon bitmap and text section, it opens a fragment
    public GSection newSection(String title, Bitmap icon,Fragment target)
    
    // icon drawable and text section, it opens an activity
    public GSection newSection(String title, Drawable icon, Intent target)
    
    // icon drawable and text section, it opens a fragment
    public GSection newSection(String title, Drawable icon, Fragment target)
Add Section Methods
// add section to the top list
public void addSection(GSection section)

// add section to the bottom list
public void addBottomSection(GSection section)
Change Section Color
int color = Color.parseColor("FFFFFF");
mySection.setSectionColor(color);
Set/get number notifications
int number = 4;
mySection.setNotifications(number);

int notifications = mySection.getNotifications();

Separators

A separator (or divisor) is a simple grey line used for diversify group of sections.

Add separator method
@Override
    public void init(Bundle savedInstanceState) {
        this.addDivisor();
    }

Account

A collection of user data.
This library not implements an Android Account, it allows only to set user data in your navigation drawer.
NB At this time you can add accounts until a max number of 3 accounts.

Create Accounts methods
public GAccount(String title, String subTitle, Drawable photo,Bitmap background)

public GAccount(String title, String subTitle, Drawable photo,Drawable background)

public GAccount(String title, String subTitle, Bitmap photo, Drawable background)

public GAccount(String title, String subTitle, Bitmap photo, Bitmap background)
Add to your navigation drawer
GAccount account;
this.addAccount(account);
Know when your account is clicked / when it change

implements GAccountListener in your GoogleNavigationDrawer and then connect your listener to the navigation drawer

// set listener
this.setAccountListener(this);

FAQ

How can I get my action bar / toolbar?

From your Activity:

// get toolbar
this.getToolbar();
// get Action Bar
this.getSupportActionBar();

From your Fragment:

// get toolbar
((GoogleNavigationDrawer)this.getActivity()).getToolbar();
// get action bar
this.getActivity().getSupportActionBar();
How can I get the current Section?

From your Activity:

this.getCurrentSection();

From your Fragment:

((GoogleNavigationDrawer)this.getActivity()).getCurrentSection();
How can I set user background/user photo asynchronously?

When your image is loaded from the web, in your async Thread change your account information like this:

// set photo
account.setPhoto(photo);
// set background
account.setBackground(background);

And then call the notifyAccountDataChanged method on ui thread:

runOnUiThread(new Runnable() {
        @Override
        public void run() {
            notifyAccountDataChanged();
        }
    });
How can I get the current Account?

From your Activity:

this.getCurrentAccount();

From your Fragment:

((GoogleNavigationDrawer)this.getActivity()).getCurrentAccount();