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

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
üst 9f3716cb
......@@ -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>
......@@ -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;
}
......
......@@ -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();
}
......@@ -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;
}
}
......@@ -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;
}
}
......@@ -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.
......
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