Add the list of accounts in the Login.View
author"Vincent Veronis"
Sun, 20 Mar 2011 02:55:29 +0100
changeset 876 e221906b6fc7
parent 875 c555133a4d72
child 877 56a04fcdd3fd
Add the list of accounts in the Login.View Send to the BeemService the account name for the connection
res/layout/login.xml
res/layout/login_row_account.xml
src/com/beem/project/beem/BeemService.java
src/com/beem/project/beem/ui/Login.java
src/com/beem/project/beem/ui/LoginAnim.java
--- a/res/layout/login.xml	Sun Mar 20 00:57:46 2011 +0100
+++ b/res/layout/login.xml	Sun Mar 20 02:55:29 2011 +0100
@@ -1,17 +1,13 @@
 <?xml version="1.0" encoding="utf-8"?>
-<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="fill_parent" android:layout_height="fill_parent" >
-	<LinearLayout android:orientation="vertical"
-		android:layout_width="fill_parent" android:layout_height="wrap_content">
-		<ListView android:id="@+id/accountlist" android:layout_width="fill_parent"
-		    android:layout_height="fill_parent" android:transcriptMode="disabled"
-		    android:textFilterEnabled="true" />
-		<ImageView android:id="@+id/log_as_logo" android:src="@drawable/logo"
-			android:layout_width="fill_parent" android:layout_height="wrap_content"
-			android:layout_marginBottom="25px" android:layout_marginTop="42px" />
-		<TextView android:id="@+id/log_as_msg" android:layout_width="fill_parent"
-			android:layout_height="wrap_content" android:gravity="center"
-			android:textColor="#FF0000" android:textStyle="bold"
-			android:textSize="14sp" />
-	</LinearLayout>
-</ScrollView>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+	android:orientation="vertical" android:layout_width="fill_parent"
+	android:layout_height="fill_parent">
+	<ImageView android:id="@+id/log_as_logo" android:src="@drawable/logo"
+		android:layout_width="fill_parent" android:layout_height="wrap_content"
+		android:layout_marginBottom="25px" android:layout_marginTop="42px" />
+	<TextView android:id="@+id/log_as_msg" android:layout_width="fill_parent"
+		android:layout_height="wrap_content" android:gravity="center"
+		android:textColor="#FF0000" android:textStyle="bold" android:textSize="14sp" />
+	<ListView android:id="@+id/accountlist" android:layout_width="fill_parent"
+		android:layout_height="fill_parent" />
+</LinearLayout>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/res/layout/login_row_account.xml	Sun Mar 20 02:55:29 2011 +0100
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+	android:textColor="@color/white" android:textColorHighlight="@color/red"
+	android:textSize="25sp" android:typeface="normal" android:textStyle="bold"
+	android:gravity="center" android:id="@+id/accountname"></TextView>
\ No newline at end of file
--- a/src/com/beem/project/beem/BeemService.java	Sun Mar 20 00:57:46 2011 +0100
+++ b/src/com/beem/project/beem/BeemService.java	Sun Mar 20 02:55:29 2011 +0100
@@ -124,7 +124,7 @@
     public IBinder onBind(Intent intent) {
 	Log.d(TAG, "ONBIND()");
 	//TODO: Prendre le bon mbind dans le tableau
-	return mBind.get("beem@elyzion.net");
+	return mBind.get(intent.getExtras().getString("account_name"));
     }
 
     @Override
@@ -212,12 +212,12 @@
      * @param notif the notification to show
      */
     public void sendNotification(int id, Notification notif) {
-//	if (mSettings.getBoolean(BeemApplication.NOTIFICATION_VIBRATE_KEY, true))
-//	    notif.defaults |= Notification.DEFAULT_VIBRATE;
-//	notif.defaults |= Notification.DEFAULT_LIGHTS;
-//	String ringtoneStr = mSettings.getString(BeemApplication.NOTIFICATION_SOUND_KEY, "");
-//	notif.sound = Uri.parse(ringtoneStr);
-//	mNotificationManager.notify(id, notif);
+	//	if (mSettings.getBoolean(BeemApplication.NOTIFICATION_VIBRATE_KEY, true))
+	//	    notif.defaults |= Notification.DEFAULT_VIBRATE;
+	//	notif.defaults |= Notification.DEFAULT_LIGHTS;
+	//	String ringtoneStr = mSettings.getString(BeemApplication.NOTIFICATION_SOUND_KEY, "");
+	//	notif.sound = Uri.parse(ringtoneStr);
+	//	mNotificationManager.notify(id, notif);
     }
 
     /**
--- a/src/com/beem/project/beem/ui/Login.java	Sun Mar 20 00:57:46 2011 +0100
+++ b/src/com/beem/project/beem/ui/Login.java	Sun Mar 20 02:55:29 2011 +0100
@@ -40,9 +40,14 @@
     Flavien Astraud, November 26, 2009
     Head of the EIP Laboratory.
 
-*/
+ */
 package com.beem.project.beem.ui;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import android.accounts.Account;
+import android.accounts.AccountManager;
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.Application;
@@ -51,16 +56,21 @@
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
 import android.os.Bundle;
+import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.BaseAdapter;
+import android.widget.ListView;
 import android.widget.TextView;
 import android.widget.Toast;
+import android.widget.AdapterView.OnItemClickListener;
 
 import com.beem.project.beem.BeemApplication;
 import com.beem.project.beem.R;
-import com.beem.project.beem.ui.wizard.Account;
-import com.beem.project.beem.utils.BeemConnectivity;
 
 /**
  * This class is the main Activity for the Beem project.
@@ -70,9 +80,12 @@
 
     private static final int LOGIN_REQUEST_CODE = 1;
     private TextView mTextView;
-    private boolean mIsResult;
     private BeemApplication mBeemApplication;
 
+    List<String> mListAccount = new ArrayList<String>();
+    private BeemAccountList mAdapterAccountList;
+    private final BeemAccountListOnClick mOnAccountClick = new BeemAccountListOnClick();
+
     /**
      * Constructor.
      */
@@ -95,26 +108,21 @@
 	}
 	setContentView(R.layout.login);
 	mTextView = (TextView) findViewById(R.id.log_as_msg);
+	ListView listView = (ListView) findViewById(R.id.accountlist);
+	mAdapterAccountList = new BeemAccountList(getLayoutInflater());
+	listView.setOnItemClickListener(mOnAccountClick);
+	listView.setAdapter(mAdapterAccountList);
     }
 
     @Override
     protected void onStart() {
 	super.onStart();
-	if (mBeemApplication.isAccountConfigured() && !mIsResult
-	    && BeemConnectivity.isConnected(getApplicationContext())) {
-	    mTextView.setText("");
-	    Intent i = new Intent(this, LoginAnim.class);
-	    startActivityForResult(i, LOGIN_REQUEST_CODE);
-	    mIsResult = false;
-	} else {
-	    mTextView.setText(R.string.login_start_msg);
-	}
+	mTextView.setText(R.string.login_start_msg);
     }
 
     @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 	if (requestCode == LOGIN_REQUEST_CODE) {
-	    mIsResult = true;
 	    if (resultCode == Activity.RESULT_OK) {
 		startActivity(new Intent(this, ContactList.class));
 		finish();
@@ -187,4 +195,67 @@
 	AlertDialog aboutDialog = builder.create();
 	aboutDialog.show();
     }
+
+    private class BeemAccountList extends BaseAdapter {
+
+	private LayoutInflater mInflater;
+
+	public BeemAccountList(LayoutInflater layoutInflater) {
+	    mInflater = layoutInflater;
+	    AccountManager am = AccountManager.get(Login.this);
+	    Account allAccount[] = am.getAccountsByType("com.beem.project.com");
+	    for (Account account : allAccount) {
+		mListAccount.add(account.name);
+		mListAccount.add(account.name);
+
+	    }
+	}
+
+	@Override
+	public int getCount() {
+	    return mListAccount.size();
+	}
+
+	@Override
+	public Object getItem(int position) {
+	    return mListAccount.get(position);
+	}
+
+	@Override
+	public long getItemId(int position) {
+	    return position;
+	}
+
+	@Override
+	public View getView(int position, View convertView, ViewGroup parent) {
+	    View v = convertView;
+	    if (convertView == null) {
+		v = mInflater.inflate(R.layout.login_row_account, null);
+	    }
+	    TextView tv = (TextView) v.findViewById(R.id.accountname);
+	    tv.setText(mListAccount.get(position));
+	    return v;
+	}
+    }
+
+    /**
+     * Event simple click on item of the contact list.
+     */
+    private class BeemAccountListOnClick implements OnItemClickListener {
+	/**
+	 * Constructor.
+	 */
+	public BeemAccountListOnClick() {
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void onItemClick(AdapterView<?> arg0, View v, int pos, long lpos) {
+	    Intent i = new Intent(Login.this, LoginAnim.class);
+	    i.putExtra("account_name",  mListAccount.get(pos));
+	    startActivityForResult(i, LOGIN_REQUEST_CODE);
+	}
+    }
 }
--- a/src/com/beem/project/beem/ui/LoginAnim.java	Sun Mar 20 00:57:46 2011 +0100
+++ b/src/com/beem/project/beem/ui/LoginAnim.java	Sun Mar 20 02:55:29 2011 +0100
@@ -121,8 +121,9 @@
 	if (mTask == null)
 	    mTask = new LoginTask();
 	if (mXmppFacade == null) {
-	    Intent i = new Intent();
-	    bindService(LoginAnim.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
+	    Intent i = new Intent(LoginAnim.SERVICE_INTENT);
+	    i.putExtra("account_name", getIntent().getExtras().getString("account_name"));
+	    bindService(i, mServConn, BIND_AUTO_CREATE);
 	}
     }