Make account selectable from preferences
authorLennart Rosam <lennart@familie-rosam.de>
Sat, 7 Apr 2012 00:15:38 +0000 (02:15 +0200)
committerLennart Rosam <lennart@familie-rosam.de>
Sat, 7 Apr 2012 00:15:38 +0000 (02:15 +0200)
17 files changed:
.classpath
AndroidManifest.xml
res/layout-large-land/files.xml [new file with mode: 0644]
res/layout-port/files.xml [deleted file]
res/layout-port/landing_page_item.xml [deleted file]
res/layout-port/main.xml [deleted file]
res/layout/files.xml
res/layout/landing_page_item.xml
res/layout/main.xml
res/values/strings.xml
res/xml/preferences.xml
src/eu/alefzero/owncloud/authenticator/AuthUtils.java
src/eu/alefzero/owncloud/ui/activity/AuthenticatorActivity.java
src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java
src/eu/alefzero/owncloud/ui/activity/Preferences.java
src/eu/alefzero/owncloud/ui/adapter/LandingScreenAdapter.java
src/eu/alefzero/owncloud/ui/fragment/FileDetail.java

index 63292d7..4d02d2c 100644 (file)
@@ -3,15 +3,15 @@
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="src" path="gen"/>
        <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="src" path="gen"/>
        <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
-       <classpathentry kind="lib" path="lib/commons-codec-1.4.jar"/>
-       <classpathentry kind="lib" path="lib/commons-logging-1.1.1.jar"/>
-       <classpathentry kind="lib" path="lib/commons-httpclient-3.0.1.jar"/>
-       <classpathentry kind="lib" path="lib/commons-io-2.0.1.jar"/>
-       <classpathentry kind="lib" path="lib/commons-httpclient-contrib-3.0.jar"/>
-       <classpathentry kind="lib" path="lib/httpclient-4.1.2.jar"/>
-       <classpathentry kind="lib" path="lib/httpcore-4.1.2.jar"/>
-       <classpathentry kind="lib" path="lib/httpmime-4.1.2.jar"/>
-       <classpathentry kind="lib" path="lib/httpclient-cache-4.1.2.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/commons-codec-1.4.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/commons-logging-1.1.1.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/commons-httpclient-3.0.1.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/commons-io-2.0.1.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/commons-httpclient-contrib-3.0.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/httpclient-4.1.2.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/httpcore-4.1.2.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/httpmime-4.1.2.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/httpclient-cache-4.1.2.jar"/>
        <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
        <classpathentry kind="output" path="bin/classes"/>
 </classpath>
        <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
        <classpathentry kind="output" path="bin/classes"/>
 </classpath>
index 8f9a8fb..12cd591 100644 (file)
@@ -60,7 +60,7 @@
                 android:resource="@xml/syncadapter_files"/>\r
         </service>\r
          <provider android:name=".cp" android:enabled="true" android:syncable="true" android:exported="false" android:authorities="org.owncloud" android:label="@string/sync_string_files"></provider>\r
                 android:resource="@xml/syncadapter_files"/>\r
         </service>\r
          <provider android:name=".cp" android:enabled="true" android:syncable="true" android:exported="false" android:authorities="org.owncloud" android:label="@string/sync_string_files"></provider>\r
-         <activity android:name=".ui.activity.AuthenticatorActivity"></activity>\r
+         <activity android:name=".ui.activity.AuthenticatorActivity" android:theme="@style/Theme.ownCloud"></activity>\r
          <service android:name=".FileDownloader">\r
          </service>\r
          <activity android:name=".ui.activity.FileDetailActivity"></activity>\r
          <service android:name=".FileDownloader">\r
          </service>\r
          <activity android:name=".ui.activity.FileDetailActivity"></activity>\r
diff --git a/res/layout-large-land/files.xml b/res/layout-large-land/files.xml
new file mode 100644 (file)
index 0000000..c43feb9
--- /dev/null
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>\r
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
+    android:layout_width="fill_parent"\r
+    android:layout_height="fill_parent"\r
+    android:background="#F7F7F7"\r
+    android:orientation="vertical" >\r
+\r
+    <LinearLayout\r
+        android:id="@+id/linearLayout1"\r
+        android:layout_width="fill_parent"\r
+        android:layout_height="fill_parent"\r
+        android:orientation="horizontal" >\r
+\r
+        <LinearLayout\r
+            android:id="@+id/file_list_container"\r
+            android:layout_width="0dp"\r
+            android:layout_height="wrap_content" \r
+            android:layout_weight="1">\r
+        </LinearLayout>\r
+\r
+        <fragment\r
+            android:id="@+id/fileDetail"\r
+            android:layout_width="0dp"\r
+            android:layout_height="fill_parent"\r
+            android:layout_weight="2"\r
+            class="eu.alefzero.owncloud.ui.fragment.FileDetail" >\r
+\r
+            <!-- Preview: layout=@layout/file_details -->\r
+        </fragment>\r
+    </LinearLayout>\r
+\r
+</LinearLayout>
\ No newline at end of file
diff --git a/res/layout-port/files.xml b/res/layout-port/files.xml
deleted file mode 100644 (file)
index d6308da..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>\r
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
-    android:layout_width="fill_parent"\r
-    android:layout_height="fill_parent"\r
-    android:background="#F7F7F7"\r
-    android:orientation="vertical" \r
-    android:id="@+id/file_list_container">\r
-\r
-</LinearLayout>
\ No newline at end of file
diff --git a/res/layout-port/landing_page_item.xml b/res/layout-port/landing_page_item.xml
deleted file mode 100644 (file)
index a15412c..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>\r
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
-    android:layout_width="fill_parent"\r
-    android:layout_height="fill_parent" >\r
-\r
-    <ImageView\r
-        android:id="@+id/gridImage"\r
-        android:layout_width="wrap_content"\r
-        android:layout_height="wrap_content"\r
-        android:layout_alignParentTop="true"\r
-        android:layout_centerHorizontal="true"\r
-        android:src="@drawable/action_item_btn" />
-\r\r\r
-    <TextView\r
-        android:id="@+id/gridText"\r
-        android:layout_width="wrap_content"\r
-        android:layout_height="wrap_content"\r
-        android:layout_below="@+id/gridImage"\r
-        android:layout_centerHorizontal="true"\r
-        android:text="Medium Text"\r
-        android:textAppearance="?android:attr/textAppearanceMedium"\r
-        android:textColor="@color/setup_text_hint" />\r
-\r
-</RelativeLayout>
\ No newline at end of file
diff --git a/res/layout-port/main.xml b/res/layout-port/main.xml
deleted file mode 100644 (file)
index 5e64435..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>\r
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
-    android:layout_width="fill_parent"\r
-    android:layout_height="fill_parent"\r
-    android:orientation="vertical" >\r
-    \r
-    <GridView\r
-        android:id="@+id/homeScreenGrid"\r
-        android:layout_width="fill_parent"\r
-        android:layout_height="fill_parent"\r
-        android:layout_gravity="center_horizontal"\r
-        android:columnWidth="90dp"\r
-        android:gravity="center"\r
-        android:horizontalSpacing="10dp"\r
-        android:numColumns="2"\r
-        android:stretchMode="columnWidth"\r
-        android:verticalSpacing="10dp" >\r
-    </GridView>\r
-\r
-    \r
-\r
-</LinearLayout>
\ No newline at end of file
index c43feb9..d6308da 100644 (file)
@@ -3,30 +3,7 @@
     android:layout_width="fill_parent"\r
     android:layout_height="fill_parent"\r
     android:background="#F7F7F7"\r
     android:layout_width="fill_parent"\r
     android:layout_height="fill_parent"\r
     android:background="#F7F7F7"\r
-    android:orientation="vertical" >\r
-\r
-    <LinearLayout\r
-        android:id="@+id/linearLayout1"\r
-        android:layout_width="fill_parent"\r
-        android:layout_height="fill_parent"\r
-        android:orientation="horizontal" >\r
-\r
-        <LinearLayout\r
-            android:id="@+id/file_list_container"\r
-            android:layout_width="0dp"\r
-            android:layout_height="wrap_content" \r
-            android:layout_weight="1">\r
-        </LinearLayout>\r
-\r
-        <fragment\r
-            android:id="@+id/fileDetail"\r
-            android:layout_width="0dp"\r
-            android:layout_height="fill_parent"\r
-            android:layout_weight="2"\r
-            class="eu.alefzero.owncloud.ui.fragment.FileDetail" >\r
-\r
-            <!-- Preview: layout=@layout/file_details -->\r
-        </fragment>\r
-    </LinearLayout>\r
+    android:orientation="vertical" \r
+    android:id="@+id/file_list_container">\r
 \r
 </LinearLayout>
\ No newline at end of file
 \r
 </LinearLayout>
\ No newline at end of file
index fde1c56..a15412c 100644 (file)
@@ -2,25 +2,23 @@
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
     android:layout_width="fill_parent"\r
     android:layout_height="fill_parent" >\r
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
     android:layout_width="fill_parent"\r
     android:layout_height="fill_parent" >\r
-    \r
-    <ImageView \r
+\r
+    <ImageView\r
         android:id="@+id/gridImage"\r
         android:layout_width="wrap_content"\r
         android:layout_height="wrap_content"\r
         android:layout_alignParentTop="true"\r
         android:id="@+id/gridImage"\r
         android:layout_width="wrap_content"\r
         android:layout_height="wrap_content"\r
         android:layout_alignParentTop="true"\r
-        android:layout_centerVertical="true"\r
-        android:src="@drawable/action_item_btn"\r
-        />\r
-    \r
+        android:layout_centerHorizontal="true"\r
+        android:src="@drawable/action_item_btn" />
+\r\r\r
     <TextView\r
         android:id="@+id/gridText"\r
         android:layout_width="wrap_content"\r
         android:layout_height="wrap_content"\r
     <TextView\r
         android:id="@+id/gridText"\r
         android:layout_width="wrap_content"\r
         android:layout_height="wrap_content"\r
-        android:layout_toRightOf="@+id/gridImage"\r
-        android:layout_centerVertical="true"\r
+        android:layout_below="@+id/gridImage"\r
+        android:layout_centerHorizontal="true"\r
         android:text="Medium Text"\r
         android:textAppearance="?android:attr/textAppearanceMedium"\r
         android:textColor="@color/setup_text_hint" />\r
         android:text="Medium Text"\r
         android:textAppearance="?android:attr/textAppearanceMedium"\r
         android:textColor="@color/setup_text_hint" />\r
-    \r
 \r
 </RelativeLayout>
\ No newline at end of file
 \r
 </RelativeLayout>
\ No newline at end of file
index dc8c8d7..33eb75a 100644 (file)
@@ -1,23 +1,23 @@
 <?xml version="1.0" encoding="utf-8"?>\r
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
 <?xml version="1.0" encoding="utf-8"?>\r
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
-    android:layout_width="match_parent"\r
-    android:layout_height="match_parent"\r
+    android:layout_width="fill_parent"\r
+    android:layout_height="fill_parent"\r
     android:orientation="vertical" >\r
     android:orientation="vertical" >\r
+    \r
+    <GridView\r
+        android:id="@+id/homeScreenGrid"\r
+        android:layout_width="fill_parent"\r
+        android:layout_height="fill_parent"\r
+        android:layout_gravity="center_horizontal"\r
+        android:columnWidth="90dp"\r
+        android:gravity="center"\r
+        android:horizontalSpacing="20dp"\r
+        android:verticalSpacing="20dp"\r
+        android:layout_marginTop="20dp"\r
+        android:numColumns="2"\r
+        android:stretchMode="columnWidth" >\r
+    </GridView>\r
 \r
 \r
-    <LinearLayout\r
-        android:id="@+id/linearLayout1"\r
-        android:layout_width="match_parent"\r
-        android:layout_height="match_parent"\r
-        android:orientation="horizontal" >\r
-\r
-        <fragment\r
-            android:id="@+id/landingPage"\r
-            android:layout_width="fill_parent"\r
-            android:layout_height="wrap_content"\r
-            class="eu.alefzero.owncloud.ui.fragment.LandingPageFragment" >\r
-\r
-            <!-- Preview: layout=@layout/landing_page_fragment -->\r
-        </fragment>\r
-    </LinearLayout>\r
+    \r
 \r
 </LinearLayout>
\ No newline at end of file
 \r
 </LinearLayout>
\ No newline at end of file
index 0d2bb3e..47daf45 100644 (file)
@@ -17,6 +17,9 @@
     <string name="prefs_general">General</string>
     <string name="prefs_sessions">Stored sessions</string>
     <string name="prefs_add_session">Add new session</string>
     <string name="prefs_general">General</string>
     <string name="prefs_sessions">Stored sessions</string>
     <string name="prefs_add_session">Add new session</string>
+    <string name="prefs_create_img_thumbnails">Create image thumbnails</string>
+    <string name="prefs_select_oc_account">Select an account</string>
+    <string name="prefs_summary_select_oc_account">Choose, which of your accounts the app should use.</string>
     <string name="new_session_id">Session Name</string>
     <string name="new_session_url">URL</string>
     <string name="new_session_username">Username</string>
     <string name="new_session_id">Session Name</string>
     <string name="new_session_url">URL</string>
     <string name="new_session_username">Username</string>
index 2b733ae..2fe8d3b 100644 (file)
@@ -1,4 +1,15 @@
 <?xml version="1.0" encoding="utf-8"?>
 <?xml version="1.0" encoding="utf-8"?>
-    <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
-        <CheckBoxPreference android:title="Create images thumbnails" android:key="create_thumbnails"></CheckBoxPreference>
-    </PreferenceScreen>
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
+
+    <CheckBoxPreference
+        android:key="create_thumbnails"
+        android:title="@string/prefs_create_img_thumbnails" 
+        />
+    
+    <ListPreference
+        android:key="select_oc_account"
+        android:title="@string/prefs_select_oc_account"
+        android:summary="@string/prefs_summary_select_oc_account" 
+        />
+
+</PreferenceScreen>
\ No newline at end of file
index e338679..e3fc32c 100644 (file)
@@ -48,8 +48,12 @@ import org.apache.http.protocol.BasicHttpContext;
 import eu.alefzero.owncloud.ui.activity.AuthenticatorActivity;\r
 \r
 \r
 import eu.alefzero.owncloud.ui.activity.AuthenticatorActivity;\r
 \r
 \r
+import android.accounts.Account;\r
+import android.accounts.AccountManager;\r
 import android.content.Context;\r
 import android.content.Context;\r
+import android.content.SharedPreferences;\r
 import android.os.Handler;\r
 import android.os.Handler;\r
+import android.preference.PreferenceManager;\r
 import android.util.Log;\r
 \r
 public class AuthUtils {\r
 import android.util.Log;\r
 \r
 public class AuthUtils {\r
@@ -219,4 +223,29 @@ public class AuthUtils {
     };\r
     return performOnBackgroundThread(r);\r
   }\r
     };\r
     return performOnBackgroundThread(r);\r
   }\r
+  \r
+  /**\r
+   * Can be used to get the currently selected ownCloud account in the preferences\r
+   * \r
+   * @param context The current appContext\r
+   * @return The current account or null, if there is none yet.\r
+   */\r
+  public static Account getCurrentOwnCloudAccount(Context context){\r
+         Account[] ocAccounts = AccountManager.get(context).getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE);\r
+         Account defaultAccount = null;\r
+         \r
+         SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(context);\r
+         String accountName = appPreferences.getString("select_oc_account", null);\r
+         \r
+         if(accountName != null){\r
+                 for(Account account : ocAccounts){\r
+                         if(account.name.equals(accountName)){\r
+                                 defaultAccount = account;\r
+                                 break;\r
+                         }\r
+                 }\r
+         }\r
+         \r
+       return defaultAccount;\r
+  }\r
 }\r
 }\r
index 31874ad..9db46e0 100644 (file)
@@ -29,9 +29,11 @@ import android.app.ProgressDialog;
 import android.content.ContentResolver;\r
 import android.content.DialogInterface;\r
 import android.content.Intent;\r
 import android.content.ContentResolver;\r
 import android.content.DialogInterface;\r
 import android.content.Intent;\r
+import android.content.SharedPreferences;\r
 import android.graphics.Color;\r
 import android.os.Bundle;\r
 import android.os.Handler;\r
 import android.graphics.Color;\r
 import android.os.Bundle;\r
 import android.os.Handler;\r
+import android.preference.PreferenceManager;\r
 import android.text.InputType;\r
 import android.util.Log;\r
 import android.view.View;\r
 import android.text.InputType;\r
 import android.util.Log;\r
 import android.view.View;\r
@@ -98,15 +100,25 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity {
             try {\r
                 url = new URL(message);\r
             } catch (MalformedURLException e) {\r
             try {\r
                 url = new URL(message);\r
             } catch (MalformedURLException e) {\r
-                // should never happend\r
+                // should never happen\r
                 Log.e(getClass().getName(), "Malformed URL: " + message);\r
                 return;\r
             }\r
 \r
             String username = username_text.getText().toString().trim();\r
                 Log.e(getClass().getName(), "Malformed URL: " + message);\r
                 return;\r
             }\r
 \r
             String username = username_text.getText().toString().trim();\r
-            Account account = new Account(username + "@" + url.getHost(), AccountAuthenticator.ACCOUNT_TYPE);\r
+            String accountName = username + "@" + url.getHost();\r
+            Account account = new Account(accountName, AccountAuthenticator.ACCOUNT_TYPE);\r
             AccountManager accManager = AccountManager.get(this);\r
             accManager.addAccountExplicitly(account, password_text.getText().toString(), null);\r
             AccountManager accManager = AccountManager.get(this);\r
             accManager.addAccountExplicitly(account, password_text.getText().toString(), null);\r
+            \r
+            // Add this account as default in the preferences, if there is none already\r
+            SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(this);\r
+            String defaultAccountName = appPreferences.getString("select_oc_account", null);\r
+            if(defaultAccountName == null){\r
+               SharedPreferences.Editor editor = appPreferences.edit();\r
+               editor.putString("select_oc_account", accountName);\r
+               editor.commit();\r
+            }\r
 \r
             final Intent intent = new Intent();\r
             intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, AccountAuthenticator.ACCOUNT_TYPE);\r
 \r
             final Intent intent = new Intent();\r
             intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, AccountAuthenticator.ACCOUNT_TYPE);\r
@@ -114,7 +126,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity {
             intent.putExtra(AccountManager.KEY_AUTHTOKEN, AccountAuthenticator.ACCOUNT_TYPE);\r
             accManager.setUserData(account, AccountAuthenticator.KEY_OC_URL, url.toString());\r
 \r
             intent.putExtra(AccountManager.KEY_AUTHTOKEN, AccountAuthenticator.ACCOUNT_TYPE);\r
             accManager.setUserData(account, AccountAuthenticator.KEY_OC_URL, url.toString());\r
 \r
-            // TODO prepare this URL during a central service\r
+            // TODO prepare this URL using a central service\r
             intent.putExtra(AccountManager.KEY_USERDATA, username);\r
             accManager.setUserData(account, AccountAuthenticator.KEY_CONTACT_URL,\r
                     url.toString().replace(AuthUtils.WEBDAV_PATH_2_0, AuthUtils.CARDDAV_PATH_2_0)\r
             intent.putExtra(AccountManager.KEY_USERDATA, username);\r
             accManager.setUserData(account, AccountAuthenticator.KEY_CONTACT_URL,\r
                     url.toString().replace(AuthUtils.WEBDAV_PATH_2_0, AuthUtils.CARDDAV_PATH_2_0)\r
index 7a79a91..e13ce67 100644 (file)
@@ -23,12 +23,10 @@ import android.accounts.AccountManager;
 import android.app.AlertDialog;\r
 import android.app.Dialog;\r
 import android.content.DialogInterface;\r
 import android.app.AlertDialog;\r
 import android.app.Dialog;\r
 import android.content.DialogInterface;\r
-import android.content.Intent;\r
 import android.content.DialogInterface.OnCancelListener;\r
 import android.content.DialogInterface.OnCancelListener;\r
-import android.content.res.Configuration;\r
+import android.content.Intent;\r
 import android.os.Bundle;\r
 import android.support.v4.app.ActionBar;\r
 import android.os.Bundle;\r
 import android.support.v4.app.ActionBar;\r
-import android.support.v4.app.FragmentTransaction;\r
 import android.support.v4.app.ActionBar.OnNavigationListener;\r
 import android.support.v4.view.Menu;\r
 import android.support.v4.view.MenuItem;\r
 import android.support.v4.app.ActionBar.OnNavigationListener;\r
 import android.support.v4.view.Menu;\r
 import android.support.v4.view.MenuItem;\r
@@ -37,7 +35,6 @@ import android.widget.ArrayAdapter;
 import eu.alefzero.owncloud.R;\r
 import eu.alefzero.owncloud.R.id;\r
 import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
 import eu.alefzero.owncloud.R;\r
 import eu.alefzero.owncloud.R.id;\r
 import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
-import eu.alefzero.owncloud.ui.fragment.FileDetail;\r
 import eu.alefzero.owncloud.ui.fragment.FileList;\r
 \r
 /**\r
 import eu.alefzero.owncloud.ui.fragment.FileList;\r
 \r
 /**\r
@@ -70,13 +67,6 @@ public class FileDisplayActivity extends android.support.v4.app.FragmentActivity
     action_bar.setNavigationMode(android.support.v4.app.ActionBar.NAVIGATION_MODE_LIST);\r
     action_bar.setDisplayShowTitleEnabled(false);\r
     action_bar.setListNavigationCallbacks(mDirectories, this);\r
     action_bar.setNavigationMode(android.support.v4.app.ActionBar.NAVIGATION_MODE_LIST);\r
     action_bar.setDisplayShowTitleEnabled(false);\r
     action_bar.setListNavigationCallbacks(mDirectories, this);\r
-\r
-    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();\r
-    ft.add(R.id.file_list_container, new FileList());\r
-    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {\r
-      ft.add(R.id.fileDetail, new FileDetail());\r
-    }\r
-    ft.commit();\r
   }\r
 \r
   @Override\r
   }\r
 \r
   @Override\r
index 46cabcf..1e35896 100644 (file)
@@ -23,11 +23,15 @@ import java.util.Vector;
 \r
 import eu.alefzero.owncloud.OwnCloudSession;\r
 import eu.alefzero.owncloud.R;\r
 \r
 import eu.alefzero.owncloud.OwnCloudSession;\r
 import eu.alefzero.owncloud.R;\r
+import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
 import eu.alefzero.owncloud.db.DbHandler;\r
 \r
 import eu.alefzero.owncloud.db.DbHandler;\r
 \r
+import android.accounts.Account;\r
+import android.accounts.AccountManager;\r
 import android.app.Activity;\r
 import android.content.Intent;\r
 import android.os.Bundle;\r
 import android.app.Activity;\r
 import android.content.Intent;\r
 import android.os.Bundle;\r
+import android.preference.ListPreference;\r
 import android.preference.Preference;\r
 import android.preference.PreferenceActivity;\r
 import android.preference.PreferenceScreen;\r
 import android.preference.Preference;\r
 import android.preference.PreferenceActivity;\r
 import android.preference.PreferenceScreen;\r
@@ -46,11 +50,12 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
  *\r
  */\r
 public class Preferences extends PreferenceActivity {\r
  *\r
  */\r
 public class Preferences extends PreferenceActivity {\r
-  private String TAG = "OwnCloudPreferences";\r
+  private static final String TAG = "OwnCloudPreferences";\r
   private final int mNewSession = 47;\r
   private final int mEditSession = 48;\r
   private DbHandler mDbHandler;\r
   private Vector<OwnCloudSession> mSessions;\r
   private final int mNewSession = 47;\r
   private final int mEditSession = 48;\r
   private DbHandler mDbHandler;\r
   private Vector<OwnCloudSession> mSessions;\r
+  private Account[] mAccounts;\r
   private int mSelectedMenuItem;\r
   \r
   @Override\r
   private int mSelectedMenuItem;\r
   \r
   @Override\r
@@ -60,6 +65,7 @@ public class Preferences extends PreferenceActivity {
     mSessions = new Vector<OwnCloudSession>();\r
     addPreferencesFromResource(R.xml.preferences);\r
     registerForContextMenu(getListView());\r
     mSessions = new Vector<OwnCloudSession>();\r
     addPreferencesFromResource(R.xml.preferences);\r
     registerForContextMenu(getListView());\r
+    populateAccountList();\r
     //populateSessionList();\r
   }\r
   \r
     //populateSessionList();\r
   }\r
   \r
@@ -76,13 +82,32 @@ public class Preferences extends PreferenceActivity {
       try {\r
         uri = new URI(mSessions.get(i).getUrl());\r
       } catch (URISyntaxException e) {\r
       try {\r
         uri = new URI(mSessions.get(i).getUrl());\r
       } catch (URISyntaxException e) {\r
-        e.printStackTrace(); // should never happend\r
+        e.printStackTrace(); // should never happen\r
         continue;\r
       }\r
       preference.setSummary(uri.getScheme() + "://" + uri.getHost()+uri.getPath());\r
       ps.addPreference(preference);\r
     }\r
   }\r
         continue;\r
       }\r
       preference.setSummary(uri.getScheme() + "://" + uri.getHost()+uri.getPath());\r
       ps.addPreference(preference);\r
     }\r
   }\r
+  \r
+  /**\r
+   * Populates the account selector\r
+   */\r
+  private void populateAccountList(){\r
+         AccountManager accMan = AccountManager.get(this);\r
+         mAccounts = accMan.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE);\r
+         ListPreference accountList = (ListPreference) findPreference("select_oc_account");\r
+         \r
+         // Transform accounts into array of string for preferences to use\r
+         String[] accNames = new String[mAccounts.length];\r
+         for(int i = 0; i < mAccounts.length; i++){\r
+                 Account account = mAccounts[i];\r
+                 accNames[i] = account.name;\r
+         }\r
+         \r
+         accountList.setEntries(accNames);\r
+         accountList.setEntryValues(accNames);\r
+  }\r
 \r
   @Override\r
   public boolean onCreateOptionsMenu(Menu menu) {\r
 \r
   @Override\r
   public boolean onCreateOptionsMenu(Menu menu) {\r
index 694225d..914ed43 100644 (file)
@@ -26,6 +26,7 @@ import android.widget.BaseAdapter;
 import android.widget.ImageView;\r
 import android.widget.TextView;\r
 import eu.alefzero.owncloud.R;\r
 import android.widget.ImageView;\r
 import android.widget.TextView;\r
 import eu.alefzero.owncloud.R;\r
+import eu.alefzero.owncloud.authenticator.AuthUtils;\r
 import eu.alefzero.owncloud.ui.activity.FileDisplayActivity;\r
 import eu.alefzero.owncloud.ui.activity.Preferences;\r
 \r
 import eu.alefzero.owncloud.ui.activity.FileDisplayActivity;\r
 import eu.alefzero.owncloud.ui.activity.Preferences;\r
 \r
@@ -65,9 +66,15 @@ public class LandingScreenAdapter extends BaseAdapter {
         */\r
        public Object getItem(int position) {\r
                Intent intent = new Intent();\r
         */\r
        public Object getItem(int position) {\r
                Intent intent = new Intent();\r
+               \r
                switch (position) {\r
                case 0:\r
                switch (position) {\r
                case 0:\r
-                       intent.setClass(mContext, FileDisplayActivity.class);\r
+                       /* \r
+                        * The FileDisplayActivity requires the ownCloud account as an parcableExtra.\r
+                        * We will put in the one that is selected in the preferences\r
+                        */\r
+                       intent.setClass(mContext, FileDisplayActivity.class);   \r
+                       intent.putExtra("ACCOUNT", AuthUtils.getCurrentOwnCloudAccount(mContext));\r
                        break;\r
                case 5:\r
                        intent.setClass(mContext, Preferences.class);\r
                        break;\r
                case 5:\r
                        intent.setClass(mContext, Preferences.class);\r
@@ -100,5 +107,4 @@ public class LandingScreenAdapter extends BaseAdapter {
                }\r
                return convertView;\r
        }\r
                }\r
                return convertView;\r
        }\r
-\r
 }\r
 }\r
index 23c90dc..4786bef 100644 (file)
@@ -66,7 +66,7 @@ public class FileDetail extends Fragment implements OnClickListener {
         null);\r
     c.moveToFirst();\r
 \r
         null);\r
     c.moveToFirst();\r
 \r
-    // retrive details from DB\r
+    // Retrieve details from DB\r
     String filename = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_NAME));\r
     String mimetype = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE));\r
     String path = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH));\r
     String filename = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_NAME));\r
     String mimetype = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE));\r
     String path = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH));\r