1 package com
.owncloud
.android
.oc_framework_test_project
;
5 import com
.owncloud
.android
.oc_framework
.network
.webdav
.OwnCloudClientFactory
;
6 import com
.owncloud
.android
.oc_framework
.network
.webdav
.WebdavClient
;
7 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperationResult
;
8 import com
.owncloud
.android
.oc_framework
.operations
.remote
.CreateRemoteFolderOperation
;
9 import com
.owncloud
.android
.oc_framework
.operations
.remote
.ReadRemoteFolderOperation
;
10 import com
.owncloud
.android
.oc_framework
.operations
.remote
.RemoveRemoteFileOperation
;
11 import com
.owncloud
.android
.oc_framework
.operations
.remote
.RenameRemoteFileOperation
;
12 import com
.owncloud
.android
.oc_framework
.operations
.remote
.UploadRemoteFileOperation
;
14 import android
.net
.Uri
;
15 import android
.os
.Bundle
;
16 import android
.os
.Environment
;
17 import android
.app
.Activity
;
18 import android
.view
.Menu
;
21 * Activity to test OC framework
23 * @author David A. Velasco
25 public class TestActivity
extends Activity
{
27 // This account must exists on the simulator / device
28 private static final String mServerUri
= "https://beta.owncloud.com/owncloud/remote.php/webdav";
29 private static final String mUser
= "testandroid";
30 private static final String mPass
= "testandroid";
32 //private Account mAccount = null;
33 private WebdavClient mClient
;
36 protected void onCreate(Bundle savedInstanceState
) {
37 super.onCreate(savedInstanceState
);
38 setContentView(R
.layout
.activity_test
);
39 Uri uri
= Uri
.parse(mServerUri
);
40 mClient
= OwnCloudClientFactory
.createOwnCloudClient(uri
,getApplicationContext(), true
);
41 mClient
.setBasicCredentials(mUser
, mPass
);
45 public boolean onCreateOptionsMenu(Menu menu
) {
46 // Inflate the menu; this adds items to the action bar if it is present.
47 getMenuInflater().inflate(R
.menu
.test
, menu
);
52 * Access to the library method to Create a Folder
53 * @param remotePath Full path to the new directory to create in the remote server.
54 * @param createFullPath 'True' means that all the ancestor folders should be created if don't exist yet.
58 public RemoteOperationResult
createFolder(String remotePath
, boolean createFullPath
) {
60 CreateRemoteFolderOperation createOperation
= new CreateRemoteFolderOperation(remotePath
, createFullPath
);
61 RemoteOperationResult result
= createOperation
.execute(mClient
);
67 * Access to the library method to Rename a File or Folder
68 * @param oldName Old name of the file.
69 * @param oldRemotePath Old remote path of the file. For folders it starts and ends by "/"
70 * @param newName New name to set as the name of file.
71 * @param isFolder 'true' for folder and 'false' for files
76 public RemoteOperationResult
renameFile(String oldName
, String oldRemotePath
, String newName
, boolean isFolder
) {
78 RenameRemoteFileOperation renameOperation
= new RenameRemoteFileOperation(oldName
, oldRemotePath
, newName
, isFolder
);
79 RemoteOperationResult result
= renameOperation
.execute(mClient
);
85 * Access to the library method to Remove a File or Folder
87 * @param remotePath Remote path of the file or folder in the server.
90 public RemoteOperationResult
removeFile(String remotePath
) {
92 RemoveRemoteFileOperation removeOperation
= new RemoveRemoteFileOperation(remotePath
);
93 RemoteOperationResult result
= removeOperation
.execute(mClient
);
99 * Access to the library method to Read a Folder (PROPFIND DEPTH 1)
104 public RemoteOperationResult
readFile(String remotePath
) {
106 ReadRemoteFolderOperation readOperation
= new ReadRemoteFolderOperation(remotePath
);
107 RemoteOperationResult result
= readOperation
.execute(mClient
);
112 /** Access to the library method to Upload a File
119 public RemoteOperationResult
uploadFile(String storagePath
, String remotePath
, String mimeType
) {
121 UploadRemoteFileOperation uploadOperation
= new UploadRemoteFileOperation(storagePath
, remotePath
, mimeType
);
122 RemoteOperationResult result
= uploadOperation
.execute(mClient
);