# HG changeset patch # User "Vincent Veronis" # Date 1318891066 -7200 # Node ID dfbc48b4eae167e2fb8b9897e59c4914a24d8883 # Parent c067ee9a604c19090b9698b4bd911e5321780544 Correction bug cursor adapter when groups are empty. Between service - ui : Send now String accountName instead of Account account. ContactList can sync manual in the menu diff -r c067ee9a604c -r dfbc48b4eae1 res/drawable-hdpi/ic_menu_changestatus.png Binary file res/drawable-hdpi/ic_menu_changestatus.png has changed diff -r c067ee9a604c -r dfbc48b4eae1 res/drawable-hdpi/ic_menu_sync.png Binary file res/drawable-hdpi/ic_menu_sync.png has changed diff -r c067ee9a604c -r dfbc48b4eae1 res/drawable-ldpi/ic_menu_changestatus.png Binary file res/drawable-ldpi/ic_menu_changestatus.png has changed diff -r c067ee9a604c -r dfbc48b4eae1 res/drawable-ldpi/ic_menu_sync.png Binary file res/drawable-ldpi/ic_menu_sync.png has changed diff -r c067ee9a604c -r dfbc48b4eae1 res/drawable-mdpi/ic_menu_changestatus.png Binary file res/drawable-mdpi/ic_menu_changestatus.png has changed diff -r c067ee9a604c -r dfbc48b4eae1 res/drawable-mdpi/ic_menu_sync.png Binary file res/drawable-mdpi/ic_menu_sync.png has changed diff -r c067ee9a604c -r dfbc48b4eae1 res/drawable/ic_menu_changestatus.png Binary file res/drawable/ic_menu_changestatus.png has changed diff -r c067ee9a604c -r dfbc48b4eae1 res/menu/contact_list.xml --- a/res/menu/contact_list.xml Fri Oct 14 18:57:07 2011 +0200 +++ b/res/menu/contact_list.xml Tue Oct 18 00:37:46 2011 +0200 @@ -1,20 +1,32 @@ - - - - + + - + - + \ No newline at end of file diff -r c067ee9a604c -r dfbc48b4eae1 res/menu/contactlist_context.xml --- a/res/menu/contactlist_context.xml Fri Oct 14 18:57:07 2011 +0200 +++ b/res/menu/contactlist_context.xml Tue Oct 18 00:37:46 2011 +0200 @@ -1,24 +1,34 @@ - - - + - - - - - + - + \ No newline at end of file diff -r c067ee9a604c -r dfbc48b4eae1 res/values-fr/strings.xml --- a/res/values-fr/strings.xml Fri Oct 14 18:57:07 2011 +0200 +++ b/res/values-fr/strings.xml Tue Oct 18 00:37:46 2011 +0200 @@ -252,6 +252,7 @@ Ajouter un contact Changer son status Paramètres + Sync Se déconnecter Tous les contacts Aucun groupe diff -r c067ee9a604c -r dfbc48b4eae1 res/values/strings.xml --- a/res/values/strings.xml Fri Oct 14 18:57:07 2011 +0200 +++ b/res/values/strings.xml Tue Oct 18 00:37:46 2011 +0200 @@ -241,6 +241,7 @@ Add a contact Change status Settings + Sync Disconnect All contacts No group diff -r c067ee9a604c -r dfbc48b4eae1 src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Fri Oct 14 18:57:07 2011 +0200 +++ b/src/com/beem/project/beem/BeemService.java Tue Oct 18 00:37:46 2011 +0200 @@ -47,8 +47,8 @@ import java.util.Map; import org.jivesoftware.smack.Roster; +import org.jivesoftware.smack.Roster.SubscriptionMode; import org.jivesoftware.smack.XMPPConnection; -import org.jivesoftware.smack.Roster.SubscriptionMode; import org.jivesoftware.smack.provider.ProviderManager; import org.jivesoftware.smackx.packet.ChatStateExtension; import org.jivesoftware.smackx.provider.DelayInfoProvider; @@ -64,7 +64,6 @@ import android.app.NotificationManager; import android.app.Service; import android.content.BroadcastReceiver; -import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; @@ -97,435 +96,427 @@ */ public class BeemService extends Service { - /** The id to use for status notification. */ - public static final int NOTIFICATION_STATUS_ID = 100; + /** The id to use for status notification. */ + public static final int NOTIFICATION_STATUS_ID = 100; + + 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_SEND_MSG = 0x3; + private static final int MESSAGE_SYNC = 0x4; + + private NotificationManager mNotificationManager; + private Map mConnection = new HashMap(); + private Map mBeemConnection = new HashMap(); + private Map mBind = new HashMap(); + + private boolean mOnOffReceiverIsRegistered; + private Handler mHandler; + private Looper mServiceLooper; + private BeemBroadcastReceiver mReceiver = new BeemBroadcastReceiver(); + private BeemServicePreferenceListener mPreferenceListener = new BeemServicePreferenceListener(); + private BeemServiceBroadcastReceiver mOnOffReceiver = new BeemServiceBroadcastReceiver(); + + /** + * Constructor. + */ + public BeemService() { + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + if (intent != null) { + handleIntent(intent); + } + return Service.START_STICKY; + } + + /** + * {@inheritDoc} + */ + @Override + public IBinder onBind(Intent intent) { + Log.d(TAG, "ONBIND()"); + return null;//(IBinder) mBind.get(accountName); + } + + @Override + public boolean onUnbind(Intent intent) { + Log.d(TAG, "ONUNBIND()"); + boolean isConnected = true; + for (XmppConnectionAdapter connection : mConnection.values()) { + if (!connection.getAdaptee().isConnected()) + isConnected = false; + } + if (!isConnected) { + this.stopSelf(); + } + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public void onCreate() { + super.onCreate(); - 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_SEND_MSG = 0x3; - private static final int MESSAGE_SYNC = 0x4; + HandlerThread thread = new HandlerThread("BeemServiceThread"); + thread.start(); + mServiceLooper = thread.getLooper(); + mHandler = new BeemServiceHandler(mServiceLooper); + registerReceiver(mReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); + configure(ProviderManager.getInstance()); + mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + Roster.setDefaultSubscriptionMode(SubscriptionMode.manual); + Log.d(TAG, "ONCREATE"); + } + + /** + * {@inheritDoc} + */ + @Override + public void onDestroy() { + super.onDestroy(); + mNotificationManager.cancelAll(); + unregisterReceiver(mReceiver); + + if (mOnOffReceiverIsRegistered) + unregisterReceiver(mOnOffReceiver); + for (XmppConnectionAdapter connection : mConnection.values()) { + if (connection.isAuthentificated() && BeemConnectivity.isConnected(this)) + connection.disconnect(); + } + Log.d(TAG, "ONDESTROY"); + } + + public XmppConnectionAdapter getConnection(String accountName) { + return mConnection.get(accountName); + } + + /** + * Show a notification using the preference of the user. + * @param id the id of the notification. + * @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); + } + + /** + * Delete a notification. + * @param id the id of the notification + */ + public void deleteNotification(int id) { + mNotificationManager.cancel(id); + } + + /** + * Reset the status to online after a disconnect. + */ + public void resetStatus() { + for (BeemConnection beemco : mBeemConnection.values()) { + Editor edit = beemco.getSettings().edit(); + edit.putInt(BeemApplication.STATUS_KEY, 1); + edit.commit(); + } + + } + + /** + * Initialize Jingle from an XmppConnectionAdapter. + * @param adaptee XmppConnection used for jingle. + */ + public void initJingle(XMPPConnection adaptee) { + } - private NotificationManager mNotificationManager; - private Map mConnection = new HashMap(); - private Map mBeemConnection = new HashMap(); - private Map mBind = new HashMap(); + /** + * Return a bind to an XmppFacade instance. + * @return IXmppFacade a bind to an XmppFacade instance + */ + public IXmppFacade getBind() { + //TODO: ?? Never bind to the service ?? + return null; + } + + /** + * Get the preference of the service. + * @return the preference + */ + public SharedPreferences getServicePreference(String accountName) { + Log.e(TAG, "Account name:" + accountName); + return mBeemConnection.get(accountName).getSettings(); + } + + /** + * Get the notification manager system service. + * @return the notification manager service. + */ + public NotificationManager getNotificationManager() { + return mNotificationManager; + } + + /** + * A sort of patch from this thread: http://www.igniterealtime.org/community/thread/31118. Avoid ClassCastException + * by bypassing the classloading shit of Smack. + * @param pm The ProviderManager. + */ + private void configure(ProviderManager pm) { + Log.d(TAG, "configure"); + // Service Discovery # Items + pm.addIQProvider("query", "http://jabber.org/protocol/disco#items", new DiscoverItemsProvider()); + // Service Discovery # Info + pm.addIQProvider("query", "http://jabber.org/protocol/disco#info", new DiscoverInfoProvider()); + + // Privacy + //pm.addIQProvider("query", "jabber:iq:privacy", new PrivacyProvider()); + // Delayed Delivery only the new version + pm.addExtensionProvider("delay", "urn:xmpp:delay", new DelayInfoProvider()); + + // Service Discovery # Items + pm.addIQProvider("query", "http://jabber.org/protocol/disco#items", new DiscoverItemsProvider()); + // Service Discovery # Info + pm.addIQProvider("query", "http://jabber.org/protocol/disco#info", new DiscoverInfoProvider()); + + // Chat State + ChatStateExtension.Provider chatState = new ChatStateExtension.Provider(); + pm.addExtensionProvider("active", "http://jabber.org/protocol/chatstates", chatState); + pm.addExtensionProvider("composing", "http://jabber.org/protocol/chatstates", chatState); + pm.addExtensionProvider("paused", "http://jabber.org/protocol/chatstates", chatState); + pm.addExtensionProvider("inactive", "http://jabber.org/protocol/chatstates", chatState); + pm.addExtensionProvider("gone", "http://jabber.org/protocol/chatstates", chatState); + // capabilities + pm.addExtensionProvider("c", "http://jabber.org/protocol/caps", new CapsProvider()); + //Pubsub + pm.addIQProvider("pubsub", "http://jabber.org/protocol/pubsub", new PubSubProvider()); + pm.addExtensionProvider("items", "http://jabber.org/protocol/pubsub", new ItemsProvider()); + pm.addExtensionProvider("items", "http://jabber.org/protocol/pubsub", new ItemsProvider()); + pm.addExtensionProvider("item", "http://jabber.org/protocol/pubsub", new ItemProvider()); + + pm.addExtensionProvider("items", "http://jabber.org/protocol/pubsub#event", new ItemsProvider()); + pm.addExtensionProvider("item", "http://jabber.org/protocol/pubsub#event", new ItemProvider()); + pm.addExtensionProvider("event", "http://jabber.org/protocol/pubsub#event", new EventProvider()); + //TODO rajouter les manquants pour du full pubsub + + //PEP avatar + pm.addExtensionProvider("metadata", "urn:xmpp:avatar:metadata", new AvatarMetadataProvider()); + pm.addExtensionProvider("data", "urn:xmpp:avatar:data", new AvatarProvider()); - private boolean mOnOffReceiverIsRegistered; - private Handler mHandler; - private Looper mServiceLooper; - private BeemBroadcastReceiver mReceiver = new BeemBroadcastReceiver(); - private BeemServicePreferenceListener mPreferenceListener = new BeemServicePreferenceListener(); - private BeemServiceBroadcastReceiver mOnOffReceiver = new BeemServiceBroadcastReceiver(); + // PEPProvider pep = new PEPProvider(); + // AvatarMetadataProvider avaMeta = new AvatarMetadataProvider(); + // pep.registerPEPParserExtension("urn:xmpp:avatar:metadata", avaMeta); + // pm.addExtensionProvider("event", "http://jabber.org/protocol/pubsub#event", pep); + + /* + * // Private Data Storage pm.addIQProvider("query", "jabber:iq:private", new + * PrivateDataManager.PrivateDataIQProvider()); // Time try { pm.addIQProvider("query", "jabber:iq:time", + * Class.forName("org.jivesoftware.smackx.packet.Time")); } catch (ClassNotFoundException e) { + * Log.w("TestClient", "Can't load class for org.jivesoftware.smackx.packet.Time"); } // Roster Exchange + * pm.addExtensionProvider("x", "jabber:x:roster", new RosterExchangeProvider()); // Message Events + * pm.addExtensionProvider("x", "jabber:x:event", new MessageEventProvider()); // XHTML + * pm.addExtensionProvider("html", "http://jabber.org/protocol/xhtml-im", new XHTMLExtensionProvider()); // + * Group Chat Invitations pm.addExtensionProvider("x", "jabber:x:conference", new + * GroupChatInvitation.Provider()); // Data Forms pm.addExtensionProvider("x", "jabber:x:data", new + * DataFormProvider()); // MUC User pm.addExtensionProvider("x", "http://jabber.org/protocol/muc#user", new + * MUCUserProvider()); // MUC Admin pm.addIQProvider("query", "http://jabber.org/protocol/muc#admin", new + * MUCAdminProvider()); // MUC Owner pm.addIQProvider("query", "http://jabber.org/protocol/muc#owner", new + * MUCOwnerProvider()); // Version try { pm.addIQProvider("query", "jabber:iq:version", + * Class.forName("org.jivesoftware.smackx.packet.Version")); } catch (ClassNotFoundException e) { // Not sure + * what's happening here. Log.w("TestClient", "Can't load class for org.jivesoftware.smackx.packet.Version"); } + * // VCard pm.addIQProvider("vCard", "vcard-temp", new VCardProvider()); // Offline Message Requests + * pm.addIQProvider("offline", "http://jabber.org/protocol/offline", new OfflineMessageRequest.Provider()); // + * Offline Message Indicator pm.addExtensionProvider("offline", "http://jabber.org/protocol/offline", new + * OfflineMessageInfo.Provider()); // Last Activity pm.addIQProvider("query", "jabber:iq:last", new + * LastActivity.Provider()); // User Search pm.addIQProvider("query", "jabber:iq:search", new + * UserSearch.Provider()); // SharedGroupsInfo pm.addIQProvider("sharedgroup", + * "http://www.jivesoftware.org/protocol/sharedgroup", new SharedGroupsInfo.Provider()); // JEP-33: Extended + * Stanza Addressing pm.addExtensionProvider("addresses", "http://jabber.org/protocol/address", new + * MultipleAddressesProvider()); // FileTransfer pm.addIQProvider("si", "http://jabber.org/protocol/si", new + * StreamInitiationProvider()); pm.addIQProvider("query", "http://jabber.org/protocol/bytestreams", new + * BytestreamsProvider()); pm.addIQProvider("open", "http://jabber.org/protocol/ibb", new IBBProviders.Open()); + * pm.addIQProvider("close", "http://jabber.org/protocol/ibb", new IBBProviders.Close()); + * pm.addExtensionProvider("data", "http://jabber.org/protocol/ibb", new IBBProviders.Data()); + * pm.addIQProvider("command", COMMAND_NAMESPACE, new AdHocCommandDataProvider()); + * pm.addExtensionProvider("malformed-action", COMMAND_NAMESPACE, new + * AdHocCommandDataProvider.MalformedActionError()); pm.addExtensionProvider("bad-locale", COMMAND_NAMESPACE, + * new AdHocCommandDataProvider.BadLocaleError()); pm.addExtensionProvider("bad-payload", COMMAND_NAMESPACE, new + * AdHocCommandDataProvider.BadPayloadError()); pm.addExtensionProvider("bad-sessionid", COMMAND_NAMESPACE, new + * AdHocCommandDataProvider.BadSessionIDError()); pm.addExtensionProvider("session-expired", COMMAND_NAMESPACE, + * new AdHocCommandDataProvider.SessionExpiredError()); + */ + } + + /** + * Listen on preference changes. + */ + public class BeemServicePreferenceListener implements SharedPreferences.OnSharedPreferenceChangeListener { + + /** + * ctor. + */ + public BeemServicePreferenceListener() { + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + if ("settings_away_chk".equals(key)) { + if (sharedPreferences.getBoolean("settings_away_chk", false)) { + mOnOffReceiverIsRegistered = true; + registerReceiver(mOnOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF)); + registerReceiver(mOnOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_ON)); + } else { + mOnOffReceiverIsRegistered = false; + unregisterReceiver(mOnOffReceiver); + } + } + } + } + + /** + * Listen on some Intent broadcast, ScreenOn and ScreenOff. + */ + private class BeemServiceBroadcastReceiver extends BroadcastReceiver { + + private String mOldStatus; + private int mOldMode; /** * Constructor. */ - public BeemService() { + public BeemServiceBroadcastReceiver() { } @Override - public int onStartCommand(Intent intent, int flags, int startId) { - if (intent != null) { - handleIntent(intent); + public void onReceive(final Context context, final Intent intent) { + String intentAction = intent.getAction(); + if (intentAction.equals(Intent.ACTION_SCREEN_OFF)) { + for (Map.Entry item : mConnection.entrySet()) { + XmppConnectionAdapter connection = item.getValue(); + mOldMode = connection.getPreviousMode(); + mOldStatus = connection.getPreviousStatus(); + if (connection.isAuthentificated()) + connection.changeStatus(Status.CONTACT_STATUS_AWAY, mBeemConnection.get(item.getKey()) + .getSettings().getString("settings_away_message", "Away")); } - return Service.START_STICKY; + } else if (intentAction.equals(Intent.ACTION_SCREEN_ON)) { + for (XmppConnectionAdapter connection : mConnection.values()) { + if (connection.isAuthentificated()) + connection.changeStatus(mOldMode, mOldStatus); + } + } } + } - /** - * {@inheritDoc} - */ - @Override - public IBinder onBind(Intent intent) { - Log.d(TAG, "ONBIND()"); - return null;//(IBinder) mBind.get(accountName); + private void handleIntent(Intent intent) { + Message msg = null; + String action = intent.getAction(); + if (BeemIntent.ACTION_CONNECT.equals(action)) { + 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_SEND_MESSAGE.equals(action)) { + msg = mHandler.obtainMessage(MESSAGE_SEND_MSG, intent.getExtras()); + } else if (BeemIntent.ACTION_SYNC.equals(action)) { + msg = mHandler.obtainMessage(MESSAGE_SYNC, intent.getExtras()); + } else { + Log.w(TAG, "Unknown intent " + intent); + } + if (msg != null) + mHandler.sendMessage(msg); + } + + private class BeemServiceHandler extends Handler { + + public BeemServiceHandler(Looper looper) { + super(looper); } @Override - public boolean onUnbind(Intent intent) { - Log.d(TAG, "ONUNBIND()"); - boolean isConnected = true; - for (XmppConnectionAdapter connection : mConnection.values()) { - if (!connection.getAdaptee().isConnected()) - isConnected = false; - } - if (!isConnected) { - this.stopSelf(); - } - return true; + public void handleMessage(Message msg) { + Bundle b = (Bundle) msg.obj; + switch (msg.what) { + case MESSAGE_CONNECT: + handleConnect(b.getString(BeemIntent.EXTRA_ACCOUNT)); + break; + case MESSAGE_DISCONNECT: + handleDisconnect(b); + break; + case MESSAGE_SEND_MSG: + String account = b.getString(BeemIntent.EXTRA_ACCOUNT); + XmppConnectionAdapter con = mConnection.get(account); + if (con != null) { + con.handleMessage(msg); + } + break; + case MESSAGE_SYNC: + String accountName = b.getString(BeemIntent.EXTRA_ACCOUNT); + //TODO: Connect with option to not show status + handleConnect(accountName); + XmppConnectionAdapter co = mConnection.get(accountName); + if (co != null) { + BeemSync sync = new BeemSync(getBaseContext()); + if (co.getAdaptee() != null) + sync.manageRoster(co.getAdaptee().getRoster(), accountName); + } + break; + default: + Log.w(TAG, "Unknown message " + msg); + } } - - /** - * {@inheritDoc} - */ - @Override - public void onCreate() { - super.onCreate(); - - HandlerThread thread = new HandlerThread("BeemServiceThread"); - thread.start(); - mServiceLooper = thread.getLooper(); - mHandler = new BeemServiceHandler(mServiceLooper); - registerReceiver(mReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); - configure(ProviderManager.getInstance()); - mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - Roster.setDefaultSubscriptionMode(SubscriptionMode.manual); - Log.d(TAG, "ONCREATE"); - } - - /** - * {@inheritDoc} - */ - @Override - public void onDestroy() { - super.onDestroy(); - mNotificationManager.cancelAll(); - unregisterReceiver(mReceiver); + } - if (mOnOffReceiverIsRegistered) - unregisterReceiver(mOnOffReceiver); - for (XmppConnectionAdapter connection : mConnection.values()) { - if (connection.isAuthentificated() && BeemConnectivity.isConnected(this)) - connection.disconnect(); - } - Log.d(TAG, "ONDESTROY"); - } - - public XmppConnectionAdapter getConnection(String accountName) { - return mConnection.get(accountName); - } + private void handleConnect(String accountName) { + Intent res = new Intent(BeemIntent.ACTION_DISCONNECTED); + res.putExtra(BeemIntent.EXTRA_MESSAGE, R.string.contact_status_msg_offline); + res.putExtra(BeemIntent.EXTRA_ACCOUNT, accountName); - /** - * Show a notification using the preference of the user. - * @param id the id of the notification. - * @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 (mConnection.containsKey(accountName)) { + res.setAction(BeemIntent.ACTION_CONNECTED); + } else { + if (accountName == null) { + //connect all + } else { + BeemConnection beemco = new BeemConnection(BeemService.this.getSharedPreferences(accountName, + MODE_PRIVATE), mPreferenceListener); + if (beemco.getSettings().getBoolean("settings_away_chk", false)) { + mOnOffReceiverIsRegistered = true; + registerReceiver(mOnOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF)); + registerReceiver(mOnOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_ON)); + } + mBeemConnection.put(accountName, beemco); + XmppConnectionAdapter beemcoAdapter = new XmppConnectionAdapter(beemco.getConnectionConfiguration(), + beemco.getJid(), beemco.getPassword(), this); - /** - * Delete a notification. - * @param id the id of the notification - */ - public void deleteNotification(int id) { - mNotificationManager.cancel(id); - } - - /** - * Reset the status to online after a disconnect. - */ - public void resetStatus() { - for (BeemConnection beemco : mBeemConnection.values()) { - Editor edit = beemco.getSettings().edit(); - edit.putInt(BeemApplication.STATUS_KEY, 1); - edit.commit(); + try { + Log.i(TAG, "Starting connection of " + accountName); + if (beemcoAdapter.connectSync()) { + mConnection.put(accountName, beemcoAdapter); + mBind.put(accountName, new XmppFacade(beemcoAdapter)); + res.setAction(BeemIntent.ACTION_CONNECTED); + Log.e(TAG, "Account configuration : " + accountName + " DONE"); + } else { + Log.w(TAG, "Unable to connect " + accountName); + res.putExtra(BeemIntent.EXTRA_MESSAGE, beemcoAdapter.getErrorMessage()); + } + } catch (RemoteException e) { + res.putExtra(BeemIntent.EXTRA_MESSAGE, beemcoAdapter.getErrorMessage()); + Log.e(TAG, "Unable to connect " + accountName, e); } - } - - /** - * Initialize Jingle from an XmppConnectionAdapter. - * @param adaptee XmppConnection used for jingle. - */ - public void initJingle(XMPPConnection adaptee) { - } - - /** - * Return a bind to an XmppFacade instance. - * @return IXmppFacade a bind to an XmppFacade instance - */ - public IXmppFacade getBind() { - //TODO: Prendre le bon mbind dans le tableau - return mBind.get(0); - } - - /** - * Get the preference of the service. - * @return the preference - */ - public SharedPreferences getServicePreference(String accountName) { - Log.e(TAG, "Account name:" + accountName); - return mBeemConnection.get(accountName).getSettings(); - } - - /** - * Get the notification manager system service. - * @return the notification manager service. - */ - public NotificationManager getNotificationManager() { - return mNotificationManager; + } } - - /** - * A sort of patch from this thread: http://www.igniterealtime.org/community/thread/31118. Avoid ClassCastException - * by bypassing the classloading shit of Smack. - * @param pm The ProviderManager. - */ - private void configure(ProviderManager pm) { - Log.d(TAG, "configure"); - // Service Discovery # Items - pm.addIQProvider("query", "http://jabber.org/protocol/disco#items", new DiscoverItemsProvider()); - // Service Discovery # Info - pm.addIQProvider("query", "http://jabber.org/protocol/disco#info", new DiscoverInfoProvider()); - - // Privacy - //pm.addIQProvider("query", "jabber:iq:privacy", new PrivacyProvider()); - // Delayed Delivery only the new version - pm.addExtensionProvider("delay", "urn:xmpp:delay", new DelayInfoProvider()); - - // Service Discovery # Items - pm.addIQProvider("query", "http://jabber.org/protocol/disco#items", new DiscoverItemsProvider()); - // Service Discovery # Info - pm.addIQProvider("query", "http://jabber.org/protocol/disco#info", new DiscoverInfoProvider()); - - // Chat State - ChatStateExtension.Provider chatState = new ChatStateExtension.Provider(); - pm.addExtensionProvider("active", "http://jabber.org/protocol/chatstates", chatState); - pm.addExtensionProvider("composing", "http://jabber.org/protocol/chatstates", chatState); - pm.addExtensionProvider("paused", "http://jabber.org/protocol/chatstates", chatState); - pm.addExtensionProvider("inactive", "http://jabber.org/protocol/chatstates", chatState); - pm.addExtensionProvider("gone", "http://jabber.org/protocol/chatstates", chatState); - // capabilities - pm.addExtensionProvider("c", "http://jabber.org/protocol/caps", new CapsProvider()); - //Pubsub - pm.addIQProvider("pubsub", "http://jabber.org/protocol/pubsub", new PubSubProvider()); - pm.addExtensionProvider("items", "http://jabber.org/protocol/pubsub", new ItemsProvider()); - pm.addExtensionProvider("items", "http://jabber.org/protocol/pubsub", new ItemsProvider()); - pm.addExtensionProvider("item", "http://jabber.org/protocol/pubsub", new ItemProvider()); - - pm.addExtensionProvider("items", "http://jabber.org/protocol/pubsub#event", new ItemsProvider()); - pm.addExtensionProvider("item", "http://jabber.org/protocol/pubsub#event", new ItemProvider()); - pm.addExtensionProvider("event", "http://jabber.org/protocol/pubsub#event", new EventProvider()); - //TODO rajouter les manquants pour du full pubsub - - //PEP avatar - pm.addExtensionProvider("metadata", "urn:xmpp:avatar:metadata", new AvatarMetadataProvider()); - pm.addExtensionProvider("data", "urn:xmpp:avatar:data", new AvatarProvider()); - - // PEPProvider pep = new PEPProvider(); - // AvatarMetadataProvider avaMeta = new AvatarMetadataProvider(); - // pep.registerPEPParserExtension("urn:xmpp:avatar:metadata", avaMeta); - // pm.addExtensionProvider("event", "http://jabber.org/protocol/pubsub#event", pep); - - /* - * // Private Data Storage pm.addIQProvider("query", "jabber:iq:private", new - * PrivateDataManager.PrivateDataIQProvider()); // Time try { pm.addIQProvider("query", "jabber:iq:time", - * Class.forName("org.jivesoftware.smackx.packet.Time")); } catch (ClassNotFoundException e) { - * Log.w("TestClient", "Can't load class for org.jivesoftware.smackx.packet.Time"); } // Roster Exchange - * pm.addExtensionProvider("x", "jabber:x:roster", new RosterExchangeProvider()); // Message Events - * pm.addExtensionProvider("x", "jabber:x:event", new MessageEventProvider()); // XHTML - * pm.addExtensionProvider("html", "http://jabber.org/protocol/xhtml-im", new XHTMLExtensionProvider()); // - * Group Chat Invitations pm.addExtensionProvider("x", "jabber:x:conference", new - * GroupChatInvitation.Provider()); // Data Forms pm.addExtensionProvider("x", "jabber:x:data", new - * DataFormProvider()); // MUC User pm.addExtensionProvider("x", "http://jabber.org/protocol/muc#user", new - * MUCUserProvider()); // MUC Admin pm.addIQProvider("query", "http://jabber.org/protocol/muc#admin", new - * MUCAdminProvider()); // MUC Owner pm.addIQProvider("query", "http://jabber.org/protocol/muc#owner", new - * MUCOwnerProvider()); // Version try { pm.addIQProvider("query", "jabber:iq:version", - * Class.forName("org.jivesoftware.smackx.packet.Version")); } catch (ClassNotFoundException e) { // Not sure - * what's happening here. Log.w("TestClient", "Can't load class for org.jivesoftware.smackx.packet.Version"); } - * // VCard pm.addIQProvider("vCard", "vcard-temp", new VCardProvider()); // Offline Message Requests - * pm.addIQProvider("offline", "http://jabber.org/protocol/offline", new OfflineMessageRequest.Provider()); // - * Offline Message Indicator pm.addExtensionProvider("offline", "http://jabber.org/protocol/offline", new - * OfflineMessageInfo.Provider()); // Last Activity pm.addIQProvider("query", "jabber:iq:last", new - * LastActivity.Provider()); // User Search pm.addIQProvider("query", "jabber:iq:search", new - * UserSearch.Provider()); // SharedGroupsInfo pm.addIQProvider("sharedgroup", - * "http://www.jivesoftware.org/protocol/sharedgroup", new SharedGroupsInfo.Provider()); // JEP-33: Extended - * Stanza Addressing pm.addExtensionProvider("addresses", "http://jabber.org/protocol/address", new - * MultipleAddressesProvider()); // FileTransfer pm.addIQProvider("si", "http://jabber.org/protocol/si", new - * StreamInitiationProvider()); pm.addIQProvider("query", "http://jabber.org/protocol/bytestreams", new - * BytestreamsProvider()); pm.addIQProvider("open", "http://jabber.org/protocol/ibb", new IBBProviders.Open()); - * pm.addIQProvider("close", "http://jabber.org/protocol/ibb", new IBBProviders.Close()); - * pm.addExtensionProvider("data", "http://jabber.org/protocol/ibb", new IBBProviders.Data()); - * pm.addIQProvider("command", COMMAND_NAMESPACE, new AdHocCommandDataProvider()); - * pm.addExtensionProvider("malformed-action", COMMAND_NAMESPACE, new - * AdHocCommandDataProvider.MalformedActionError()); pm.addExtensionProvider("bad-locale", COMMAND_NAMESPACE, - * new AdHocCommandDataProvider.BadLocaleError()); pm.addExtensionProvider("bad-payload", COMMAND_NAMESPACE, new - * AdHocCommandDataProvider.BadPayloadError()); pm.addExtensionProvider("bad-sessionid", COMMAND_NAMESPACE, new - * AdHocCommandDataProvider.BadSessionIDError()); pm.addExtensionProvider("session-expired", COMMAND_NAMESPACE, - * new AdHocCommandDataProvider.SessionExpiredError()); - */ - } - - /** - * Listen on preference changes. - */ - public class BeemServicePreferenceListener implements SharedPreferences.OnSharedPreferenceChangeListener { - - /** - * ctor. - */ - public BeemServicePreferenceListener() { - } - - @Override - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - if ("settings_away_chk".equals(key)) { - if (sharedPreferences.getBoolean("settings_away_chk", false)) { - mOnOffReceiverIsRegistered = true; - registerReceiver(mOnOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF)); - registerReceiver(mOnOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_ON)); - } else { - mOnOffReceiverIsRegistered = false; - unregisterReceiver(mOnOffReceiver); - } - } - } - } + sendBroadcast(res); + } - /** - * Listen on some Intent broadcast, ScreenOn and ScreenOff. - */ - private class BeemServiceBroadcastReceiver extends BroadcastReceiver { - - private String mOldStatus; - private int mOldMode; - - /** - * Constructor. - */ - public BeemServiceBroadcastReceiver() { - } - - @Override - public void onReceive(final Context context, final Intent intent) { - String intentAction = intent.getAction(); - if (intentAction.equals(Intent.ACTION_SCREEN_OFF)) { - for (Map.Entry item : mConnection.entrySet()) { - XmppConnectionAdapter connection = item.getValue(); - mOldMode = connection.getPreviousMode(); - mOldStatus = connection.getPreviousStatus(); - if (connection.isAuthentificated()) - connection.changeStatus(Status.CONTACT_STATUS_AWAY, mBeemConnection.get(item.getKey()) - .getSettings().getString("settings_away_message", "Away")); - } - } else if (intentAction.equals(Intent.ACTION_SCREEN_ON)) { - for (XmppConnectionAdapter connection : mConnection.values()) { - if (connection.isAuthentificated()) - connection.changeStatus(mOldMode, mOldStatus); - } - } - } - } - - private void handleIntent(Intent intent) { - Message msg = null; - String action = intent.getAction(); - if (BeemIntent.ACTION_CONNECT.equals(action)) { - 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_SEND_MESSAGE.equals(action)) { - msg = mHandler.obtainMessage(MESSAGE_SEND_MSG, intent.getExtras()); - } else if (BeemIntent.ACTION_SYNC.equals(action)) { - msg = mHandler.obtainMessage(MESSAGE_SYNC, intent.getExtras()); - } else { - Log.w(TAG, "Unknown intent " + intent); - } - if (msg != null) - mHandler.sendMessage(msg); - } - - private class BeemServiceHandler extends Handler { - - public BeemServiceHandler(Looper looper) { - super(looper); - } - - @Override - public void handleMessage(Message msg) { - Bundle b = (Bundle) msg.obj; - switch (msg.what) { - case MESSAGE_CONNECT: - handleConnect(b); - break; - case MESSAGE_DISCONNECT: - handleDisconnect(b); - break; - case MESSAGE_SEND_MSG: - String account = b.getString(BeemIntent.EXTRA_ACCOUNT); - XmppConnectionAdapter con = mConnection.get(account); - if (con != null) { - con.handleMessage(msg); - } - break; - case MESSAGE_SYNC: - Account a = b.getParcelable(BeemIntent.EXTRA_ACCOUNT); - Bundle accountName = new Bundle(); - accountName.putString(BeemIntent.EXTRA_ACCOUNT, a.name); - //TODO: Connect with option to not show status - handleConnect(accountName); - XmppConnectionAdapter co = mConnection.get(a.name); - if (co != null) { - BeemSync sync = new BeemSync(getBaseContext()); - if (co.getAdaptee() != null) - sync.manageRoster(co.getAdaptee().getRoster(), a); - } - break; - default: - Log.w(TAG, "Unknown message " + msg); - } - } - } - - private void handleConnect(Bundle b) { - Intent res = new Intent(BeemIntent.ACTION_DISCONNECTED); - res.putExtra(BeemIntent.EXTRA_MESSAGE, R.string.contact_status_msg_offline); - - String account = null; - if (b != null) { - account = b.getString(BeemIntent.EXTRA_ACCOUNT); - res.putExtra(BeemIntent.EXTRA_ACCOUNT, account); - } - if (mConnection.containsKey(account)) { - res.setAction(BeemIntent.ACTION_CONNECTED); - } else { - if (account == null) //TODO temporary - account = "dummy"; - if (account == null) { - //connect all - } else { - BeemConnection beemco = new BeemConnection( - BeemService.this.getSharedPreferences(account, MODE_PRIVATE), mPreferenceListener); - if (beemco.getSettings().getBoolean("settings_away_chk", false)) { - mOnOffReceiverIsRegistered = true; - registerReceiver(mOnOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF)); - registerReceiver(mOnOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_ON)); - } - mBeemConnection.put(account, beemco); - XmppConnectionAdapter beemcoAdapter = new XmppConnectionAdapter(beemco.getConnectionConfiguration(), - beemco.getJid(), beemco.getPassword(), this); - - try { - Log.i(TAG, "Starting connection of " + account); - if (beemcoAdapter.connectSync()) { - mConnection.put(account, beemcoAdapter); - mBind.put(account, new XmppFacade(beemcoAdapter)); - res.setAction(BeemIntent.ACTION_CONNECTED); - Log.e(TAG, "Account configuration : " + account.toString() + " DONE"); - } else { - Log.w(TAG, "Unable to connect " + account); - res.putExtra(BeemIntent.EXTRA_MESSAGE, beemcoAdapter.getErrorMessage()); - } - } catch (RemoteException e) { - res.putExtra(BeemIntent.EXTRA_MESSAGE, beemcoAdapter.getErrorMessage()); - Log.e(TAG, "Unable to connect " + account, e); - } - - } - } - sendBroadcast(res); - } - - private void handleDisconnect(Bundle b) { - Intent res = new Intent(BeemIntent.ACTION_DISCONNECTED); - String account = b.getString(BeemIntent.EXTRA_ACCOUNT); - mConnection.remove(account); - sendBroadcast(res); - } + private void handleDisconnect(Bundle b) { + Intent res = new Intent(BeemIntent.ACTION_DISCONNECTED); + String account = b.getString(BeemIntent.EXTRA_ACCOUNT); + mConnection.remove(account); + sendBroadcast(res); + } } diff -r c067ee9a604c -r dfbc48b4eae1 src/com/beem/project/beem/BeemSync.java --- a/src/com/beem/project/beem/BeemSync.java Fri Oct 14 18:57:07 2011 +0200 +++ b/src/com/beem/project/beem/BeemSync.java Tue Oct 18 00:37:46 2011 +0200 @@ -38,6 +38,7 @@ import org.jivesoftware.smack.packet.Presence; import android.accounts.Account; +import android.accounts.AccountManager; import android.content.ContentProviderOperation; import android.content.ContentUris; import android.content.ContentValues; @@ -58,288 +59,301 @@ */ public class BeemSync { - private static final String TAG = "BeemSync"; - private static final int NB_DB_OPERATION = 50; + private static final String TAG = "BeemSync"; + private static final int NB_DB_OPERATION = 50; - private Context mContext; + private Context mContext; - /** - * Constructor. - * @param c the context parameter. - */ - public BeemSync(Context c) { - mContext = c; - } + /** + * Constructor. + * @param c the context parameter. + */ + public BeemSync(Context c) { + mContext = c; + } - /** - * Method to execute content provider operation. - * @param ops - */ - private void executeOperation(final ArrayList ops) { - try { - mContext.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); - } catch (RemoteException e) { - Log.d(TAG, "Error during sync of contact", e); - } catch (OperationApplicationException e) { - Log.d(TAG, "Error during sync of contact", e); - } - ops.clear(); + /** + * Method to execute content provider operation. + * @param ops + */ + private void executeOperation(final ArrayList ops) { + try { + mContext.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); + } catch (RemoteException e) { + Log.d(TAG, "Error during sync of contact", e); + } catch (OperationApplicationException e) { + Log.d(TAG, "Error during sync of contact", e); } + ops.clear(); + } - /** - * Roster sync method. - * @param r The roster to sync - * @param a The account related - */ - public void manageRoster(final Roster r, final Account a) { - if (r == null) { - Log.w(TAG, "Roster is null cant sync informations"); - return; - } - ArrayList ops = new ArrayList(); - for (RosterGroup group : r.getGroups()) { - if (group != null) { - manageGroup(ops, a, group); - } - if (ops.size() > NB_DB_OPERATION) - executeOperation(ops); - } - if (ops.size() > 0) - executeOperation(ops); - for (RosterEntry entry : r.getEntries()) { - if (entry != null) { - long rawContactID = manageEntry(ops, a, entry); - addUpdateStatus(ops, entry, r.getPresence(entry.getUser()), rawContactID); - } - if (ops.size() > NB_DB_OPERATION) - executeOperation(ops); - } - if (ops.size() > 0) - executeOperation(ops); + /** + * Roster sync method. + * @param r The roster to sync + * @param a The account related + */ + public void manageRoster(final Roster r, final String accountName) { + if (r == null) { + Log.w(TAG, "Roster is null cant sync informations"); + return; } + ArrayList ops = new ArrayList(); + for (RosterGroup group : r.getGroups()) { + if (group != null) { + manageGroup(ops, accountName, group); + } + if (ops.size() > NB_DB_OPERATION) + executeOperation(ops); + } + if (ops.size() > 0) + executeOperation(ops); + for (RosterEntry entry : r.getEntries()) { + if (entry != null) { + long rawContactID = manageEntry(ops, accountName, entry); + addUpdateStatus(ops, entry, r.getPresence(entry.getUser()), rawContactID); + } + if (ops.size() > NB_DB_OPERATION) + executeOperation(ops); + } + if (ops.size() > 0) + executeOperation(ops); + } - private void manageGroup(ArrayList ops, Account account, RosterGroup group) { - Log.i(TAG, "Sync group : " + group.getName() + " " + group.getEntryCount()); - long rawGroupID = getRawGroupID(account.name, group.getName()); - if (rawGroupID == -1) { - ContentProviderOperation.Builder builder = ContentProviderOperation - .newInsert(ContactsContract.Groups.CONTENT_URI); - builder.withValue(ContactsContract.Groups.ACCOUNT_NAME, account.name); - builder.withValue(ContactsContract.Groups.ACCOUNT_TYPE, account.type); - builder.withValue(ContactsContract.Groups.TITLE, group.getName()); - ops.add(builder.build()); + private void manageGroup(ArrayList ops, String accountName, RosterGroup group) { + Log.i(TAG, "Sync group : " + group.getName() + " " + group.getEntryCount()); + long rawGroupID = getRawGroupID(accountName, group.getName()); + if (rawGroupID == -1) { + + ContentProviderOperation.Builder builder = ContentProviderOperation + .newInsert(ContactsContract.Groups.CONTENT_URI); + Account[] accounts = AccountManager.get(mContext).getAccounts(); + for (Account account : accounts) { + if (account.name.equals(accountName)) { + builder.withValue(ContactsContract.Groups.ACCOUNT_NAME, account.name); + builder.withValue(ContactsContract.Groups.ACCOUNT_TYPE, account.type); + break; } + } + builder.withValue(ContactsContract.Groups.TITLE, group.getName()); + ops.add(builder.build()); } + } - /** - * RosterEntry sync method. - * @param ops The content provider operation - * @param account The account related - * @param entry The roster entry to sync - * @return The raw contact ID - */ - private long manageEntry(ArrayList ops, Account account, RosterEntry entry) { - long rawContactID = getRawContactID(account.name, entry.getUser()); - Log.i(TAG, "Sync Contact : " + entry.getUser() + " RawContactID : " + rawContactID); - if (rawContactID == -1) { // Not found in database, add new - ContentValues values = new ContentValues(); - values.put(ContactsContract.RawContacts.ACCOUNT_TYPE, account.type); - values.put(ContactsContract.RawContacts.ACCOUNT_NAME, account.name); - values.put(ContactsContract.RawContacts.SOURCE_ID, entry.getUser()); - Uri rawContactUri = mContext.getContentResolver().insert(ContactsContract.RawContacts.CONTENT_URI, values); - rawContactID = ContentUris.parseId(rawContactUri); - values.clear(); - ContentProviderOperation.Builder builder = addUpdateStructuredName(entry, rawContactID, true); - ops.add(builder.build()); - for (RosterGroup group : entry.getGroups()) { - builder = addUpdateGroup(entry, rawContactID, getRawGroupID(account.name, group.getName()), true); - ops.add(builder.build()); - } - builder = createProfile(entry, rawContactID, account); - ops.add(builder.build()); - } else { // Found, update - ContentProviderOperation.Builder builder = addUpdateStructuredName(entry, rawContactID, false); - ops.add(builder.build()); - // TODO: ADD AVATAR - // builder = addUpdatePhoto(entry, rawContactID, false); - // ops.add(builder.build()); + /** + * RosterEntry sync method. + * @param ops The content provider operation + * @param account The account related + * @param entry The roster entry to sync + * @return The raw contact ID + */ + private long manageEntry(ArrayList ops, String accountName, RosterEntry entry) { + long rawContactID = getRawContactID(accountName, entry.getUser()); + Log.i(TAG, "Sync Contact : " + entry.getUser() + " RawContactID : " + rawContactID); + if (rawContactID == -1) { // Not found in database, add new + ContentValues values = new ContentValues(); + Account[] accounts = AccountManager.get(mContext).getAccounts(); + for (Account account : accounts) { + if (account.name.equals(accountName)) { + values.put(ContactsContract.RawContacts.ACCOUNT_TYPE, account.type); + values.put(ContactsContract.RawContacts.ACCOUNT_NAME, account.name); + break; } - return rawContactID; + } + values.put(ContactsContract.RawContacts.SOURCE_ID, entry.getUser()); + Uri rawContactUri = mContext.getContentResolver().insert(ContactsContract.RawContacts.CONTENT_URI, values); + rawContactID = ContentUris.parseId(rawContactUri); + values.clear(); + ContentProviderOperation.Builder builder = addUpdateStructuredName(entry, rawContactID, true); + ops.add(builder.build()); + for (RosterGroup group : entry.getGroups()) { + builder = addUpdateGroup(entry, rawContactID, getRawGroupID(accountName, group.getName()), true); + ops.add(builder.build()); + } + builder = createProfile(entry, rawContactID, accountName); + ops.add(builder.build()); + } else { // Found, update + ContentProviderOperation.Builder builder = addUpdateStructuredName(entry, rawContactID, false); + ops.add(builder.build()); + // TODO: ADD AVATAR + // builder = addUpdatePhoto(entry, rawContactID, false); + // ops.add(builder.build()); } - - /** - * Method to insert or update structured name informations. - * @param entry The roster entry to sync - * @param rawContactID The contact ID in the android database - * @param isInsert Insert boolean - * @return - */ - private ContentProviderOperation.Builder addUpdateStructuredName(RosterEntry entry, long rawContactID, - boolean isInsert) { - String displayName = entry.getName() != null ? entry.getName() : entry.getUser(); - ContentProviderOperation.Builder builder; - if (isInsert) { - builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); - builder.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactID); - builder.withValue(ContactsContract.Data.MIMETYPE, - ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE); - builder.withValue(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, rawContactID); - } else { - builder = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI); - builder.withSelection( - ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID + " =? AND " - + ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE - + "'", new String[] { String.valueOf(rawContactID) }); - } - builder.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, displayName); - builder.withValue(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, displayName); - builder.withValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, displayName); - return builder; - } + return rawContactID; + } - /** - * Method to insert or update avatar. - * @param entry The roster entry to sync - * @param rawContactID The contact ID in the android database - * @param isInsert Insert boolean - * @return - */ - private ContentProviderOperation.Builder addUpdatePhoto(RosterEntry entry, long rawContactID, boolean isInsert) { - String displayName = entry.getName() != null ? entry.getName() : entry.getUser(); - ContentProviderOperation.Builder builder; - if (isInsert) { - builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); - builder.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactID); - builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE); - builder.withValue(ContactsContract.CommonDataKinds.Photo.RAW_CONTACT_ID, rawContactID); - } else { - builder = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI); - builder.withSelection(ContactsContract.CommonDataKinds.Photo.RAW_CONTACT_ID + " =? AND " - + ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE - + "'", new String[] { String.valueOf(rawContactID) }); - } - BeemAvatarCache bac = new BeemAvatarCache(mContext); - try { - builder.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, bac.get(entry.getUser())); - } catch (IOException e) { - Log.e(TAG, "Error cache beem avatar", e); - } - return builder; + /** + * Method to insert or update structured name informations. + * @param entry The roster entry to sync + * @param rawContactID The contact ID in the android database + * @param isInsert Insert boolean + * @return + */ + private ContentProviderOperation.Builder addUpdateStructuredName(RosterEntry entry, long rawContactID, + boolean isInsert) { + String displayName = entry.getName() != null ? entry.getName() : entry.getUser(); + ContentProviderOperation.Builder builder; + if (isInsert) { + builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); + builder.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactID); + builder.withValue(ContactsContract.Data.MIMETYPE, + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE); + builder.withValue(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, rawContactID); + } else { + builder = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI); + builder.withSelection( + ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID + " =? AND " + + ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE + + "'", new String[] { String.valueOf(rawContactID) }); } + builder.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, displayName); + builder.withValue(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, displayName); + builder.withValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, displayName); + return builder; + } - /** - * Method to insert or update group name informations. - * @param entry The roster entry to sync - * @param rawContactID The contact ID in the android database - * @param rawGroupID The group ID in the android database - * @param isInsert Insert boolean - * @return - */ - private ContentProviderOperation.Builder addUpdateGroup(RosterEntry entry, long rawContactID, long rawGroupID, - boolean isInsert) { - String displayName = entry.getName() != null ? entry.getName() : entry.getUser(); - Log.e(TAG + "UPDATE GROUP", "Contact : " + displayName + " GroupID :" + rawGroupID); - ContentProviderOperation.Builder builder = null; - if (isInsert) { - builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); - builder.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactID); - builder.withValue(ContactsContract.Data.MIMETYPE, - ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE); - builder.withValue(ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID, rawGroupID); - } - // TODO: delete - contact doesnt appear anymore in this group - return builder; + /** + * Method to insert or update avatar. + * @param entry The roster entry to sync + * @param rawContactID The contact ID in the android database + * @param isInsert Insert boolean + * @return + */ + private ContentProviderOperation.Builder addUpdatePhoto(RosterEntry entry, long rawContactID, boolean isInsert) { + String displayName = entry.getName() != null ? entry.getName() : entry.getUser(); + ContentProviderOperation.Builder builder; + if (isInsert) { + builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); + builder.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactID); + builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE); + builder.withValue(ContactsContract.CommonDataKinds.Photo.RAW_CONTACT_ID, rawContactID); + } else { + builder = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI); + builder.withSelection(ContactsContract.CommonDataKinds.Photo.RAW_CONTACT_ID + " =? AND " + + ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + + "'", new String[] { String.valueOf(rawContactID) }); } + BeemAvatarCache bac = new BeemAvatarCache(mContext); + try { + builder.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, bac.get(entry.getUser())); + } catch (IOException e) { + Log.e(TAG, "Error cache beem avatar", e); + } + return builder; + } - /** - * Method to insert or update IM informations. - * @param entry The roster entry to sync - * @param rawContactID The contact ID in the android database - * @param isInsert Insert boolean - * @return - */ - private ContentProviderOperation.Builder createProfile(RosterEntry entry, long rawContactID, Account account) { - String displayName = entry.getName() != null ? entry.getName() : entry.getUser(); - ContentProviderOperation.Builder builder; - builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); - builder.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactID); - builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE); - builder.withValue(ContactsContract.CommonDataKinds.Im.RAW_CONTACT_ID, rawContactID); - builder.withValue(ContactsContract.CommonDataKinds.Im.DATA1, displayName); - builder.withValue(ContactsContract.CommonDataKinds.Im.PROTOCOL, - ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER); - return builder; + /** + * Method to insert or update group name informations. + * @param entry The roster entry to sync + * @param rawContactID The contact ID in the android database + * @param rawGroupID The group ID in the android database + * @param isInsert Insert boolean + * @return + */ + private ContentProviderOperation.Builder addUpdateGroup(RosterEntry entry, long rawContactID, long rawGroupID, + boolean isInsert) { + String displayName = entry.getName() != null ? entry.getName() : entry.getUser(); + Log.e(TAG + "UPDATE GROUP", "Contact : " + displayName + " GroupID :" + rawGroupID); + ContentProviderOperation.Builder builder = null; + if (isInsert) { + builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); + builder.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactID); + builder.withValue(ContactsContract.Data.MIMETYPE, + ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE); + builder.withValue(ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID, rawGroupID); } + // TODO: delete - contact doesnt appear anymore in this group + return builder; + } - /** - * Method to insert or update IM informations. - * @param entry The roster entry to sync - * @param rawContactID The contact ID in the android database - * @param isInsert Insert boolean - * @return - */ - private void addUpdateStatus(ArrayList ops, RosterEntry entry, Presence p, - long rawContactID) { - String displayName = entry.getName() != null ? entry.getName() : entry.getUser(); - Log.i(TAG + "UPDATESTATUS", "Contact : " + displayName + " Presence status : " + p.getStatus() - + " Presence status state : " + Status.getStatusFromPresence(p)); - ContentProviderOperation.Builder builder; - builder = ContentProviderOperation.newInsert(ContactsContract.StatusUpdates.CONTENT_URI); - builder.withValue(ContactsContract.StatusUpdates.PROTOCOL, ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER); - builder.withValue(ContactsContract.StatusUpdates.IM_HANDLE, displayName); - // TODO: Get account name - builder.withValue(ContactsContract.StatusUpdates.IM_ACCOUNT, "beem@elyzion.net"); - builder.withValue(ContactsContract.StatusUpdates.STATUS, p.getStatus()); - builder.withValue(ContactsContract.StatusUpdates.STATUS_RES_PACKAGE, "com.beem.project.beem"); - builder.withValue(ContactsContract.StatusUpdates.STATUS_LABEL, R.string.app_name); - // TODO: Get status icon - builder.withValue(ContactsContract.StatusUpdates.STATUS_ICON, R.drawable.beem_status_icon); - // TODO: Pb presence ... 2 appear on 3 raw .... random appear - builder.withValue(ContactsContract.StatusUpdates.PRESENCE, Status.getStatusFromPresence(p)); - ops.add(builder.build()); - } + /** + * Method to insert or update IM informations. + * @param entry The roster entry to sync + * @param rawContactID The contact ID in the android database + * @param isInsert Insert boolean + * @return + */ + private ContentProviderOperation.Builder createProfile(RosterEntry entry, long rawContactID, String accountName) { + String displayName = entry.getName() != null ? entry.getName() : entry.getUser(); + ContentProviderOperation.Builder builder; + builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); + builder.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactID); + builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE); + builder.withValue(ContactsContract.CommonDataKinds.Im.RAW_CONTACT_ID, rawContactID); + builder.withValue(ContactsContract.CommonDataKinds.Im.DATA1, displayName); + builder.withValue(ContactsContract.CommonDataKinds.Im.PROTOCOL, + ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER); + return builder; + } - /** - * Get contact ID from android database. - * @param account The account related - * @param jid The jid related - * @return ID in the database of the jid - */ - private long getRawContactID(String account, String jid) { - long authorId = -1; - final Cursor c = mContext.getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI, - new String[] { ContactsContract.RawContacts._ID, ContactsContract.RawContacts.SOURCE_ID }, - ContactsContract.RawContacts.ACCOUNT_NAME + "=? AND " + ContactsContract.RawContacts.SOURCE_ID + "=?", - new String[] { account, jid }, null); - try { - if (c.moveToFirst()) - authorId = c.getInt(c.getColumnIndex(ContactsContract.RawContacts._ID)); - } finally { - if (c != null) - c.close(); - } - return authorId; - } + /** + * Method to insert or update IM informations. + * @param entry The roster entry to sync + * @param rawContactID The contact ID in the android database + * @param isInsert Insert boolean + * @return + */ + private void addUpdateStatus(ArrayList ops, RosterEntry entry, Presence p, + long rawContactID) { + String displayName = entry.getName() != null ? entry.getName() : entry.getUser(); + Log.i(TAG + "UPDATESTATUS", "Contact : " + displayName + " Presence status : " + p.getStatus() + + " Presence status state : " + Status.getStatusFromPresence(p)); + ContentProviderOperation.Builder builder; + builder = ContentProviderOperation.newInsert(ContactsContract.StatusUpdates.CONTENT_URI); + builder.withValue(ContactsContract.StatusUpdates.PROTOCOL, ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER); + builder.withValue(ContactsContract.StatusUpdates.IM_HANDLE, displayName); + // TODO: Get account name + builder.withValue(ContactsContract.StatusUpdates.IM_ACCOUNT, "beem@elyzion.net"); + builder.withValue(ContactsContract.StatusUpdates.STATUS, p.getStatus()); + builder.withValue(ContactsContract.StatusUpdates.STATUS_RES_PACKAGE, "com.beem.project.beem"); + builder.withValue(ContactsContract.StatusUpdates.STATUS_LABEL, R.string.app_name); + // TODO: Get status icon + builder.withValue(ContactsContract.StatusUpdates.STATUS_ICON, R.drawable.beem_status_icon); + // TODO: Pb presence ... 2 appear on 3 raw .... random appear + builder.withValue(ContactsContract.StatusUpdates.PRESENCE, Status.getStatusFromPresence(p)); + ops.add(builder.build()); + } - /** - * Get group ID from android database. - * @param account The account related - * @param group The group related - * @return ID in the database of the jid - */ - private long getRawGroupID(String account, String group) { - long authorId = -1; - final Cursor c = mContext.getContentResolver().query(ContactsContract.Groups.CONTENT_URI, - new String[] { ContactsContract.Groups._ID }, - ContactsContract.Groups.ACCOUNT_NAME + "=? AND " + ContactsContract.Groups.TITLE + "=?", - new String[] { account, group }, null); - try { - if (c.moveToFirst()) - authorId = c.getInt(c.getColumnIndex(ContactsContract.Groups._ID)); - } finally { - if (c != null) - c.close(); - } - return authorId; + /** + * Get contact ID from android database. + * @param account The account related + * @param jid The jid related + * @return ID in the database of the jid + */ + private long getRawContactID(String account, String jid) { + long authorId = -1; + final Cursor c = mContext.getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI, + new String[] { ContactsContract.RawContacts._ID, ContactsContract.RawContacts.SOURCE_ID }, + ContactsContract.RawContacts.ACCOUNT_NAME + "=? AND " + ContactsContract.RawContacts.SOURCE_ID + "=?", + new String[] { account, jid }, null); + try { + if (c.moveToFirst()) + authorId = c.getInt(c.getColumnIndex(ContactsContract.RawContacts._ID)); + } finally { + if (c != null) + c.close(); } + return authorId; + } + + /** + * Get group ID from android database. + * @param account The account related + * @param group The group related + * @return ID in the database of the jid + */ + private long getRawGroupID(String account, String group) { + long authorId = -1; + final Cursor c = mContext.getContentResolver().query(ContactsContract.Groups.CONTENT_URI, + new String[] { ContactsContract.Groups._ID }, + ContactsContract.Groups.ACCOUNT_NAME + "=? AND " + ContactsContract.Groups.TITLE + "=?", + new String[] { account, group }, null); + try { + if (c.moveToFirst()) + authorId = c.getInt(c.getColumnIndex(ContactsContract.Groups._ID)); + } finally { + if (c != null) + c.close(); + } + return authorId; + } } diff -r c067ee9a604c -r dfbc48b4eae1 src/com/beem/project/beem/providers/MessageProvider.java --- a/src/com/beem/project/beem/providers/MessageProvider.java Fri Oct 14 18:57:07 2011 +0200 +++ b/src/com/beem/project/beem/providers/MessageProvider.java Tue Oct 18 00:37:46 2011 +0200 @@ -25,27 +25,10 @@ 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.providers; -import java.text.SimpleDateFormat; -import java.util.Date; import java.util.HashMap; import android.content.ContentProvider; @@ -56,203 +39,184 @@ import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteQueryBuilder; import android.net.Uri; import android.util.Log; -import com.beem.project.beem.service.Message; - /** * Provider to store messages send/receive. * @author marseille */ public class MessageProvider extends ContentProvider { - private static final String TAG = "MessageProvider"; - private static final String DATABASE_NAME = "messages.db"; - private static final int DATABASE_VERSION = 1; - private static final int MESSAGES = 1; - private static final String MESSAGES_TABLE_NAME = "messages"; - private static final UriMatcher sUriMatcher; + private static final String TAG = "MessageProvider"; + private static final String DATABASE_NAME = "messages.db"; + private static final int DATABASE_VERSION = 1; + private static final int MESSAGES = 1; + private static final String MESSAGES_TABLE_NAME = "messages"; + private static final UriMatcher sUriMatcher; + + public static final String AUTHORITY = "com.beem.project.beem.providers.messageprovider"; + + private static HashMap messagesProjectionMap; + private DatabaseHelper mDbHelper; + private Context mContext; - public static final String AUTHORITY = "com.beem.project.beem.providers.messageprovider"; + /** + * Constructor. + */ + public MessageProvider() { + Log.i(TAG, "Constructeur MessageProvider"); + } - private static HashMap messagesProjectionMap; - private DatabaseHelper mDbHelper; - private Context mContext; + @Override + public boolean onCreate() { + Log.i(TAG, "On Create MessageProvider"); + mDbHelper = new DatabaseHelper(getContext()); + return true; - /** - * Constructor. - */ - public MessageProvider() { - Log.i(TAG, "Constructeur MessageProvider"); - } + } - @Override - public boolean onCreate() { - Log.i(TAG, "On Create MessageProvider"); - mDbHelper = new DatabaseHelper(getContext()); - return true; + @Override + public Uri insert(Uri uri, ContentValues initialValues) { + if (sUriMatcher.match(uri) != MESSAGES) { + throw new IllegalArgumentException("Unknown URI " + uri); + } + ContentValues values; + if (initialValues != null) + values = new ContentValues(initialValues); + else + values = new ContentValues(); + SQLiteDatabase db = null; + db = mDbHelper.getWritableDatabase(); + long rowId = db.insert(MESSAGES_TABLE_NAME, Messages.BODY, values); + if (rowId == -1) + throw new SQLException("Failed to insert row into " + uri); + Uri messageUri = ContentUris.withAppendedId(Messages.CONTENT_URI, rowId); + mContext.getContentResolver().notifyChange(messageUri, null); + return messageUri; - } + } + @Override + public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { + SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); - @Override - public Uri insert(Uri uri, ContentValues initialValues) { - Log.i(TAG, "insert1"); - if (sUriMatcher.match(uri) != MESSAGES) { - throw new IllegalArgumentException("Unknown URI " + uri); - } - Log.i(TAG, "insert2"); - ContentValues values; - if (initialValues != null) - values = new ContentValues(initialValues); - else - values = new ContentValues(); + switch (sUriMatcher.match(uri)) { + case MESSAGES: + qb.setTables(MESSAGES_TABLE_NAME); + qb.setProjectionMap(messagesProjectionMap); + break; + + default: + throw new IllegalArgumentException("Unknown URI " + uri); + } + SQLiteDatabase db = mDbHelper.getReadableDatabase(); + Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder); + c.setNotificationUri(mContext.getContentResolver(), uri); + return c; + } + + @Override + public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { + int count; + SQLiteDatabase db = mDbHelper.getWritableDatabase(); + switch (sUriMatcher.match(uri)) { + case MESSAGES: + count = db.update(MESSAGES_TABLE_NAME, values, selection, selectionArgs); + break; + + default: + throw new IllegalArgumentException("Unknown URI " + uri); + } + mContext.getContentResolver().notifyChange(uri, null); + return count; + } - Log.i(TAG, "insert3"); - if (mDbHelper == null) - Log.e("mDbHelper", "NULL"); - SQLiteDatabase db = null; - try { - db = mDbHelper.getWritableDatabase(); - } catch (SQLiteException e) { - Log.e("SQLITEEXCEPTION", "OOOO", e); - } - Log.i(TAG, "insert3.5"); - if (db == null) - Log.e("db", "NULL"); - long rowId = db.insert(MESSAGES_TABLE_NAME, Messages.BODY, values); - Log.i(TAG, "insert4"); - if (rowId == -1) - throw new SQLException("Failed to insert row into " + uri); - Uri messageUri = ContentUris.withAppendedId(Messages.CONTENT_URI, rowId); - mContext.getContentResolver().notifyChange(messageUri, null); - Log.i(TAG, "Message inserted in database "); - return messageUri; + @Override + public int delete(Uri uri, String selection, String[] selectionArgs) { + int count; + SQLiteDatabase db = mDbHelper.getWritableDatabase(); + switch (sUriMatcher.match(uri)) { + case MESSAGES: + count = db.delete(MESSAGES_TABLE_NAME, selection, selectionArgs); + break; + + default: + throw new IllegalArgumentException("Unknown URI " + uri); + } + mContext.getContentResolver().notifyChange(uri, null); + return count; + } + @Override + public String getType(Uri uri) { + switch (sUriMatcher.match(uri)) { + case MESSAGES: + return Messages.CONTENT_TYPE; + default: + throw new IllegalArgumentException("Unknown URI " + uri); } - - @Override - public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { - SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); + } - switch (sUriMatcher.match(uri)) { - case MESSAGES: - qb.setTables(MESSAGES_TABLE_NAME); - qb.setProjectionMap(messagesProjectionMap); - break; + private class DatabaseHelper extends SQLiteOpenHelper { - default: - throw new IllegalArgumentException("Unknown URI " + uri); - } - SQLiteDatabase db = mDbHelper.getReadableDatabase(); - Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder); - c.setNotificationUri(mContext.getContentResolver(), uri); - return c; + DatabaseHelper(Context context) { + super(context, DATABASE_NAME, null, DATABASE_VERSION); + Log.e(TAG, "ConStructeur"); } @Override - public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { - int count; - SQLiteDatabase db = mDbHelper.getWritableDatabase(); - switch (sUriMatcher.match(uri)) { - case MESSAGES: - count = db.update(MESSAGES_TABLE_NAME, values, selection, selectionArgs); - break; - - default: - throw new IllegalArgumentException("Unknown URI " + uri); - } - mContext.getContentResolver().notifyChange(uri, null); - return count; - } - - @Override - public int delete(Uri uri, String selection, String[] selectionArgs) { - int count; - SQLiteDatabase db = mDbHelper.getWritableDatabase(); - switch (sUriMatcher.match(uri)) { - case MESSAGES: - count = db.delete(MESSAGES_TABLE_NAME, selection, selectionArgs); - break; - - default: - throw new IllegalArgumentException("Unknown URI " + uri); - } - mContext.getContentResolver().notifyChange(uri, null); - return count; + public void onCreate(SQLiteDatabase db) { + Log.e(TAG, "onCreate"); + String createDatabase = "CREATE TABLE " + MESSAGES_TABLE_NAME + " ("; + createDatabase += Messages._ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"; + createDatabase += Messages.FROM + " VARCHAR(255),"; + createDatabase += Messages.MESSAGE_ID + " VARCHAR(255),"; + createDatabase += Messages.TO + " VARCHAR(255),"; + createDatabase += Messages.TYPE + " VARCHAR(255),"; + createDatabase += Messages.SUBJECT + " VARCHAR(255),"; + createDatabase += Messages.BODY + " LONGTEXT,"; + createDatabase += Messages.THREAD + " VARCHAR(255),"; + createDatabase += Messages.EXTRAS + " VARCHAR(255),"; + createDatabase += Messages.IS_RECEIVE + " BOOLEAN,"; + createDatabase += Messages.DATE_RECEIVE + " DATE,"; + createDatabase += Messages.DATE_READ + " DATE"; + createDatabase += ");"; + try { + db.execSQL(createDatabase); + } catch (SQLException e) { + Log.e(TAG, "CREATE DB PROBLEM", e); + } } @Override - public String getType(Uri uri) { - switch (sUriMatcher.match(uri)) { - case MESSAGES: - return Messages.CONTENT_TYPE; - default: - throw new IllegalArgumentException("Unknown URI " + uri); - } + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion + + ", which will destroy all old data"); + db.execSQL("DROP TABLE IF EXISTS " + MESSAGES_TABLE_NAME); + onCreate(db); } - - private class DatabaseHelper extends SQLiteOpenHelper { + } - DatabaseHelper(Context context) { - super(context, DATABASE_NAME, null, DATABASE_VERSION); - Log.e(TAG, "ConStructeur"); - } + static { + sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH); + sUriMatcher.addURI(AUTHORITY, MESSAGES_TABLE_NAME, MESSAGES); - @Override - public void onCreate(SQLiteDatabase db) { - Log.e(TAG, "onCreate"); - String createDatabase = "CREATE TABLE " + MESSAGES_TABLE_NAME + " ("; - createDatabase += Messages._ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"; - createDatabase += Messages.FROM + " VARCHAR(255),"; - createDatabase += Messages.MESSAGE_ID + " VARCHAR(255),"; - createDatabase += Messages.TO + " VARCHAR(255),"; - createDatabase += Messages.TYPE + " VARCHAR(255),"; - createDatabase += Messages.SUBJECT + " VARCHAR(255),"; - createDatabase += Messages.BODY + " LONGTEXT,"; - createDatabase += Messages.THREAD + " VARCHAR(255),"; - createDatabase += Messages.EXTRAS + " VARCHAR(255),"; - createDatabase += Messages.IS_RECEIVE + " BOOLEAN,"; - createDatabase += Messages.DATE_RECEIVE + " DATE,"; - createDatabase += Messages.DATE_READ + " DATE"; - createDatabase += ");"; - try { - db.execSQL(createDatabase); - } catch (SQLException e) { - Log.e(TAG, "CREATE DB PROBLEM", e); - } - } - - @Override - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion - + ", which will destroy all old data"); - db.execSQL("DROP TABLE IF EXISTS " + MESSAGES_TABLE_NAME); - onCreate(db); - } - } - - static { - sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH); - sUriMatcher.addURI(AUTHORITY, MESSAGES_TABLE_NAME, MESSAGES); - - messagesProjectionMap = new HashMap(); - messagesProjectionMap.put(Messages._ID, Messages._ID); - messagesProjectionMap.put(Messages.FROM, Messages.FROM); - messagesProjectionMap.put(Messages.MESSAGE_ID, Messages.MESSAGE_ID); - messagesProjectionMap.put(Messages.TO, Messages.TO); - messagesProjectionMap.put(Messages.TYPE, Messages.TYPE); - messagesProjectionMap.put(Messages.SUBJECT, Messages.SUBJECT); - messagesProjectionMap.put(Messages.BODY, Messages.BODY); - messagesProjectionMap.put(Messages.THREAD, Messages.THREAD); - messagesProjectionMap.put(Messages.EXTRAS, Messages.EXTRAS); - messagesProjectionMap.put(Messages.IS_RECEIVE, Messages.IS_RECEIVE); - messagesProjectionMap.put(Messages.DATE_RECEIVE, Messages.DATE_RECEIVE); - messagesProjectionMap.put(Messages.DATE_READ, Messages.DATE_READ); - } + messagesProjectionMap = new HashMap(); + messagesProjectionMap.put(Messages._ID, Messages._ID); + messagesProjectionMap.put(Messages.FROM, Messages.FROM); + messagesProjectionMap.put(Messages.MESSAGE_ID, Messages.MESSAGE_ID); + messagesProjectionMap.put(Messages.TO, Messages.TO); + messagesProjectionMap.put(Messages.TYPE, Messages.TYPE); + messagesProjectionMap.put(Messages.SUBJECT, Messages.SUBJECT); + messagesProjectionMap.put(Messages.BODY, Messages.BODY); + messagesProjectionMap.put(Messages.THREAD, Messages.THREAD); + messagesProjectionMap.put(Messages.EXTRAS, Messages.EXTRAS); + messagesProjectionMap.put(Messages.IS_RECEIVE, Messages.IS_RECEIVE); + messagesProjectionMap.put(Messages.DATE_RECEIVE, Messages.DATE_RECEIVE); + messagesProjectionMap.put(Messages.DATE_READ, Messages.DATE_READ); + } } diff -r c067ee9a604c -r dfbc48b4eae1 src/com/beem/project/beem/providers/Messages.java --- a/src/com/beem/project/beem/providers/Messages.java Fri Oct 14 18:57:07 2011 +0200 +++ b/src/com/beem/project/beem/providers/Messages.java Tue Oct 18 00:37:46 2011 +0200 @@ -1,3 +1,32 @@ +/* + 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 . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + */ + package com.beem.project.beem.providers; import android.net.Uri; @@ -17,7 +46,7 @@ public static final String _ID = "_id"; public static final String FROM = "_FROM"; - public static final String MESSAGE_ID = "_MESSAGE_ID"; + public static final String MESSAGE_ID = "_MESSAGE_ID"; public static final String TO = "_TO"; public static final String TYPE = "_TYPE"; public static final String SUBJECT = "_SUBJECT"; @@ -27,6 +56,5 @@ public static final String IS_RECEIVE = "_IS_RECEIVE"; public static final String DATE_RECEIVE = "_DATE_RECEIVE"; public static final String DATE_READ = "_DATE_READ"; - } diff -r c067ee9a604c -r dfbc48b4eae1 src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Fri Oct 14 18:57:07 2011 +0200 +++ b/src/com/beem/project/beem/ui/ContactList.java Tue Oct 18 00:37:46 2011 +0200 @@ -90,489 +90,466 @@ /** * The contact list activity displays the roster of the user. - * * @author Vincent V. */ 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 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"; + + /** + * Map containing a list of the different contacts of a given group. Each list is a @{link SortedList} so there is + * no need to sort it again. + */ + + private final BeemContactListOnClick mOnContactClick = new BeemContactListOnClick(); + + private final ComparatorContactListByStatusAndName mComparator = new ComparatorContactListByStatusAndName(); + private IRoster mRoster; + private Contact mSelectedContact; + private IXmppFacade mXmppFacade; + private IChatManager mChatManager; + private SharedPreferences mSettings; + private BeemBanner mAdapterBanner; + private BeemContactList mAdapterContactList; + + private String mAccountName; + + /** + * Constructor. + */ + public ContactList() { + } + + @Override + protected void onCreate(Bundle saveBundle) { + super.onCreate(saveBundle); + mSettings = PreferenceManager.getDefaultSharedPreferences(this); + setContentView(R.layout.contactlist); + + mAccountName = getIntent().getExtras().getString(BeemIntent.EXTRA_ACCOUNT); + + // Get Groups list + final Cursor cursorGroup = getContentResolver().query(ContactsContract.Groups.CONTENT_URI, + new String[] { ContactsContract.Groups._ID, ContactsContract.Groups.TITLE }, + ContactsContract.Groups.ACCOUNT_NAME + "=?", new String[] { mAccountName }, null); + mAdapterBanner = new BeemBanner(this, R.layout.contactlist_group, cursorGroup, + new String[] { ContactsContract.Groups.TITLE }, new int[] { R.id.contactlist_group }); + + // Get Contacts list + // TODO: Get contact list by account + final Cursor cursorContact = getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI, + new String[] { ContactsContract.RawContacts._ID, 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.RawContacts.SOURCE_ID }, new int[] { R.id.avatar, + R.id.contactlistpseudo, R.id.contactlistmsgperso }); + + ListView listView = (ListView) findViewById(R.id.contactlist); + listView.setOnItemClickListener(mOnContactClick); + registerForContextMenu(listView); + listView.setAdapter(mAdapterContactList); + Log.e(TAG, "ONCREATE"); + } + + @Override + protected void onResume() { + super.onResume(); + if (!mSettings.getBoolean("settings_key_hide_groups", false)) + showGroups(); + else + hideGroups(); + } + + @Override + public final boolean onCreateOptionsMenu(Menu menu) { + super.onCreateOptionsMenu(menu); + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.contact_list, menu); + return true; + } + + @Override + public final boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.contact_list_menu_settings: + Intent i = new Intent(this, Settings.class); + i.putExtra("account_name", mAccountName); + startActivity(i); + return true; + case R.id.contact_list_menu_add_contact: + startActivity(new Intent(ContactList.this, AddContact.class)); + return true; + case R.id.menu_change_status: + startActivity(new Intent(ContactList.this, ChangeStatus.class)); + return true; + case R.id.contact_list_menu_chatlist: + List openedChats; + try { + openedChats = mChatManager.getOpenedChatList(); + Log.d(TAG, "opened chats = " + openedChats); + Dialog chatList = new ChatList(ContactList.this, openedChats).create(); + chatList.show(); + } catch (RemoteException e) { + e.printStackTrace(); + } + return true; + case R.id.contact_list_menu_sync: + //TODO: Manual Sync operation + Log.i(TAG, "performSync: " + mAccountName); + Intent intent = new Intent(BeemIntent.ACTION_SYNC ); + intent.putExtra(BeemIntent.EXTRA_ACCOUNT, mAccountName); + startService(intent); + return true; + case R.id.menu_disconnect: + stopService(SERVICE_INTENT); + return true; + default: + return false; + } + } + + @Override + public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, v, menuInfo); + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.contactlist_context, menu); + AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; + // Contact c = new Contact(); + // try { + // mSelectedContact = mRoster.getContact(c.getJID()); + // } catch (RemoteException e) { + // e.printStackTrace(); + // } + // menu.setHeaderTitle(mSelectedContact.getJID()); + } + + @Override + public boolean onContextItemSelected(MenuItem item) { + Intent in; + boolean result; + if (mSelectedContact != null) { + switch (item.getItemId()) { + case R.id.contact_list_context_menu_chat_item: + List res = mSelectedContact.getMRes(); + if (res.isEmpty()) { + result = false; + break; + } + for (String resv : res) { + in = new Intent(this, Chat.class); + in.setData(mSelectedContact.toUri(resv)); + item.getSubMenu().add(resv).setIntent(in); + } + result = true; + break; + case R.id.contact_list_context_menu_call_item: + try { + mXmppFacade.call(mSelectedContact.getJID() + "/psi"); + result = true; + } catch (RemoteException e) { + e.printStackTrace(); + } + result = true; + break; + case R.id.contact_list_context_menu_user_info: + item.getSubMenu().setHeaderTitle(mSelectedContact.getJID()); + result = true; + break; + case R.id.contact_list_context_menu_userinfo_alias: + Dialog alias = new Alias(ContactList.this, mRoster, mSelectedContact).create(); + alias.show(); + result = true; + break; + case R.id.contact_list_context_menu_userinfo_group: + in = new Intent(this, GroupList.class); + in.putExtra("contact", mSelectedContact); + startActivity(in); + result = true; + break; + case R.id.contact_list_context_menu_userinfo_subscription: + Dialog subscription = new ResendSubscription(ContactList.this, mXmppFacade, mSelectedContact) + .create(); + subscription.show(); + result = true; + break; + case R.id.contact_list_context_menu_userinfo_block: + result = true; + break; + case R.id.contact_list_context_menu_userinfo_delete: + Dialog delete = new DeleteContact(ContactList.this, mRoster, mSelectedContact).create(); + delete.show(); + result = true; + break; + default: + result = super.onContextItemSelected(item); + break; + } + return result; + } + return super.onContextItemSelected(item); + } + + /** + * Build and display the contact list. + * @param group name of the contact list. + */ + private void buildContactList(String group) { + + } + + /** + * Show the groups view. + */ + private void 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); + g.setSelection(0); + } else { + ((LinearLayout) findViewById(R.id.contactlist_groupstub)).setVisibility(View.VISIBLE); + Gallery g = (Gallery) findViewById(R.id.contactlist_banner); + g.setSelection(0); + } + } + + /** + * Hide the groups view. + */ + private void hideGroups() { + View v = findViewById(R.id.contactlist_groupstub); + if (v != null) + v.setVisibility(View.GONE); + } + + /** + * Adapter contact list. + */ + private static class BeemContactList extends SimpleCursorAdapter implements Filterable { + + private Context mContext; + private int mLayout; + + public BeemContactList(Context context, int layout, Cursor c, String[] from, int[] to) { + super(context, layout, c, from, to); + mContext = context; + mLayout = layout; } - private static final String SETTINGS_HIDDEN_CONTACT = "settings_key_hidden_contact"; - private static final String TAG = "ContactList"; + @Override + public View newView(Context context, Cursor cursor, ViewGroup parent) { + final LayoutInflater inflater = LayoutInflater.from(mContext); + return inflater.inflate(mLayout, parent, false); + } + + @Override + public void bindView(View view, Context context, Cursor cursor) { + String name = cursor.getString(cursor.getColumnIndex(ContactsContract.RawContacts.SOURCE_ID)); + String jid = cursor.getString(cursor.getColumnIndex(ContactsContract.RawContacts.SOURCE_ID)); + TextView nameText = (TextView) view.findViewById(R.id.contactlistpseudo); + if (nameText != null) { + nameText.setText(name); + } + + // String msgStatus = cursor.getString(cursor + // .getColumnIndex(ContactsContract.Contacts.CONTACT_STATUS)); + // TextView msgStatusText = (TextView) view + // .findViewById(R.id.contactlistmsgperso); + // if (msgStatusText != null) { + // msgStatusText.setText(msgStatus); + // } + + view.setTag(jid); + + // ImageView img = (ImageView) view.findViewById(R.id.avatar); + // String avatarId = curContact.getAvatarId(); + // int contactStatus = curContact.getStatus(); + // Drawable avatar = getAvatarStatusDrawable(avatarId); + // img.setImageDrawable(avatar); + // img.setImageLevel(contactStatus); + } + + // @Override + // public Filter getFilter() { + // return mFilter; + // } /** - * Map containing a list of the different contacts of a given group. Each - * list is a @{link SortedList} so there is no need to sort it again. + * Get a LayerDrawable containing the avatar and the status icon. The status icon will change with the level of + * the drawable. + * @param avatarId the avatar id to retrieve or null to get default + * @return a LayerDrawable + */ + // private Drawable getAvatarStatusDrawable(String avatarId) { + // Drawable avatarDrawable = null; + // if (avatarId != null) { + // Uri uri = + // AvatarProvider.CONTENT_URI.buildUpon().appendPath(avatarId).build(); + // InputStream in = null; + // try { + // try { + // in = getContentResolver().openInputStream(uri); + // avatarDrawable = Drawable.createFromStream(in, avatarId); + // } finally { + // if (in != null) + // in.close(); + // } + // } catch (IOException e) { + // Log.w(TAG, "Error while setting the avatar", e); + // } + // } + // if (avatarDrawable == null) + // avatarDrawable = + // getResources().getDrawable(R.drawable.beem_launcher_icon_silver); + // LayerDrawable ld = (LayerDrawable) + // getResources().getDrawable(R.drawable.avatar_status); + // ld.setLayerInset(1, 36, 36, 0, 0); + // ld.setDrawableByLayerId(R.id.avatar, avatarDrawable); + // return ld; + // } + + /** + * A Filter which select Contact to display by searching in ther Jid. */ - - private final BeemContactListOnClick mOnContactClick = new BeemContactListOnClick(); + // private class ContactFilter extends Filter { + // + // /** + // * Create a ContactFilter. + // */ + // public ContactFilter() { + // } + // + // @Override + // protected Filter.FilterResults performFiltering(CharSequence + // constraint) { + // Log.d(TAG, "performFiltering"); + // List result = mListContact; + // if (constraint.length() > 0) { + // result = new LinkedList(); + // 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 contacts = (List) results.values; + // mListContact = contacts; + // notifyDataSetChanged(); + // } + // } + } - private final ComparatorContactListByStatusAndName mComparator = new ComparatorContactListByStatusAndName(); - private IRoster mRoster; - private Contact mSelectedContact; - private IXmppFacade mXmppFacade; - private IChatManager mChatManager; - private SharedPreferences mSettings; - private BeemBanner mAdapterBanner; - private BeemContactList mAdapterContactList; + /** + * Adapter banner group list. + */ + private static class BeemBanner extends SimpleCursorAdapter { + + private Context mContext; + private int mLayout; + + public BeemBanner(Context context, int layout, Cursor c, String[] from, int[] to) { + super(context, layout, c, from, to); + mContext = context; + mLayout = layout; + } + + @Override + public View newView(Context context, Cursor cursor, ViewGroup parent) { + final LayoutInflater inflater = LayoutInflater.from(mContext); + return inflater.inflate(mLayout, parent, false); + } + + @Override + public void bindView(View view, Context context, Cursor cursor) { + if (cursor.getCount() > 0) { + String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Groups.TITLE)); + TextView nameText = (TextView) view.findViewById(R.id.contactlist_group); + if (nameText != null) { + nameText.setText(name); + } + } + } + } - private String mAccountName; + /** + * Comparator Contact by status and name. + */ + private static class ComparatorContactListByStatusAndName implements Comparator { + /** + * Constructor. + */ + public ComparatorContactListByStatusAndName() { + } + + @Override + public int compare(T c1, T c2) { + if (((Contact) c1).getStatus() < ((Contact) c2).getStatus()) { + return 1; + } else if (((Contact) c1).getStatus() > ((Contact) c2).getStatus()) { + return -1; + } else + return ((Contact) c1).getName().compareToIgnoreCase(((Contact) c2).getName()); + } + } + + /** + * Event simple click on item of the contact list. + */ + private class BeemContactListOnClick implements OnItemClickListener { + /** + * Constructor. + */ + public BeemContactListOnClick() { + } + + /** + * {@inheritDoc} + */ + @Override + public void onItemClick(AdapterView arg0, View v, int pos, long lpos) { + String jid = (String) v.getTag(); + Log.i(TAG, "OnClick Jid :" + jid); + Intent i = new Intent(ContactList.this, Chat.class); + i.setData(Uri.parse("imto://jabber/" + jid)); + startActivity(i); + } + } + + /** + * Event simple click on middle group name. + */ + private class OnItemClickGroupName implements OnItemClickListener { /** * Constructor. */ - public ContactList() { - } - - @Override - protected void onCreate(Bundle saveBundle) { - super.onCreate(saveBundle); - mSettings = PreferenceManager.getDefaultSharedPreferences(this); - setContentView(R.layout.contactlist); - - mAccountName = getIntent().getExtras().getString( - BeemIntent.EXTRA_ACCOUNT); - - // Get Groups list - final Cursor cursorGroup = getContentResolver().query( - ContactsContract.Groups.CONTENT_URI, - new String[] { ContactsContract.Groups._ID, - ContactsContract.Groups.TITLE }, - ContactsContract.Groups.ACCOUNT_NAME + "=?", - new String[] { mAccountName }, null); - mAdapterBanner = new BeemBanner(this, R.layout.contactlist_group, - cursorGroup, new String[] { ContactsContract.Groups.TITLE }, - new int[] { R.id.contactlist_group }); - - // Get Contacts list - // TODO: Get contact list by account - final Cursor cursorContact = getContentResolver().query( - ContactsContract.RawContacts.CONTENT_URI, - new String[] { ContactsContract.RawContacts._ID, - 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.RawContacts.SOURCE_ID }, new int[] { - R.id.avatar, R.id.contactlistpseudo, - R.id.contactlistmsgperso }); - - ListView listView = (ListView) findViewById(R.id.contactlist); - listView.setOnItemClickListener(mOnContactClick); - registerForContextMenu(listView); - listView.setAdapter(mAdapterContactList); - Log.e(TAG, "ONCREATE"); - } - - @Override - protected void onResume() { - super.onResume(); - if (!mSettings.getBoolean("settings_key_hide_groups", false)) - showGroups(); - else - hideGroups(); - } - - @Override - public final boolean onCreateOptionsMenu(Menu menu) { - super.onCreateOptionsMenu(menu); - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.contact_list, menu); - return true; - } - - @Override - public final boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.contact_list_menu_settings: - Intent i = new Intent(this, Settings.class); - i.putExtra("account_name", mAccountName); - startActivity(i); - return true; - case R.id.contact_list_menu_add_contact: - startActivity(new Intent(ContactList.this, AddContact.class)); - return true; - case R.id.menu_change_status: - startActivity(new Intent(ContactList.this, ChangeStatus.class)); - return true; - case R.id.contact_list_menu_chatlist: - List openedChats; - try { - openedChats = mChatManager.getOpenedChatList(); - Log.d(TAG, "opened chats = " + openedChats); - Dialog chatList = new ChatList(ContactList.this, openedChats) - .create(); - chatList.show(); - } catch (RemoteException e) { - e.printStackTrace(); - } - return true; - case R.id.menu_disconnect: - stopService(SERVICE_INTENT); - finish(); - default: - return false; - } - } - - @Override - public void onCreateContextMenu(ContextMenu menu, View v, - ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, v, menuInfo); - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.contactlist_context, menu); - AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; - // Contact c = new Contact(); - // try { - // mSelectedContact = mRoster.getContact(c.getJID()); - // } catch (RemoteException e) { - // e.printStackTrace(); - // } - // menu.setHeaderTitle(mSelectedContact.getJID()); + public OnItemClickGroupName() { } @Override - public boolean onContextItemSelected(MenuItem item) { - Intent in; - boolean result; - if (mSelectedContact != null) { - switch (item.getItemId()) { - case R.id.contact_list_context_menu_chat_item: - List res = mSelectedContact.getMRes(); - if (res.isEmpty()) { - result = false; - break; - } - for (String resv : res) { - in = new Intent(this, Chat.class); - in.setData(mSelectedContact.toUri(resv)); - item.getSubMenu().add(resv).setIntent(in); - } - result = true; - break; - case R.id.contact_list_context_menu_call_item: - try { - mXmppFacade.call(mSelectedContact.getJID() + "/psi"); - result = true; - } catch (RemoteException e) { - e.printStackTrace(); - } - result = true; - break; - case R.id.contact_list_context_menu_user_info: - item.getSubMenu().setHeaderTitle(mSelectedContact.getJID()); - result = true; - break; - case R.id.contact_list_context_menu_userinfo_alias: - Dialog alias = new Alias(ContactList.this, mRoster, - mSelectedContact).create(); - alias.show(); - result = true; - break; - case R.id.contact_list_context_menu_userinfo_group: - in = new Intent(this, GroupList.class); - in.putExtra("contact", mSelectedContact); - startActivity(in); - result = true; - break; - case R.id.contact_list_context_menu_userinfo_subscription: - Dialog subscription = new ResendSubscription(ContactList.this, - mXmppFacade, mSelectedContact).create(); - subscription.show(); - result = true; - break; - case R.id.contact_list_context_menu_userinfo_block: - result = true; - break; - case R.id.contact_list_context_menu_userinfo_delete: - Dialog delete = new DeleteContact(ContactList.this, mRoster, - mSelectedContact).create(); - delete.show(); - result = true; - break; - default: - result = super.onContextItemSelected(item); - break; - } - return result; - } - return super.onContextItemSelected(item); - } - - /** - * Build and display the contact list. - * - * @param group - * name of the contact list. - */ - private void buildContactList(String group) { - - } - - /** - * Show the groups view. - */ - private void 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); - g.setSelection(0); - } else { - ((LinearLayout) findViewById(R.id.contactlist_groupstub)) - .setVisibility(View.VISIBLE); - Gallery g = (Gallery) findViewById(R.id.contactlist_banner); - g.setSelection(0); - } - } - - /** - * Hide the groups view. - */ - private void hideGroups() { - View v = findViewById(R.id.contactlist_groupstub); - if (v != null) - v.setVisibility(View.GONE); + public void onItemClick(AdapterView arg0, View v, int i, long l) { + // String group = mListGroup.get(i); + // buildContactList(group); } - - /** - * Adapter contact list. - */ - private static class BeemContactList extends SimpleCursorAdapter implements - Filterable { - - private Context mContext; - private int mLayout; - - public BeemContactList(Context context, int layout, Cursor c, - String[] from, int[] to) { - super(context, layout, c, from, to); - mContext = context; - mLayout = layout; - } - - @Override - public View newView(Context context, Cursor cursor, ViewGroup parent) { - final LayoutInflater inflater = LayoutInflater.from(mContext); - return inflater.inflate(mLayout, parent, false); - } - - @Override - public void bindView(View view, Context context, Cursor cursor) { - String name = cursor.getString(cursor - .getColumnIndex(ContactsContract.RawContacts.SOURCE_ID)); - String jid = cursor.getString(cursor - .getColumnIndex(ContactsContract.RawContacts.SOURCE_ID)); - TextView nameText = (TextView) view - .findViewById(R.id.contactlistpseudo); - if (nameText != null) { - nameText.setText(name); - } - - // String msgStatus = cursor.getString(cursor - // .getColumnIndex(ContactsContract.Contacts.CONTACT_STATUS)); - // TextView msgStatusText = (TextView) view - // .findViewById(R.id.contactlistmsgperso); - // if (msgStatusText != null) { - // msgStatusText.setText(msgStatus); - // } - - view.setTag(jid); - - // ImageView img = (ImageView) view.findViewById(R.id.avatar); - // String avatarId = curContact.getAvatarId(); - // int contactStatus = curContact.getStatus(); - // Drawable avatar = getAvatarStatusDrawable(avatarId); - // img.setImageDrawable(avatar); - // img.setImageLevel(contactStatus); - } - - // @Override - // public Filter getFilter() { - // return mFilter; - // } - - /** - * Get a LayerDrawable containing the avatar and the status icon. The - * status icon will change with the level of the drawable. - * - * @param avatarId - * the avatar id to retrieve or null to get default - * @return a LayerDrawable - */ - // private Drawable getAvatarStatusDrawable(String avatarId) { - // Drawable avatarDrawable = null; - // if (avatarId != null) { - // Uri uri = - // AvatarProvider.CONTENT_URI.buildUpon().appendPath(avatarId).build(); - // InputStream in = null; - // try { - // try { - // in = getContentResolver().openInputStream(uri); - // avatarDrawable = Drawable.createFromStream(in, avatarId); - // } finally { - // if (in != null) - // in.close(); - // } - // } catch (IOException e) { - // Log.w(TAG, "Error while setting the avatar", e); - // } - // } - // if (avatarDrawable == null) - // avatarDrawable = - // getResources().getDrawable(R.drawable.beem_launcher_icon_silver); - // LayerDrawable ld = (LayerDrawable) - // getResources().getDrawable(R.drawable.avatar_status); - // ld.setLayerInset(1, 36, 36, 0, 0); - // ld.setDrawableByLayerId(R.id.avatar, avatarDrawable); - // return ld; - // } - - /** - * 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 result = mListContact; - // if (constraint.length() > 0) { - // result = new LinkedList(); - // 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 contacts = (List) results.values; - // mListContact = contacts; - // notifyDataSetChanged(); - // } - // } - } - - /** - * Adapter banner group list. - */ - private static class BeemBanner extends SimpleCursorAdapter { - - private Context mContext; - private int mLayout; - - public BeemBanner(Context context, int layout, Cursor c, String[] from, - int[] to) { - super(context, layout, c, from, to); - mContext = context; - mLayout = layout; - } - - @Override - public View newView(Context context, Cursor cursor, ViewGroup parent) { - final LayoutInflater inflater = LayoutInflater.from(mContext); - return inflater.inflate(mLayout, parent, false); - } - - @Override - public void bindView(View view, Context context, Cursor cursor) { - String name = cursor.getString(cursor - .getColumnIndex(ContactsContract.Groups.TITLE)); - TextView nameText = (TextView) view - .findViewById(R.id.contactlist_group); - if (nameText != null) { - nameText.setText(name); - } - } - } - - /** - * Comparator Contact by status and name. - */ - private static class ComparatorContactListByStatusAndName implements - Comparator { - /** - * Constructor. - */ - public ComparatorContactListByStatusAndName() { - } - - @Override - public int compare(T c1, T c2) { - if (((Contact) c1).getStatus() < ((Contact) c2).getStatus()) { - return 1; - } else if (((Contact) c1).getStatus() > ((Contact) c2).getStatus()) { - return -1; - } else - return ((Contact) c1).getName().compareToIgnoreCase( - ((Contact) c2).getName()); - } - } - - /** - * Event simple click on item of the contact list. - */ - private class BeemContactListOnClick implements OnItemClickListener { - /** - * Constructor. - */ - public BeemContactListOnClick() { - } - - /** - * {@inheritDoc} - */ - @Override - public void onItemClick(AdapterView arg0, View v, int pos, long lpos) { - String jid = (String) v.getTag(); - Log.i(TAG, "OnClick Jid :" + jid); - Intent i = new Intent(ContactList.this, Chat.class); - i.setData(Uri.parse("imto://jabber/" + jid)); - startActivity(i); - } - } - - /** - * Event simple click on middle group name. - */ - private class OnItemClickGroupName implements OnItemClickListener { - - /** - * Constructor. - */ - public OnItemClickGroupName() { - } - - @Override - public void onItemClick(AdapterView arg0, View v, int i, long l) { - // String group = mListGroup.get(i); - // buildContactList(group); - } - } + } } diff -r c067ee9a604c -r dfbc48b4eae1 src/com/beem/project/beem/ui/Login.java --- a/src/com/beem/project/beem/ui/Login.java Fri Oct 14 18:57:07 2011 +0200 +++ b/src/com/beem/project/beem/ui/Login.java Tue Oct 18 00:37:46 2011 +0200 @@ -46,7 +46,6 @@ import java.util.ArrayList; import java.util.List; -import android.util.Log; import android.accounts.Account; import android.accounts.AccountManager; import android.app.Activity; @@ -67,11 +66,11 @@ import android.view.ViewGroup; import android.view.animation.AnimationUtils; import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; import android.widget.BaseAdapter; import android.widget.ImageButton; import android.widget.ListView; import android.widget.TextView; -import android.widget.AdapterView.OnItemClickListener; import com.beem.project.beem.BeemIntent; import com.beem.project.beem.R; @@ -82,257 +81,256 @@ */ public class Login extends Activity { - private BeemAccountList mAdapterAccountList; - private List mListAccount = new ArrayList(); - private final BeemAccountListOnClick mOnAccountClick = new BeemAccountListOnClick(); - private final BroadcastReceiver mOnBroadcastReceiver = new BeemBroadcastReceiver(); + private BeemAccountList mAdapterAccountList; + private List mListAccount = new ArrayList(); + private final BeemAccountListOnClick mOnAccountClick = new BeemAccountListOnClick(); + private final BroadcastReceiver mOnBroadcastReceiver = new BeemBroadcastReceiver(); + + /** + * Constructor. + */ + public Login() { + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.login); + ListView listView = (ListView) findViewById(R.id.accountlist); + mAdapterAccountList = new BeemAccountList(getLayoutInflater()); + listView.setClickable(true); + listView.setOnItemClickListener(mOnAccountClick); + listView.setAdapter(mAdapterAccountList); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + super.onCreateOptionsMenu(menu); + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.login, menu); + return true; + } + + @Override + public final boolean onOptionsItemSelected(MenuItem item) { + boolean result; + switch (item.getItemId()) { + case R.id.login_menu_settings: + startActivity(new Intent(Login.this, Settings.class)); + result = true; + break; + case R.id.login_menu_about: + createAboutDialog(); + result = true; + break; + case R.id.login_menu_login: + result = true; + break; + default: + result = false; + break; + } + return result; + } + + /** + * Create an about "BEEM" dialog. + */ + private void createAboutDialog() { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + String versionname; + try { + PackageManager pm = getPackageManager(); + PackageInfo pi = pm.getPackageInfo("com.beem.project.beem", 0); + versionname = pi.versionName; + } catch (PackageManager.NameNotFoundException e) { + versionname = ""; + } + String title = getString(R.string.login_about_title, versionname); + builder.setTitle(title).setMessage(R.string.login_about_msg).setCancelable(false); + builder.setNeutralButton(R.string.login_about_button, new DialogInterface.OnClickListener() { + + public void onClick(DialogInterface dialog, int whichButton) { + dialog.cancel(); + } + }); + AlertDialog aboutDialog = builder.create(); + aboutDialog.show(); + } + + /** + * Populate row account. + */ + 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); + } + } + + @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); + } + 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(); + if (hash < 0) + hash = hash * -1; + v.setId(hash); + return v; + } + + } + + /** + * Event simple click on item of the button of account list. + */ + private class BeemConnectionOnClick implements android.view.View.OnClickListener { + private View mView; /** * Constructor. */ - public Login() { + public BeemConnectionOnClick(View v) { + mView = v; + } + + @Override + public void onClick(View v) { + //TODO: Check if already connected -> disconnect + TextView accountStatus = (TextView) mView.findViewById(R.id.accountstatus); + accountStatus.setText(R.string.login_pending); + + ImageButton logo = (ImageButton) mView.findViewById(R.id.loginanim_logo_anim); + logo.startAnimation(AnimationUtils.loadAnimation(mView.getContext(), R.anim.rotate_and_scale)); + + TextView accountName = (TextView) mView.findViewById(R.id.accountname); + Intent intent = new Intent(BeemIntent.ACTION_CONNECT); + intent.putExtra(BeemIntent.EXTRA_ACCOUNT, accountName.getText()); + IntentFilter filter = new IntentFilter(BeemIntent.ACTION_CONNECTED); + filter.addAction(BeemIntent.ACTION_DISCONNECTED); + registerReceiver(mOnBroadcastReceiver, filter); + startService(intent); + } + } + + /** + * Event simple long click on item of the button of account list. + */ + private class BeemConnectionOnLongClick implements android.view.View.OnLongClickListener { + private View mView; + + /** + * Constructor. + */ + public BeemConnectionOnLongClick(View v) { + mView = v; } @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.login); - ListView listView = (ListView) findViewById(R.id.accountlist); - mAdapterAccountList = new BeemAccountList(getLayoutInflater()); - listView.setClickable(true); - listView.setOnItemClickListener(mOnAccountClick); - listView.setAdapter(mAdapterAccountList); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - super.onCreateOptionsMenu(menu); - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.login, menu); - return true; - } + public boolean onLongClick(View v) { + TextView accountName = (TextView) mView.findViewById(R.id.accountname); + Intent i = new Intent(Login.this, ChangeStatus.class); + i.putExtra("beem_account", accountName.getText()); + startActivity(i); + return true; + } + } - @Override - public final boolean onOptionsItemSelected(MenuItem item) { - boolean result; - switch (item.getItemId()) { - case R.id.login_menu_settings: - startActivity(new Intent(Login.this, Settings.class)); - result = true; - break; - case R.id.login_menu_about: - createAboutDialog(); - result = true; - break; - case R.id.login_menu_login: - result = true; - break; - default: - result = false; - break; - } - return result; - } - + /** + * Event simple click on item of the account list. + */ + private class BeemAccountListOnClick implements OnItemClickListener { /** - * Create an about "BEEM" dialog. + * Constructor. */ - private void createAboutDialog() { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - String versionname; - try { - PackageManager pm = getPackageManager(); - PackageInfo pi = pm.getPackageInfo("com.beem.project.beem", 0); - versionname = pi.versionName; - } catch (PackageManager.NameNotFoundException e) { - versionname = ""; - } - String title = getString(R.string.login_about_title, versionname); - builder.setTitle(title).setMessage(R.string.login_about_msg).setCancelable(false); - builder.setNeutralButton(R.string.login_about_button, new DialogInterface.OnClickListener() { - - public void onClick(DialogInterface dialog, int whichButton) { - dialog.cancel(); - } - }); - AlertDialog aboutDialog = builder.create(); - aboutDialog.show(); + public BeemAccountListOnClick() { } /** - * Populate row account. + * {@inheritDoc} */ - 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); - } - } - - @Override - public int getCount() { - return mListAccount.size(); - } + @Override + public void onItemClick(AdapterView arg0, View v, int pos, long lpos) { + Intent i = new Intent(Login.this, ContactList.class); + TextView accountName = (TextView) v.findViewById(R.id.accountname); + i.putExtra(BeemIntent.EXTRA_ACCOUNT, accountName.getText()); + startActivity(i); + } + } - @Override - public Object getItem(int position) { - return mListAccount.get(position); - } - - @Override - public long getItemId(int position) { - return position; - } + /** + * Event receive from service. + */ + private class BeemBroadcastReceiver extends BroadcastReceiver { - @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); - } - 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(); - if (hash < 0) - hash = hash * -1; - v.setId(hash); - return v; - } + /** + * Constructor. + */ + public BeemBroadcastReceiver() { } /** - * Event simple click on item of the button of account list. + * {@inheritDoc} */ - private class BeemConnectionOnClick implements android.view.View.OnClickListener { - private View mView; + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + String account = intent.getExtras().getString(BeemIntent.EXTRA_ACCOUNT); + int hash = account.hashCode(); + if (hash < 0) + hash = hash * -1; - /** - * Constructor. - */ - public BeemConnectionOnClick(View v) { - mView = v; - } - - @Override - public void onClick(View v) { - //TODO: Check if already connected -> disconnect - TextView accountStatus = (TextView) mView.findViewById(R.id.accountstatus); - accountStatus.setText(R.string.login_pending); - - ImageButton logo = (ImageButton) mView.findViewById(R.id.loginanim_logo_anim); - logo.startAnimation(AnimationUtils.loadAnimation(mView.getContext(), R.anim.rotate_and_scale)); + View v = findViewById(hash); + TextView text = (TextView) v.findViewById(R.id.accountstatus); + ImageButton logo = (ImageButton) v.findViewById(R.id.loginanim_logo_anim); - TextView accountName = (TextView) mView.findViewById(R.id.accountname); - Intent intent = new Intent(BeemIntent.ACTION_CONNECT); - intent.putExtra(BeemIntent.EXTRA_ACCOUNT, accountName.getText()); - IntentFilter filter = new IntentFilter(BeemIntent.ACTION_CONNECTED); - filter.addAction(BeemIntent.ACTION_DISCONNECTED); - registerReceiver(mOnBroadcastReceiver, filter); - startService(intent); - } - } - - /** - * Event simple long click on item of the button of account list. - */ - private class BeemConnectionOnLongClick implements android.view.View.OnLongClickListener { - private View mView; - - /** - * Constructor. - */ - public BeemConnectionOnLongClick(View v) { - mView = v; + if (BeemIntent.ACTION_CONNECTED.equals(action)) { + if (text != null) + text.setText(R.string.contact_status_msg_available); + if (logo != null) { + logo.setImageResource(R.drawable.beem_launcher_icon_color); + logo.clearAnimation(); } - - @Override - public boolean onLongClick(View v) { - TextView accountName = (TextView) mView.findViewById(R.id.accountname); - Intent i = new Intent(Login.this, ChangeStatus.class); - i.putExtra("beem_account", accountName.getText()); - startActivity(i); - return true; - } + } else if (BeemIntent.ACTION_DISCONNECTED.equals(action)) { + String message = intent.getExtras().getString(BeemIntent.EXTRA_MESSAGE); + if (text != null) + text.setText(message); + if (logo != null) { + logo.setImageResource(R.drawable.beem_launcher_icon_silver); + logo.clearAnimation(); + } + } } - - /** - * Event simple click on item of the account 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, ContactList.class); - TextView accountName = (TextView) v.findViewById(R.id.accountname); - i.putExtra(BeemIntent.EXTRA_ACCOUNT, accountName.getText()); - startActivity(i); - } - } - - /** - * Event receive from service. - */ - private class BeemBroadcastReceiver extends BroadcastReceiver { - - /** - * Constructor. - */ - public BeemBroadcastReceiver() { - - } - - /** - * {@inheritDoc} - */ - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - String account = intent.getExtras().getString(BeemIntent.EXTRA_ACCOUNT); - int hash = account.hashCode(); - if (hash < 0) - hash = hash * -1; - - View v = findViewById(hash); - TextView text = (TextView) v.findViewById(R.id.accountstatus); - ImageButton logo = (ImageButton) v.findViewById(R.id.loginanim_logo_anim); - - if (BeemIntent.ACTION_CONNECTED.equals(action)) { - if (text != null) - text.setText(R.string.contact_status_msg_available); - if (logo != null) { - logo.setImageResource(R.drawable.beem_launcher_icon_color); - logo.clearAnimation(); - } - } else if (BeemIntent.ACTION_DISCONNECTED.equals(action)) { - String message = intent.getExtras().getString(BeemIntent.EXTRA_MESSAGE); - if (text != null) - text.setText(message); - if (logo != null) { - logo.setImageResource(R.drawable.beem_launcher_icon_silver); - logo.clearAnimation(); - } - } - } - - } + } }