082557dea541cb7118d7cfda9a295a43235e1c56
[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.IOException;
4
5 import com.owncloud.android.oc_framework.accounts.AccountUtils.AccountNotFoundException;
6 import com.owncloud.android.oc_framework.network.webdav.OwnCloudClientFactory;
7 import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
8 import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
9 import com.owncloud.android.oc_framework.operations.remote.CreateRemoteFolderOperation;
10
11 import android.os.Bundle;
12 import android.accounts.Account;
13 import android.accounts.AccountManager;
14 import android.accounts.AuthenticatorException;
15 import android.accounts.OperationCanceledException;
16 import android.app.Activity;
17 import android.util.Log;
18 import android.view.Menu;
19
20 /**
21 * Activity to test OC framework
22 * @author masensio
23 *
24 */
25 public class TestActivity extends Activity {
26
27 private static final String TAG = "TestActivity";
28
29 private Account mAccount = null;
30 private WebdavClient mClient;
31
32 @Override
33 protected void onCreate(Bundle savedInstanceState) {
34 super.onCreate(savedInstanceState);
35 setContentView(R.layout.activity_test);
36
37 // This account must exists on the simulator / device
38 String accountHost = "beta.owncloud.com";
39 String accountUser = "testandroid";
40 String accountName = accountUser + "@"+ accountHost;
41 String accountPass = "testandroid";
42 String accountType = "owncloud";
43
44 AccountManager am = AccountManager.get(this);
45
46 Account[] ocAccounts = am.getAccountsByType(accountType);
47 for (Account ac : ocAccounts) {
48 if (ac.name.equals(accountName)) {
49 mAccount = ac;
50 break;
51 }
52 }
53
54 // if (mAccount == null) {
55 // mAccount = new Account(accountName, accountType);
56 // am.addAccountExplicitly(mAccount, accountPass, null);
57 // am.setUserData(mAccount, "oc_version", "5.0.14");
58 // am.setUserData(mAccount, "oc_base_url", "http://beta.owncloud.com/owncloud");
59 // } else {
60 Log.d(TAG, "oc_version --->"+ am.getUserData(mAccount, "oc_version") );
61 Log.d(TAG, "oc_base_url --->"+ am.getUserData(mAccount, "oc_base_url") );
62 // }
63
64
65 try {
66 mClient = OwnCloudClientFactory.createOwnCloudClient(mAccount, this.getApplicationContext());
67 } catch (OperationCanceledException e) {
68 Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
69 e.printStackTrace();
70 } catch (AuthenticatorException e) {
71 Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
72 e.printStackTrace();
73 } catch (AccountNotFoundException e) {
74 Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
75 e.printStackTrace();
76 } catch (IOException e) {
77 Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
78 e.printStackTrace();
79 }
80 }
81
82 @Override
83 public boolean onCreateOptionsMenu(Menu menu) {
84 // Inflate the menu; this adds items to the action bar if it is present.
85 getMenuInflater().inflate(R.menu.test, menu);
86 return true;
87 }
88
89 /**
90 * Access to the library method to Create a Folder
91 * @param remotePath
92 * @param createFullPath
93 * @return
94 */
95 public RemoteOperationResult createFolder(String remotePath, boolean createFullPath) {
96
97 CreateRemoteFolderOperation createOperation = new CreateRemoteFolderOperation(remotePath, createFullPath);
98 RemoteOperationResult result = createOperation.execute(mClient);
99
100 return result;
101 }
102 }