summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorJacobo Aragunde Pérez <jaragunde@igalia.com>2015-01-15 16:30:08 +0000
committerJacobo Aragunde Pérez <jaragunde@igalia.com>2015-01-19 09:46:44 +0000
commit9f3716cb7d99ceb5c3c390e650c13188f6515e61 (patch)
tree04200e4c4d6d6e7eb0d78140029751d30f5c02b8 /android
parente0517616fac5b9b64ad82257534db95f39df568d (diff)
Android: reimplement DocumentProviderFactory as a singleton
The factory will require some objects that are not available from a static context. Change-Id: Idf852f5b9ab3023644b1a9577951a94c4f21c4e9
Diffstat (limited to 'android')
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/storage/DocumentProviderFactory.java37
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java10
2 files changed, 38 insertions, 9 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/DocumentProviderFactory.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/DocumentProviderFactory.java
index 57b0437b5ab5..2ec0dc9514fd 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/DocumentProviderFactory.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/DocumentProviderFactory.java
@@ -16,22 +16,47 @@ 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.
+ *
+ * The factory follows the Singleton pattern, there is only one instance of it
+ * in the application and it must be retrieved with
+ * DocumentProviderFactory.getInstance().
*/
-public class DocumentProviderFactory {
+public final class DocumentProviderFactory {
+
+ /**
+ * Private factory instance for the Singleton pattern.
+ */
+ private static DocumentProviderFactory instance = null;
- private static IDocumentProvider[] providers = {
+ private IDocumentProvider[] providers = {
new LocalDocumentsDirectoryProvider(), new LocalDocumentsProvider() };
- private static String[] providerNames = {
+ private String[] providerNames = {
"Local documents", "Local file system" };
+ private DocumentProviderFactory() {
+ // private to prevent external instances of the factory
+ }
+
+ /**
+ * Retrieve the unique instance of the factory.
+ *
+ * @return the unique factory object.
+ */
+ public static DocumentProviderFactory getInstance() {
+ if (instance == null) {
+ instance = new DocumentProviderFactory();
+ }
+ return instance;
+ }
+
/**
* Retrieve the provider associated to a certain position.
*
* @param position
* @return document provider in that position.
*/
- public static IDocumentProvider getProvider(int position) {
+ public IDocumentProvider getProvider(int position) {
return providers[position];
}
@@ -41,7 +66,7 @@ public class DocumentProviderFactory {
*
* @return Array with the names of the available providers.
*/
- public static String[] getNames() {
+ public String[] getNames() {
return providerNames;
}
@@ -50,7 +75,7 @@ public class DocumentProviderFactory {
*
* @return default provider.
*/
- public static IDocumentProvider getDefaultProvider() {
+ public 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 041eda83a438..1ee88bf86000 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -78,6 +78,7 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
FileFilter fileFilter;
FilenameFilter filenameFilter;
private List<IFile> filePaths;
+ private DocumentProviderFactory documentProviderFactory;
private IDocumentProvider documentProvider;
private IFile homeDirectory;
private IFile currentDirectory;
@@ -105,8 +106,11 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
super.onCreate(savedInstanceState);
Log.d(tag, "onCreate - tweaked - meeks !");
+
+ documentProviderFactory = DocumentProviderFactory.getInstance();
+
//Set the "home" - top level - directory.
- documentProvider = DocumentProviderFactory.getDefaultProvider();
+ documentProvider = documentProviderFactory.getDefaultProvider();
homeDirectory = documentProvider.getRootDirectory();
currentDirectory = homeDirectory;
//Load default settings
@@ -177,13 +181,13 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
// Set the adapter for the list view
drawerList.setAdapter(new ArrayAdapter<String>(this,
- R.layout.item_in_drawer, DocumentProviderFactory.getNames()));
+ 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);
+ documentProvider = documentProviderFactory.getProvider(position);
homeDirectory = documentProvider.getRootDirectory();
currentDirectory = homeDirectory;
createUI();