1d7b485ea51d3f5d6fcd443ba63d1f1487d5700a
[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 com.owncloud.android.oc_framework.network.webdav.OwnCloudClientFactory;
4 import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
5 import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
6 import com.owncloud.android.oc_framework.operations.remote.CreateRemoteFolderOperation;
7 import com.owncloud.android.oc_framework.operations.remote.ReadRemoteFileOperation;
8 import com.owncloud.android.oc_framework.operations.remote.RemoveRemoteFileOperation;
9 import com.owncloud.android.oc_framework.operations.remote.RenameRemoteFileOperation;
10
11 import android.net.Uri;
12 import android.os.Bundle;
13 import android.app.Activity;
14 import android.view.Menu;
15
16 /**
17 * Activity to test OC framework
18 * @author masensio
19 * @author David A. Velasco
20 */
21 public class TestActivity extends Activity {
22
23 // This account must exists on the simulator / device
24 private static final String mServerUri = "https://beta.owncloud.com/owncloud/remote.php/webdav";
25 private static final String mUser = "testandroid";
26 private static final String mPass = "testandroid";
27
28 //private Account mAccount = null;
29 private WebdavClient mClient;
30
31 @Override
32 protected void onCreate(Bundle savedInstanceState) {
33 super.onCreate(savedInstanceState);
34 setContentView(R.layout.activity_test);
35 Uri uri = Uri.parse(mServerUri);
36 mClient = OwnCloudClientFactory.createOwnCloudClient(uri ,getApplicationContext(), true);
37 mClient.setBasicCredentials(mUser, mPass);
38 }
39
40 @Override
41 public boolean onCreateOptionsMenu(Menu menu) {
42 // Inflate the menu; this adds items to the action bar if it is present.
43 getMenuInflater().inflate(R.menu.test, menu);
44 return true;
45 }
46
47 /**
48 * Access to the library method to Create a Folder
49 * @param remotePath Full path to the new directory to create in the remote server.
50 * @param createFullPath 'True' means that all the ancestor folders should be created if don't exist yet.
51 *
52 * @return
53 */
54 public RemoteOperationResult createFolder(String remotePath, boolean createFullPath) {
55
56 CreateRemoteFolderOperation createOperation = new CreateRemoteFolderOperation(remotePath, createFullPath);
57 RemoteOperationResult result = createOperation.execute(mClient);
58
59 return result;
60 }
61
62 /**
63 * Access to the library method to Rename a File or Folder
64 * @param oldName Old name of the file.
65 * @param oldRemotePath Old remote path of the file. For folders it starts and ends by "/"
66 * @param newName New name to set as the name of file.
67 * @param isFolder 'true' for folder and 'false' for files
68 *
69 * @return
70 */
71
72 public RemoteOperationResult renameFile(String oldName, String oldRemotePath, String newName, boolean isFolder) {
73
74 RenameRemoteFileOperation renameOperation = new RenameRemoteFileOperation(oldName, oldRemotePath, newName, isFolder);
75 RemoteOperationResult result = renameOperation.execute(mClient);
76
77 return result;
78 }
79
80 /**
81 * Access to the library method to Remove a File or Folder
82 *
83 * @param remotePath Remote path of the file or folder in the server.
84 * @return
85 */
86 public RemoteOperationResult removeFile(String remotePath) {
87
88 RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
89 RemoteOperationResult result = removeOperation.execute(mClient);
90
91 return result;
92 }
93
94 /**
95 * Access to the library method to Read a File or Folder (PROPFIND DEPTH 1)
96 * @param remotePath
97 *
98 * @return
99 */
100 public RemoteOperationResult readFile(String remotePath) {
101
102 ReadRemoteFileOperation readOperation= new ReadRemoteFileOperation(remotePath);
103 RemoteOperationResult result = readOperation.execute(mClient);
104
105 return result;
106 }
107
108 }