super.onBackPressed();
}
+ /**
+ * checks if the drawer exists and is opened.
+ *
+ * @return <code>true</code> if the drawer is open, else <code>false</code>
+ */
public boolean isDrawerOpen() {
- return mDrawerLayout.isDrawerOpen(GravityCompat.START);
+ if(mDrawerLayout != null) {
+ return mDrawerLayout.isDrawerOpen(GravityCompat.START);
+ } else {
+ return false;
+ }
}
+ /**
+ * closes the navigation drawer.
+ */
public void closeNavDrawer() {
- mDrawerLayout.closeDrawer(GravityCompat.START);
+ if(mDrawerLayout != null) {
+ mDrawerLayout.closeDrawer(GravityCompat.START);
+ }
}
protected void initDrawer(){
// }
// Display username in drawer
- Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
- if (account != null) {
- TextView username = (TextView) navigationDrawerLayout.findViewById(R.id.drawer_username);
- int lastAtPos = account.name.lastIndexOf("@");
- username.setText(account.name.substring(0, lastAtPos));
- }
+ setUsernameInDrawer(navigationDrawerLayout, AccountUtils.getCurrentOwnCloudAccount(getApplicationContext()));
// load slide menu items
mDrawerTitles = getResources().getStringArray(R.array.drawer_items);
}
/**
+ * sets the given account name in the drawer in case the drawer is available. The account name
+ * is shortened beginning from the @-sign in the username.
+ *
+ * @param navigationDrawerLayout the drawer layout to be used
+ * @param account the account to be set in the drawer
+ */
+ protected void setUsernameInDrawer(RelativeLayout navigationDrawerLayout, Account account) {
+ if (navigationDrawerLayout != null && getAccount() != null) {
+ TextView username = (TextView) navigationDrawerLayout.findViewById(R.id.drawer_username);
+ int lastAtPos = account.name.lastIndexOf("@");
+ username.setText(account.name.substring(0, lastAtPos));
+ }
+ }
+
+ /**
* Updates title bar and home buttons (state and icon).
*
* Assumes that navigation drawer is NOT visible.