Android: add UI selector for the available IDocumentProviders.

Implemented a DrawerLayout in the main activity where the providers
are listed. Also added the class DocumentProviderFactory which keeps
the instances of the providers.

Change-Id: I821958e93b9ea1008921db321e825648a8766405
diff --git a/android/experimental/LOAndroid3/res/layout/file_grid.xml b/android/experimental/LOAndroid3/res/layout/file_grid.xml
index 6b41977..ec7fdd0 100644
--- a/android/experimental/LOAndroid3/res/layout/file_grid.xml
+++ b/android/experimental/LOAndroid3/res/layout/file_grid.xml
@@ -5,11 +5,13 @@
 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/.
 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    android:layout_height="match_parent">

    <!-- The main content view -->
    <GridView
        android:id="@+id/file_explorer_grid_view"
        android:layout_width="fill_parent"
@@ -22,5 +24,14 @@
        android:gravity="center">
    </GridView>

    <!-- The navigation drawer -->
    <ListView android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#111"/>

</LinearLayout>
</android.support.v4.widget.DrawerLayout>
diff --git a/android/experimental/LOAndroid3/res/layout/file_list.xml b/android/experimental/LOAndroid3/res/layout/file_list.xml
index 48dfb1e3..dd5346f 100644
--- a/android/experimental/LOAndroid3/res/layout/file_list.xml
+++ b/android/experimental/LOAndroid3/res/layout/file_list.xml
@@ -6,15 +6,27 @@
 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/.
 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    android:layout_height="match_parent">

    <!-- The main content view -->
    <ListView
        android:id="@+id/file_explorer_list_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    </ListView>

</LinearLayout>
    <!-- The navigation drawer -->
    <ListView android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#111"/>

</android.support.v4.widget.DrawerLayout>
diff --git a/android/experimental/LOAndroid3/res/layout/item_in_drawer.xml b/android/experimental/LOAndroid3/res/layout/item_in_drawer.xml
new file mode 100644
index 0000000..da73063
--- /dev/null
+++ b/android/experimental/LOAndroid3/res/layout/item_in_drawer.xml
@@ -0,0 +1,17 @@
<?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/experimental/LOAndroid3/src/java/org/libreoffice/storage/DocumentProviderFactory.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/DocumentProviderFactory.java
new file mode 100644
index 0000000..57b0437
--- /dev/null
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/DocumentProviderFactory.java
@@ -0,0 +1,56 @@
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * 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/.
 */

package org.libreoffice.storage;

import org.libreoffice.storage.local.LocalDocumentsDirectoryProvider;
import org.libreoffice.storage.local.LocalDocumentsProvider;

/**
 * Keeps the instances of the available IDocumentProviders in the system.
 * Instances are maintained in a sorted list and providers have to be
 * accessed from their position.
 */
public class DocumentProviderFactory {

    private static IDocumentProvider[] providers = {
            new LocalDocumentsDirectoryProvider(), new LocalDocumentsProvider() };

    private static String[] providerNames = {
            "Local documents", "Local file system" };

    /**
     * Retrieve the provider associated to a certain position.
     *
     * @param position
     * @return document provider in that position.
     */
    public static IDocumentProvider getProvider(int position) {
        return providers[position];
    }

    /**
     * Returns a sorted list of the names of the providers. Order is meaningful
     * to retrieve the actual provider object with getProvider().
     *
     * @return Array with the names of the available providers.
     */
    public static String[] getNames() {
        return providerNames;
    }

    /**
     * Returns the default provider.
     *
     * @return default provider.
     */
    public static IDocumentProvider getDefaultProvider() {
        return providers[0];
    }
}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
index 8bb64f3..041eda8 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -12,6 +12,7 @@ package org.libreoffice.ui;
import org.libreoffice.R;
import org.libreoffice.LOAbout;
import org.libreoffice.android.Bootstrap;
import org.libreoffice.storage.DocumentProviderFactory;
import org.libreoffice.storage.IDocumentProvider;
import org.libreoffice.storage.IFile;
import org.libreoffice.storage.local.LocalDocumentsProvider;
@@ -40,6 +41,7 @@ import android.database.DataSetObserver;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
@@ -76,7 +78,7 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
    FileFilter fileFilter;
    FilenameFilter filenameFilter;
    private List<IFile> filePaths;
    private IDocumentProvider documentProvider = new LocalDocumentsProvider();
    private IDocumentProvider documentProvider;
    private IFile homeDirectory;
    private IFile currentDirectory;

@@ -89,6 +91,8 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
    public static final int GRID_VIEW = 0;
    public static final int LIST_VIEW = 1;

    private DrawerLayout drawerLayout;
    private ListView drawerList;
    GridView gv;
    ListView lv;

@@ -102,6 +106,7 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
        super.onCreate(savedInstanceState);
        Log.d(tag, "onCreate - tweaked - meeks !");
        //Set the "home" - top level - directory.
        documentProvider = DocumentProviderFactory.getDefaultProvider();
        homeDirectory = documentProvider.getRootDirectory();
        currentDirectory = homeDirectory;
        //Load default settings
@@ -165,6 +170,26 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
            registerForContextMenu(lv);
        }

        // setup the drawer

        drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawerList = (ListView) findViewById(R.id.left_drawer);

        // 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) {
                documentProvider = DocumentProviderFactory.getProvider(position);
                homeDirectory = documentProvider.getRootDirectory();
                currentDirectory = homeDirectory;
                createUI();
            }
        });

    }

    @Override