Integration nouvelle contact list.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/res/layout/contactlist.xml Wed Sep 16 21:45:38 2009 +0200
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout android:id="@+id/linlayoutBase"
+ android:layout_width="fill_parent" android:layout_height="fill_parent"
+ android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <LinearLayout android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+ <Button android:id="@+id/btn1" android:layout_width="wrap_content"
+ android:layout_height="wrap_content" android:text="Left"
+ android:layout_weight="1">
+ </Button>
+ <Button android:id="@+id/btn2" android:layout_width="wrap_content"
+ android:layout_height="wrap_content" android:text="GroupName"
+ android:layout_weight="1">
+ </Button>
+ <Button android:id="@+id/btn3" android:layout_width="wrap_content"
+ android:layout_height="wrap_content" android:text="Right"
+ android:layout_weight="1">
+ </Button>
+ </LinearLayout>
+
+ <LinearLayout android:layout_width="fill_parent"
+ android:layout_height="fill_parent" android:orientation="horizontal">
+ <ListView android:id="@+id/contactlist" android:layout_width="fill_parent"
+ android:layout_height="fill_parent" />
+ </LinearLayout>
+
+
+</LinearLayout>
--- a/res/layout/login.xml Wed Sep 16 15:38:12 2009 +0200
+++ b/res/layout/login.xml Wed Sep 16 21:45:38 2009 +0200
@@ -8,13 +8,4 @@
<TextView android:id="@+id/log_as_msg" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:gravity="center"
android:textColor="#FF0000" />
- <LinearLayout android:orientation="vertical"
- android:layout_width="fill_parent" android:layout_height="fill_parent"
- android:gravity="bottom">
- <Button android:id="@+id/log_as_settings" android:layout_width="fill_parent"
- android:layout_height="wrap_content" android:text="@string/login_settings_button" />
- <Button android:id="@+id/log_as_login" android:layout_width="fill_parent"
- android:layout_height="wrap_content" android:text="@string/login_login_button" />
- </LinearLayout>
-
</LinearLayout>
\ No newline at end of file
--- a/src/com/beem/project/beem/ui/ContactList.java Wed Sep 16 15:38:12 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java Wed Sep 16 21:45:38 2009 +0200
@@ -1,19 +1,16 @@
package com.beem.project.beem.ui;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import org.jivesoftware.smack.util.StringUtils;
-import android.app.ExpandableListActivity;
+import android.app.Activity;
import android.content.ComponentName;
+import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
-import android.database.DataSetObserver;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
@@ -26,10 +23,9 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
-import android.view.View.OnClickListener;
-import android.view.View.OnLongClickListener;
-import android.widget.ExpandableListAdapter;
+import android.widget.BaseAdapter;
import android.widget.ImageView;
+import android.widget.ListView;
import android.widget.TextView;
import com.beem.project.beem.BeemService;
@@ -44,15 +40,13 @@
/**
* The contact list activity displays the roster of the user.
*/
-public class ContactList extends ExpandableListActivity {
+public class ContactList extends Activity {
public static final String DEFAULT_GROUP = "Default";
private static final String TAG = "CONTACTLIST_ACT";
private static final int REQUEST_CODE = 1;
- private MyExpandableListAdapter mAdapter;
+ private BeemContactList mAdapter;
private IRoster mRoster;
- private Map<String, List<Contact>> mGroupMap;
- private List<String> mGroupName;
private List<Contact> mListContact;
private Handler mHandler;
private IXmppFacade mXmppFacade;
@@ -105,9 +99,9 @@
@Override
protected void onCreate(Bundle saveBundle) {
super.onCreate(saveBundle);
+ setContentView(R.layout.contactlist);
+
mHandler = new Handler();
- mGroupMap = new HashMap<String, List<Contact>>();
- mGroupName = new ArrayList<String>();
}
@Override
@@ -121,8 +115,6 @@
Log.e(TAG, "UNBINSERVICE");
super.onStop();
unbindService(mServConn);
- mGroupName.clear();
- mGroupMap.clear();
}
class ComparatorContactListByName<T> implements Comparator<T> {
@@ -147,181 +139,94 @@
private void buildContactList(List<Contact> listContact) {
mListContact = listContact;
Collections.sort(mListContact, new ComparatorContactListByStatusAndName<Contact>());
- Collections.sort(mGroupName);
- for (Contact contact : mListContact) {
- for (String group : contact.getGroups()) {
- addGroup(group);
- addContactInGroup(contact, group);
- }
- if (contact.getGroups().isEmpty()) {
- addGroup(DEFAULT_GROUP);
- addContactInGroup(contact, DEFAULT_GROUP);
- }
- }
- Collections.sort(mGroupName);
- mAdapter = new MyExpandableListAdapter();
- setListAdapter(mAdapter);
- }
+ mAdapter = new BeemContactList(this);
- protected void addGroup(String group) {
- if (!mGroupMap.containsKey(group)) {
- mGroupMap.put(group, new ArrayList<Contact>());
- mGroupName.add(group);
- }
- }
-
- protected void addContactInGroup(Contact c, String group) {
- boolean found = false;
- for (Contact tmpContact : mGroupMap.get(group)) {
- if (c.getJID().equals(tmpContact.getJID())) {
- found = true;
- break;
- }
- }
- if (!found)
- mGroupMap.get(group).add(c);
- }
-
- protected void delContactInGroup(Contact c, String group) {
- mGroupMap.get(group).remove(c);
- c.delGroup(group);
- if (mGroupMap.get(group).isEmpty()) {
- mGroupMap.remove(group);
- mGroupName.remove(group);
- }
+ ListView listView = (ListView) findViewById(R.id.contactlist);
+ listView.setAdapter(mAdapter);
}
private class BeemRosterListener extends IBeemRosterListener.Stub {
@Override
public void onEntriesAdded(List<String> addresses) throws RemoteException {
- for (String str : addresses) {
- Contact curContact = mRoster.getContact(str);
- for (String group : curContact.getGroups()) {
- addGroup(group);
- addContactInGroup(curContact, group);
- }
- }
+ /*
+ * TODO:
+ */
mHandler.post(new RunnableChange());
}
@Override
public void onEntriesDeleted(List<String> addresses) throws RemoteException {
- for (String user : addresses) {
- List<Contact> tmpListContact = mGroupMap.get(DEFAULT_GROUP);
- for (Contact contact : tmpListContact) {
- if (contact.getJID().equals(user)) {
- delContactInGroup(contact, DEFAULT_GROUP);
- break;
- }
- }
- }
+ /*
+ * TODO:
+ */
mHandler.post(new RunnableChange());
}
@Override
public void onEntriesUpdated(List<String> addresses) throws RemoteException {
- for (String str : addresses) {
- Contact curContact = mRoster.getContact(str);
- for (String group : curContact.getGroups()) {
- addGroup(group);
- addContactInGroup(curContact, group);
- }
- }
+ /*
+ * TODO:
+ */
mHandler.post(new RunnableChange());
}
@Override
public void onPresenceChanged(PresenceAdapter presence) throws RemoteException {
- for (Contact curContact : mListContact) {
- if (curContact.getJID().equals(StringUtils.parseBareAddress(presence.getFrom()))) {
- curContact.setStatus(mRoster.getPresence(StringUtils.parseBareAddress(presence.getFrom())));
- mHandler.post(new RunnableChange());
- return;
- }
- }
+ /*
+ * TODO:
+ */
}
private class RunnableChange implements Runnable {
@Override
public void run() {
- mAdapter.changed();
+ /*
+ * TODO:
+ */
}
}
@Override
public void onEntryDeleteFromGroup(String group, String jid) throws RemoteException {
- for (Contact contact : mListContact) {
- if (jid.equals(contact.getJID())) {
- delContactInGroup(contact, group);
- if (contact.getGroups().size() == 0) {
- addGroup(DEFAULT_GROUP);
- addContactInGroup(contact, DEFAULT_GROUP);
- }
- break;
- }
- }
+ /*
+ * TODO:
+ */
mHandler.post(new RunnableChange());
}
}
- private class MyExpandableListAdapter implements ExpandableListAdapter {
-
- class MyOnClickListener implements OnClickListener {
-
- private final Contact mContact;
+ private class BeemContactList extends BaseAdapter {
+ private LayoutInflater mInflater;
- /**
- * Constructor.
- */
- public MyOnClickListener(Contact contact) {
- mContact = contact;
- }
-
- @Override
- public void onClick(View v) {
- Intent i = new Intent(ContactList.this, SendIM.class);
- i.setData(mContact.toUri());
- startActivity(i);
- }
-
+ public BeemContactList(Context context) {
+ mInflater = LayoutInflater.from(context);
}
- class MyOnLongClickListener implements OnLongClickListener {
-
- private final Contact mContact;
- private final String mGroup;
-
- /**
- * Constructor.
- */
- public MyOnLongClickListener(Contact contact, String group) {
- mContact = contact;
- mGroup = group;
- }
-
- /**
- * @{inheritDoc}
- */
- @Override
- public boolean onLongClick(View v) {
- createDialog(mContact, mGroup);
- return true;
- }
- }
-
- private final List<DataSetObserver> mObservers;
-
- /**
- * Constructor.
- */
- public MyExpandableListAdapter() {
- mObservers = new ArrayList<DataSetObserver>();
+ @Override
+ public int getCount() {
+ return mListContact.size();
}
@Override
- public boolean areAllItemsEnabled() {
- return true;
+ public Object getItem(int position) {
+ return position;
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ if (convertView == null) {
+ convertView = mInflater.inflate(R.layout.contactlistcontact, null);
+ }
+
+ Contact c = mListContact.get(position);
+ bindView(convertView, c);
+ return convertView;
}
private void bindView(View view, Contact curContact) {
@@ -377,143 +282,6 @@
*/
}
}
-
- public void changed() {
- Collections.sort(mGroupName);
- for (String name : mGroupName) {
- Collections.sort(mGroupMap.get(name), new ComparatorContactListByStatusAndName<Contact>());
- }
- for (DataSetObserver obs : mObservers) {
- obs.onChanged();
- }
- }
-
- void createDialog(Contact contact, String group) {
- ContactDialog dialogContact = new ContactDialog(ContactList.this, contact, group);
- dialogContact.setOwnerActivity(ContactList.this);
- dialogContact.show();
- }
-
- @Override
- public Object getChild(int groupPosition, int childPosition) {
- try {
- return mGroupMap.get(mGroupName.get(groupPosition)).get(childPosition);
- } catch (NullPointerException e) {
- Log.e(TAG, "Child not found", e);
- return null;
- }
- }
-
- @Override
- public long getChildId(int groupPosition, int childPosition) {
- try {
- mGroupMap.get(mGroupName.get(groupPosition)).get(childPosition);
- } catch (NullPointerException e) {
- Log.e(TAG, "Child not found", e);
- return 0;
- }
- return childPosition;
- }
-
- @Override
- public int getChildrenCount(int groupPosition) {
- try {
- return mGroupMap.get(mGroupName.get(groupPosition)).size();
- } catch (NullPointerException e) {
- Log.e(TAG, "Child not found", e);
- return 0;
- }
- }
-
- @Override
- public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,
- ViewGroup parent) {
- View v;
- if (convertView == null) {
- v = LayoutInflater.from(ContactList.this).inflate(R.layout.contactlistcontact, null);
- } else {
- v = convertView;
- }
- Contact contact = mGroupMap.get(mGroupName.get(groupPosition)).get(childPosition);
- bindView(v, contact);
-
- v.setOnLongClickListener(new MyOnLongClickListener(contact, mGroupName.get(groupPosition)));
- v.setOnClickListener(new MyOnClickListener(contact));
- return v;
- }
-
- @Override
- public long getCombinedChildId(long groupId, long childId) {
- return 1000 * groupId + childId;
- }
-
- @Override
- public long getCombinedGroupId(long groupId) {
- return 1000 * groupId;
- }
-
- @Override
- public Object getGroup(int groupPosition) {
- try {
- return mGroupMap.get(mGroupName.get(groupPosition));
- } catch (NullPointerException e) {
- Log.e(TAG, "Group not found", e);
- return null;
- }
- }
-
- @Override
- public int getGroupCount() {
- return mGroupMap.size();
- }
-
- @Override
- public long getGroupId(int groupPosition) {
- return groupPosition;
- }
-
- @Override
- public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
- if (convertView == null) {
- convertView = LayoutInflater.from(ContactList.this).inflate(R.layout.contactlistgroup, null);
- }
- TextView groupTextView = (TextView) convertView.findViewById(R.id.textgroup);
- groupTextView.setText(mGroupName.get(groupPosition));
- return convertView;
- }
-
- @Override
- public boolean hasStableIds() {
- return false;
- }
-
- @Override
- public boolean isChildSelectable(int groupPosition, int childPosition) {
- return true;
- }
-
- @Override
- public boolean isEmpty() {
- return mGroupMap.isEmpty();
- }
-
- @Override
- public void onGroupCollapsed(int groupPosition) {
- }
-
- @Override
- public void onGroupExpanded(int groupPosition) {
- }
-
- @Override
- public void registerDataSetObserver(DataSetObserver observer) {
- mObservers.add(observer);
- }
-
- @Override
- public void unregisterDataSetObserver(DataSetObserver observer) {
- mObservers.remove(observer);
- }
}
/**
@@ -525,7 +293,9 @@
/**
* Constructor.
*/
- public BeemServiceConnection() { }
+ public BeemServiceConnection() {
+ }
+
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mXmppFacade = IXmppFacade.Stub.asInterface(service);
--- a/src/com/beem/project/beem/ui/Login.java Wed Sep 16 15:38:12 2009 +0200
+++ b/src/com/beem/project/beem/ui/Login.java Wed Sep 16 21:45:38 2009 +0200
@@ -13,6 +13,9 @@
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
@@ -78,24 +81,6 @@
super.onCreate(savedInstanceState);
mSettings = getSharedPreferences(getString(R.string.settings_filename), MODE_PRIVATE);
setContentView(R.layout.login);
- Button button = (Button) findViewById(R.id.log_as_settings);
- button.setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View v) {
- startActivity(new Intent(Login.this, EditSettings.class));
- }
-
- });
- mButtonLogin = (Button) findViewById(R.id.log_as_login);
- mButtonLogin.setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View v) {
- bindService(Login.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
- }
-
- });
mProgressDialog = new ProgressDialog(this);
}
@@ -113,7 +98,6 @@
@Override
public void onStart() {
super.onStart();
- Log.e("LOGIN", "BINDSERVICE");
mIsConfigured = mSettings.getBoolean(getString(R.string.PreferenceIsConfigured), false);
if (mIsConfigured)
@@ -122,6 +106,37 @@
mButtonLogin.setEnabled(false);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ super.onCreateOptionsMenu(menu);
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.login, menu);
+ return true;
+ }
+
+
+ /**
+ * Callback for menu item selected.
+ * @param item the item selected
+ * @return true on success, false otherwise
+ */
+ @Override
+ public final boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.login_menu_settings:
+ startActivity(new Intent(Login.this, EditSettings.class));
+ return true;
+ case R.id.login_menu_about:
+ createAboutDialog();
+ return true;
+ default:
+ return false;
+ }
+ }
/**
* Listener use to check the state of the connection with the server.