# HG changeset patch # User "Vincent Veronis" # Date 1298643089 -3600 # Node ID 85977e23817aecbc7eea1790695ff6cb2c94ae2f # Parent 1a0caf61fc7c2c167523753f89f8e5a7335dd0f5 Account Manager Creation OK Multi Account FAIL diff -r 1a0caf61fc7c -r 85977e23817a AndroidManifest.xml --- a/AndroidManifest.xml Sat Feb 05 21:25:11 2011 +0100 +++ b/AndroidManifest.xml Fri Feb 25 15:11:29 2011 +0100 @@ -13,7 +13,8 @@ - + @@ -30,8 +31,7 @@ + android:launchMode="singleTask" android:windowSoftInputMode="stateHidden"> @@ -76,6 +76,14 @@ android:name="android.intent.action.BOOT_COMPLETED" /> --> + + + + + + @@ -87,13 +95,15 @@ - - + android:name="com.beem.project.beem.BEEM_SERVICE" /> + + - - - + + + + - + android:normalScreens="true" android:smallScreens="true" + android:anyDensity="true" /> + \ No newline at end of file diff -r 1a0caf61fc7c -r 85977e23817a default.properties --- a/default.properties Sat Feb 05 21:25:11 2011 +0100 +++ b/default.properties Fri Feb 25 15:11:29 2011 +0100 @@ -8,4 +8,4 @@ # project structure. # Project target. -target=android-7 +target=android-8 diff -r 1a0caf61fc7c -r 85977e23817a res/xml/authenticator.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/res/xml/authenticator.xml Fri Feb 25 15:11:29 2011 +0100 @@ -0,0 +1,8 @@ + + \ No newline at end of file diff -r 1a0caf61fc7c -r 85977e23817a src/com/beem/project/beem/account/Authenticator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/account/Authenticator.java Fri Feb 25 15:11:29 2011 +0100 @@ -0,0 +1,67 @@ +package com.beem.project.beem.account; + +import com.beem.project.beem.ui.wizard.AccountConfigure; + +import android.accounts.AbstractAccountAuthenticator; +import android.accounts.Account; +import android.accounts.AccountAuthenticatorResponse; +import android.accounts.AccountManager; +import android.accounts.NetworkErrorException; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; + +public class Authenticator extends AbstractAccountAuthenticator { + + private Context mContext; + + public Authenticator(Context context) { + super(context); + mContext = context; + } + + @Override + public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, + String[] requiredFeatures, Bundle options) throws NetworkErrorException { + Intent intent = new Intent(mContext, AccountConfigure.class); + intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); + Bundle reply = new Bundle(); + reply.putParcelable(AccountManager.KEY_INTENT, intent); + return reply; + } + + @Override + public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) + throws NetworkErrorException { + return null; + } + + @Override + public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) { + return null; + } + + @Override + public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, + Bundle options) throws NetworkErrorException { + return null; + } + + @Override + public String getAuthTokenLabel(String authTokenType) { + return null; + } + + @Override + public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features) + throws NetworkErrorException { + return null; + } + + @Override + public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType, + Bundle options) throws NetworkErrorException { + return null; + } + +} diff -r 1a0caf61fc7c -r 85977e23817a src/com/beem/project/beem/account/AuthenticatorService.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/account/AuthenticatorService.java Fri Feb 25 15:11:29 2011 +0100 @@ -0,0 +1,29 @@ +package com.beem.project.beem.account; + +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; + +public class AuthenticatorService extends Service { + + private Authenticator mAuth; + + public AuthenticatorService() { + super(); + } + + @Override + public void onCreate() { + super.onCreate(); + mAuth = new Authenticator(getApplicationContext()); + } + + @Override + public IBinder onBind(Intent intent) { + IBinder ret = null; + if (intent.getAction().equals(android.accounts.AccountManager.ACTION_AUTHENTICATOR_INTENT)) + ret = mAuth.getIBinder(); + return ret; + } + +} diff -r 1a0caf61fc7c -r 85977e23817a src/com/beem/project/beem/account/SyncAdapter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/account/SyncAdapter.java Fri Feb 25 15:11:29 2011 +0100 @@ -0,0 +1,27 @@ + +package com.beem.project.beem.account; + +import android.accounts.Account; +import android.accounts.AccountManager; +import android.content.AbstractThreadedSyncAdapter; +import android.content.ContentProviderClient; +import android.content.Context; +import android.content.SyncResult; +import android.os.Bundle; + + +public class SyncAdapter extends AbstractThreadedSyncAdapter { + + private Context mContext; + + public SyncAdapter(Context context, boolean autoInitialize) { + super(context, autoInitialize); + mContext = context; + } + + @Override + public void onPerformSync(Account account, Bundle extras, String authority, + ContentProviderClient provider, SyncResult syncResult) { + } + +} diff -r 1a0caf61fc7c -r 85977e23817a src/com/beem/project/beem/ui/wizard/AccountConfigure.java --- a/src/com/beem/project/beem/ui/wizard/AccountConfigure.java Sat Feb 05 21:25:11 2011 +0100 +++ b/src/com/beem/project/beem/ui/wizard/AccountConfigure.java Fri Feb 25 15:11:29 2011 +0100 @@ -40,9 +40,14 @@ Flavien Astraud, November 26, 2009 Head of the EIP Laboratory. -*/ + */ package com.beem.project.beem.ui.wizard; +import org.jivesoftware.smack.util.StringUtils; + +import android.accounts.Account; +import android.accounts.AccountAuthenticatorResponse; +import android.accounts.AccountManager; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; @@ -58,16 +63,13 @@ import android.widget.Button; import android.widget.EditText; -import org.jivesoftware.smack.util.StringUtils; - +import com.beem.project.beem.BeemApplication; +import com.beem.project.beem.R; import com.beem.project.beem.ui.Login; import com.beem.project.beem.ui.Settings; -import com.beem.project.beem.BeemApplication; -import com.beem.project.beem.R; /** * Activity to enter the information required in order to configure a XMPP account. - * * @author Da Risk */ public class AccountConfigure extends Activity implements OnClickListener { @@ -81,6 +83,7 @@ private final PasswordTextWatcher mPasswordTextWatcher = new PasswordTextWatcher(); private boolean mValidJid; private boolean mValidPassword; + private AccountManager mAccountManager; /** * Constructor. @@ -99,7 +102,6 @@ mAccountJID = (EditText) findViewById(R.id.account_username); mAccountPassword = (EditText) findViewById(R.id.account_password); - InputFilter[] orgFilters = mAccountJID.getFilters(); InputFilter[] newFilters = new InputFilter[orgFilters.length + 1]; int i; @@ -109,6 +111,7 @@ mAccountJID.setFilters(newFilters); mAccountJID.addTextChangedListener(mJidTextWatcher); mAccountPassword.addTextChangedListener(mPasswordTextWatcher); + mAccountManager = AccountManager.get(this); } @Override @@ -150,6 +153,22 @@ edit.putString(BeemApplication.ACCOUNT_USERNAME_KEY, mAccountJID.getText().toString()); edit.putString(BeemApplication.ACCOUNT_PASSWORD_KEY, mAccountPassword.getText().toString()); edit.commit(); + Account account = new Account(mAccountJID.getText().toString(), "com.beem.project.com"); + boolean accountCreated = mAccountManager.addAccountExplicitly(account, mAccountPassword.getText().toString(), + null); + Bundle extras = getIntent().getExtras(); + if (extras != null) { + if (accountCreated) { + AccountAuthenticatorResponse response = extras + .getParcelable(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE); + Bundle result = new Bundle(); + result.putString(AccountManager.KEY_ACCOUNT_NAME, mAccountJID.getText().toString()); + result.putString(AccountManager.KEY_ACCOUNT_TYPE, "com.beem.project.com"); + response.onResult(result); + finish(); + } + } + } /** @@ -195,11 +214,11 @@ } @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { + public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { + public void onTextChanged(CharSequence s, int start, int before, int count) { } } @@ -221,11 +240,11 @@ } @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { + public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { + public void onTextChanged(CharSequence s, int start, int before, int count) { } } }