import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
-import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
-import android.support.v7.app.ActionBarActivity;
+import android.support.v7.app.ActionBarDrawerToggle;
+import android.support.v7.app.AppCompatActivity;
+import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
-import android.widget.LinearLayout;
import android.widget.ListView;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
import android.widget.Toast;
import com.owncloud.android.BuildConfig;
* Activity with common behaviour for activities handling {@link OCFile}s in ownCloud
* {@link Account}s .
*/
-public class FileActivity extends ActionBarActivity
+public class FileActivity extends AppCompatActivity
implements OnRemoteOperationListener, ComponentsGetter {
public static final String EXTRA_FILE = "com.owncloud.android.ui.activity.FILE";
// Sync the toggle state after onRestoreInstanceState has occurred.
if (mDrawerToggle != null) {
mDrawerToggle.syncState();
- if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
+ if (isDrawerOpen()) {
getSupportActionBar().setTitle(R.string.app_name);
mDrawerToggle.setDrawerIndicatorEnabled(true);
}
}
}
+ @Override
+ public void onBackPressed() {
+ if (isDrawerOpen()) {
+ closeNavDrawer();
+ return;
+ }
+ 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() {
+ if(mDrawerLayout != null) {
+ return mDrawerLayout.isDrawerOpen(GravityCompat.START);
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * closes the navigation drawer.
+ */
+ public void closeNavDrawer() {
+ if(mDrawerLayout != null) {
+ mDrawerLayout.closeDrawer(GravityCompat.START);
+ }
+ }
+
protected void initDrawer(){
// constant settings for action bar when navigation drawer is inited
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
// Notification Drawer
- LinearLayout navigationDrawerLayout = (LinearLayout) findViewById(R.id.left_drawer);
+ RelativeLayout navigationDrawerLayout = (RelativeLayout) findViewById(R.id.left_drawer);
mDrawerList = (ListView) navigationDrawerLayout.findViewById(R.id.drawer_list);
// TODO re-enable when "Accounts" is available in Navigation Drawer
// username.setText(account.name.substring(0, lastAtPos));
// }
+ // 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));
+ }
+
// load slide menu items
mDrawerTitles = getResources().getStringArray(R.array.drawer_items);
// mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0],
// mDrawerContentDescriptions[0]));
// All Files
- mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0], mDrawerContentDescriptions[0]));
+ mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0], mDrawerContentDescriptions[0],
+ R.drawable.ic_folder_open));
// TODO Enable when "On Device" is recovered
// On Device
// mDrawerContentDescriptions[2]));
// Settings
- mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[1], mDrawerContentDescriptions[1]));
+ mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[1], mDrawerContentDescriptions[1],
+ R.drawable.ic_settings));
// Logs
if (BuildConfig.DEBUG) {
mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2],
- mDrawerContentDescriptions[2]));
+ mDrawerContentDescriptions[2],R.drawable.ic_log));
}
// setting the nav drawer list adapter
mDrawerItems);
mDrawerList.setAdapter(mNavigationDrawerAdapter);
- mDrawerToggle = new ActionBarDrawerToggle(
- this,
- mDrawerLayout,
- R.drawable.ic_drawer,
- R.string.app_name,
- R.string.drawer_close) {
+
+ mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,R.string.drawer_open,R.string.drawer_close) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
invalidateOptionsMenu();
}
};
-
- //mDrawerToggle.setDrawerIndicatorEnabled(true);
+
// Set the list's click listener
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
+ mDrawerToggle.setDrawerIndicatorEnabled(false);
}
/**
outState.putBoolean(FileActivity.EXTRA_FROM_NOTIFICATION, mFromNotification);
outState.putLong(KEY_WAITING_FOR_OP_ID, mFileOperationsHelper.getOpIdWaitingFor());
outState.putBoolean(KEY_TRY_SHARE_AGAIN, mTryShareAgain);
- outState.putString(KEY_ACTION_BAR_TITLE, getSupportActionBar().getTitle().toString());
+ if(getSupportActionBar().getTitle() != null) {
+ // Null check in case the actionbar is used in ActionBar.NAVIGATION_MODE_LIST
+ // since it doesn't have a title then
+ outState.putString(KEY_ACTION_BAR_TITLE, getSupportActionBar().getTitle().toString());
+ }
}