Merge beem-account and Beem-avatar
author"Vincent Veronis"
Sat, 19 Mar 2011 19:31:31 +0100
changeset 871 be08c9157636
parent 863 85977e23817a (diff)
parent 870 2236fe5b2db1 (current diff)
child 872 11a7b9c1c500
Merge beem-account and Beem-avatar
AndroidManifest.xml
--- a/AndroidManifest.xml	Sat Mar 05 17:44:41 2011 +0100
+++ b/AndroidManifest.xml	Sat Mar 19 19:31:31 2011 +0100
@@ -13,25 +13,62 @@
 			</intent-filter>
 		</activity>
 		<activity android:name=".ui.wizard.Account" android:label="Account wizard" />
-		<activity android:name=".ui.wizard.AccountConfigure" android:label="Account wizard" />
+		<activity android:name=".ui.wizard.AccountConfigure"
+			android:label="Account wizard" />
 		<activity android:name=".ui.LoginAnim" android:label="@string/login_login_progress"
 			android:launchMode="singleTop" android:screenOrientation="portrait" />
-		<activity android:name=".ui.Settings" android:label="@string/edit_settings_name" />
+		<activity android:name=".ui.Settings" android:label="@string/edit_settings_name">
+			<intent-filter android:label="Beem Connection">
+				<action
+					android:name="com.beem.project.beem.service.XmppConnectionAdapter.CONNECTION_CLOSED" />
+			</intent-filter>
+		</activity>
 		<activity android:name=".ui.Chat" android:label="@string/chat_name"
-		    android:launchMode="singleTop" />
+			android:launchMode="singleTop">
+			<intent-filter android:label="Beem Connection">
+				<action
+					android:name="com.beem.project.beem.service.XmppConnectionAdapter.CONNECTION_CLOSED" />
+			</intent-filter>
+		</activity>
 		<activity android:name=".ui.ChangeStatus" android:label="@string/ChangeStatusActTitle"
-		    android:launchMode="singleTop"
-		    android:windowSoftInputMode="stateHidden" />
-		<activity android:name=".ui.AddContact" android:label="@string/AddCActTitle" />
-		<activity android:name=".ui.Subscription" android:label="@string/app_name" />
+			android:launchMode="singleTask" android:windowSoftInputMode="stateHidden">
+			<intent-filter android:label="Beem Connection">
+				<action
+					android:name="com.beem.project.beem.service.XmppConnectionAdapter.CONNECTION_CLOSED" />
+			</intent-filter>
+		</activity>
+		<activity android:name=".ui.AddContact" android:label="@string/AddCActTitle">
+			<intent-filter android:label="Beem Connection">
+				<action
+					android:name="com.beem.project.beem.service.XmppConnectionAdapter.CONNECTION_CLOSED" />
+			</intent-filter>
+		</activity>
+		<activity android:name=".ui.Subscription" android:label="@string/app_name">
+			<intent-filter android:label="Beem Connection">
+				<action
+					android:name="com.beem.project.beem.service.XmppConnectionAdapter.CONNECTION_CLOSED" />
+			</intent-filter>
+		</activity>
 		<activity android:name=".ui.CreateAccount" android:label="@string/create_account_name" />
-
 		<activity android:name=".ui.ContactList" android:label="@string/contact_list_name"
-		    android:launchMode="singleTask" />
-
-		<activity android:name=".ui.GroupList" android:label="GroupList" />
-		<activity android:name=".ui.PrivacyList" android:label="@string/privacy_list_name" />
-
+			android:launchMode="singleTask">
+			<intent-filter android:label="Beem Connection">
+				<action
+					android:name="com.beem.project.beem.service.XmppConnectionAdapter.CONNECTION_CLOSED" />
+			</intent-filter>
+		</activity>
+		<activity android:name=".ui.GroupList" android:label="GroupList">
+			<intent-filter android:label="Beem Connection">
+				<action
+					android:name="com.beem.project.beem.service.XmppConnectionAdapter.CONNECTION_CLOSED" />
+			</intent-filter>
+		</activity>
+		<activity android:name=".ui.PrivacyList" android:label="@string/privacy_list_name">
+			<intent-filter android:label="Beem Connection">
+				<action
+					android:name="com.beem.project.beem.service.XmppConnectionAdapter.CONNECTION_CLOSED" />
+			</intent-filter>
+		</activity>
 		<!--
 			Could be interesting if we would launch beem at startup <receiver
 			android:name=".tool.BeemBroadcastReceiver" android:enabled="true">
@@ -39,27 +76,38 @@
 			android:name="android.intent.action.BOOT_COMPLETED" />
 			</intent-filter> </receiver>
 		-->
-		<provider android:name=".providers.AvatarProvider"
+	<provider android:name=".providers.AvatarProvider"
 		    android:authorities="com.beem.project.beem.providers.avatarprovider"
 		    android:exported="false" />
 
+		<service android:name=".account.AuthenticatorService"
+			android:exported="true" android:process=":auth">
+			<intent-filter>
+				<action android:name="android.accounts.AccountAuthenticator" />
+			</intent-filter>
+			<meta-data android:name="android.accounts.AccountAuthenticator"
+				android:resource="@xml/authenticator" />
+		</service>
 		<service android:name="BeemService" android:enabled="true"
 			android:label="Beem Service" android:permission="com.beem.project.beem.BEEM_SERVICE">
 			<intent-filter>
 				<action android:name="com.beem.project.beem.BeemService"></action>
+				<action android:name="android.intent.action.SCREEN_OFF"></action>
+				<action android:name="android.intent.action.SCREEN_ON"></action>
 			</intent-filter>
 		</service>
 	</application>
 	<permission android:permissionGroup="android.permission-group.NETWORK"
 		android:label="BeemService" android:description="@string/BeemServiceDescription"
-		android:name="com.beem.project.beem.BEEM_SERVICE"/>
-	<uses-permission android:name="android.permission.INTERNET"/>
-	<uses-permission android:name="android.permission.VIBRATE"/>
+		android:name="com.beem.project.beem.BEEM_SERVICE" />
+	<uses-permission android:name="android.permission.INTERNET" />
+	<uses-permission android:name="android.permission.VIBRATE" />
 	<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
-	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
-	<uses-permission android:name="com.beem.project.beem.BEEM_SERVICE"/>
-	<uses-feature name="android.hardware.touchscreen" required="false" />
-	<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="7" />
+	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+	<uses-permission android:name="com.beem.project.beem.BEEM_SERVICE" />
+	<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
+	<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" />
 	<supports-screens android:largeScreens="true"
-		android:normalScreens="true" android:smallScreens="true" android:anyDensity="true" />
+		android:normalScreens="true" android:smallScreens="true"
+		android:anyDensity="true" />
 </manifest>
--- a/default.properties	Sat Mar 05 17:44:41 2011 +0100
+++ b/default.properties	Sat Mar 19 19:31:31 2011 +0100
@@ -8,4 +8,4 @@
 # project structure.
 
 # Project target.
-target=android-7
+target=android-8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/res/xml/authenticator.xml	Sat Mar 19 19:31:31 2011 +0100
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<account-authenticator
+	xmlns:android="http://schemas.android.com/apk/res/android"
+	android:accountType="com.beem.project.com"
+	android:icon="@drawable/beem_launcher_icon_silver"
+	android:smallIcon="@drawable/beem_status_icon"
+	android:label="@string/app_name"
+	android:accountPreferences="@xml/preferences" />
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/account/Authenticator.java	Sat Mar 19 19:31:31 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;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/account/AuthenticatorService.java	Sat Mar 19 19:31:31 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;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/account/SyncAdapter.java	Sat Mar 19 19:31:31 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) {
+	}
+
+}
--- a/src/com/beem/project/beem/ui/wizard/AccountConfigure.java	Sat Mar 05 17:44:41 2011 +0100
+++ b/src/com/beem/project/beem/ui/wizard/AccountConfigure.java	Sat Mar 19 19:31:31 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 <darisk972@gmail.com>
  */
 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) {
 	}
     }
 }