7687bb2f6d0c0fb5dfae3cd4332a1555b703b5d0
[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.RenameRemoteFileOperation;
8
9 import android.net.Uri;
10 import android.os.Bundle;
11 import android.app.Activity;
12 import android.view.Menu;
13
14 /**
15 * Activity to test OC framework
16 * @author masensio
17 * @author David A. Velasco
18 */
19 public class TestActivity extends Activity {
20
21 // This account must exists on the simulator / device
22 private static final String mServerUri = "https://beta.owncloud.com/owncloud/remote.php/webdav";
23 private static final String mUser = "testandroid";
24 private static final String mPass = "testandroid";
25
26 //private Account mAccount = null;
27 private WebdavClient mClient;
28
29 @Override
30 protected void onCreate(Bundle savedInstanceState) {
31 super.onCreate(savedInstanceState);
32 setContentView(R.layout.activity_test);
33 Uri uri = Uri.parse(mServerUri);
34 mClient = OwnCloudClientFactory.createOwnCloudClient(uri ,getApplicationContext(), true);
35 mClient.setBasicCredentials(mUser, mPass);
36 }
37
38 @Override
39 public boolean onCreateOptionsMenu(Menu menu) {
40 // Inflate the menu; this adds items to the action bar if it is present.
41 getMenuInflater().inflate(R.menu.test, menu);
42 return true;
43 }
44
45 /**
46 * Access to the library method to Create a Folder
47 * @param remotePath
48 * @param createFullPath
49 *
50 * @return
51 */
52 public RemoteOperationResult createFolder(String remotePath, boolean createFullPath) {
53
54 CreateRemoteFolderOperation createOperation = new CreateRemoteFolderOperation(remotePath, createFullPath);
55 RemoteOperationResult result = createOperation.execute(mClient);
56
57 return result;
58 }
59
60 /**
61 * Access to the library method to Rename a File or Folder
62 * @param oldName Old name of the file.
63 * @param oldRemotePath Old remote path of the file. For folders it starts and ends by "/"
64 * @param newName New name to set as the name of file.
65 * @param isFolder 'true' for folder and 'false' for files
66 *
67 * @return
68 */
69
70 public RemoteOperationResult renameFile(String oldName, String oldRemotePath, String newName, boolean isFolder) {
71
72 RenameRemoteFileOperation renameOperation = new RenameRemoteFileOperation(oldName, oldRemotePath, newName, isFolder);
73 RemoteOperationResult result = renameOperation.execute(mClient);
74
75 return result;
76 }
77
78 }