Kaydet (Commit) b610c98b authored tarafından aleksandar-stefanovic's avatar aleksandar-stefanovic Kaydeden (comit) jan iversen

Revamped the navigation drawer

Replaced the custom implementation of the drawer with the support library one.
This one inherently follows Material Design guidelines, and is much easier to
maintain. This implementation also allows for header in the drawer, and so
we could put something useful there to make the drawer even better. Also kept
the original way of programatically adding the menu items, although I find this
practice somewhat unelegant. Maybe we could have static list of items, and then
grey-out the ones that aren't currently available? Also added appropriate icons
to the menu items (which are vector drawables, of course), but I only covered
the providers that appeared on my device (I can't confirm that there are no
other providers), so if the provider is covered, it will have an icon, but if
I didn't cover it, it will appear just fine, but without an icon. Maybe we
could move the settings and sorting to the navigation drawer, also? It would
be cleaner and more elegant, IMO.

Change-Id: I02a051f0b75c6d4e16f518aa19fb9c6eef00f5e4
Reviewed-on: https://gerrit.libreoffice.org/32881Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarjan iversen <jani@documentfoundation.org>
üst ad694ef6
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4 9.11,4 6.6,5.64 5.35,8.04 2.34,8.36 0,10.91 0,14c0,3.31 2.69,6 6,6h13c2.76,0 5,-2.24 5,-5 0,-2.64 -2.05,-4.78 -4.65,-4.96z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0" >
<path android:fillColor="#FF000000" android:pathData="M6,2c-1.1,0 -1.99,0.9 -1.99,2L4,20c0,1.1 0.89,2 1.99,2L18,22c1.1,0 2,-0.9 2,-2L20,8l-6,-6L6,2zM13,9L13,3.5L18.5,9L13,9z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M18,2h-8L4.02,8 4,20c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,4c0,-1.1 -0.9,-2 -2,-2zM12,8h-2L10,4h2v4zM15,8h-2L13,4h2v4zM18,8h-2L16,4h2v4z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M2,20h20v-4L2,16v4zM4,17h2v2L4,19v-2zM2,4v4h20L22,4L2,4zM6,7L4,7L4,5h2v2zM2,14h20v-4L2,10v4zM4,11h2v2L4,13v-2z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0" >
<path android:fillColor="#FF000000" android:pathData="M15,7v4h1v2h-3V5h2l-3,-4 -3,4h2v8H8v-2.07c0.7,-0.37 1.2,-1.08 1.2,-1.93 0,-1.21 -0.99,-2.2 -2.2,-2.2 -1.21,0 -2.2,0.99 -2.2,2.2 0,0.85 0.5,1.56 1.2,1.93V13c0,1.11 0.89,2 2,2h3v3.05c-0.71,0.37 -1.2,1.1 -1.2,1.95 0,1.22 0.99,2.2 2.2,2.2 1.21,0 2.2,-0.98 2.2,-2.2 0,-0.85 -0.49,-1.58 -1.2,-1.95V15h3c1.11,0 2,-0.89 2,-2v-2h1V7h-4z"/>
</vector>
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
--> -->
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" 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_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" > android:orientation="vertical" >
...@@ -26,18 +27,18 @@ ...@@ -26,18 +27,18 @@
android:id="@+id/browser_main_content" android:id="@+id/browser_main_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/background_normal"
android:orientation="vertical" /> android:orientation="vertical" />
<!-- The navigation drawer --> <!-- The navigation drawer -->
<ListView <android.support.design.widget.NavigationView
android:id="@+id/left_drawer" android:id="@+id/navigation_drawer"
android:layout_width="240dp" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="start" android:layout_gravity="start"
android:background="#111" android:background="@color/background_normal"
android:choiceMode="singleChoice" app:menu="@menu/navigation_menu"
android:divider="@android:color/transparent" android:theme="@style/LibreOfficeTheme.NavigationView" />
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout> </android.support.v4.widget.DrawerLayout>
</LinearLayout> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is part of the LibreOffice project.
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="48dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/white"
android:gravity="center_vertical"
android:paddingLeft="48dp"
/>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group
android:checkableBehavior="single"
android:id="@+id/group_providers">
<!--Items will be added programmatically in LibreOfficeUIActivity.java-->
</group>
</menu>
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
- file, You can obtain one at http://mozilla.org/MPL/2.0/. --> - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<resources> <resources>
<color name="background_light">#FFECF0F3</color> <color name="background_light">#FAFAFA</color> <!--Material Grey 50-->
<color name="background_normal">#FFCED7DE</color> <color name="background_normal">#F5F5F5</color> <!--Material Grey 100-->
<color name="background_private">#FF292C29</color> <color name="background_private">#FF292C29</color>
<color name="background_tabs">#FF363B40</color> <color name="background_tabs">#FF363B40</color>
<color name="highlight">#33000000</color> <color name="highlight">#33000000</color>
......
...@@ -19,4 +19,8 @@ ...@@ -19,4 +19,8 @@
<item name="colorPrimary">@color/toolbar_background</item> <item name="colorPrimary">@color/toolbar_background</item>
</style> </style>
<style name="LibreOfficeTheme.NavigationView">
<item name="colorPrimary">@android:color/black</item>
</style>
</resources> </resources>
...@@ -49,6 +49,7 @@ import android.widget.ListAdapter; ...@@ -49,6 +49,7 @@ import android.widget.ListAdapter;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import android.support.design.widget.NavigationView;
import org.libreoffice.LOAbout; import org.libreoffice.LOAbout;
import org.libreoffice.LibreOfficeMainActivity; import org.libreoffice.LibreOfficeMainActivity;
...@@ -65,6 +66,8 @@ import java.io.FilenameFilter; ...@@ -65,6 +66,8 @@ import java.io.FilenameFilter;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -94,7 +97,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity { ...@@ -94,7 +97,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity {
public static final int LIST_VIEW = 1; public static final int LIST_VIEW = 1;
private DrawerLayout drawerLayout; private DrawerLayout drawerLayout;
private ListView drawerList; private NavigationView navigationDrawer;
private ActionBarDrawerToggle drawerToggle; private ActionBarDrawerToggle drawerToggle;
GridView gv; GridView gv;
ListView lv; ListView lv;
...@@ -178,10 +181,54 @@ public class LibreOfficeUIActivity extends AppCompatActivity { ...@@ -178,10 +181,54 @@ public class LibreOfficeUIActivity extends AppCompatActivity {
registerForContextMenu(lv); registerForContextMenu(lv);
} }
// setup the drawer //Setting up navigation drawer
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerList = (ListView) findViewById(R.id.left_drawer); navigationDrawer = (NavigationView) findViewById(R.id.navigation_drawer);
/*
* These are the currently-known document providers (for which icons are assigned).
* This is to ensure that there is an icon available if the provider is recognized, while
* the unrecognized ones still appear, but without an icon. If there is a document provider
* not on this list, it should be added and an icon assigned to it, in the if-else ladder
* bellow. This is a hacky implementation, maybe we could make something better in the
* future, i.e. we could move this into the menu file and load it that way.
*/
final String LOCAL_DOCUMENTS_NAME = "Local documents";
final String LOCAL_FILE_SYSTEM_NAME = "Local file system";
final String EXTERNAL_SD_NAME = "External SD";
final String OTG_FILE_SYSTEM_NAME = "OTG device (experimental)";
final String OWNCLOUD_NAME = "Remote server";
//Provider names are wrapped as a ArrayList so indexOf(Object) method could be used
final ArrayList<CharSequence> providerNames = new ArrayList<CharSequence>(
Arrays.asList(documentProviderFactory.getNames())
);
for (CharSequence name : providerNames) {
int iconRes = 0;
if (name.equals(LOCAL_DOCUMENTS_NAME)) {
iconRes = R.drawable.ic_insert_drive_file_black_24dp;
} else if (name.equals(LOCAL_FILE_SYSTEM_NAME)) {
iconRes = R.drawable.ic_storage_black_24dp;
} else if (name.equals(EXTERNAL_SD_NAME)) {
iconRes = R.drawable.ic_sd_card_black_24dp;
} else if (name.equals(OTG_FILE_SYSTEM_NAME)) {
iconRes = R.drawable.ic_usb_black_24dp;
} else if (name.equals(OWNCLOUD_NAME)) {
iconRes = R.drawable.ic_cloud_black_24dp;
}
MenuItem item = navigationDrawer.getMenu().add(R.id.group_providers, Menu.NONE, Menu.NONE, name)
.setCheckable(true);
if (iconRes != 0) {
item.setIcon(iconRes);
}
}
navigationDrawer.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(final MenuItem item) {
int position = providerNames.indexOf(item.getTitle());
switchToDocumentProvider(documentProviderFactory.getProvider(position));
return true;
}
});
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, drawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
R.string.document_locations, R.string.close_document_locations) { R.string.document_locations, R.string.close_document_locations) {
...@@ -189,7 +236,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity { ...@@ -189,7 +236,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity {
public void onDrawerOpened(View drawerView) { public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView); super.onDrawerOpened(drawerView);
supportInvalidateOptionsMenu(); supportInvalidateOptionsMenu();
drawerList.requestFocus(); // Make keypad navigation easier navigationDrawer.requestFocus(); // Make keypad navigation easier
} }
@Override @Override
...@@ -199,21 +246,8 @@ public class LibreOfficeUIActivity extends AppCompatActivity { ...@@ -199,21 +246,8 @@ public class LibreOfficeUIActivity extends AppCompatActivity {
} }
}; };
drawerToggle.setDrawerIndicatorEnabled(true); drawerToggle.setDrawerIndicatorEnabled(true);
drawerLayout.setDrawerListener(drawerToggle); drawerLayout.addDrawerListener(drawerToggle);
drawerToggle.syncState(); drawerToggle.syncState();
// Set the adapter for the list view
drawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.item_in_drawer, documentProviderFactory.getNames()));
// Set the list's click listener
drawerList.setOnItemClickListener(new ListView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View view,
int position, long id) {
switchToDocumentProvider(documentProviderFactory
.getProvider(position));
}
});
} }
@Override @Override
...@@ -241,13 +275,13 @@ public class LibreOfficeUIActivity extends AppCompatActivity { ...@@ -241,13 +275,13 @@ public class LibreOfficeUIActivity extends AppCompatActivity {
filePaths)); filePaths));
} }
// close drawer if it was open // close drawer if it was open
drawerLayout.closeDrawer(drawerList); drawerLayout.closeDrawer(navigationDrawer);
} }
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if (drawerLayout.isDrawerOpen(drawerList)) { if (drawerLayout.isDrawerOpen(navigationDrawer)) {
drawerLayout.closeDrawer(drawerList); drawerLayout.closeDrawer(navigationDrawer);
} else if (!currentDirectory.equals(homeDirectory)) { } else if (!currentDirectory.equals(homeDirectory)) {
// navigate upwards in directory hierarchy // navigate upwards in directory hierarchy
openParentDirectory(); openParentDirectory();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment