Эх сурвалжийг харах

Fixed test of oc_framework; more simple initialization

David A. Velasco 11 жил өмнө
parent
commit
11c261c6cc

+ 3 - 3
oc_framework-test-project/.classpath

@@ -1,10 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-	<classpathentry kind="src" path="src"/>
-	<classpathentry kind="src" path="gen"/>
 	<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
 	<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
 	<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
-	<classpathentry exported="true" kind="lib" path="/oc_framework/bin/oc_framework.jar"/>
+	<classpathentry exported="true" kind="lib" path="/oc_framework/bin/oc_framework.jar" sourcepath="/oc_framework"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="gen"/>
 	<classpathentry kind="output" path="bin/classes"/>
 </classpath>

BIN
oc_framework-test-project/libs/android-support-v4.jar


+ 2 - 2
oc_framework-test-project/oc_framework-test-test/.classpath

@@ -1,10 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-	<classpathentry kind="src" path="src"/>
-	<classpathentry kind="src" path="gen"/>
 	<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
 	<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
 	<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
 	<classpathentry combineaccessrules="false" kind="src" path="/oc_framework-test-project"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="gen"/>
 	<classpathentry kind="output" path="bin/classes"/>
 </classpath>

+ 1 - 0
oc_framework-test-project/res/values/strings.xml

@@ -4,5 +4,6 @@
     <string name="app_name">oc_framework-test-project</string>
     <string name="action_settings">Settings</string>
     <string name="hello_world">Hello world!</string>
+    <string name="test_account_not_found">The test account %1$s could not be found in the device</string>
 
 </resources>

+ 9 - 68
oc_framework-test-project/src/com/owncloud/android/oc_framework_test_project/TestActivity.java

@@ -1,63 +1,38 @@
 package com.owncloud.android.oc_framework_test_project;
 
-import java.io.IOException;
-
-import com.owncloud.android.oc_framework.accounts.AccountUtils.AccountNotFoundException;
 import com.owncloud.android.oc_framework.network.webdav.OwnCloudClientFactory;
 import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
 import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
 import com.owncloud.android.oc_framework.operations.remote.CreateRemoteFolderOperation;
 import com.owncloud.android.oc_framework.operations.remote.RenameRemoteFileOperation;
 
-import android.os.AsyncTask;
+import android.net.Uri;
 import android.os.Bundle;
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.accounts.AuthenticatorException;
-import android.accounts.OperationCanceledException;
 import android.app.Activity;
-import android.content.Context;
-import android.util.Log;
 import android.view.Menu;
 
 /**
  * Activity to test OC framework
  * @author masensio
- *
+ * @author David A. Velasco
  */
 public class TestActivity extends Activity {
 	
-	private static final String TAG = "TestActivity";
-	
 	// This account must exists on the simulator / device
-	private static final String mAccountHost = "beta.owncloud.com";
-	private static final String mAccountUser = "testandroid";
-	private static final String mAccountName = mAccountUser + "@"+ mAccountHost;
-	private static final String mAccountPass = "testandroid";
-	private static final String mAccountType = "owncloud";	
+	private static final String mServerUri = "https://beta.owncloud.com/owncloud/remote.php/webdav";
+	private static final String mUser = "testandroid";
+	private static final String mPass = "testandroid";
 	
-	private Account mAccount = null;
+	//private Account mAccount = null;
 	private WebdavClient mClient;
 	
 	@Override
 	protected void onCreate(Bundle savedInstanceState) {
 		super.onCreate(savedInstanceState);
 		setContentView(R.layout.activity_test);
-
-		AccountManager am = AccountManager.get(this);
-		
-		Account[] ocAccounts = am.getAccountsByType(mAccountType);
-        for (Account ac : ocAccounts) {
-           if (ac.name.equals(mAccountName)) {
-        	   mAccount = ac;
-        	   break;
-            }
-        }
-
-        // Get the WebDavClient
-        AuthTask task = new AuthTask();
-        task.execute(this.getApplicationContext());
-        
+    	Uri uri = Uri.parse(mServerUri);
+    	mClient = OwnCloudClientFactory.createOwnCloudClient(uri ,getApplicationContext(), true);
+    	mClient.setBasicCredentials(mUser, mPass);
 	}
 
 	@Override
@@ -100,38 +75,4 @@ public class TestActivity extends Activity {
 		return result;
 	}
 	
-	private class AuthTask extends AsyncTask<Context, Void, WebdavClient> {
-
-		@Override
-		protected WebdavClient doInBackground(Context... params) {
-			WebdavClient client = null;
-			try {
-				client = OwnCloudClientFactory.createOwnCloudClient(mAccount, (Context) params[0] );
-			} catch (OperationCanceledException e) {
-				Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
-				e.printStackTrace();
-			} catch (AuthenticatorException e) {
-				Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
-				e.printStackTrace();
-			} catch (AccountNotFoundException e) {
-				Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
-				e.printStackTrace();
-			} catch (IOException e) {
-				Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
-				e.printStackTrace();
-			} catch (IllegalStateException e) {
-				Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
-				e.printStackTrace();
-			}
-			return client;
-		}
-
-		@Override
-		protected void onPostExecute(WebdavClient result) {
-			// TODO Auto-generated method stub
-			super.onPostExecute(result);
-			mClient = result;
-		}
-		
-	}
 }