summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacobo Aragunde Pérez <jaragunde@igalia.com>2015-01-14 12:51:56 +0000
committerJacobo Aragunde Pérez <jaragunde@igalia.com>2015-01-19 09:46:44 +0000
commit61682ae51129310b62290be77c8349754845aedb (patch)
tree2153283e3c197ad84645f301c52d2804b8699e37
parent9f3716cb7d99ceb5c3c390e650c13188f6515e61 (diff)
Android: i18n-ized document provider names.
The factory will need access to the Context to be able to transform the resources into Strings, and the only way to receive it is from the Activity. Implemented initialize(Context) for that reason. Change-Id: If6e81a9c4ad73180851e43968ac97aa1e74231e7
-rw-r--r--android/experimental/LOAndroid3/res/values/strings.xml4
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/storage/DocumentProviderFactory.java29
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/storage/IDocumentProvider.java8
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/storage/local/LocalDocumentsDirectoryProvider.java6
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/storage/local/LocalDocumentsProvider.java7
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java2
6 files changed, 51 insertions, 5 deletions
diff --git a/android/experimental/LOAndroid3/res/values/strings.xml b/android/experimental/LOAndroid3/res/values/strings.xml
index 2d03388e5aab..7cd74232dc20 100644
--- a/android/experimental/LOAndroid3/res/values/strings.xml
+++ b/android/experimental/LOAndroid3/res/values/strings.xml
@@ -30,4 +30,8 @@
<string name="share">Share</string>
<string name="share_via">Share via</string>
+ <!-- Document provider names -->
+ <string name="local_documents">Local documents</string>
+ <string name="local_file_system">Local file system</string>
+
</resources>
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 2ec0dc9514fd..9aa19735bbd4 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/DocumentProviderFactory.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/DocumentProviderFactory.java
@@ -12,6 +12,8 @@ package org.libreoffice.storage;
import org.libreoffice.storage.local.LocalDocumentsDirectoryProvider;
import org.libreoffice.storage.local.LocalDocumentsProvider;
+import android.content.Context;
+
/**
* Keeps the instances of the available IDocumentProviders in the system.
* Instances are maintained in a sorted list and providers have to be
@@ -31,22 +33,39 @@ public final class DocumentProviderFactory {
private IDocumentProvider[] providers = {
new LocalDocumentsDirectoryProvider(), new LocalDocumentsProvider() };
- private String[] providerNames = {
- "Local documents", "Local file system" };
+ private String[] providerNames;
private DocumentProviderFactory() {
// private to prevent external instances of the factory
}
/**
- * Retrieve the unique instance of the factory.
+ * Initializes the factory with some context. If this method is called for
+ * twice or more times those calls will have no effect.
*
- * @return the unique factory object.
+ * @param context
+ * Application context for the factory.
*/
- public static DocumentProviderFactory getInstance() {
+ public static void initialize(Context context) {
if (instance == null) {
+ // initialize instance
instance = new DocumentProviderFactory();
+
+ // initialize document providers list
+ instance.providerNames = new String[instance.providers.length];
+ for (int i = 0; i < instance.providers.length; i++) {
+ instance.providerNames[i] = context.getString(instance
+ .getProvider(i).getNameResource());
+ }
}
+ }
+
+ /**
+ * Retrieve the unique instance of the factory.
+ *
+ * @return the unique factory object or null if it is not yet initialized.
+ */
+ public static DocumentProviderFactory getInstance() {
return instance;
}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/IDocumentProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/IDocumentProvider.java
index bf50523299bb..191a1437e26b 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/IDocumentProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/IDocumentProvider.java
@@ -33,4 +33,12 @@ public interface IDocumentProvider {
* @return IFile object pointing to the content represented by uri.
*/
IFile createFromUri(URI uri);
+
+ /**
+ * Get internationalized name for this provider. This name is intended to be
+ * shown in the UI.
+ *
+ * @return string resource pointing to the provider name.
+ */
+ int getNameResource();
}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/local/LocalDocumentsDirectoryProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/local/LocalDocumentsDirectoryProvider.java
index 62bbd599010f..92d93d6ae075 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/local/LocalDocumentsDirectoryProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/local/LocalDocumentsDirectoryProvider.java
@@ -12,6 +12,7 @@ package org.libreoffice.storage.local;
import java.io.File;
import org.libreoffice.storage.IFile;
+import org.libreoffice.R;
import android.os.Environment;
@@ -31,4 +32,9 @@ public class LocalDocumentsDirectoryProvider extends LocalDocumentsProvider {
documentsDirectory.mkdirs();
return new LocalFile(documentsDirectory);
}
+
+ @Override
+ public int getNameResource() {
+ return R.string.local_documents;
+ }
}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/local/LocalDocumentsProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/local/LocalDocumentsProvider.java
index 8e211822ae99..cc96ef0a46de 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/local/LocalDocumentsProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/local/LocalDocumentsProvider.java
@@ -14,6 +14,8 @@ import java.net.URI;
import org.libreoffice.storage.IDocumentProvider;
import org.libreoffice.storage.IFile;
+import org.libreoffice.R;
+
import android.os.Environment;
/**
@@ -30,4 +32,9 @@ public class LocalDocumentsProvider implements IDocumentProvider {
public IFile createFromUri(URI uri) {
return new LocalFile(uri);
}
+
+ @Override
+ public int getNameResource() {
+ return R.string.local_file_system;
+ }
}
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 1ee88bf86000..c1d0dcb9f899 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -107,6 +107,8 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
super.onCreate(savedInstanceState);
Log.d(tag, "onCreate - tweaked - meeks !");
+ // initialize document provider factory
+ DocumentProviderFactory.initialize(this);
documentProviderFactory = DocumentProviderFactory.getInstance();
//Set the "home" - top level - directory.