f259ec4701bdcfbb5840282814161072e6bc320e
[pub/Android/ownCloud.git] / oc_framework-test-project / src / com / owncloud / android / oc_framework_test_project / TestActivity.java
1 package com.owncloud.android.oc_framework_test_project;
2
3 import java.io.File;
4
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;
13
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;
19
20 /**
21 * Activity to test OC framework
22 * @author masensio
23 * @author David A. Velasco
24 */
25 public class TestActivity extends Activity {
26
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";
31
32 //private Account mAccount = null;
33 private WebdavClient mClient;
34
35 @Override
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);
42 }
43
44 @Override
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);
48 return true;
49 }
50
51 /**
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.
55 *
56 * @return
57 */
58 public RemoteOperationResult createFolder(String remotePath, boolean createFullPath) {
59
60 CreateRemoteFolderOperation createOperation = new CreateRemoteFolderOperation(remotePath, createFullPath);
61 RemoteOperationResult result = createOperation.execute(mClient);
62
63 return result;
64 }
65
66 /**
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
72 *
73 * @return
74 */
75
76 public RemoteOperationResult renameFile(String oldName, String oldRemotePath, String newName, boolean isFolder) {
77
78 RenameRemoteFileOperation renameOperation = new RenameRemoteFileOperation(oldName, oldRemotePath, newName, isFolder);
79 RemoteOperationResult result = renameOperation.execute(mClient);
80
81 return result;
82 }
83
84 /**
85 * Access to the library method to Remove a File or Folder
86 *
87 * @param remotePath Remote path of the file or folder in the server.
88 * @return
89 */
90 public RemoteOperationResult removeFile(String remotePath) {
91
92 RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
93 RemoteOperationResult result = removeOperation.execute(mClient);
94
95 return result;
96 }
97
98 /**
99 * Access to the library method to Read a Folder (PROPFIND DEPTH 1)
100 * @param remotePath
101 *
102 * @return
103 */
104 public RemoteOperationResult readFile(String remotePath) {
105
106 ReadRemoteFolderOperation readOperation= new ReadRemoteFolderOperation(remotePath);
107 RemoteOperationResult result = readOperation.execute(mClient);
108
109 return result;
110 }
111
112 /** Access to the library method to Upload a File
113 * @param storagePath
114 * @param remotePath
115 * @param mimeType
116 *
117 * @return
118 */
119 public RemoteOperationResult uploadFile(String storagePath, String remotePath, String mimeType) {
120
121 UploadRemoteFileOperation uploadOperation = new UploadRemoteFileOperation(storagePath, remotePath, mimeType);
122 RemoteOperationResult result = uploadOperation.execute(mClient);
123
124 return result;
125 }
126 }