diff options
author | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2015-01-21 13:05:41 +0000 |
---|---|---|
committer | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2015-06-10 17:08:00 +0000 |
commit | 69773f54bbac08953f0fbce16eecea0816e04338 (patch) | |
tree | c0802e8f3adc7e80af451dee43996b5a17ace541 /android | |
parent | sw: remove embedded data source on location deregistration (diff) | |
download | core-69773f54bbac08953f0fbce16eecea0816e04338.tar.gz core-69773f54bbac08953f0fbce16eecea0816e04338.zip |
Android: initial implementation of ownCloud provider.
This implementation can connect to a local server and browser its
contents, but cannot download and open the documents yet.
TODO:
* Download and open documents.
* UI to configure server, user and password.
* Implement filtering to show only the documents of the desired type.
* Improve error handling.
Change-Id: I54a2e2e1d3e8ec8d824d75639e176ca452551f3e
Reviewed-on: https://gerrit.libreoffice.org/16191
Reviewed-by: Jacobo Aragunde Pérez <jaragunde@igalia.com>
Tested-by: Jacobo Aragunde Pérez <jaragunde@igalia.com>
Diffstat (limited to 'android')
5 files changed, 199 insertions, 2 deletions
diff --git a/android/source/AndroidManifest.xml.in b/android/source/AndroidManifest.xml.in index 9364ea837a68..06b8089ef9ed 100644 --- a/android/source/AndroidManifest.xml.in +++ b/android/source/AndroidManifest.xml.in @@ -9,6 +9,7 @@ <uses-feature android:glEsVersion="0x00020000" android:required="true" /> <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> + <uses-permission android:name="android.permission.INTERNET" /> <application @ANDROID_DEBUGGABLE@ diff --git a/android/source/res/values/strings.xml b/android/source/res/values/strings.xml index e43c5a58b6ec..d978413b092e 100644 --- a/android/source/res/values/strings.xml +++ b/android/source/res/values/strings.xml @@ -47,6 +47,7 @@ <!-- Document provider names --> <string name="local_documents">Local documents</string> <string name="local_file_system">Local file system</string> + <string name="owncloud">ownCloud</string> <!-- Edit action names --> <string name="action_bold">Bold</string> diff --git a/android/source/src/java/org/libreoffice/storage/DocumentProviderFactory.java b/android/source/src/java/org/libreoffice/storage/DocumentProviderFactory.java index 9aa19735bbd4..3d462e655f86 100644 --- a/android/source/src/java/org/libreoffice/storage/DocumentProviderFactory.java +++ b/android/source/src/java/org/libreoffice/storage/DocumentProviderFactory.java @@ -11,6 +11,7 @@ package org.libreoffice.storage; import org.libreoffice.storage.local.LocalDocumentsDirectoryProvider; import org.libreoffice.storage.local.LocalDocumentsProvider; +import org.libreoffice.storage.owncloud.OwnCloudProvider; import android.content.Context; @@ -30,8 +31,7 @@ public final class DocumentProviderFactory { */ private static DocumentProviderFactory instance = null; - private IDocumentProvider[] providers = { - new LocalDocumentsDirectoryProvider(), new LocalDocumentsProvider() }; + private IDocumentProvider[] providers; private String[] providerNames; @@ -52,6 +52,12 @@ public final class DocumentProviderFactory { instance = new DocumentProviderFactory(); // initialize document providers list + instance.providers = new IDocumentProvider[3]; + instance.providers[0] = new LocalDocumentsDirectoryProvider(); + instance.providers[1] = new LocalDocumentsProvider(); + instance.providers[2] = new OwnCloudProvider(context); + + // initialize document provider names list instance.providerNames = new String[instance.providers.length]; for (int i = 0; i < instance.providers.length; i++) { instance.providerNames[i] = context.getString(instance diff --git a/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java b/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java new file mode 100644 index 000000000000..8e6d6cf136ff --- /dev/null +++ b/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java @@ -0,0 +1,113 @@ +package org.libreoffice.storage.owncloud; + +import java.io.File; +import java.io.FileFilter; +import java.net.URI; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.libreoffice.storage.IFile; + +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation; +import com.owncloud.android.lib.resources.files.RemoteFile; + +/** + * Implementation of IFile for ownCloud servers. + */ +public class OwnCloudFile implements IFile { + + private OwnCloudProvider provider; + private RemoteFile file; + + private String name; + private String parentPath; + + protected OwnCloudFile(OwnCloudProvider provider, RemoteFile file) { + this.provider = provider; + this.file = file; + + // get name and parent from path + File localFile = new File(file.getRemotePath()); + this.name = localFile.getName(); + this.parentPath = localFile.getParent(); + } + + @Override + public URI getUri() { + return URI.create(file.getRemotePath()); + } + + @Override + public String getName() { + return name; + } + + @Override + public boolean isDirectory() { + return file.getMimeType().equals("DIR"); + } + + @Override + public long getSize() { + return file.getLength(); + } + + @Override + public Date getLastModified() { + return new Date(file.getModifiedTimestamp()); + } + + @Override + public List<IFile> listFiles() { + List<IFile> children = new ArrayList<IFile>(); + if (isDirectory()) { + ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation( + file.getRemotePath()); + RemoteOperationResult result = refreshOperation.execute(provider + .getClient()); + if (!result.isSuccess()) { + throw new RuntimeException(result.getLogMessage(), + result.getException()); + } + for (Object obj : result.getData()) { + RemoteFile child = (RemoteFile) obj; + if (!child.getRemotePath().equals(file.getRemotePath())) + children.add(new OwnCloudFile(provider, child)); + } + } + return children; + } + + @Override + public List<IFile> listFiles(FileFilter filter) { + // TODO no filtering yet + return listFiles(); + } + + @Override + public IFile getParent() { + if (parentPath == null) + // this is the root node + return null; + + return provider.createFromUri(URI.create(parentPath)); + } + + @Override + public File getDocument() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean equals(Object object) { + if (this == object) + return true; + if (!(object instanceof OwnCloudFile)) + return false; + OwnCloudFile file = (OwnCloudFile) object; + return file.getUri().equals(getUri()); + } +} diff --git a/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java b/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java new file mode 100644 index 000000000000..7bd78e3550e5 --- /dev/null +++ b/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java @@ -0,0 +1,76 @@ +package org.libreoffice.storage.owncloud; + +import java.net.URI; + +import org.libreoffice.R; +import org.libreoffice.storage.IDocumentProvider; +import org.libreoffice.storage.IFile; + +import android.content.Context; +import android.net.Uri; + +import com.owncloud.android.lib.common.OwnCloudClient; +import com.owncloud.android.lib.common.OwnCloudClientFactory; +import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.resources.files.FileUtils; +import com.owncloud.android.lib.resources.files.ReadRemoteFileOperation; +import com.owncloud.android.lib.resources.files.RemoteFile; + +/** + * Implementation of IDocumentProvider for ownCloud servers. + */ +public class OwnCloudProvider implements IDocumentProvider { + + private OwnCloudClient client; + + // TODO: these must be configurable + final private String serverUrl = "http://10.0.2.2/owncloud"; //emulator host machine + final private String userName = "admin"; + final private String password = "admin"; + + public OwnCloudProvider(Context context) { + Uri serverUri = Uri.parse(serverUrl); + client = OwnCloudClientFactory.createOwnCloudClient(serverUri, + context, true); + client.setCredentials(OwnCloudCredentialsFactory.newBasicCredentials( + userName, password)); + + } + + @Override + public IFile getRootDirectory() { + return createFromUri(URI.create(FileUtils.PATH_SEPARATOR)); + } + + @Override + public IFile createFromUri(URI uri) { + ReadRemoteFileOperation refreshOperation = new ReadRemoteFileOperation( + uri.getPath()); + RemoteOperationResult result = refreshOperation.execute(client); + if (!result.isSuccess()) { + throw new RuntimeException(result.getLogMessage(), + result.getException()); + } + if (result.getData().size() > 0) { + return new OwnCloudFile(this, (RemoteFile) result.getData().get(0)); + } + return null; + } + + @Override + public int getNameResource() { + return R.string.owncloud; + } + + /** + * Used by OwnCloudFiles to get a configured client to run their own + * operations. + * + * @return configured OwnCloudClient. + */ + protected OwnCloudClient getClient() { + return client; + } + +} |