Kaydet (Commit) 23313891 authored tarafından Jacobo Aragunde Pérez's avatar Jacobo Aragunde Pérez

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
üst 280f1c03
...@@ -5,11 +5,13 @@ ...@@ -5,11 +5,13 @@
License, v. 2.0. If a copy of the MPL was not distributed with this 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/. 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_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:orientation="vertical" >
<!-- The main content view -->
<GridView <GridView
android:id="@+id/file_explorer_grid_view" android:id="@+id/file_explorer_grid_view"
android:layout_width="fill_parent" android:layout_width="fill_parent"
...@@ -22,5 +24,14 @@ ...@@ -22,5 +24,14 @@
android:gravity="center"> android:gravity="center">
</GridView> </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>
...@@ -6,15 +6,27 @@ ...@@ -6,15 +6,27 @@
License, v. 2.0. If a copy of the MPL was not distributed with this 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/. 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_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:orientation="vertical" >
<!-- The main content view -->
<ListView <ListView
android:id="@+id/file_explorer_list_view" android:id="@+id/file_explorer_list_view"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent"> android:layout_height="fill_parent">
</ListView> </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>
<?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"
/>
/* -*- 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];
}
}
...@@ -12,6 +12,7 @@ package org.libreoffice.ui; ...@@ -12,6 +12,7 @@ package org.libreoffice.ui;
import org.libreoffice.R; import org.libreoffice.R;
import org.libreoffice.LOAbout; import org.libreoffice.LOAbout;
import org.libreoffice.android.Bootstrap; import org.libreoffice.android.Bootstrap;
import org.libreoffice.storage.DocumentProviderFactory;
import org.libreoffice.storage.IDocumentProvider; import org.libreoffice.storage.IDocumentProvider;
import org.libreoffice.storage.IFile; import org.libreoffice.storage.IFile;
import org.libreoffice.storage.local.LocalDocumentsProvider; import org.libreoffice.storage.local.LocalDocumentsProvider;
...@@ -40,6 +41,7 @@ import android.database.DataSetObserver; ...@@ -40,6 +41,7 @@ import android.database.DataSetObserver;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.widget.DrawerLayout;
import android.util.Log; import android.util.Log;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
...@@ -76,7 +78,7 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga ...@@ -76,7 +78,7 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
FileFilter fileFilter; FileFilter fileFilter;
FilenameFilter filenameFilter; FilenameFilter filenameFilter;
private List<IFile> filePaths; private List<IFile> filePaths;
private IDocumentProvider documentProvider = new LocalDocumentsProvider(); private IDocumentProvider documentProvider;
private IFile homeDirectory; private IFile homeDirectory;
private IFile currentDirectory; private IFile currentDirectory;
...@@ -89,6 +91,8 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga ...@@ -89,6 +91,8 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
public static final int GRID_VIEW = 0; public static final int GRID_VIEW = 0;
public static final int LIST_VIEW = 1; public static final int LIST_VIEW = 1;
private DrawerLayout drawerLayout;
private ListView drawerList;
GridView gv; GridView gv;
ListView lv; ListView lv;
...@@ -102,6 +106,7 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga ...@@ -102,6 +106,7 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Log.d(tag, "onCreate - tweaked - meeks !"); Log.d(tag, "onCreate - tweaked - meeks !");
//Set the "home" - top level - directory. //Set the "home" - top level - directory.
documentProvider = DocumentProviderFactory.getDefaultProvider();
homeDirectory = documentProvider.getRootDirectory(); homeDirectory = documentProvider.getRootDirectory();
currentDirectory = homeDirectory; currentDirectory = homeDirectory;
//Load default settings //Load default settings
...@@ -165,6 +170,26 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga ...@@ -165,6 +170,26 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
registerForContextMenu(lv); 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 @Override
......
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