Account_type now = package name.
authorVincent V.<marseille@beem-project.com>
Mon, 14 Nov 2011 00:47:02 +0100
changeset 919 b1815efd3cf6
parent 918 80d2be82fa84
child 920 68372d462902
Account_type now = package name. Continue clean on aidl ContactList update request on contact to get display name Clean on add_contact user interface
res/layout/addcontact.xml
res/xml/authenticator.xml
res/xml/sync_contacts.xml
src/com/beem/project/beem/BeemApplication.java
src/com/beem/project/beem/service/aidl/IBeemRosterListener.aidl
src/com/beem/project/beem/service/aidl/IMessageListener.aidl
src/com/beem/project/beem/ui/AddContact.java
src/com/beem/project/beem/ui/ContactList.java
src/com/beem/project/beem/ui/Login.java
src/com/beem/project/beem/ui/wizard/AccountConfigure.java
--- a/res/layout/addcontact.xml	Sun Nov 06 21:22:00 2011 +0100
+++ b/res/layout/addcontact.xml	Mon Nov 14 00:47:02 2011 +0100
@@ -12,25 +12,7 @@
 			android:imeOptions="actionNext" android:scrollHorizontally="true"
 			android:layout_width="fill_parent" android:layout_height="wrap_content"
 			android:layout_margin="3dip"
-			android:contentDescription="@string/AddCLogin"/>
-		<TextView android:layout_width="fill_parent"
-			android:layout_height="wrap_content" android:text="@string/AddCAlias"
-			style="@style/Label" />
-		<EditText android:id="@+id/addc_alias" android:inputType="text"
-			android:imeOptions="actionNext" android:textSize="16sp"
-			android:layout_width="fill_parent" android:layout_height="wrap_content"
-			android:scrollHorizontally="true" android:layout_margin="3dip"
-			android:contentDescription="@string/AddCAlias"/>
-		<TextView android:layout_width="fill_parent"
-			android:layout_height="wrap_content" android:text="@string/AddCGroup"
-			style="@style/Label" />
-		<EditText android:id="@+id/addc_group" android:inputType="text"
-			android:textSize="16sp" android:layout_width="fill_parent"
-			android:scrollHorizontally="true" android:layout_height="wrap_content"
-			android:layout_margin="3dip"
-			android:contentDescription="@string/AddCGroup"/>
-		<View android:layout_width="fill_parent" android:layout_height="wrap_content"
-			android:layout_weight="1" android:layout_marginBottom="18dp" />
+			android:contentDescription="@string/AddCLogin"/>		
 		<Button android:id="@+id/addc_ok" android:layout_width="fill_parent"
 			android:layout_height="wrap_content" android:textStyle="bold"
 			android:text="@string/AddCOkButton" android:layout_gravity="bottom"
--- a/res/xml/authenticator.xml	Sun Nov 06 21:22:00 2011 +0100
+++ b/res/xml/authenticator.xml	Mon Nov 14 00:47:02 2011 +0100
@@ -1,7 +1,7 @@
 <?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:accountType="com.beem.project.beem"
 	android:icon="@drawable/beem_launcher_icon_silver"
 	android:smallIcon="@drawable/beem_status_icon"
 	android:label="@string/app_name"
--- a/res/xml/sync_contacts.xml	Sun Nov 06 21:22:00 2011 +0100
+++ b/res/xml/sync_contacts.xml	Mon Nov 14 00:47:02 2011 +0100
@@ -2,4 +2,4 @@
 <sync-adapter
 	xmlns:android="http://schemas.android.com/apk/res/android"
 	android:contentAuthority="com.android.contacts"
-	android:accountType="com.beem.project.com" />
\ No newline at end of file
+	android:accountType="com.beem.project.beem" />
\ No newline at end of file
--- a/src/com/beem/project/beem/BeemApplication.java	Sun Nov 06 21:22:00 2011 +0100
+++ b/src/com/beem/project/beem/BeemApplication.java	Mon Nov 14 00:47:02 2011 +0100
@@ -91,6 +91,7 @@
     public static final String CHAT_HISTORY_KEY = "settings_chat_history_path";
 
     //TODO add the other one
+    public static final String BEEM_PACKAGE = "com.beem.project.beem";
 
     private boolean mIsConnected;
     private boolean mIsAccountConfigured;
--- a/src/com/beem/project/beem/service/aidl/IBeemRosterListener.aidl	Sun Nov 06 21:22:00 2011 +0100
+++ b/src/com/beem/project/beem/service/aidl/IBeemRosterListener.aidl	Mon Nov 14 00:47:02 2011 +0100
@@ -43,7 +43,7 @@
 */
 package com.beem.project.beem.service.aidl;
 
-import com.beem.project.beem.service.PresenceAdapter;
+//import com.beem.project.beem.service.PresenceAdapter;
 
 interface IBeemRosterListener {
     void onEntriesAdded(in List<String> addresses);
--- a/src/com/beem/project/beem/service/aidl/IMessageListener.aidl	Sun Nov 06 21:22:00 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-/*
-    BEEM is a videoconference application on the Android Platform.
-
-    Copyright (C) 2009 by Frederic-Charles Barthelery,
-                          Jean-Manuel Da Silva,
-                          Nikita Kozlov,
-                          Philippe Lago,
-                          Jean Baptiste Vergely,
-                          Vincent Veronis.
-
-    This file is part of BEEM.
-
-    BEEM is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    BEEM is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with BEEM.  If not, see <http://www.gnu.org/licenses/>.
-
-    Please send bug reports with examples or suggestions to
-    contact@beem-project.com or http://dev.beem-project.com/
-
-    Epitech, hereby disclaims all copyright interest in the program "Beem"
-    written by Frederic-Charles Barthelery,
-               Jean-Manuel Da Silva,
-               Nikita Kozlov,
-               Philippe Lago,
-               Jean Baptiste Vergely,
-               Vincent Veronis.
-
-    Nicolas Sadirac, November 26, 2009
-    President of Epitech.
-
-    Flavien Astraud, November 26, 2009
-    Head of the EIP Laboratory.
-
-*/
-package com.beem.project.beem.service.aidl;
-
-import com.beem.project.beem.service.Message;
-import com.beem.project.beem.service.aidl.IChat;
-
-interface IMessageListener {
-
-	/**
-	 * This method is executed when a chat receive a message.
-	 * @param chat the chat receiving the message.
-	 * @param msg the message received in the chat.
-	 */
-	//void processMessage(in IChat chat, in Message msg);
-
-	/**
-	 * This method is executed when a new ChatState is received by the chat.
-	 * You can use IChat.getState() in order to get the new state.
-	 * @param chat the chat changed.
-	 */
-	//void stateChanged(in IChat chat);
-}
--- a/src/com/beem/project/beem/ui/AddContact.java	Sun Nov 06 21:22:00 2011 +0100
+++ b/src/com/beem/project/beem/ui/AddContact.java	Mon Nov 14 00:47:02 2011 +0100
@@ -47,19 +47,22 @@
 import java.util.List;
 import java.util.regex.Pattern;
 
+import android.accounts.Account;
+import android.accounts.AccountManager;
 import android.app.Activity;
-import android.content.ComponentName;
 import android.content.Intent;
-import android.content.IntentFilter;
 import android.os.Bundle;
+import android.util.Log;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.Button;
 import android.widget.EditText;
 import android.widget.Toast;
 
+import com.beem.project.beem.BeemApplication;
+import com.beem.project.beem.BeemIntent;
 import com.beem.project.beem.R;
-import com.beem.project.beem.utils.BeemBroadcastReceiver;
+import com.beem.project.beem.ui.wizard.AccountConfigure;
 
 /**
  * This activity is used to add a contact.
@@ -67,15 +70,10 @@
  */
 public class AddContact extends Activity {
 
-    private static final Intent SERVICE_INTENT = new Intent();
     private static final String TAG = "AddContact";
-    private final List<String> mGroup = new ArrayList<String>();
-    private final BeemBroadcastReceiver mReceiver = new BeemBroadcastReceiver();
     private final OkListener mOkListener = new OkListener();
 
-    static {
-	SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
-    }
+    private String mAccount = null;
 
     /**
      * Constructor.
@@ -90,46 +88,31 @@
     protected void onCreate(Bundle savedInstanceState) {
 	super.onCreate(savedInstanceState);
 	setContentView(R.layout.addcontact);
+
 	Button ok = (Button) findViewById(R.id.addc_ok);
 	ok.setOnClickListener(mOkListener);
-	this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+
     }
 
-    /*
-     * (non-Javadoc)
-     * @see android.app.Activity#onStart()
-     */
-    @Override
-    protected void onStart() {
-	super.onStart();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
     @Override
     protected void onResume() {
 	super.onResume();
-//	bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected void onPause() {
-	super.onPause();
-//	unbindService(mServConn);
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see android.app.Activity#onDestroy()
-     */
-    @Override
-    protected void onDestroy() {
-	super.onDestroy();
-	this.unregisterReceiver(mReceiver);
+	Bundle b = getIntent().getExtras();
+	if (b != null && b.containsKey(BeemIntent.EXTRA_ACCOUNT))
+	    mAccount = b.getString(BeemIntent.EXTRA_ACCOUNT);
+	else {
+	    AccountManager am = AccountManager.get(AddContact.this);
+	    Account allAccount[] = am.getAccountsByType(BeemApplication.BEEM_PACKAGE);
+	    Log.e(TAG, "NB ACCOUNT :" + allAccount.length);
+	    if (allAccount.length == 0) {
+		//TODO: Add toast to advice need to configure at least 1 beem account
+		startActivity(new Intent(AddContact.this, AccountConfigure.class));
+	    } else if (allAccount.length == 1) {
+		//TODO: Add toast to advice we are adding contact to the account : mAccount
+		mAccount = allAccount[0].name;
+	    } else if (allAccount.length > 1)
+		;// TODO : if multi account propose select
+	}
     }
 
     /**
@@ -155,44 +138,15 @@
 
 	@Override
 	public void onClick(View v) {
-	    String login;
-	    login = getWidgetText(R.id.addc_login);
-	    if (login.length() == 0) {
-		Toast.makeText(AddContact.this, getString(R.string.AddCBadForm), Toast.LENGTH_SHORT).show();
-		return;
-	    }
+	    Log.e(TAG, "Account : " + mAccount);
+	    String login = getWidgetText(R.id.addc_login);
 	    boolean isEmail = Pattern.matches("[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+.)+[a-zA-Z]{2,4}", login);
 	    if (!isEmail) {
 		Toast.makeText(AddContact.this, getString(R.string.AddCContactAddedLoginError), Toast.LENGTH_SHORT)
 		    .show();
 		return;
 	    }
-	    String alias;
-	    alias = getWidgetText(R.id.addc_alias);
-	    if (getWidgetText(R.id.addc_group).length() != 0)
-		mGroup.add(getWidgetText(R.id.addc_group));
-	    //	    try {
-	    //		if (mXmppFacade != null) {
-	    //		    if (mXmppFacade.getRoster().getContact(login) != null) {
-	    //			mGroup.addAll(mXmppFacade.getRoster().getContact(login).getGroups());
-	    //			Toast.makeText(AddContact.this, getString(R.string.AddCContactAlready), Toast.LENGTH_SHORT)
-	    //			    .show();
-	    //			return;
-	    //		    }
-	    //		    if (mXmppFacade.getRoster().addContact(login, alias, mGroup.toArray(new String[mGroup.size()])) == null) {
-	    //			Toast.makeText(AddContact.this, getString(R.string.AddCContactAddedError), Toast.LENGTH_SHORT)
-	    //			    .show();
-	    //			return;
-	    //		    } else {
-	    //			Toast.makeText(AddContact.this, getString(R.string.AddCContactAdded), Toast.LENGTH_SHORT)
-	    //			    .show();
-	    //			finish();
-	    //		    }
-	    //		}
-	    //	    } catch (RemoteException e) {
-	    //		Toast.makeText(AddContact.this, e.getMessage(), Toast.LENGTH_SHORT).show();
-	    //		Log.e(TAG, "Problem adding contact", e);
-	    //	    }
+	    //TODO: Intent -> add contact
 
 	}
     };
--- a/src/com/beem/project/beem/ui/ContactList.java	Sun Nov 06 21:22:00 2011 +0100
+++ b/src/com/beem/project/beem/ui/ContactList.java	Mon Nov 14 00:47:02 2011 +0100
@@ -30,6 +30,7 @@
 
 import android.app.Activity;
 import android.content.ComponentName;
+import android.content.ContentUris;
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
@@ -58,8 +59,10 @@
 import android.widget.SimpleCursorAdapter;
 import android.widget.TextView;
 
+import com.beem.project.beem.BeemApplication;
 import com.beem.project.beem.BeemIntent;
 import com.beem.project.beem.R;
+import com.beem.project.beem.ui.wizard.AccountConfigure;
 
 /**
  * The contact list activity displays the roster of the user.
@@ -99,8 +102,12 @@
 	super.onCreate(saveBundle);
 	mSettings = PreferenceManager.getDefaultSharedPreferences(this);
 	setContentView(R.layout.contactlist);
-
-	mAccountName = getIntent().getExtras().getString(BeemIntent.EXTRA_ACCOUNT);
+	Bundle b = getIntent().getExtras();
+	if (b == null) {
+	    //TODO: Add toast to advice need to configure at least 1 beem account (Should not happend)
+	    startActivity(new Intent(ContactList.this, AccountConfigure.class));
+	}
+	mAccountName = b.getString(BeemIntent.EXTRA_ACCOUNT);
 
 	// Get Groups list
 	final Cursor cursorGroup = getContentResolver().query(ContactsContract.Groups.CONTENT_URI,
@@ -109,16 +116,14 @@
 	mAdapterBanner = new BeemBanner(this, R.layout.contactlist_group, cursorGroup,
 	    new String[] { ContactsContract.Groups.TITLE }, new int[] { R.id.contactlist_group });
 	cursorGroup.registerContentObserver(new BeemGroupObserver(new Handler()));
+
 	// Get Contacts list
-	// TODO: Get contact list by account  -> Create Sqlite View or join
-	final Cursor cursorContact = getContentResolver().query(
-	    ContactsContract.RawContacts.CONTENT_URI,
-	    new String[] { ContactsContract.RawContacts._ID, ContactsContract.Contacts.DISPLAY_NAME,
-		ContactsContract.RawContacts.SOURCE_ID }, ContactsContract.RawContacts.ACCOUNT_NAME + "=?",
-	    new String[] { mAccountName }, null);
-	// TODO: GetAvatar + Presence
-	mAdapterContactList = new BeemContactList(this, R.layout.contactlistcontact, cursorContact, new String[] {
-	    ContactsContract.RawContacts._ID, ContactsContract.Contacts.DISPLAY_NAME,
+	Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon()
+	    .appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_NAME, mAccountName)
+	    .appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_TYPE, BeemApplication.BEEM_PACKAGE).build();
+	Cursor cursorRawContact = getContentResolver().query(rawContactUri, null, null, null, null);
+	mAdapterContactList = new BeemContactList(this, R.layout.contactlistcontact, cursorRawContact, new String[] {
+	    ContactsContract.RawContacts._ID, ContactsContract.RawContacts.CONTACT_ID,
 	    ContactsContract.RawContacts.SOURCE_ID }, new int[] { R.id.avatar, R.id.contactlistpseudo,
 	    R.id.contactlistmsgperso });
 
@@ -309,21 +314,35 @@
 
 	@Override
 	public void bindView(View view, Context context, Cursor cursor) {
-	    String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
-	    String jid = cursor.getString(cursor.getColumnIndex(ContactsContract.RawContacts.SOURCE_ID));
-	    TextView nameText = (TextView) view.findViewById(R.id.contactlistpseudo);
-	    if (nameText != null) {
-		nameText.setText(name);
+	    long id = cursor.getLong(cursor.getColumnIndex(ContactsContract.RawContacts.CONTACT_ID));
+
+	    Uri rawContactUri = ContentUris.withAppendedId(ContactsContract.RawContacts.CONTENT_URI, id);
+	    Uri entityUri = Uri.withAppendedPath(rawContactUri, ContactsContract.RawContacts.Entity.CONTENT_DIRECTORY);
+	    Cursor cursorContact = mContext.getContentResolver().query(
+		entityUri,
+		new String[] { ContactsContract.RawContacts.SOURCE_ID, ContactsContract.RawContacts.Entity.DATA_ID,
+		    ContactsContract.RawContacts.Entity.MIMETYPE, ContactsContract.RawContacts.Entity.DATA1 }, null,
+		null, null);
+	    try {
+		while (cursorContact.moveToNext()) {
+		    if (!cursorContact.isNull(1)) {
+			String mimeType = cursorContact.getString(2);
+			String data = cursorContact.getString(3);
+			Log.e(TAG, "SOURCE ID :" + data + " - " + mimeType);
+			if (mimeType.equals(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)) {
+			    TextView nameText = (TextView) view.findViewById(R.id.contactlistpseudo);
+			    nameText.setText(data);
+			}
+			//else if other mimetype
+
+		    }
+
+		}
+	    } finally {
+		cursorContact.close();
 	    }
 
-	    // String msgStatus = cursor.getString(cursor
-	    // .getColumnIndex(ContactsContract.Contacts.CONTACT_STATUS));
-	    // TextView msgStatusText = (TextView) view
-	    // .findViewById(R.id.contactlistmsgperso);
-	    // if (msgStatusText != null) {
-	    // msgStatusText.setText(msgStatus);
-	    // }
-
+	    String jid = cursor.getString(cursor.getColumnIndex(ContactsContract.RawContacts.SOURCE_ID));
 	    view.setTag(jid);
 
 	    // ImageView img = (ImageView) view.findViewById(R.id.avatar);
@@ -333,7 +352,6 @@
 	    // img.setImageDrawable(avatar);
 	    // img.setImageLevel(contactStatus);
 	}
-
 	// @Override
 	// public Filter getFilter() {
 	// return mFilter;
--- a/src/com/beem/project/beem/ui/Login.java	Sun Nov 06 21:22:00 2011 +0100
+++ b/src/com/beem/project/beem/ui/Login.java	Mon Nov 14 00:47:02 2011 +0100
@@ -72,6 +72,7 @@
 import android.widget.ListView;
 import android.widget.TextView;
 
+import com.beem.project.beem.BeemApplication;
 import com.beem.project.beem.BeemIntent;
 import com.beem.project.beem.BeemService;
 import com.beem.project.beem.R;
@@ -99,7 +100,7 @@
 	super.onCreate(savedInstanceState);
 
 	AccountManager am = AccountManager.get(Login.this);
-	Account allAccount[] = am.getAccountsByType("com.beem.project.com");
+	Account allAccount[] = am.getAccountsByType(BeemApplication.BEEM_PACKAGE);
 	for (Account account : allAccount) {
 	    mListAccount.add(account.name);
 	}
--- a/src/com/beem/project/beem/ui/wizard/AccountConfigure.java	Sun Nov 06 21:22:00 2011 +0100
+++ b/src/com/beem/project/beem/ui/wizard/AccountConfigure.java	Mon Nov 14 00:47:02 2011 +0100
@@ -158,7 +158,7 @@
 	edit.putString(BeemApplication.ACCOUNT_USERNAME_KEY, jid);
 	edit.putString(BeemApplication.ACCOUNT_PASSWORD_KEY, mAccountPassword.getText().toString());
 	edit.commit();
-	Account account = new Account(jid, "com.beem.project.com");
+	Account account = new Account(jid, BeemApplication.BEEM_PACKAGE);
 	boolean accountCreated = mAccountManager.addAccountExplicitly(account, mAccountPassword.getText().toString(),
 	    null);
 	Bundle extras = getIntent().getExtras();
@@ -168,7 +168,7 @@
 		    .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");
+		result.putString(AccountManager.KEY_ACCOUNT_TYPE, BeemApplication.BEEM_PACKAGE);
 		response.onResult(result);
 		finish();
 	    }