1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package eu
.alefzero
.owncloud
;
21 import eu
.alefzero
.owncloud
.authenticator
.AccountAuthenticator
;
23 import android
.accounts
.Account
;
24 import android
.accounts
.AccountManager
;
25 import android
.content
.Context
;
26 import android
.content
.SharedPreferences
;
27 import android
.preference
.PreferenceManager
;
29 public class AccountUtils
{
30 public static final String WEBDAV_PATH_1_2
= "/webdav/owncloud.php";
31 public static final String WEBDAV_PATH_2_0
= "/files/webdav.php";
32 public static final String CARDDAV_PATH_2_0
= "/apps/contacts/carddav.php";
35 * Can be used to get the currently selected ownCloud account in the preferences
37 * @param context The current appContext
38 * @return The current account or null, if there is none yet.
40 public static Account
getCurrentOwnCloudAccount(Context context
){
41 Account
[] ocAccounts
= AccountManager
.get(context
).getAccountsByType(AccountAuthenticator
.ACCOUNT_TYPE
);
42 Account defaultAccount
= null
;
44 SharedPreferences appPreferences
= PreferenceManager
.getDefaultSharedPreferences(context
);
45 String accountName
= appPreferences
.getString("select_oc_account", null
);
47 if(accountName
!= null
){
48 for(Account account
: ocAccounts
){
49 if(account
.name
.equals(accountName
)){
50 defaultAccount
= account
;
54 } else if (ocAccounts
.length
!= 0) {
55 // we at least need to take first account as fallback
56 defaultAccount
= ocAccounts
[0];
59 return defaultAccount
;