From: masensio Date: Fri, 18 Oct 2013 10:32:22 +0000 (+0200) Subject: Merge branch 'setup_multiaccount' into setup_app_name X-Git-Tag: oc-android-1.5.5~159^2~8 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/31f6e61f894efd0867d1a34c8d3cb53d7bb5fc4a?hp=ea7f8fe49152fee3d92f1762d0e6538fa081c9d8 Merge branch 'setup_multiaccount' into setup_app_name Conflicts: res/values/setup.xml src/com/owncloud/android/authentication/AccountAuthenticator.java --- diff --git a/res/values/setup.xml b/res/values/setup.xml index 2c73d269..ecf3afe6 100644 --- a/res/values/setup.xml +++ b/res/values/setup.xml @@ -22,4 +22,7 @@ #1D2D44 #1D2D44 + + true + diff --git a/res/values/strings.xml b/res/values/strings.xml index a27ee047..eb5174d8 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -216,6 +216,7 @@ Connecting to authentication server… Follow instructions above to get authenticated The server does not support this authentication method + This version of ownCloud doesn\'t support multiaccount Application terminated unexpectedly. Would you like to submit a crash report? Send report diff --git a/src/com/owncloud/android/authentication/AccountAuthenticator.java b/src/com/owncloud/android/authentication/AccountAuthenticator.java index 5d798917..c9da67bc 100644 --- a/src/com/owncloud/android/authentication/AccountAuthenticator.java +++ b/src/com/owncloud/android/authentication/AccountAuthenticator.java @@ -22,9 +22,15 @@ import android.accounts.*; import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.os.Handler; +import android.widget.Toast; + import com.owncloud.android.Log_OC; import com.owncloud.android.MainApp; +import com.owncloud.android.R; + + /** * Authenticator for ownCloud accounts. * @@ -86,10 +92,13 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator { private static final String TAG = AccountAuthenticator.class.getSimpleName(); private Context mContext; + + private Handler mHandler; public AccountAuthenticator(Context context) { super(context); mContext = context; + mHandler = new Handler(); } /** @@ -102,25 +111,49 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator { throws NetworkErrorException { Log_OC.i(TAG, "Adding account with type " + accountType + " and auth token " + authTokenType); - try { - validateAccountType(accountType); - } catch (AuthenticatorException e) { - Log_OC.e(TAG, "Failed to validate account type " + accountType + ": " - + e.getMessage()); - e.printStackTrace(); - return e.getFailureBundle(); - } - final Intent intent = new Intent(mContext, AuthenticatorActivity.class); - intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); - intent.putExtra(KEY_AUTH_TOKEN_TYPE, authTokenType); - intent.putExtra(KEY_REQUIRED_FEATURES, requiredFeatures); - intent.putExtra(KEY_LOGIN_OPTIONS, options); - intent.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_CREATE); - - setIntentFlags(intent); final Bundle bundle = new Bundle(); - bundle.putParcelable(AccountManager.KEY_INTENT, intent); + + AccountManager accountManager = AccountManager.get(mContext); + Account[] accounts = accountManager.getAccountsByType(MainApp.getAccountType()); + + if (mContext.getResources().getBoolean(R.bool.multiaccount_support) || accounts.length < 1) { + try { + validateAccountType(accountType); + } catch (AuthenticatorException e) { + Log_OC.e(TAG, "Failed to validate account type " + accountType + ": " + + e.getMessage()); + e.printStackTrace(); + return e.getFailureBundle(); + } + + final Intent intent = new Intent(mContext, AuthenticatorActivity.class); + intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); + intent.putExtra(KEY_AUTH_TOKEN_TYPE, authTokenType); + intent.putExtra(KEY_REQUIRED_FEATURES, requiredFeatures); + intent.putExtra(KEY_LOGIN_OPTIONS, options); + intent.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_CREATE); + + setIntentFlags(intent); + + bundle.putParcelable(AccountManager.KEY_INTENT, intent); + + } else { + + // Return an error + bundle.putInt(AccountManager.KEY_ERROR_CODE, AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION); + bundle.putString(AccountManager.KEY_ERROR_MESSAGE, mContext.getString(R.string.auth_unsupported_multiaccount)); + + mHandler.post(new Runnable() { + + @Override + public void run() { + Toast.makeText(mContext, R.string.auth_unsupported_multiaccount, Toast.LENGTH_SHORT).show(); + } + }); + + } + return bundle; } diff --git a/src/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/com/owncloud/android/authentication/AuthenticatorActivity.java index 0b722c8c..53f18bb4 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -49,6 +49,7 @@ import android.widget.CheckBox; import android.widget.EditText; import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; +import android.widget.Toast; import com.actionbarsherlock.app.SherlockDialogFragment; import com.owncloud.android.Log_OC; diff --git a/src/com/owncloud/android/ui/activity/AccountSelectActivity.java b/src/com/owncloud/android/ui/activity/AccountSelectActivity.java index a98c38e7..f5d06dcb 100644 --- a/src/com/owncloud/android/ui/activity/AccountSelectActivity.java +++ b/src/com/owncloud/android/ui/activity/AccountSelectActivity.java @@ -111,8 +111,11 @@ public class AccountSelectActivity extends SherlockListActivity implements @Override public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getSherlock().getMenuInflater(); - inflater.inflate(R.menu.account_picker, menu); + // Show Create Account if Multiaccount is enabled + if (getResources().getBoolean(R.bool.multiaccount_support)) { + MenuInflater inflater = getSherlock().getMenuInflater(); + inflater.inflate(R.menu.account_picker, menu); + } return true; } @@ -147,7 +150,6 @@ public class AccountSelectActivity extends SherlockListActivity implements this, null, null); - return true; } return false; @@ -212,6 +214,7 @@ public class AccountSelectActivity extends SherlockListActivity implements android.R.layout.simple_list_item_single_choice, new String[] { "NAME" }, new int[] { android.R.id.text1 })); registerForContextMenu(getListView()); + } @Override