Просмотр исходного кода

initial rewrite to make use of the toolbar

Andy Scherzinger 9 лет назад
Родитель
Сommit
ed33c0aff4

+ 4 - 3
AndroidManifest.xml

@@ -59,11 +59,12 @@
         android:name=".MainApp"
         android:icon="@mipmap/ic_launcher"
         android:label="@string/app_name"
-        android:theme="@style/Theme.ownCloud"
+        android:theme="@style/Theme.ownCloud.Toolbar"
         android:manageSpaceActivity=".ui.activity.ManageSpaceActivity">
         <activity
             android:name=".ui.activity.FileDisplayActivity"
-            android:label="@string/app_name" >
+            android:label="@string/app_name"
+            android:theme="@style/Theme.ownCloud.Toolbar.Drawer">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
 
@@ -156,7 +157,7 @@
             android:name=".authentication.AuthenticatorActivity"
             android:exported="true"
             android:launchMode="singleTask"
-            android:theme="@style/Theme.ownCloud.noActionBar" >
+            android:theme="@style/Theme.ownCloud.Toolbar" >
             <intent-filter>
                 <action android:name="android.intent.action.VIEW" />
 

+ 8 - 53
res/layout/drawer.xml

@@ -16,17 +16,17 @@
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
   -->
-<merge xmlns:android="http://schemas.android.com/apk/res/android">
-    <RelativeLayout
-        android:id="@+id/left_drawer"
-        android:layout_width="240dp"
+<merge xmlns:android="http://schemas.android.com/apk/res/android"
+       xmlns:app="http://schemas.android.com/apk/res-auto">
+
+    <android.support.design.widget.NavigationView
+        android:id="@+id/nav_view"
+        android:layout_width="wrap_content"
         android:layout_height="match_parent"
         android:layout_gravity="start"
-        android:gravity="center"
-        android:orientation="vertical"
         android:fitsSystemWindows="true"
-        android:background="@color/background_color"
-        >
+        app:headerLayout="@layout/drawer_header"
+        app:menu="@menu/drawer_menu"/>
 
         <!--TODO re-enable when "Accounts" is available in Navigation Drawer-->
         <!--<LinearLayout-->
@@ -55,49 +55,4 @@
             <!--android:layout_width="fill_parent"-->
             <!--android:layout_height="2dip"-->
             <!--android:background="@color/list_item_lastmod_and_filesize_text" />-->
-
-        <ListView
-            android:id="@+id/drawer_list"
-            android:choiceMode="singleChoice"
-            android:layout_width="fill_parent"
-            android:layout_height="match_parent"
-            android:background="@color/background_color"
-            android:divider="@null"
-            android:dividerHeight="0dp"
-            android:paddingTop="100dp" />
-
-        <LinearLayout
-            android:layout_width="fill_parent"
-            android:layout_height="100dp"
-            android:paddingTop="@dimen/standard_padding"
-            android:paddingBottom="@dimen/standard_padding"
-            android:background="@color/drawer_header_color">
-
-            <ImageView
-                android:id="@+id/itemIcon"
-                android:layout_width="24dp"
-                android:layout_height="24dp"
-                android:layout_marginLeft="@dimen/standard_padding"
-                android:layout_marginBottom="3dp"
-                android:layout_gravity="bottom"
-                android:src="@drawable/ic_account_circle"
-                />
-
-            <TextView
-                android:id="@+id/drawer_username"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_gravity="bottom"
-                android:gravity="bottom"
-                android:orientation="vertical"
-                android:text="@string/app_name"
-                android:textColor="#FFF"
-                android:paddingLeft="22dp"
-                android:paddingRight="@dimen/standard_padding"
-                android:textSize="24sp"
-                android:ellipsize="end"
-                android:singleLine="true"
-                />
-        </LinearLayout>
-    </RelativeLayout>
 </merge>

+ 50 - 0
res/layout/drawer_header.xml

@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+  ownCloud Android client application
+
+  Copyright (C) 2016 ownCloud Inc.
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License version 2,
+  as published by the Free Software Foundation.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+  -->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="100dp"
+    android:paddingTop="@dimen/standard_padding"
+    android:paddingBottom="@dimen/standard_padding"
+    android:background="@color/drawer_header_color">
+
+    <ImageView
+        android:id="@+id/itemIcon"
+        android:layout_width="24dp"
+        android:layout_height="24dp"
+        android:layout_marginLeft="@dimen/standard_padding"
+        android:layout_marginBottom="3dp"
+        android:layout_gravity="bottom"
+        android:src="@drawable/ic_account_circle"
+        />
+
+    <TextView
+        android:id="@+id/drawer_username"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="bottom"
+        android:gravity="bottom"
+        android:orientation="vertical"
+        android:text="@string/app_name"
+        android:textColor="#FFF"
+        android:paddingLeft="22dp"
+        android:paddingRight="@dimen/standard_padding"
+        android:textSize="24sp"
+        android:ellipsize="end"
+        android:singleLine="true"
+        />
+</LinearLayout>

+ 4 - 11
res/layout/files.xml

@@ -18,9 +18,11 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
   -->
 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
+                                        xmlns:app="http://schemas.android.com/apk/res-auto"
     android:id="@+id/drawer_layout"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:fitsSystemWindows="true"
     android:clickable="true" >
 
     <!-- The main content view -->
@@ -29,17 +31,8 @@
         android:layout_height="match_parent"
         android:orientation="vertical">
 
-        <ProgressBar android:id="@+id/progressBar"
-            android:layout_width="match_parent"
-            android:layout_height="4dp"
-            android:padding="0dp"
-            android:layout_margin="0dp"
-            style="@style/Widget.ownCloud.TopProgressBar"
-            android:indeterminate="false"
-            android:indeterminateOnly="false"
-            android:background="@color/background_color"
-            android:visibility="visible"
-            />
+        <include
+            layout="@layout/toolbar_standard" />
 
         <LinearLayout
             xmlns:android="http://schemas.android.com/apk/res/android"

+ 2 - 12
res/layout/files_folder_picker.xml

@@ -19,20 +19,10 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:background="@color/background_color"
     android:orientation="vertical" >
 
-    <ProgressBar android:id="@+id/progressBar"
-        android:layout_width="match_parent"
-        android:layout_height="4dp"
-        android:padding="0dp"
-        android:layout_margin="0dp"
-        style="@style/Widget.ownCloud.TopProgressBar"
-        android:indeterminate="false"
-        android:indeterminateOnly="false"
-        android:background="@color/background_color"
-        android:visibility="visible"
-        />
+    <include
+        layout="@layout/toolbar_standard" />
 
 	<FrameLayout 
 		android:layout_width="match_parent"

+ 48 - 0
res/layout/toolbar_standard.xml

@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ownCloud Android client application
+
+  Copyright (C) 2016 ownCloud Inc.
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License version 2,
+  as published by the Free Software Foundation.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+-->
+<android.support.design.widget.AppBarLayout
+    android:id="@+id/appbar"
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
+
+    <android.support.v7.widget.Toolbar
+        android:id="@+id/toolbar"
+        android:layout_width="match_parent"
+        android:layout_height="?attr/actionBarSize"
+        android:background="?attr/colorPrimary"
+        app:layout_scrollFlags="scroll|enterAlways|snap"
+        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
+
+    <ProgressBar
+        android:id="@+id/progressBar"
+        style="@style/Widget.ownCloud.TopProgressBar"
+        android:layout_width="match_parent"
+        android:layout_height="4dp"
+        android:layout_margin="0dp"
+        android:background="@color/background_color"
+        android:indeterminate="false"
+        android:indeterminateOnly="false"
+        android:padding="0dp"
+        android:visibility="visible"
+        />
+
+</android.support.design.widget.AppBarLayout>

+ 4 - 1
res/layout/upload_files_layout.xml

@@ -17,12 +17,15 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
  -->
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              xmlns:app="http://schemas.android.com/apk/res-auto"
     android:id="@+id/upload_files_layout"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
-    android:background="@color/background_color"
     android:orientation="vertical" >
 
+    <include
+        layout="@layout/toolbar_standard" />
+
     <fragment
         android:id="@+id/local_files_list"
         android:layout_width="match_parent"

+ 38 - 0
res/menu/drawer_menu.xml

@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ownCloud Android client application
+
+  Copyright (C) 2016 ownCloud Inc.
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License version 2,
+  as published by the Free Software Foundation.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+-->
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+    <group android:checkableBehavior="single">
+        <item
+            android:id="@+id/nav_all_files"
+            android:icon="@drawable/ic_folder_open"
+            android:title="@string/drawer_item_all_files"/>
+        <item
+            android:id="@+id/nav_uploads"
+            android:icon="@drawable/ic_uploads"
+            android:title="Uploads"/>
+    </group>
+
+    <!-- add an id to the group to get a separator line -->
+    <group>
+        <item
+            android:id="@+id/nav_settings"
+            android:icon="@drawable/ic_settings"
+            android:title="@string/actionbar_settings"/>
+    </group>
+</menu>

+ 12 - 5
res/values-v21/styles.xml

@@ -17,12 +17,19 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 -->
 <resources xmlns:android="http://schemas.android.com/apk/res/android">
-	<style name="ProgressDialogTheme" parent="ownCloud.Dialog">
-	</style>
-    <style name="Theme.ownCloud.NoActionBar">
-        <item name="windowActionBar">false</item>
-        <item name="windowNoTitle">true</item>
+    <style name="Theme.ownCloud.Toolbar">
         <item name="android:windowDrawsSystemBarBackgrounds">true</item>
+        <item name="windowNoTitle">true</item>
+        <item name="windowActionBar">false</item>
+        <item name="colorPrimary">@color/primary</item>
+        <item name="colorPrimaryDark">@color/primary_dark</item>
+        <item name="colorAccent">@color/color_accent</item>
+        <item name="android:alertDialogTheme">@style/Theme.ownCloud.Dialog</item>
+        <item name="alertDialogTheme">@style/ownCloud.AlertDialog</item>
+        <item name="searchViewStyle">@style/ownCloud.SearchView</item>
+    </style>
+
+    <style name="Theme.ownCloud.Toolbar.Drawer">
         <item name="android:statusBarColor">@android:color/transparent</item>
     </style>
 </resources>

+ 2 - 2
res/values/styles.xml

@@ -34,7 +34,7 @@
 	</style>
 
 	<!-- seperate action bar style for activities without an action bar -->
-	<style name="Theme.ownCloud.noActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
+	<style name="Theme.ownCloud.Toolbar" parent="Theme.AppCompat.NoActionBar">
 		<item name="windowNoTitle">true</item>
 		<item name="windowActionBar">false</item>
 		<item name="colorPrimary">@color/primary</item>
@@ -46,7 +46,7 @@
 		<item name="searchViewStyle">@style/ownCloud.SearchView</item>
     </style>
 
-	<style name="Theme.ownCloud.noActionBar.Login" parent="Theme.ownCloud.noActionBar">
+	<style name="Theme.ownCloud.noActionBar.Login" parent="Theme.ownCloud.Toolbar">
 		<item name="colorAccent">@color/white</item>
 	</style>
 

+ 218 - 0
src/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -0,0 +1,218 @@
+package com.owncloud.android.ui.activity;
+
+import android.accounts.Account;
+import android.content.Intent;
+import android.content.res.Configuration;
+import android.os.Bundle;
+import android.support.design.widget.NavigationView;
+import android.support.v4.view.GravityCompat;
+import android.support.v4.widget.DrawerLayout;
+import android.support.v7.app.ActionBar;
+import android.support.v7.app.ActionBarDrawerToggle;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.TextView;
+
+import com.owncloud.android.R;
+import com.owncloud.android.datamodel.FileDataStorageManager;
+import com.owncloud.android.datamodel.OCFile;
+
+/**
+ * Base class to handle setup of the drawer implementation.
+ */
+public abstract class DrawerActivity extends ToolbarActivity {
+    // Navigation Drawer
+    protected DrawerLayout mDrawerLayout;
+    protected ActionBarDrawerToggle mDrawerToggle;
+
+    /**
+     * Initializes the drawer and its content. This method needs to be called after the content view has been set.
+     */
+    protected void setupDrawer() {
+        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
+
+        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
+        if (navigationView != null) {
+            setupDrawerContent(navigationView);
+        }
+
+        // TODO re-enable when "Accounts" is available in Navigation Drawer
+//        // load Account in the Drawer Title
+//        // User-Icon
+//        ImageView userIcon = (ImageView) navigationDrawerLayout.findViewById(R.id.drawer_userIcon);
+//        userIcon.setImageResource(DisplayUtils.getSeasonalIconId());
+//
+//        // Username
+//        TextView username = (TextView) navigationDrawerLayout.findViewById(R.id.drawer_username);
+//        Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
+//
+//        if (account != null) {
+//            int lastAtPos = account.name.lastIndexOf("@");
+//            username.setText(account.name.substring(0, lastAtPos));
+//        }
+/*
+        // Display username in drawer
+        setUsernameInDrawer(navigationDrawerLayout, AccountUtils.getCurrentOwnCloudAccount(getApplicationContext()));
+
+        // load slide menu items
+        mDrawerTitles = getResources().getStringArray(R.array.drawer_items);
+
+        // nav drawer content description from resources
+        mDrawerContentDescriptions = getResources().
+                getStringArray(R.array.drawer_content_descriptions);
+
+        // nav drawer items
+        mDrawerItems = new ArrayList<NavigationDrawerItem>();
+        // adding nav drawer items to array
+        // TODO re-enable when "Accounts" is available in Navigation Drawer
+        // Accounts
+        // mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0],
+        // mDrawerContentDescriptions[0]));
+        // All Files
+        mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0], mDrawerContentDescriptions[0],
+                R.drawable.ic_folder_open));
+
+        // TODO Enable when "On Device" is recovered
+        // On Device
+        //mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2],
+        //        mDrawerContentDescriptions[2]));
+*/
+        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) {
+                super.onDrawerClosed(view);
+                updateActionBarTitleAndHomeButton(null);
+                invalidateOptionsMenu();
+            }
+
+            /** Called when a drawer has settled in a completely open state. */
+            public void onDrawerOpened(View drawerView) {
+                super.onDrawerOpened(drawerView);
+                getSupportActionBar().setTitle(R.string.app_name);
+                mDrawerToggle.setDrawerIndicatorEnabled(true);
+                invalidateOptionsMenu();
+            }
+        };
+        /*
+        // Set the list's click listener
+        mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
+*/
+        // Set the drawer toggle as the DrawerListener
+        mDrawerLayout.setDrawerListener(mDrawerToggle);
+        mDrawerToggle.setDrawerIndicatorEnabled(false);
+    }
+
+    /**
+     * setup drawer content, basically setting the item selected listener.
+     *
+     * @param navigationView the drawers navigation view
+     */
+    protected void setupDrawerContent(NavigationView navigationView) {
+        navigationView.setNavigationItemSelectedListener(
+                new NavigationView.OnNavigationItemSelectedListener() {
+                    @Override
+                    public boolean onNavigationItemSelected(MenuItem menuItem) {
+                        mDrawerLayout.closeDrawers();
+
+                        switch (menuItem.getItemId()) {
+                            case R.id.nav_all_files:
+                                menuItem.setChecked(true);
+                                allFilesOption();
+                                break;
+                            case R.id.nav_settings:
+                                Intent settingsIntent = new Intent(getApplicationContext(),
+                                        Preferences.class);
+                                startActivity(settingsIntent);
+                                break;
+                        }
+
+                        return true;
+                    }
+                });
+    }
+
+    /**
+     * 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);
+        }
+    }
+
+    /**
+     * Method that gets called on drawer menu click for 'All Files'.
+     */
+    public abstract void allFilesOption();
+
+    /**
+     * Updates title bar and home buttons (state and icon).
+     * <p/>
+     * Assumes that navigation drawer is NOT visible.
+     */
+    protected void updateActionBarTitleAndHomeButton(OCFile chosenFile) {
+        super.updateActionBarTitleAndHomeButton(chosenFile);
+
+        /// set home button properties
+        mDrawerToggle.setDrawerIndicatorEnabled(isRoot(chosenFile));
+    }
+
+    /**
+     * 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 accountName            the account to be set in the drawer
+     */
+    protected void setUsernameInDrawer(String accountName) {
+        if (mDrawerLayout != null && accountName != null) {
+            TextView username = (TextView) ((NavigationView) findViewById(R.id.nav_view))
+                    .getHeaderView(0).findViewById(R.id.drawer_username);
+            int lastAtPos = accountName.lastIndexOf("@");
+            username.setText(accountName.substring(0, lastAtPos));
+        }
+    }
+
+    @Override
+    protected void onPostCreate(Bundle savedInstanceState) {
+        super.onPostCreate(savedInstanceState);
+        // Sync the toggle state after onRestoreInstanceState has occurred.
+        if (mDrawerToggle != null) {
+            mDrawerToggle.syncState();
+            if (isDrawerOpen()) {
+                getSupportActionBar().setTitle(R.string.app_name);
+                mDrawerToggle.setDrawerIndicatorEnabled(true);
+            }
+        }
+    }
+
+    @Override
+    public void onConfigurationChanged(Configuration newConfig) {
+        super.onConfigurationChanged(newConfig);
+        if (mDrawerToggle != null) {
+            mDrawerToggle.onConfigurationChanged(newConfig);
+        }
+    }
+
+    @Override
+    public void onBackPressed() {
+        if (isDrawerOpen()) {
+            closeNavDrawer();
+            return;
+        }
+        super.onBackPressed();
+    }
+}

+ 4 - 218
src/com/owncloud/android/ui/activity/FileActivity.java

@@ -35,6 +35,7 @@ import android.content.res.Configuration;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.IBinder;
+import android.support.design.widget.NavigationView;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentTransaction;
@@ -43,6 +44,7 @@ import android.support.v4.widget.DrawerLayout;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.ActionBarDrawerToggle;
 import android.support.v7.app.AppCompatActivity;
+import android.view.MenuItem;
 import android.view.View;
 import android.widget.AdapterView;
 import android.widget.ListView;
@@ -96,7 +98,7 @@ import java.util.ArrayList;
  * Activity with common behaviour for activities handling {@link OCFile}s in ownCloud
  * {@link Account}s .
  */
-public class FileActivity extends AppCompatActivity
+public class FileActivity extends DrawerActivity
         implements OnRemoteOperationListener, ComponentsGetter, SslUntrustedCertDialog.OnSslUntrustedCertListener {
 
     public static final String EXTRA_FILE = "com.owncloud.android.ui.activity.FILE";
@@ -161,21 +163,6 @@ public class FileActivity extends AppCompatActivity
     protected FileUploaderBinder mUploaderBinder = null;
     private ServiceConnection mDownloadServiceConnection, mUploadServiceConnection = null;
 
-    // Navigation Drawer
-    protected DrawerLayout mDrawerLayout;
-    protected ActionBarDrawerToggle mDrawerToggle;
-    protected ListView mDrawerList;
-
-    // Slide menu items
-    protected String[] mDrawerTitles;
-    protected String[] mDrawerContentDescriptions;
-
-    protected ArrayList<NavigationDrawerItem> mDrawerItems;
-
-    protected NavigationDrawerListAdapter mNavigationDrawerAdapter = null;
-
-
-
     // TODO re-enable when "Accounts" is available in Navigation Drawer
 //    protected boolean mShowAccounts = false;
 
@@ -302,208 +289,6 @@ public class FileActivity extends AppCompatActivity
         super.onDestroy();
     }
 
-    @Override
-    protected void onPostCreate(Bundle savedInstanceState) {
-        super.onPostCreate(savedInstanceState);
-        // Sync the toggle state after onRestoreInstanceState has occurred.
-        if (mDrawerToggle != null) {
-            mDrawerToggle.syncState();
-            if (isDrawerOpen()) {
-                getSupportActionBar().setTitle(R.string.app_name);
-                mDrawerToggle.setDrawerIndicatorEnabled(true);
-            }
-        }
-    }
-
-    @Override
-    public void onConfigurationChanged(Configuration newConfig) {
-        super.onConfigurationChanged(newConfig);
-        if (mDrawerToggle != null) {
-            mDrawerToggle.onConfigurationChanged(newConfig);
-        }
-    }
-
-    @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
-        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
-//        // load Account in the Drawer Title
-//        // User-Icon
-//        ImageView userIcon = (ImageView) navigationDrawerLayout.findViewById(R.id.drawer_userIcon);
-//        userIcon.setImageResource(DisplayUtils.getSeasonalIconId());
-//
-//        // Username
-//        TextView username = (TextView) navigationDrawerLayout.findViewById(R.id.drawer_username);
-//        Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
-//
-//        if (account != null) {
-//            int lastAtPos = account.name.lastIndexOf("@");
-//            username.setText(account.name.substring(0, lastAtPos));
-//        }
-
-        // Display username in drawer
-        setUsernameInDrawer(navigationDrawerLayout, AccountUtils.getCurrentOwnCloudAccount(getApplicationContext()));
-
-        // load slide menu items
-        mDrawerTitles = getResources().getStringArray(R.array.drawer_items);
-
-        // nav drawer content description from resources
-        mDrawerContentDescriptions = getResources().
-                getStringArray(R.array.drawer_content_descriptions);
-
-        // nav drawer items
-        mDrawerItems = new ArrayList<NavigationDrawerItem>();
-        // adding nav drawer items to array
-        // TODO re-enable when "Accounts" is available in Navigation Drawer
-        // Accounts
-        // mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0],
-        // mDrawerContentDescriptions[0]));
-        // All Files
-        mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0], mDrawerContentDescriptions[0],
-                R.drawable.ic_folder_open));
-
-        // TODO Enable when "On Device" is recovered
-        // On Device
-        //mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2],
-        //        mDrawerContentDescriptions[2]));
-
-        // Uploads
-        mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[1], mDrawerContentDescriptions[2],
-                R.drawable.ic_uploads));
-
-        // Settings
-        mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2], mDrawerContentDescriptions[1],
-                R.drawable.ic_settings));
-
-        // setting the nav drawer list adapter
-        mNavigationDrawerAdapter = new NavigationDrawerListAdapter(getApplicationContext(), this,
-                mDrawerItems);
-        mDrawerList.setAdapter(mNavigationDrawerAdapter);
-
-
-        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) {
-                super.onDrawerClosed(view);
-                updateActionBarTitleAndHomeButton(null);
-                invalidateOptionsMenu();
-            }
-
-            /** Called when a drawer has settled in a completely open state. */
-            public void onDrawerOpened(View drawerView) {
-                super.onDrawerOpened(drawerView);
-                getSupportActionBar().setTitle(R.string.app_name);
-                mDrawerToggle.setDrawerIndicatorEnabled(true);
-                invalidateOptionsMenu();
-            }
-        };
-        
-        // Set the list's click listener
-        mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
-
-        // Set the drawer toggle as the DrawerListener
-        mDrawerLayout.setDrawerListener(mDrawerToggle);
-        mDrawerToggle.setDrawerIndicatorEnabled(false);
-    }
-
-    /**
-     * 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(View navigationDrawerLayout, Account account) {
-        if (navigationDrawerLayout != null && account != 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.
-     */
-    protected void updateActionBarTitleAndHomeButton(OCFile chosenFile) {
-        String title = getDefaultTitle();    // default
-        boolean inRoot;
-
-        /// choose the appropiate title
-        if (chosenFile == null) {
-            chosenFile = mFile;     // if no file is passed, current file decides
-        }
-        inRoot = (
-                chosenFile == null ||
-                (chosenFile.isFolder() && chosenFile.getParentId() == FileDataStorageManager.ROOT_PARENT_ID)
-        );
-        if (!inRoot) {
-            title = chosenFile.getFileName();
-        }
-
-        /// set the chosen title
-        ActionBar actionBar = getSupportActionBar();
-        actionBar.setTitle(title);
-        /// also as content description
-        View actionBarTitleView = getWindow().getDecorView().findViewById(
-                getResources().getIdentifier("action_bar_title", "id", "android")
-        );
-        if (actionBarTitleView != null) {    // it's null in Android 2.x
-            actionBarTitleView.setContentDescription(title);
-        }
-
-        /// set home button properties
-        mDrawerToggle.setDrawerIndicatorEnabled(inRoot);
-        actionBar.setDisplayHomeAsUpEnabled(true);
-        actionBar.setDisplayShowTitleEnabled(true);
-
-    }
-
-    protected String getDefaultTitle() {
-        return getString(R.string.default_display_name_for_root_folder);
-    }
-
     /**
      *  Sets and validates the ownCloud {@link Account} associated to the Activity.
      *
@@ -998,6 +783,7 @@ public class FileActivity extends AppCompatActivity
         startActivity(i);
     }
 
+    @Override
     public void allFilesOption(){
         restart();
     }

+ 16 - 14
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -40,6 +40,7 @@ import android.os.Build;
 import android.os.Bundle;
 import android.os.IBinder;
 import android.os.Parcelable;
+import android.support.design.widget.NavigationView;
 import android.support.design.widget.Snackbar;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
@@ -47,6 +48,7 @@ import android.support.v4.app.FragmentTransaction;
 import android.support.v4.content.ContextCompat;
 import android.support.v4.view.GravityCompat;
 import android.support.v7.app.AlertDialog;
+import android.support.v7.widget.Toolbar;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
@@ -110,7 +112,6 @@ public class FileDisplayActivity extends HookActivity
     private boolean mDualPane;
     private View mLeftFragmentContainer;
     private View mRightFragmentContainer;
-    private ProgressBar mProgressBar;
 
     private static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
     private static final String KEY_SYNC_IN_PROGRESS = "SYNC_IN_PROGRESS";
@@ -166,13 +167,11 @@ public class FileDisplayActivity extends HookActivity
         // Inflate and set the layout view
         setContentView(R.layout.files);
 
-        // Navigation Drawer
-        initDrawer();
+        // setup toolbar
+        setupToolbar();
 
-        mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
-        mProgressBar.setIndeterminateDrawable(
-                ContextCompat.getDrawable(this,
-                        R.drawable.actionbar_progress_indeterminate_horizontal));
+        // setup drawer
+        setupDrawer();
 
         mDualPane = getResources().getBoolean(R.bool.large_land_layout);
         mLeftFragmentContainer = findViewById(R.id.left_fragment_container);
@@ -231,7 +230,7 @@ public class FileDisplayActivity extends HookActivity
             createMinFragments();
         }
 
-        mProgressBar.setIndeterminate(mSyncInProgress);
+        setIndeterminate(mSyncInProgress);
         // always AFTER setContentView(...) in onCreate(); to work around bug in its implementation
 
         setBackgroundText();
@@ -309,7 +308,7 @@ public class FileDisplayActivity extends HookActivity
             setFile(file);
 
             if (mAccountWasSet) {
-                setUsernameInDrawer(findViewById(R.id.left_drawer), getAccount());
+                setUsernameInDrawer(getAccount().name);
             }
 
             if (!stateWasRecovered) {
@@ -839,8 +838,9 @@ public class FileDisplayActivity extends HookActivity
     protected void onResume() {
         Log_OC.v(TAG, "onResume() start");
         super.onResume();
+        //TODO re-enable account list
         // refresh Navigation Drawer account list
-        mNavigationDrawerAdapter.updateAccountList();
+        //mNavigationDrawerAdapter.updateAccountList();
 
         // refresh list of files
         refreshListOfFilesFragment();
@@ -996,10 +996,9 @@ public class FileDisplayActivity extends HookActivity
                     }
                     removeStickyBroadcast(intent);
                     Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
-                    mProgressBar.setIndeterminate(mSyncInProgress);
+                    setIndeterminate(mSyncInProgress);
 
                     setBackgroundText();
-
                 }
 
                 if (synchResult != null) {
@@ -1107,7 +1106,7 @@ public class FileDisplayActivity extends HookActivity
                     }
                 }
 
-                mProgressBar.setIndeterminate(false);
+                setIndeterminate(false);
 
             } finally {
                 if (intent != null) {
@@ -1241,6 +1240,9 @@ public class FileDisplayActivity extends HookActivity
 
     @Override
     protected void updateActionBarTitleAndHomeButton(OCFile chosenFile) {
+        if (chosenFile == null) {
+            chosenFile = getFile();     // if no file is passed, current file decides
+        }
         if (mDualPane) {
             // in dual pane mode, keep the focus of title an action bar in the current folder
             super.updateActionBarTitleAndHomeButton(getCurrentDir());
@@ -1625,7 +1627,7 @@ public class FileDisplayActivity extends HookActivity
                                     null
                             );
 
-                            mProgressBar.setIndeterminate(true);
+                            setIndeterminate(true);
 
                             setBackgroundText();
 

+ 6 - 13
src/com/owncloud/android/ui/activity/FolderPickerActivity.java

@@ -74,8 +74,6 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
 
     protected Button mCancelBtn;
     protected Button mChooseBtn;
-    private ProgressBar mProgressBar;
-
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -93,15 +91,10 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
         initControls();
 
         // Action bar setup
-        ActionBar actionBar = getSupportActionBar();
-        actionBar.setDisplayShowTitleEnabled(true);
-        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
-
-        mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
-        mProgressBar.setIndeterminateDrawable(
-                getResources().getDrawable(
-                        R.drawable.actionbar_progress_indeterminate_horizontal));
-        mProgressBar.setIndeterminate(mSyncInProgress);
+        setupToolbar();
+        getSupportActionBar().setDisplayShowTitleEnabled(true);
+
+        setIndeterminate(mSyncInProgress);
         // always AFTER setContentView(...) ; to work around bug in its implementation
         
         // sets message for empty list of folders
@@ -219,7 +212,7 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
                                                                       );
         synchFolderOp.execute(getAccount(), this, null, null);
 
-        mProgressBar.setIndeterminate(true);
+        setIndeterminate(true);
 
         setBackgroundText();
     }
@@ -502,7 +495,7 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
                     removeStickyBroadcast(intent);
                     Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
 
-                    mProgressBar.setIndeterminate(mSyncInProgress);
+                    setIndeterminate(mSyncInProgress);
 
                     setBackgroundText();
                 }

+ 92 - 0
src/com/owncloud/android/ui/activity/ToolbarActivity.java

@@ -0,0 +1,92 @@
+package com.owncloud.android.ui.activity;
+
+import android.os.Bundle;
+import android.support.v4.content.ContextCompat;
+import android.support.v7.app.ActionBar;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
+import android.view.View;
+import android.widget.ProgressBar;
+
+import com.owncloud.android.R;
+import com.owncloud.android.datamodel.FileDataStorageManager;
+import com.owncloud.android.datamodel.OCFile;
+
+/**
+ * Base class providing toolbar registration functionality, see {@link #setupToolbar()}.
+ */
+public class ToolbarActivity extends AppCompatActivity {
+    private ProgressBar mProgressBar;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+    }
+
+    /**
+     * Toolbar setup that must be called in implementer's {@link #onCreate} after {@link #setContentView} if they
+     * want to use the toolbar.
+     */
+    protected void setupToolbar() {
+        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+        setSupportActionBar(toolbar);
+
+        mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
+        mProgressBar.setIndeterminateDrawable(
+                ContextCompat.getDrawable(this, R.drawable.actionbar_progress_indeterminate_horizontal));
+    }
+
+    /**
+     * Updates title bar and home buttons (state and icon).
+     */
+    protected void updateActionBarTitleAndHomeButton(OCFile chosenFile) {
+        String title = getString(R.string.default_display_name_for_root_folder);    // default
+        boolean inRoot;
+
+        // choose the appropiate title
+        inRoot = (
+                chosenFile == null ||
+                        (chosenFile.isFolder() && chosenFile.getParentId() == FileDataStorageManager.ROOT_PARENT_ID)
+        );
+        if (!inRoot) {
+            title = chosenFile.getFileName();
+        }
+
+        /// set the chosen title
+        ActionBar actionBar = getSupportActionBar();
+        actionBar.setTitle(title);
+
+        /// also as content description
+        View actionBarTitleView = getWindow().getDecorView().findViewById(
+                getResources().getIdentifier("action_bar_title", "id", "android")
+        );
+        // TODO remove legacy code
+        if (actionBarTitleView != null) {    // it's null in Android 2.x
+            actionBarTitleView.setContentDescription(title);
+        }
+
+        /// set home button properties
+        actionBar.setDisplayHomeAsUpEnabled(true);
+        actionBar.setDisplayShowTitleEnabled(true);
+    }
+
+    /**
+     * checks if the given file is the root folder.
+     *
+     * @param file file to be checked if it is the root folder
+     * @return <code>true</code> if it is <code>null</code> or the root folder, else returns <code>false</code>
+     */
+    public boolean isRoot(OCFile file) {
+        return file == null ||
+                (file.isFolder() && file.getParentId() == FileDataStorageManager.ROOT_PARENT_ID);
+    }
+
+    /**
+     * Change the indeterminate mode for the toolbar's progress bar.
+     *
+     * @param indeterminate <code>true</code> to enable the indeterminate mode
+     */
+    public void setIndeterminate(boolean indeterminate) {
+        mProgressBar.setIndeterminate(indeterminate);
+    }
+}

+ 4 - 1
src/com/owncloud/android/ui/activity/UploadFilesActivity.java

@@ -119,6 +119,7 @@ public class UploadFilesActivity extends FileActivity implements
 
         // Inflate and set the layout view
         setContentView(R.layout.upload_files_layout);
+
         mFileListFragment = (LocalFileListFragment)
                 getSupportFragmentManager().findFragmentById(R.id.local_files_list);
         
@@ -143,7 +144,9 @@ public class UploadFilesActivity extends FileActivity implements
         if (localBehaviour == FileUploader.LOCAL_BEHAVIOUR_COPY){
             mRadioBtnCopyFiles.setChecked(true);
         }
-        
+
+        // setup the toolbar
+        setupToolbar();
             
         // Action bar setup
         ActionBar actionBar = getSupportActionBar();

+ 1 - 1
src/com/owncloud/android/ui/preview/PreviewImageActivity.java

@@ -96,7 +96,7 @@ public class PreviewImageActivity extends FileActivity implements
         setContentView(R.layout.preview_image_activity);
 
         // Navigation Drawer
-        initDrawer();
+        setupDrawer();
 
         // ActionBar
         ActionBar actionBar = getSupportActionBar();