[Libreoffice-commits] core.git: android/source

aleksandar-stefanovic theonewithideas at gmail.com
Mon Jan 16 08:02:39 UTC 2017


 android/source/res/drawable/ic_cloud_black_24dp.xml                   |    9 +
 android/source/res/drawable/ic_insert_drive_file_black_24dp.xml       |    7 
 android/source/res/drawable/ic_sd_card_black_24dp.xml                 |    9 +
 android/source/res/drawable/ic_storage_black_24dp.xml                 |    9 +
 android/source/res/drawable/ic_usb_black_24dp.xml                     |    7 
 android/source/res/layout/activity_document_browser.xml               |   15 +
 android/source/res/layout/item_in_drawer.xml                          |   17 --
 android/source/res/menu/navigation_menu.xml                           |   10 +
 android/source/res/values/colors.xml                                  |    4 
 android/source/res/values/themes.xml                                  |    4 
 android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java |   78 +++++++---
 11 files changed, 121 insertions(+), 48 deletions(-)

New commits:
commit b610c98b5981b9d2ab531196e17a6c6059e8d272
Author: aleksandar-stefanovic <theonewithideas at gmail.com>
Date:   Mon Jan 9 11:58:59 2017 +0100

    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/32881
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: jan iversen <jani at documentfoundation.org>

diff --git a/android/source/res/drawable/ic_cloud_black_24dp.xml b/android/source/res/drawable/ic_cloud_black_24dp.xml
new file mode 100644
index 0000000..e0940ca
--- /dev/null
+++ b/android/source/res/drawable/ic_cloud_black_24dp.xml
@@ -0,0 +1,9 @@
+<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>
diff --git a/android/source/res/drawable/ic_insert_drive_file_black_24dp.xml b/android/source/res/drawable/ic_insert_drive_file_black_24dp.xml
new file mode 100644
index 0000000..aaeb289
--- /dev/null
+++ b/android/source/res/drawable/ic_insert_drive_file_black_24dp.xml
@@ -0,0 +1,7 @@
+<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>
diff --git a/android/source/res/drawable/ic_sd_card_black_24dp.xml b/android/source/res/drawable/ic_sd_card_black_24dp.xml
new file mode 100644
index 0000000..f9ad72d
--- /dev/null
+++ b/android/source/res/drawable/ic_sd_card_black_24dp.xml
@@ -0,0 +1,9 @@
+<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>
diff --git a/android/source/res/drawable/ic_storage_black_24dp.xml b/android/source/res/drawable/ic_storage_black_24dp.xml
new file mode 100644
index 0000000..53c595c
--- /dev/null
+++ b/android/source/res/drawable/ic_storage_black_24dp.xml
@@ -0,0 +1,9 @@
+<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>
diff --git a/android/source/res/drawable/ic_usb_black_24dp.xml b/android/source/res/drawable/ic_usb_black_24dp.xml
new file mode 100644
index 0000000..d9b39ba
--- /dev/null
+++ b/android/source/res/drawable/ic_usb_black_24dp.xml
@@ -0,0 +1,7 @@
+<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>
diff --git a/android/source/res/layout/activity_document_browser.xml b/android/source/res/layout/activity_document_browser.xml
index 297dba1..675c147 100644
--- a/android/source/res/layout/activity_document_browser.xml
+++ b/android/source/res/layout/activity_document_browser.xml
@@ -8,6 +8,7 @@
  -->
 <LinearLayout
     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="match_parent"
     android:orientation="vertical" >
@@ -26,18 +27,18 @@
             android:id="@+id/browser_main_content"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
+            android:background="@color/background_normal"
             android:orientation="vertical" />
 
         <!-- The navigation drawer -->
-        <ListView
-            android:id="@+id/left_drawer"
-            android:layout_width="240dp"
+        <android.support.design.widget.NavigationView
+            android:id="@+id/navigation_drawer"
+            android:layout_width="wrap_content"
             android:layout_height="match_parent"
             android:layout_gravity="start"
-            android:background="#111"
-            android:choiceMode="singleChoice"
-            android:divider="@android:color/transparent"
-            android:dividerHeight="0dp" />
+            android:background="@color/background_normal"
+            app:menu="@menu/navigation_menu"
+            android:theme="@style/LibreOfficeTheme.NavigationView" />
 
     </android.support.v4.widget.DrawerLayout>
 </LinearLayout>
diff --git a/android/source/res/layout/item_in_drawer.xml b/android/source/res/layout/item_in_drawer.xml
deleted file mode 100644
index da73063..0000000
--- a/android/source/res/layout/item_in_drawer.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-<?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"
-/>
diff --git a/android/source/res/menu/navigation_menu.xml b/android/source/res/menu/navigation_menu.xml
new file mode 100644
index 0000000..a14ff7ab4
--- /dev/null
+++ b/android/source/res/menu/navigation_menu.xml
@@ -0,0 +1,10 @@
+<?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>
diff --git a/android/source/res/values/colors.xml b/android/source/res/values/colors.xml
index 8cd9e95..4348b5b 100644
--- a/android/source/res/values/colors.xml
+++ b/android/source/res/values/colors.xml
@@ -4,8 +4,8 @@
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <resources>
-    <color name="background_light">#FFECF0F3</color>
-    <color name="background_normal">#FFCED7DE</color>
+    <color name="background_light">#FAFAFA</color> <!--Material Grey 50-->
+    <color name="background_normal">#F5F5F5</color> <!--Material Grey 100-->
     <color name="background_private">#FF292C29</color>
     <color name="background_tabs">#FF363B40</color>
     <color name="highlight">#33000000</color>
diff --git a/android/source/res/values/themes.xml b/android/source/res/values/themes.xml
index 807bf81..3c89209 100644
--- a/android/source/res/values/themes.xml
+++ b/android/source/res/values/themes.xml
@@ -19,4 +19,8 @@
         <item name="colorPrimary">@color/toolbar_background</item>
     </style>
 
+    <style name="LibreOfficeTheme.NavigationView">
+        <item name="colorPrimary">@android:color/black</item>
+    </style>
+
 </resources>
diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
index 6580d53..0f4bf06 100644
--- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -49,6 +49,7 @@ import android.widget.ListAdapter;
 import android.widget.ListView;
 import android.widget.TextView;
 import android.widget.Toast;
+import android.support.design.widget.NavigationView;
 
 import org.libreoffice.LOAbout;
 import org.libreoffice.LibreOfficeMainActivity;
@@ -65,6 +66,8 @@ import java.io.FilenameFilter;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
 
@@ -94,7 +97,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity {
     public static final int LIST_VIEW = 1;
 
     private DrawerLayout drawerLayout;
-    private ListView drawerList;
+    private NavigationView navigationDrawer;
     private ActionBarDrawerToggle drawerToggle;
     GridView gv;
     ListView lv;
@@ -178,10 +181,54 @@ public class LibreOfficeUIActivity extends AppCompatActivity {
             registerForContextMenu(lv);
         }
 
-        // setup the drawer
-
+        //Setting up navigation drawer
         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,
                 R.string.document_locations, R.string.close_document_locations) {
 
@@ -189,7 +236,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity {
             public void onDrawerOpened(View drawerView) {
                 super.onDrawerOpened(drawerView);
                 supportInvalidateOptionsMenu();
-                drawerList.requestFocus(); // Make keypad navigation easier
+                navigationDrawer.requestFocus(); // Make keypad navigation easier
             }
 
             @Override
@@ -199,21 +246,8 @@ public class LibreOfficeUIActivity extends AppCompatActivity {
             }
         };
         drawerToggle.setDrawerIndicatorEnabled(true);
-        drawerLayout.setDrawerListener(drawerToggle);
+        drawerLayout.addDrawerListener(drawerToggle);
         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
@@ -241,13 +275,13 @@ public class LibreOfficeUIActivity extends AppCompatActivity {
                     filePaths));
         }
         // close drawer if it was open
-        drawerLayout.closeDrawer(drawerList);
+        drawerLayout.closeDrawer(navigationDrawer);
     }
 
     @Override
     public void onBackPressed() {
-        if (drawerLayout.isDrawerOpen(drawerList)) {
-            drawerLayout.closeDrawer(drawerList);
+        if (drawerLayout.isDrawerOpen(navigationDrawer)) {
+            drawerLayout.closeDrawer(navigationDrawer);
         } else if (!currentDirectory.equals(homeDirectory)) {
             // navigate upwards in directory hierarchy
             openParentDirectory();


More information about the Libreoffice-commits mailing list