--- a/AndroidManifest.xml Mon Nov 21 23:50:14 2011 +0100
+++ b/AndroidManifest.xml Wed Dec 28 23:49:53 2011 +0100
@@ -188,6 +188,7 @@
<action android:name="com.beem.project.beem.intent.action.SYNC" />
<action android:name="com.beem.project.beem.intent.action.CONNECT" />
<action android:name="com.beem.project.beem.intent.action.DISCONNECT" />
+ <action android:name="com.beem.project.beem.intent.action.IS_CONNECTED" />
<action android:name="com.beem.project.beem.intent.action.SEND_MESSAGE" />
<action android:name="com.beem.project.beem.intent.action.ADD_CONTACT" />
</intent-filter>
--- a/src/com/beem/project/beem/BeemIntent.java Mon Nov 21 23:50:14 2011 +0100
+++ b/src/com/beem/project/beem/BeemIntent.java Wed Dec 28 23:49:53 2011 +0100
@@ -49,6 +49,8 @@
public static final String ACTION_CONNECT = "com.beem.project.beem.intent.action.CONNECT";
public static final String ACTION_DISCONNECT = "com.beem.project.beem.intent.action.DISCONNECT";
+
+ public static final String ACTION_ISCONNECTED = "com.beem.project.beem.intent.action.IS_CONNECTED";
public static final String ACTION_SEND_MESSAGE = "com.beem.project.beem.intent.action.SEND_MESSAGE";
--- a/src/com/beem/project/beem/BeemService.java Mon Nov 21 23:50:14 2011 +0100
+++ b/src/com/beem/project/beem/BeemService.java Wed Dec 28 23:49:53 2011 +0100
@@ -101,6 +101,7 @@
private static final String TAG = "BeemService";
private static final int MESSAGE_CONNECT = 0x1;
private static final int MESSAGE_DISCONNECT = 0x2;
+ private static final int MESSAGE_IS_CONNECTED = 0x06;
private static final int MESSAGE_SEND_MSG = 0x3;
private static final int MESSAGE_SYNC = 0x4;
private static final int MESSAGE_ADD_CONTACT = 0x5;
@@ -391,6 +392,8 @@
msg = mHandler.obtainMessage(MESSAGE_CONNECT, intent.getExtras());
} else if (BeemIntent.ACTION_DISCONNECT.equals(action)) {
msg = mHandler.obtainMessage(MESSAGE_DISCONNECT, intent.getExtras());
+ } else if (BeemIntent.ACTION_ISCONNECTED.equals(action)) {
+ msg = mHandler.obtainMessage(MESSAGE_IS_CONNECTED, intent.getExtras());
} else if (BeemIntent.ACTION_SEND_MESSAGE.equals(action)) {
msg = mHandler.obtainMessage(MESSAGE_SEND_MSG, intent.getExtras());
} else if (BeemIntent.ACTION_SYNC.equals(action)) {
@@ -420,7 +423,8 @@
connection = mConnection.get(accountName);
}
if (connection == null && msg.what != MESSAGE_CONNECT && msg.what != MESSAGE_SYNC) {
- Toast.makeText(BeemService.this, getString(R.string.BeemServiceNotConnected, accountName), Toast.LENGTH_LONG).show();
+ Toast.makeText(BeemService.this, getString(R.string.BeemServiceNotConnected, accountName),
+ Toast.LENGTH_LONG).show();
return;
}
switch (msg.what) {
@@ -430,6 +434,14 @@
case MESSAGE_DISCONNECT:
handleDisconnect(accountName);
break;
+ case MESSAGE_IS_CONNECTED:
+ Intent res = new Intent(BeemIntent.ACTION_DISCONNECTED);
+ res.putExtra(BeemIntent.EXTRA_MESSAGE, R.string.contact_status_msg_offline);
+ res.putExtra(BeemIntent.EXTRA_ACCOUNT, accountName);
+ if (mConnection.containsKey(accountName))
+ res.setAction(BeemIntent.ACTION_CONNECTED);
+ sendBroadcast(res);
+ break;
case MESSAGE_SEND_MSG:
connection.handleMessage(accountName, msg);
break;
--- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java Mon Nov 21 23:50:14 2011 +0100
+++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java Wed Dec 28 23:49:53 2011 +0100
@@ -120,7 +120,7 @@
private final RemoteCallbackList<IBeemConnectionListener> mRemoteConnListeners = new RemoteCallbackList<IBeemConnectionListener>();
private final SubscribePacketListener mSubscribePacketListener = new SubscribePacketListener();
- private final ConnexionListenerAdapter mConListener = new ConnexionListenerAdapter();
+ //private final ConnexionListenerAdapter mConListener = new ConnexionListenerAdapter();
/**
* Constructor.
@@ -190,7 +190,7 @@
else {
try {
mAdaptee.connect();
- mAdaptee.addConnectionListener(mConListener);
+ //mAdaptee.addConnectionListener(mConListener);
return true;
} catch (XMPPException e) {
Log.e(TAG, "Error while connecting", e);
--- a/src/com/beem/project/beem/ui/ContactList.java Mon Nov 21 23:50:14 2011 +0100
+++ b/src/com/beem/project/beem/ui/ContactList.java Wed Dec 28 23:49:53 2011 +0100
@@ -29,7 +29,6 @@
package com.beem.project.beem.ui;
import android.app.Activity;
-import android.content.ComponentName;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
@@ -39,7 +38,6 @@
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
-import android.preference.PreferenceManager;
import android.provider.ContactsContract;
import android.util.Log;
import android.view.ContextMenu;
@@ -53,6 +51,7 @@
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
+import android.widget.Filter;
import android.widget.Filterable;
import android.widget.Gallery;
import android.widget.ListView;
@@ -70,11 +69,6 @@
*/
public class ContactList extends Activity {
- private static final Intent SERVICE_INTENT = new Intent();
- static {
- SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
- }
-
private static final String SETTINGS_HIDDEN_CONTACT = "settings_key_hidden_contact";
private static final String TAG = "ContactList";
@@ -100,7 +94,7 @@
@Override
protected void onCreate(Bundle saveBundle) {
super.onCreate(saveBundle);
- mSettings = PreferenceManager.getDefaultSharedPreferences(this);
+
setContentView(R.layout.contactlist);
Bundle b = getIntent().getExtras();
if (b == null) {
@@ -108,6 +102,11 @@
startActivity(new Intent(ContactList.this, AccountConfigure.class));
}
mAccountName = b.getString(BeemIntent.EXTRA_ACCOUNT);
+ if (mAccountName == null) {
+ //TODO: Add toast to advice need to configure at least 1 beem account (Should not happend)
+ startActivity(new Intent(ContactList.this, AccountConfigure.class));
+ }
+ mSettings = getSharedPreferences(mAccountName, MODE_PRIVATE);
// Get Groups list
final Cursor cursorGroup = getContentResolver().query(ContactsContract.Groups.CONTENT_URI,
@@ -118,10 +117,12 @@
cursorGroup.registerContentObserver(new BeemGroupObserver(new Handler()));
// Get Contacts list
- Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon()
+ final 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);
+ Cursor cursorRawContact = getContentResolver().query(rawContactUri, null,
+ ContactsContract.RawContacts.DELETED + "= 0", 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,
@@ -131,11 +132,20 @@
listView.setOnItemClickListener(mOnContactClick);
registerForContextMenu(listView);
listView.setAdapter(mAdapterContactList);
+
+ // mAdapterContactList.setFilterQueryProvider(new FilterQueryProvider() {
+ // public Cursor runQuery(CharSequence constraint) {
+ // String s = '%' + constraint.toString() + '%';
+ // return getContentResolver().query(rawContactUri, null,
+ // ContactsContract.RawContacts.SOURCE_ID+ " LIKE ? ", new String[] { s }, null);
+ // }
+ // });
}
@Override
protected void onResume() {
super.onResume();
+ Log.e(TAG, "onResume : " + mSettings.getBoolean("settings_key_hide_groups", false));
if (!mSettings.getBoolean("settings_key_hide_groups", false))
showGroups();
else
@@ -181,7 +191,6 @@
startService(intent);
return true;
case R.id.menu_disconnect:
- stopService(SERVICE_INTENT);
return true;
default:
return false;
@@ -270,12 +279,14 @@
* Show the groups view.
*/
private void showGroups() {
+ Log.e(TAG, "SHOWGROUPS");
ViewStub stub = (ViewStub) findViewById(R.id.contactlist_stub);
if (stub != null) {
View v = stub.inflate();
Gallery g = (Gallery) v.findViewById(R.id.contactlist_banner);
g.setOnItemClickListener(new OnItemClickGroupName());
g.setAdapter(mAdapterBanner);
+ Log.e(TAG, "SHOWGROUPS" + mAdapterBanner.getCount());
if (mAdapterBanner.getCount() == 0)
v.setVisibility(View.GONE);
else
@@ -287,6 +298,7 @@
* Hide the groups view.
*/
private void hideGroups() {
+ Log.e(TAG, "hideGroups");
View v = findViewById(R.id.contactlist_groupstub);
if (v != null)
v.setVisibility(View.GONE);
@@ -299,6 +311,8 @@
private Context mContext;
private int mLayout;
+ private final ContactFilter mContactFilter = new ContactFilter();
+ private final GroupFilter mGroupFilter = new GroupFilter();
public BeemContactList(Context context, int layout, Cursor c, String[] from, int[] to) {
super(context, layout, c, from, to);
@@ -323,6 +337,7 @@
new String[] { ContactsContract.RawContacts.SOURCE_ID, ContactsContract.RawContacts.Entity.DATA_ID,
ContactsContract.RawContacts.Entity.MIMETYPE, ContactsContract.RawContacts.Entity.DATA1 }, null,
null, null);
+ Log.e(TAG, "BINDVIEW");
try {
while (cursorContact.moveToNext()) {
if (!cursorContact.isNull(1)) {
@@ -351,10 +366,14 @@
// img.setImageDrawable(avatar);
// img.setImageLevel(contactStatus);
}
- // @Override
- // public Filter getFilter() {
- // return mFilter;
- // }
+
+ public Filter getContactFilter() {
+ return mContactFilter;
+ }
+
+ public Filter getGroupFilter() {
+ return mGroupFilter;
+ }
/**
* Get a LayerDrawable containing the avatar and the status icon. The status icon will change with the level of
@@ -393,41 +412,85 @@
/**
* A Filter which select Contact to display by searching in ther Jid.
*/
- // private class ContactFilter extends Filter {
- //
- // /**
- // * Create a ContactFilter.
- // */
- // public ContactFilter() {
- // }
- //
- // @Override
- // protected Filter.FilterResults performFiltering(CharSequence
- // constraint) {
- // Log.d(TAG, "performFiltering");
- // List<Contact> result = mListContact;
- // if (constraint.length() > 0) {
- // result = new LinkedList<Contact>();
- // for (Contact c : mContactOnGroup.get(mSelectedGroup)) {
- // if (c.getJID().contains(constraint))
- // result.add(c);
- // }
- // }
- // Filter.FilterResults fr = new Filter.FilterResults();
- // fr.values = result;
- // fr.count = result.size();
- // return fr;
- // }
- //
- // @Override
- // protected void publishResults(CharSequence constraint,
- // Filter.FilterResults results) {
- // Log.d(TAG, "publishResults");
- // List<Contact> contacts = (List<Contact>) results.values;
- // mListContact = contacts;
- // notifyDataSetChanged();
- // }
- // }
+ private class ContactFilter extends Filter {
+
+ /**
+ * Create a ContactFilter.
+ */
+ public ContactFilter() {
+ }
+
+ @Override
+ protected Filter.FilterResults performFiltering(CharSequence constraint) {
+ Log.d(TAG, "performFiltering");
+ // while (mCursor.moveToNext()) {
+ //
+ // }
+ // List<Contact> result = mListContact;
+ // if (constraint.length() > 0) {
+ // result = new LinkedList<Contact>();
+ // for (Contact c : mContactOnGroup.get(mSelectedGroup)) {
+ // if (c.getJID().contains(constraint))
+ // result.add(c);
+ // }
+ // }
+ // Filter.FilterResults fr = new Filter.FilterResults();
+ // fr.values = result;
+ // fr.count = result.size();
+ // return fr;
+ return null;
+ }
+
+ @Override
+ protected void publishResults(CharSequence constraint, Filter.FilterResults results) {
+ Log.d(TAG, "publishResults");
+ // List<Contact> contacts = (List<Contact>) results.values;
+ // mListContact = contacts;
+ // notifyDataSetChanged();
+ }
+ }
+
+ /**
+ * A Filter which select Contact to display by searching in ther Jid.
+ */
+ private class GroupFilter extends Filter {
+
+ /**
+ * Create a ContactFilter.
+ */
+ public GroupFilter() {
+ }
+
+ @Override
+ protected Filter.FilterResults performFiltering(CharSequence constraint) {
+ Log.d(TAG, "performFiltering");
+
+ Cursor cursorContact = mContext.getContentResolver().query(ContactsContract.Data.CONTENT_URI,
+ new String[] { ContactsContract.Data.RAW_CONTACT_ID }, ContactsContract.Data.MIMETYPE + " =? ",
+ new String[] { ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE }, null);
+ try {
+ while (cursorContact.moveToNext()) {
+ Log.e(
+ TAG,
+ "HOW MUCH "
+ + cursorContact.getString(cursorContact
+ .getColumnIndex(ContactsContract.Data.RAW_CONTACT_ID)));
+ }
+ } finally {
+ cursorContact.close();
+ }
+
+ Filter.FilterResults fr = new Filter.FilterResults();
+ fr.values = cursorContact;
+ fr.count = cursorContact.getCount();
+ return fr;
+ }
+
+ @Override
+ protected void publishResults(CharSequence constraint, Filter.FilterResults results) {
+ Log.d(TAG, "publishResults " + results.count);
+ }
+ }
}
/**
@@ -496,8 +559,19 @@
@Override
public void onItemClick(AdapterView<?> arg0, View v, int i, long l) {
- // String group = mListGroup.get(i);
- // buildContactList(group);
+ Log.e(TAG, "ONGROUPCLICK");
+ TextView nameGroup = (TextView) v.findViewById(R.id.contactlist_group);
+ Uri groupUri = ContactsContract.Groups.CONTENT_URI.buildUpon()
+ .appendQueryParameter(ContactsContract.Groups.ACCOUNT_NAME, mAccountName)
+ .appendQueryParameter(ContactsContract.Groups.ACCOUNT_TYPE, BeemApplication.BEEM_PACKAGE)
+ .appendQueryParameter(ContactsContract.Groups.TITLE, nameGroup.toString()).build();
+ nameGroup.setTextColor(R.color.vert_manu);
+ Cursor cursorGroup = getContentResolver().query(groupUri, null, ContactsContract.Groups.DELETED + "= 0",
+ null, null);
+ if (cursorGroup.moveToFirst()) {
+ String _id = cursorGroup.getString(cursorGroup.getColumnIndex(ContactsContract.Groups._ID));
+ mAdapterContactList.getGroupFilter().filter(_id);
+ }
}
}
--- a/src/com/beem/project/beem/ui/Login.java Mon Nov 21 23:50:14 2011 +0100
+++ b/src/com/beem/project/beem/ui/Login.java Wed Dec 28 23:49:53 2011 +0100
@@ -58,6 +58,7 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@@ -220,16 +221,28 @@
if (convertView == null) {
v = mInflater.inflate(R.layout.login_row_account, null);
}
+
+ String accountName = mListAccount.get(position);
+
+ //Check if already connected
+ Intent intent = new Intent(BeemIntent.ACTION_ISCONNECTED);
+ intent.putExtra(BeemIntent.EXTRA_ACCOUNT, accountName);
+ startService(intent);
+
ImageButton logo = (ImageButton) v.findViewById(R.id.loginanim_logo_anim);
+
logo.setFocusable(false);
logo.setOnClickListener(new BeemConnectionOnClick(v));
logo.setOnLongClickListener(new BeemConnectionOnLongClick(v));
+
TextView name = (TextView) v.findViewById(R.id.accountname);
- name.setText(mListAccount.get(position));
- int hash = mListAccount.get(position).hashCode();
+ name.setText(accountName);
+
+ int hash = accountName.hashCode();
if (hash < 0)
hash = hash * -1;
v.setId(hash);
+
return v;
}