浏览代码

Add new preference category on settings and list in it the accounts

jabarros 10 年之前
父节点
当前提交
5cba80a1ab
共有 3 个文件被更改,包括 37 次插入2 次删除
  1. 2 0
      res/values/strings.xml
  2. 3 1
      res/xml/preferences.xml
  3. 32 1
      src/com/owncloud/android/ui/activity/Preferences.java

+ 2 - 0
res/values/strings.xml

@@ -279,4 +279,6 @@
 	<string name="uploader_upload_forbidden_permissions">to upload in this folder</string>
 	<string name="downloader_download_file_not_found">The file is no longer available on the server</string>
 
+	<string name="prefs_category_accounts">Accounts</string>
+
 </resources>

+ 3 - 1
res/xml/preferences.xml

@@ -18,8 +18,10 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 -->
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
-	<PreferenceCategory android:title="@string/prefs_category_general">
+    <PreferenceCategory android:title="@string/prefs_category_accounts" android:key="accounts_category">
+    </PreferenceCategory>
     
+	<PreferenceCategory android:title="@string/prefs_category_general">
     <!-- ListPreference
         android:key="select_oc_account"
         android:title="@string/prefs_select_oc_account"

+ 32 - 1
src/com/owncloud/android/ui/activity/Preferences.java

@@ -18,6 +18,7 @@
 package com.owncloud.android.ui.activity;
 
 import android.accounts.Account;
+import android.accounts.AccountManager;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.pm.PackageInfo;
@@ -35,6 +36,7 @@ import com.actionbarsherlock.app.ActionBar;
 import com.actionbarsherlock.app.SherlockPreferenceActivity;
 import com.actionbarsherlock.view.Menu;
 import com.actionbarsherlock.view.MenuItem;
+import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.db.DbHandler;
@@ -69,6 +71,13 @@ public class Preferences extends SherlockPreferenceActivity {
         actionBar.setIcon(DisplayUtils.getSeasonalIconId());
         actionBar.setDisplayHomeAsUpEnabled(true);
         
+        // Load the accounts category for adding the list of accounts
+        PreferenceCategory accountsPrefCategory = (PreferenceCategory) findPreference("accounts_category");
+
+        // Populate the accounts category with the list of accounts
+        createAccountsCheckboxPreferences(accountsPrefCategory);
+
+
         Preference p = findPreference("manage_account");
         if (p != null)
         p.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@@ -301,5 +310,27 @@ public class Preferences extends SherlockPreferenceActivity {
         mDbHandler.close();
         super.onDestroy();
     }
-    
+
+    /**
+     * Create the list of accounts that have been added into the app
+     * 
+     * @param accountsPrefCategory
+     */
+    private void createAccountsCheckboxPreferences(PreferenceCategory accountsPrefCategory) {
+        AccountManager am = (AccountManager) getSystemService(ACCOUNT_SERVICE);
+        Account accounts[] = am.getAccountsByType(MainApp.getAccountType());
+        Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
+        for (Account a : accounts) {
+            CheckBoxPreference checkBoxPreference = new CheckBoxPreference(this);
+            checkBoxPreference.setKey(a.name);
+            checkBoxPreference.setTitle(a.name);
+
+            // Check the current account that is being used
+            if (a.name.equals(currentAccount.name)) {
+                checkBoxPreference.setChecked(true);
+            }
+
+            accountsPrefCategory.addPreference(checkBoxPreference);
+        }
+    }
 }