Recode Classes of the connection.
Add some beem status icons.
+ A lot of things i don't remember :)
--- a/AndroidManifest.xml Sun May 06 12:28:38 2012 +0200
+++ b/AndroidManifest.xml Mon Jul 16 11:43:10 2012 +0200
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.beem.project.beem"
- android:versionCode="7"
- android:versionName="0.1.5" >
+ android:versionCode="-1"
+ android:versionName="0.2.0" >
<application
android:name=".BeemApplication"
@@ -139,7 +139,7 @@
</intent-filter>
</activity>
<activity
- android:name="com.beem.project.beem.account.ManageAccountsSettings"
+ android:name=".account.ManageAccountsSettings"
android:label="Sync Settings" >
</activity>
<!--
@@ -191,7 +191,7 @@
android:resource="@xml/contacts" />
</service>
<service
- android:name="BeemService"
+ android:name=".BeemService"
android:enabled="true"
android:label="Beem Service"
android:permission="com.beem.project.beem.BEEM_SERVICE" >
Binary file libs/asmack-android-7-beem.jar has changed
Binary file res/drawable/beem_status_icon_available.png has changed
Binary file res/drawable/beem_status_icon_away.png has changed
Binary file res/drawable/beem_status_icon_busy.png has changed
Binary file res/drawable/beem_status_icon_chat.png has changed
Binary file res/drawable/beem_status_icon_gray.png has changed
Binary file res/drawable/beem_status_icon_offline.png has changed
--- a/res/layout/login_anim.xml Sun May 06 12:28:38 2012 +0200
+++ b/res/layout/login_anim.xml Mon Jul 16 11:43:10 2012 +0200
@@ -3,8 +3,8 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:orientation="vertical">
- <ImageView android:id="@+id/loginanim_logo_anim" android:src="@drawable/beem_icon_launcher_color"
- android:layout_height="wrap_content" android:layout_width="wrap_content"
+ <ImageView android:id="@+id/loginanim_logo_anim" android:src="@drawable/beem_status_icon_offline"
+ android:layout_height="0dip" android:layout_width="wrap_content"
android:layout_gravity="center_vertical|center_horizontal|center"
android:layout_weight="1" />
<TextView android:id="@+id/loginanim_status_text"
--- a/res/layout/login_row_account.xml Sun May 06 12:28:38 2012 +0200
+++ b/res/layout/login_row_account.xml Mon Jul 16 11:43:10 2012 +0200
@@ -13,7 +13,7 @@
android:layout_height="48dip"
android:layout_gravity="center_vertical|center_horizontal|center"
android:layout_weight="1"
- android:background="@drawable/beem_launcher_icon_silver"
+ android:background="@android:color/transparent"
android:onClick="BeemConnectionOnClick" />
<TextView
android:id="@+id/accountname"
--- a/res/layout/notification.xml Sun May 06 12:28:38 2012 +0200
+++ b/res/layout/notification.xml Mon Jul 16 11:43:10 2012 +0200
@@ -1,28 +1,31 @@
-<RelativeLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/layout"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:padding="10dp">
- <ImageButton
- android:id="@+id/status"
- android:background="@drawable/beem_launcher_icon_silver"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:layout_alignParentLeft="true"
- android:layout_marginRight="10dp" />
- <TextView
- android:id="@+id/pseudo"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toRightOf="@id/status"
- style="@style/NotificationTitle" />
- <TextView
- android:id="@+id/msgstatus"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toRightOf="@id/status"
- android:layout_below="@id/pseudo"
- style="@style/NotificationText" />
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/layout"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:padding="10dp" >
+
+ <ImageButton
+ android:id="@+id/status"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true"
+ android:layout_centerVertical="true"
+ android:layout_marginRight="10dp"
+ android:background="@drawable/beem_launcher_icon_silver" />
+
+ <TextView
+ android:id="@+id/pseudo"
+ style="@style/NotificationTitle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_toRightOf="@id/status" />
+
+ <TextView
+ android:id="@+id/msgstatus"
+ style="@style/NotificationText"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/pseudo"
+ android:layout_toRightOf="@id/status" />
+
</RelativeLayout>
\ No newline at end of file
--- a/res/layout/preferences.xml Sun May 06 12:28:38 2012 +0200
+++ b/res/layout/preferences.xml Mon Jul 16 11:43:10 2012 +0200
@@ -70,12 +70,19 @@
<PreferenceScreen
android:title="@string/notification_preferences">
<CheckBoxPreference
+ android:title="@string/notification_enable"
+ android:defaultValue="false"
+ android:summary="@string/notification_enable_sum"
+ android:key="notification_enable" />
+ <CheckBoxPreference
android:title="@string/notification_enable_vibrate_title"
+ android:dependency="notification_enable"
android:defaultValue="false"
android:summary="@string/notification_enable_vibrate_sum"
android:key="notification_vibrate" />
<RingtonePreference
android:title="@string/notification_snd_title"
+ android:dependency="notification_enable"
android:key="notification_sound"
android:summary="@string/notification_snd_sum"
android:ringtoneType="notification"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/res/menu/contactlistmuc_context.xml Mon Jul 16 11:43:10 2012 +0200
@@ -0,0 +1,13 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android" >
+
+ <item
+ android:id="@+id/contact_list_context_menu_chat_item"
+ android:title="@string/CDChat">
+ <menu>
+ </menu>
+ </item>
+ <item
+ android:id="@+id/contact_list_context_menu_userinfo_delete"
+ android:title="@string/userinfo_label_delete"/>
+
+</menu>
\ No newline at end of file
--- a/res/values/arrays.xml Sun May 06 12:28:38 2012 +0200
+++ b/res/values/arrays.xml Mon Jul 16 11:43:10 2012 +0200
@@ -6,12 +6,12 @@
<item>SOCKS5</item>
</string-array>
<string-array name="status_types">
- <item name="AvailableForChat">@string/contact_status_msg_available_chat</item>
- <item name="Available">@string/contact_status_msg_available</item>
- <item name="Busy">@string/contact_status_msg_dnd</item>
- <item name="Away">@string/contact_status_msg_away</item>
- <item name="Unavailable">@string/contact_status_msg_xa</item>
- <item name="Disconnected">@string/contact_status_msg_offline</item>
+ <item value="600" name="600">@string/contact_status_msg_available_chat</item>
+ <item value="500" name="500">@string/contact_status_msg_available</item>
+ <item value="400" name="400">@string/contact_status_msg_dnd</item>
+ <item value="300" name="300">@string/contact_status_msg_away</item>
+ <item value="200" name="200">@string/contact_status_msg_xa</item>
+ <item value="100" name="100">@string/contact_status_msg_offline</item>
</string-array>
<string-array name="privacy_list_select_dialog">
<item name="@string/privacy_list_select_dialog_buddies">Buddies</item>
--- a/res/values/strings.xml Sun May 06 12:28:38 2012 +0200
+++ b/res/values/strings.xml Mon Jul 16 11:43:10 2012 +0200
@@ -124,6 +124,8 @@
<string name="away_message_sum">The away message that will be displayed</string>
<string name="away_message_hint">I\'m away, my cellphone screen is off</string>
<string name="notification_preferences">Notification settings</string>
+ <string name="notification_enable">Enable notification</string>
+ <string name="notification_enable_sum">Show highlight for this account on the notification bar</string>
<string name="notification_enable_vibrate_title">Enable vibrate</string>
<string name="notification_enable_vibrate_sum">Enable vibrate on incoming messages</string>
<string name="notification_snd_title">Message ringtone</string>
--- a/src/com/beem/project/beem/BeemApplication.java Sun May 06 12:28:38 2012 +0200
+++ b/src/com/beem/project/beem/BeemApplication.java Mon Jul 16 11:43:10 2012 +0200
@@ -40,7 +40,7 @@
Flavien Astraud, November 26, 2009
Head of the EIP Laboratory.
-*/
+ */
package com.beem.project.beem;
@@ -49,15 +49,14 @@
import android.preference.PreferenceManager;
/**
- * This class contains informations that needs to be global in the application.
- * Theses informations must be necessary for the activities and the service.
+ * This class contains informations that needs to be global in the application. Theses informations must be necessary
+ * for the activities and the service.
* @author Da Risk <darisk972@gmail.com>
*/
public class BeemApplication extends Application {
- /* Constants for PREFERENCE_KEY
- * The format of the Preference key is :
- * $name_KEY = "$name"
+ /*
+ * Constants for PREFERENCE_KEY The format of the Preference key is : $name_KEY = "$name"
*/
/** Preference key for account username. */
public static final String ACCOUNT_USERNAME_KEY = "account_username";
@@ -65,6 +64,8 @@
public static final String ACCOUNT_PASSWORD_KEY = "account_password";
/** Preference key for status (available, busy, away, ...). */
public static final String STATUS_KEY = "status";
+ /** Preference key for resource */
+ public static final String RESOURCE_KEY = "settings_key_resource";
/** Preference key for status message. */
public static final String STATUS_TEXT_KEY = "status_text";
/** Preference key for the use of a proxy. */
@@ -79,6 +80,8 @@
public static final String PROXY_USERNAME_KEY = "proxy_username";
/** Preference key for the proxy password. */
public static final String PROXY_PASSWORD_KEY = "proxy_password";
+ /** Preference key for enable notification. */
+ public static final String NOTIFICATION_ENABLE_KEY = "notification_enable";
/** Preference key for vibrate on notification. */
public static final String NOTIFICATION_VIBRATE_KEY = "notification_vibrate";
/** Preference key for notification sound. */
@@ -93,12 +96,18 @@
//TODO add the other one
// String not use for reference but all around the application
public static final String BEEM_PACKAGE = "com.beem.project.beem";
-
+
// String for the contact list
- public static final String ALL_CONTACT= "all_contact";
+ public static final String ALL_CONTACT = "all_contact";
public static final String NO_GROUP = "no_group";
public static final String MUC = "muc";
+ // String for the MUCs - AddMuc
+ public static final String MUC_NAME = "muc_name";
+ public static final String MUC_NICKNAME = "muc_nickname";
+ public static final String MUC_PASSWORD = "muc_password";
+ public static final String MUC_AUTOJOIN = "muc_autojoin";
+
private boolean mIsConnected;
private boolean mIsAccountConfigured;
private SharedPreferences mSettings;
@@ -163,7 +172,7 @@
}
@Override
- public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (BeemApplication.ACCOUNT_USERNAME_KEY.equals(key) || BeemApplication.ACCOUNT_PASSWORD_KEY.equals(key)) {
String login = mSettings.getString(BeemApplication.ACCOUNT_USERNAME_KEY, "");
String password = mSettings.getString(BeemApplication.ACCOUNT_PASSWORD_KEY, "");
--- a/src/com/beem/project/beem/BeemConnection.java Sun May 06 12:28:38 2012 +0200
+++ b/src/com/beem/project/beem/BeemConnection.java Mon Jul 16 11:43:10 2012 +0200
@@ -1,224 +1,334 @@
-/*
- BEEM is a videoconference application on the Android Platform.
-
- Copyright (C) 2009 by Frederic-Charles Barthelery,
- Jean-Manuel Da Silva,
- Nikita Kozlov,
- Philippe Lago,
- Jean Baptiste Vergely,
- Vincent Veronis.
-
- This file is part of BEEM.
-
- BEEM is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- BEEM is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with BEEM. If not, see <http://www.gnu.org/licenses/>.
-
- Please send bug reports with examples or suggestions to
- contact@beem-project.com or http://dev.beem-project.com/
-
- Epitech, hereby disclaims all copyright interest in the program "Beem"
- written by Frederic-Charles Barthelery,
- Jean-Manuel Da Silva,
- Nikita Kozlov,
- Philippe Lago,
- Jean Baptiste Vergely,
- Vincent Veronis.
-
- Nicolas Sadirac, November 26, 2009
- President of Epitech.
-
- Flavien Astraud, November 26, 2009
- Head of the EIP Laboratory.
-
- */
-
-package com.beem.project.beem;
-
-import org.jivesoftware.smack.ConnectionConfiguration;
-
-import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
-import org.jivesoftware.smack.proxy.ProxyInfo;
-import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType;
-import org.jivesoftware.smack.util.StringUtils;
-
-import com.beem.project.beem.BeemService.BeemServicePreferenceListener;
-
-import android.content.SharedPreferences;
-
-/**
- * Class for connection informations
- * @author marseille
- */
-public class BeemConnection {
-
- private static final int DEFAULT_XMPP_PORT = 5222;
-
- private String mLogin;
- private String mJid;
- private String mPassword;
- private String mHost;
- private String mService;
- private int mPort;
- private ConnectionConfiguration mConnectionConfiguration;
- private ProxyInfo mProxyInfo;
- private boolean mUseProxy;
-
- private SharedPreferences mSettings;
- private BeemServicePreferenceListener mPreferenceListener;
-
- /**
- * Constructor.
- */
- public BeemConnection(SharedPreferences settings, BeemServicePreferenceListener preferenceListener) {
- mSettings = settings;
- mPreferenceListener = preferenceListener;
-
- mJid = mSettings.getString(BeemApplication.ACCOUNT_USERNAME_KEY, "");
- mLogin = StringUtils.parseName(mJid);
- mPassword = mSettings.getString(BeemApplication.ACCOUNT_PASSWORD_KEY, "");
- mPort = DEFAULT_XMPP_PORT;
- mService = StringUtils.parseServer(mJid);
- mHost = mService;
-
- if (mSettings.getBoolean("settings_key_specific_server", false)) {
- mHost = mSettings.getString("settings_key_xmpp_server", "");
- if ("".equals(mHost))
- mHost = mService;
- String tmpPort = mSettings.getString("settings_key_xmpp_port", "5222");
- mPort = ("".equals(tmpPort)) ? DEFAULT_XMPP_PORT : Integer.parseInt(tmpPort);
- }
- if (mSettings.getBoolean(BeemApplication.FULL_JID_LOGIN_KEY, false) || "gmail.com".equals(mService)
- || "googlemail.com".equals(mService)) {
- mLogin = mJid;
- }
- initConnectionConfig();
-
- mSettings.registerOnSharedPreferenceChangeListener(mPreferenceListener);
-
- }
-
- /**
- * Initialize the connection.
- */
- private void initConnectionConfig() {
- mUseProxy = mSettings.getBoolean(BeemApplication.PROXY_USE_KEY, false);
- if (mUseProxy) {
- String stype = mSettings.getString(BeemApplication.PROXY_TYPE_KEY, "HTTP");
- String phost = mSettings.getString(BeemApplication.PROXY_SERVER_KEY, "");
- String puser = mSettings.getString(BeemApplication.PROXY_USERNAME_KEY, "");
- String ppass = mSettings.getString(BeemApplication.PROXY_PASSWORD_KEY, "");
- int pport = Integer.parseInt(mSettings.getString(BeemApplication.PROXY_PORT_KEY, "1080"));
- ProxyInfo.ProxyType type = ProxyType.valueOf(stype);
- mProxyInfo = new ProxyInfo(type, phost, pport, puser, ppass);
- } else {
- mProxyInfo = ProxyInfo.forNoProxy();
- }
- if (mSettings.getBoolean("settings_key_specific_server", false))
- mConnectionConfiguration = new ConnectionConfiguration(mHost, mPort, mService, mProxyInfo);
- else
- mConnectionConfiguration = new ConnectionConfiguration(mService, mProxyInfo);
-
- if (mSettings.getBoolean("settings_key_xmpp_tls_use", false)
- || mSettings.getBoolean("settings_key_gmail", false)) {
- mConnectionConfiguration.setSecurityMode(SecurityMode.required);
- }
- if (mSettings.getBoolean(BeemApplication.SMACK_DEBUG_KEY, false))
- mConnectionConfiguration.setDebuggerEnabled(true);
- mConnectionConfiguration.setSendPresence(true);
- // maybe not the universal path, but it works on most devices (Samsung Galaxy, Google Nexus One)
- mConnectionConfiguration.setTruststoreType("BKS");
- mConnectionConfiguration.setTruststorePath("/system/etc/security/cacerts.bks");
- }
-
- protected void finalize() {
- mSettings.unregisterOnSharedPreferenceChangeListener(mPreferenceListener);
- }
-
- /**
- * Don't send presence ex. SyncAdapter.
- */
- public void setNoPresence() {
- mConnectionConfiguration.setSendPresence(false);
- }
-
- /**
- * @return the login
- */
- public String getLogin() {
- return mLogin;
- }
-
- /**
- * @param login the login to set
- */
- public void setLogin(String login) {
- this.mLogin = login;
- }
-
- /**
- * @return the connectionConfiguration
- */
- public ConnectionConfiguration getConnectionConfiguration() {
- return mConnectionConfiguration;
- }
-
- /**
- * @param connectionConfiguration the connectionConfiguration to set
- */
- public void setConnectionConfiguration(ConnectionConfiguration connectionConfiguration) {
- this.mConnectionConfiguration = connectionConfiguration;
- }
-
- /**
- * @return the password
- */
- public String getPassword() {
- return mPassword;
- }
-
- /**
- * @param password the password to set
- */
- public void setPassword(String password) {
- this.mPassword = password;
- }
-
- /**
- * @return the settings
- */
- public SharedPreferences getSettings() {
- return mSettings;
- }
-
- /**
- * @param settings the settings to set
- */
- public void setSettings(SharedPreferences settings) {
- this.mSettings = settings;
- }
-
- /**
- * @return the jid
- */
- public String getJid() {
- return mJid;
- }
-
- /**
- * @param jid the jid to set
- */
- public void setJid(String jid) {
- this.mJid = jid;
- }
-
-}
+/*
+ BEEM is a videoconference application on the Android Platform.
+
+ Copyright (C) 2009 by Frederic-Charles Barthelery,
+ Jean-Manuel Da Silva,
+ Nikita Kozlov,
+ Philippe Lago,
+ Jean Baptiste Vergely,
+ Vincent Veronis.
+
+ This file is part of BEEM.
+
+ BEEM is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ BEEM is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with BEEM. If not, see <http://www.gnu.org/licenses/>.
+
+ Please send bug reports with examples or suggestions to
+ contact@beem-project.com or http://dev.beem-project.com/
+
+ */
+
+package com.beem.project.beem;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.jivesoftware.smack.Roster;
+import org.jivesoftware.smack.SmackConfiguration;
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smack.XMPPException;
+import org.jivesoftware.smack.filter.PacketFilter;
+import org.jivesoftware.smack.packet.Message;
+import org.jivesoftware.smack.packet.Packet;
+import org.jivesoftware.smack.packet.Presence;
+import org.jivesoftware.smackx.XmppStreamHandler;
+import org.jivesoftware.smackx.bookmark.BookmarkManager;
+import org.jivesoftware.smackx.muc.DiscussionHistory;
+import org.jivesoftware.smackx.muc.MultiUserChat;
+
+import android.content.BroadcastReceiver;
+import android.content.ContentValues;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.database.Cursor;
+import android.os.Bundle;
+import android.util.Log;
+
+import com.beem.project.beem.providers.MUCs;
+import com.beem.project.beem.providers.Messages;
+import com.beem.project.beem.utils.Status;
+
+/**
+ * Connection.
+ * @author marseille
+ */
+public class BeemConnection {
+
+ private static final String TAG = BeemConnection.class.getName();
+
+ private static final int SMACK_PRIORITY_MIN = -128;
+ private static final int SMACK_PRIORITY_MAX = 128;
+
+ private final Context mContext;
+ private final XMPPConnection mXMPPConnection;
+ private final SharedPreferences mSharedPreferences;
+ private final BeemServiceBroadcastReceiver mOnOffReceiver = new BeemServiceBroadcastReceiver();
+ private final BeemInfoConnection mInfoConnection;
+
+ private XmppStreamHandler mStreamHandler;
+ private String mErrorMsg;
+
+ private String mPreviousStatus;
+
+ private int mPreviousMode;
+
+ private int mPreviousPriority;
+
+ /**
+ * Constructor.
+ */
+ BeemConnection(Context c, String accountName) {
+ mContext = c;
+ mSharedPreferences = c.getSharedPreferences(accountName, BeemService.MODE_PRIVATE);
+ mInfoConnection = new BeemInfoConnection(mSharedPreferences);
+ mXMPPConnection = new XMPPConnection(mInfoConnection.getConnectionConfiguration());
+ }
+
+ public void finalize() {
+ mXMPPConnection.disconnect();
+ editSharedPreferences(BeemApplication.STATUS_KEY, Status.CONTACT_STATUS_DISCONNECT);
+ }
+
+ public final boolean connect() {
+ try {
+ mXMPPConnection.connect();
+ mXMPPConnection.login(mInfoConnection.getLogin(), mInfoConnection.getPassword(),
+ mInfoConnection.getResource());
+ } catch (XMPPException e) {
+ setErrorMessage(e, "Error while connecting");
+ return false;
+ }
+ mStreamHandler = new XmppStreamHandler(mXMPPConnection);
+ mStreamHandler.notifyInitialLogin();
+ mXMPPConnection.addPacketListener(new BeemPacketListener(mContext, mXMPPConnection), new BeemPacketFilter());
+ return true;
+ }
+
+ public void handleXMPPMessage(String accountName, android.os.Message msg) {
+
+ Bundle b = (Bundle) msg.obj;
+ String to = b.getString(BeemIntent.EXTRA_JID);
+ String body = b.getString(BeemIntent.EXTRA_MESSAGE);
+
+ Message send = new Message();
+ send.setFrom(accountName);
+ send.setThread(""); //TODO: set ThreadID
+ send.setTo(to);
+ send.setBody(body);
+ send.setType(Message.Type.chat);
+ // TODO gerer les messages contenant des XMPPError
+ try {
+ mXMPPConnection.sendPacket(send);
+ } catch (IllegalStateException e) {
+ Log.e(TAG, "Message not send", e);
+ return;
+ }
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ ContentValues values = new ContentValues();
+ values.put(Messages.FROM, accountName);
+ values.put(Messages.MESSAGE_ID, "message id");
+ values.put(Messages.TO, to);
+ values.put(Messages.TYPE, Message.Type.chat.toString());
+ values.put(Messages.SUBJECT, "SUBJECT");
+ values.put(Messages.BODY, body);
+ values.put(Messages.THREAD, "");
+ values.put(Messages.EXTRAS, "");
+ values.put(Messages.IS_RECEIVE, true);
+ values.put(Messages.DATE_RECEIVE, dateFormat.format(new Date()));
+ values.put(Messages.DATE_READ, dateFormat.format(new Date()));
+ mContext.getContentResolver().insert(Messages.CONTENT_URI, values);
+
+ }
+
+ /**
+ * 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<String, XmppConnectionAdapter> 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);
+ // }
+ // }
+ }
+ }
+
+ public void syncRoster() {
+ BeemSync sync = new BeemSync(mContext);
+ sync.manageRoster(mXMPPConnection.getRoster(), mInfoConnection.getJid());
+ sync.syncMUC(mXMPPConnection, mInfoConnection.getJid());
+ }
+
+ private void setErrorMessage(XMPPException e, String errorMsg) {
+ Log.e(TAG, errorMsg, e);
+ if (e.getXMPPError() != null) {
+ String condition = e.getXMPPError().getCondition();
+ String message = e.getXMPPError().getMessage();
+ mErrorMsg = condition + " " + message;
+ } else if (e.getMessage() != null) {
+ mErrorMsg = e.getMessage();
+ } else {
+ mErrorMsg = e.toString();
+ }
+ }
+
+ public String getErrorMessage() {
+ return mErrorMsg;
+ }
+
+ //TODO: useless here, delete from this class
+ public void editSharedPreferences(String key, String value) {
+ SharedPreferences settings = mContext.getSharedPreferences(mInfoConnection.getJid(), Context.MODE_PRIVATE);
+ SharedPreferences.Editor prefEditor = settings.edit();
+ prefEditor.putString(key, value);
+ prefEditor.commit();
+ }
+
+ //TODO: useless here, delete from this class
+ public void editSharedPreferences(String key, int value) {
+ SharedPreferences settings = mContext.getSharedPreferences(mInfoConnection.getJid(), Context.MODE_PRIVATE);
+ SharedPreferences.Editor prefEditor = settings.edit();
+ prefEditor.putInt(key, value);
+ prefEditor.commit();
+ }
+
+ public boolean addContact(String jid) {
+
+ Roster r = mXMPPConnection.getRoster();
+ if (r == null) {
+ Log.w(TAG, "Has not logged in yet : " + jid);
+ mErrorMsg = "Has not logged in yet : " + jid;
+ return false;
+ }
+ try {
+ r.createEntry(jid, jid, null);
+ } catch (XMPPException e) {
+ setErrorMessage(e, "Problem during add contact");
+ return false;
+ }
+ return true;
+ }
+
+ public boolean mucJoin(String mucjid) {
+ MultiUserChat muc = new MultiUserChat(mXMPPConnection, mucjid);
+
+ DiscussionHistory history = new DiscussionHistory();
+ history.setMaxStanzas(5);
+ Cursor c = mContext.getContentResolver().query(MUCs.CONTENT_URI, new String[] { MUCs.NICKNAME, MUCs.PASSWORD },
+ MUCs.ACCOUNT_NAME + "=? AND " + MUCs.ACCOUNT_TYPE + "=? AND " + MUCs.JID + "=?",
+ new String[] { mInfoConnection.getJid(), BeemApplication.BEEM_PACKAGE, mucjid }, null);
+ if (c.moveToFirst()) {
+ try {
+ muc.join(c.getString(c.getColumnIndex(MUCs.NICKNAME)), c.getString(c.getColumnIndex(MUCs.PASSWORD)),
+ history, SmackConfiguration.getPacketReplyTimeout());
+ } catch (XMPPException e) {
+ setErrorMessage(e, "MUC Join Problem");
+ return false;
+ }
+ return true;
+ } // else TODO: join directly
+
+ return false;
+
+ }
+
+ public void changeStatus(int status, String msg, int priority) {
+ Presence pres = new Presence(Presence.Type.available);
+ //Change status
+ Presence.Mode mode = Status.getPresenceModeFromStatus(status);
+ int m;
+ if (mode != null) {
+ m = status;
+ } else {
+ m = mPreviousMode;
+ }
+ pres.setMode(Status.getPresenceModeFromStatus(m));
+ mPreviousMode = m;
+ // Change status message
+ String smode;
+ if (msg != null)
+ smode = msg;
+ else
+ smode = mPreviousStatus;
+ pres.setStatus(smode);
+ mPreviousStatus = smode;
+ // Change priority
+ int p = priority;
+ if (priority < SMACK_PRIORITY_MIN)
+ p = SMACK_PRIORITY_MIN;
+ if (priority > SMACK_PRIORITY_MAX)
+ p = SMACK_PRIORITY_MAX;
+ mPreviousPriority = p;
+ pres.setPriority(p);
+ mXMPPConnection.sendPacket(pres);
+ editSharedPreferences(BeemApplication.STATUS_KEY, status);
+ editSharedPreferences(BeemApplication.STATUS_TEXT_KEY, msg);
+ }
+
+ public boolean mucSendMsg(String jid, String msg) {
+ MultiUserChat mucmsg = new MultiUserChat(mXMPPConnection, jid);
+ try {
+ mucmsg.sendMessage(msg);
+ } catch (XMPPException e) {
+ setErrorMessage(e, "MUC Error send message");
+ return false;
+ }
+ return true;
+ }
+
+ public void mucAdd(String jid, Bundle extra) {
+ String mucName = extra.getString(BeemApplication.MUC_NAME);
+ String mucNickname = extra.getString(BeemApplication.MUC_NICKNAME);
+ String mucPassword = extra.getString(BeemApplication.MUC_PASSWORD);
+ boolean mucAutojoin = extra.getBoolean(BeemApplication.MUC_AUTOJOIN);
+ BookmarkManager bm;
+ try {
+ bm = BookmarkManager.getBookmarkManager(mXMPPConnection);
+ bm.addBookmarkedConference(mucName, jid, mucAutojoin, mucNickname, mucPassword);
+ } catch (XMPPException e) {
+ Log.e(TAG, "Error add muc", e);
+ }
+ }
+
+ private class BeemPacketFilter implements PacketFilter {
+
+ @Override
+ public boolean accept(Packet packet) {
+ return true;
+ }
+
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/BeemInfoConnection.java Mon Jul 16 11:43:10 2012 +0200
@@ -0,0 +1,229 @@
+/*
+ BEEM is a videoconference application on the Android Platform.
+
+ Copyright (C) 2009 by Frederic-Charles Barthelery,
+ Jean-Manuel Da Silva,
+ Nikita Kozlov,
+ Philippe Lago,
+ Jean Baptiste Vergely,
+ Vincent Veronis.
+
+ This file is part of BEEM.
+
+ BEEM is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ BEEM is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with BEEM. If not, see <http://www.gnu.org/licenses/>.
+
+ Please send bug reports with examples or suggestions to
+ contact@beem-project.com or http://dev.beem-project.com/
+
+ Epitech, hereby disclaims all copyright interest in the program "Beem"
+ written by Frederic-Charles Barthelery,
+ Jean-Manuel Da Silva,
+ Nikita Kozlov,
+ Philippe Lago,
+ Jean Baptiste Vergely,
+ Vincent Veronis.
+
+ Nicolas Sadirac, November 26, 2009
+ President of Epitech.
+
+ Flavien Astraud, November 26, 2009
+ Head of the EIP Laboratory.
+
+ */
+
+package com.beem.project.beem;
+
+import org.jivesoftware.smack.ConnectionConfiguration;
+
+import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
+import org.jivesoftware.smack.proxy.ProxyInfo;
+import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType;
+import org.jivesoftware.smack.util.StringUtils;
+
+import android.content.SharedPreferences;
+
+/**
+ * Class for connection informations
+ * @author marseille
+ */
+public class BeemInfoConnection {
+
+ private static final int DEFAULT_XMPP_PORT = 5222;
+
+ private String mLogin;
+ private String mJid;
+ private String mPassword;
+ private String mHost;
+ private String mService;
+ private String mResource;
+ private int mPort;
+ private ConnectionConfiguration mConnectionConfiguration;
+ private ProxyInfo mProxyInfo;
+ private boolean mUseProxy;
+
+ private SharedPreferences mSettings;
+
+ /**
+ * Constructor.
+ */
+ public BeemInfoConnection(SharedPreferences settings) {
+ mSettings = settings;
+
+ mJid = mSettings.getString(BeemApplication.ACCOUNT_USERNAME_KEY, "");
+ mLogin = StringUtils.parseName(mJid);
+ mPassword = mSettings.getString(BeemApplication.ACCOUNT_PASSWORD_KEY, "");
+ mPort = DEFAULT_XMPP_PORT;
+ mService = StringUtils.parseServer(mJid);
+ mHost = mService;
+ mResource = mSettings.getString(BeemApplication.RESOURCE_KEY, "BEEM");
+
+ if (mSettings.getBoolean("settings_key_specific_server", false)) {
+ mHost = mSettings.getString("settings_key_xmpp_server", "");
+ if ("".equals(mHost))
+ mHost = mService;
+ String tmpPort = mSettings.getString("settings_key_xmpp_port", "5222");
+ mPort = ("".equals(tmpPort)) ? DEFAULT_XMPP_PORT : Integer.parseInt(tmpPort);
+ }
+ if (mSettings.getBoolean(BeemApplication.FULL_JID_LOGIN_KEY, false) || "gmail.com".equals(mService)
+ || "googlemail.com".equals(mService)) {
+ mLogin = mJid;
+ }
+ initConnectionConfig();
+
+ }
+
+ /**
+ * Initialize the connection.
+ */
+ private void initConnectionConfig() {
+ mUseProxy = mSettings.getBoolean(BeemApplication.PROXY_USE_KEY, false);
+ if (mUseProxy) {
+ String stype = mSettings.getString(BeemApplication.PROXY_TYPE_KEY, "HTTP");
+ String phost = mSettings.getString(BeemApplication.PROXY_SERVER_KEY, "");
+ String puser = mSettings.getString(BeemApplication.PROXY_USERNAME_KEY, "");
+ String ppass = mSettings.getString(BeemApplication.PROXY_PASSWORD_KEY, "");
+ int pport = Integer.parseInt(mSettings.getString(BeemApplication.PROXY_PORT_KEY, "1080"));
+ ProxyInfo.ProxyType type = ProxyType.valueOf(stype);
+ mProxyInfo = new ProxyInfo(type, phost, pport, puser, ppass);
+ } else {
+ mProxyInfo = ProxyInfo.forNoProxy();
+ }
+ if (mSettings.getBoolean("settings_key_specific_server", false))
+ mConnectionConfiguration = new ConnectionConfiguration(mHost, mPort, mService, mProxyInfo);
+ else
+ mConnectionConfiguration = new ConnectionConfiguration(mService, mProxyInfo);
+
+ if (mSettings.getBoolean("settings_key_xmpp_tls_use", false)
+ || mSettings.getBoolean("settings_key_gmail", false)) {
+ mConnectionConfiguration.setSecurityMode(SecurityMode.required);
+ }
+ if (mSettings.getBoolean(BeemApplication.SMACK_DEBUG_KEY, false))
+ mConnectionConfiguration.setDebuggerEnabled(true);
+ mConnectionConfiguration.setSendPresence(true);
+ // maybe not the universal path, but it works on most devices (Samsung Galaxy, Google Nexus One)
+ mConnectionConfiguration.setTruststoreType("BKS");
+ mConnectionConfiguration.setTruststorePath("/system/etc/security/cacerts.bks");
+ }
+
+ /**
+ * Edit presence ex. SyncAdapter = false
+ */
+ public void setPresence(boolean bPresence) {
+ mConnectionConfiguration.setSendPresence(bPresence);
+ }
+
+ /**
+ * @return the login
+ */
+ public String getLogin() {
+ return mLogin;
+ }
+
+ /**
+ * @param login the login to set
+ */
+ public void setLogin(String login) {
+ this.mLogin = login;
+ }
+
+ /**
+ * @return the connectionConfiguration
+ */
+ public ConnectionConfiguration getConnectionConfiguration() {
+ return mConnectionConfiguration;
+ }
+
+ /**
+ * @param connectionConfiguration the connectionConfiguration to set
+ */
+ public void setConnectionConfiguration(ConnectionConfiguration connectionConfiguration) {
+ this.mConnectionConfiguration = connectionConfiguration;
+ }
+
+ /**
+ * @return the password
+ */
+ public String getPassword() {
+ return mPassword;
+ }
+
+ /**
+ * @param password the password to set
+ */
+ public void setPassword(String password) {
+ this.mPassword = password;
+ }
+
+ /**
+ * @return the settings
+ */
+ public SharedPreferences getSettings() {
+ return mSettings;
+ }
+
+ /**
+ * @param settings the settings to set
+ */
+ public void setSettings(SharedPreferences settings) {
+ this.mSettings = settings;
+ }
+
+ /**
+ * @return the jid
+ */
+ public String getJid() {
+ return mJid;
+ }
+
+ /**
+ * @param jid the jid to set
+ */
+ public void setJid(String jid) {
+ this.mJid = jid;
+ }
+
+ /**
+ * @return the resource
+ */
+ public String getResource() {
+ return mResource;
+ }
+
+ /**
+ * @param the resource
+ */
+ public void setResource(String resource) {
+ mResource = resource;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/BeemPacketListener.java Mon Jul 16 11:43:10 2012 +0200
@@ -0,0 +1,108 @@
+package com.beem.project.beem;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.jivesoftware.smack.PacketListener;
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smack.packet.IQ;
+import org.jivesoftware.smack.packet.Message;
+import org.jivesoftware.smack.packet.Packet;
+import org.jivesoftware.smack.packet.Presence;
+
+import android.content.ContentValues;
+import android.content.Context;
+import android.util.Log;
+
+import com.beem.project.beem.providers.Messages;
+
+public class BeemPacketListener implements PacketListener {
+
+ private static final String TAG = BeemPacketListener.class.getName();
+ private Context mContext;
+ private XMPPConnection mXMPPConnection;
+
+ public BeemPacketListener(Context c, XMPPConnection connection) {
+ mContext = c;
+ mXMPPConnection = connection;
+ }
+
+ @Override
+ public void processPacket(Packet packet) {
+ if (packet instanceof Presence) {
+ Presence pres = (Presence) packet;
+ if (pres.getType() == Presence.Type.subscribe) {
+ //TODO: Notification on receive presence subscribe
+// String from = packet.getFrom();
+// Notification notif = new Notification(android.R.drawable.stat_notify_more, mService.getString(
+// R.string.AcceptContactRequest, from), System.currentTimeMillis());
+// notif.flags = Notification.FLAG_AUTO_CANCEL;
+// Intent intent = new Intent(mService, Subscription.class);
+// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).putExtra("from", from);
+// notif.setLatestEventInfo(mService, from, mService.getString(R.string.AcceptContactRequestFrom, from),
+// PendingIntent.getActivity(mService, 0, intent, PendingIntent.FLAG_ONE_SHOT));
+// int id = packet.hashCode();
+// mService.sendNotification(id, notif);
+// Presence p = (Presence) packet;
+// updateNotification(Status.getStatusFromPresence(p), p.getStatus());
+ }
+ } else if (packet instanceof Message) {
+ Message msg = (Message) packet;
+ if (msg.getType() == Message.Type.error) {
+ ;
+ } else if (msg.getBody() != null) {
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ ContentValues values = new ContentValues();
+ values.put(Messages.FROM, msg.getFrom());
+ values.put(Messages.MESSAGE_ID, msg.getPacketID());
+ values.put(Messages.TO, msg.getTo());
+ values.put(Messages.TYPE, Message.Type.chat.toString());
+ values.put(Messages.SUBJECT, msg.getSubject());
+ values.put(Messages.BODY, msg.getBody());
+ values.put(Messages.THREAD, msg.getThread());
+ values.put(Messages.EXTRAS, "");
+ values.put(Messages.IS_RECEIVE, true);
+ values.put(Messages.DATE_RECEIVE, dateFormat.format(new Date()));
+ values.put(Messages.DATE_READ, dateFormat.format(new Date()));
+ mContext.getContentResolver().insert(Messages.CONTENT_URI, values);
+ } else {
+ Log.w(TAG, "Unknow Message packet (body null): " + msg.getType());
+ }
+ } else if (packet instanceof PingExtension) {
+ PingExtension p = (PingExtension) packet;
+ if (p.getType() == IQ.Type.GET) {
+ PingExtension pong = new PingExtension();
+ pong.setType(IQ.Type.RESULT);
+ pong.setTo(p.getFrom());
+ pong.setPacketID(p.getPacketID());
+ mXMPPConnection.sendPacket(pong);
+ } else {
+ Log.w(TAG, "Unknow PingExtension packet : " + packet.getClass().toString());
+ }
+
+ }
+ }
+
+ public class PingExtension extends IQ {
+
+ /** Namespace of the Ping XEP. */
+ public static final String NAMESPACE = "urn:xmpp:ping";
+
+ /** Xml element name for the ping. */
+ public static final String ELEMENT = "ping";
+
+ /**
+ * Create a ping iq packet.
+ */
+ public PingExtension() {
+ }
+
+ @Override
+ public String getChildElementXML() {
+ if (getType() == IQ.Type.RESULT)
+ return null;
+ return "<" + ELEMENT + " xmlns=\"" + NAMESPACE + "\" />";
+ }
+
+ }
+}
--- a/src/com/beem/project/beem/BeemService.java Sun May 06 12:28:38 2012 +0200
+++ b/src/com/beem/project/beem/BeemService.java Mon Jul 16 11:43:10 2012 +0200
@@ -43,24 +43,18 @@
*/
package com.beem.project.beem;
-import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.Roster.SubscriptionMode;
-import org.jivesoftware.smack.PacketListener;
-import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
-import org.jivesoftware.smack.XMPPException;
-import org.jivesoftware.smack.packet.Packet;
+import org.jivesoftware.smack.packet.UnknownPacket;
import org.jivesoftware.smack.provider.ProviderManager;
+import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.PrivateDataManager;
-import org.jivesoftware.smackx.bookmark.BookmarkManager;
-import org.jivesoftware.smackx.bookmark.BookmarkedConference;
-import org.jivesoftware.smackx.muc.DiscussionHistory;
-import org.jivesoftware.smackx.muc.MultiUserChat;
+import org.jivesoftware.smackx.XmppStreamHandler;
import org.jivesoftware.smackx.packet.ChatStateExtension;
import org.jivesoftware.smackx.provider.DelayInfoProvider;
import org.jivesoftware.smackx.provider.DiscoverInfoProvider;
@@ -70,35 +64,22 @@
import org.jivesoftware.smackx.pubsub.provider.ItemsProvider;
import org.jivesoftware.smackx.pubsub.provider.PubSubProvider;
-import android.app.Notification;
+import android.accounts.Account;
+import android.accounts.AccountManager;
import android.app.Service;
-import android.content.BroadcastReceiver;
-import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
-import android.content.SharedPreferences.Editor;
-import android.database.Cursor;
import android.net.ConnectivityManager;
-import android.os.Bundle;
-import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
-import android.os.Looper;
-import android.os.Message;
-import android.os.RemoteException;
import android.util.Log;
-import android.widget.Toast;
-import com.beem.project.beem.providers.MUCs;
-import com.beem.project.beem.service.XmppConnectionAdapter;
import com.beem.project.beem.smack.avatar.AvatarMetadataProvider;
import com.beem.project.beem.smack.avatar.AvatarProvider;
import com.beem.project.beem.smack.caps.CapsProvider;
-import com.beem.project.beem.ui.BeemNotification;
+import com.beem.project.beem.ui.Notification.BeemNotification;
import com.beem.project.beem.utils.BeemBroadcastReceiver;
-import com.beem.project.beem.utils.BeemConnectivity;
-import com.beem.project.beem.utils.Status;
/**
* This class is for the Beem service. It must contains every global informations needed to maintain the background
@@ -111,31 +92,12 @@
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_IS_CONNECTED = 0x06;
- private static final int MESSAGE_SEND_MSG = 0x3;
- private static final int MESSAGE_SYNC = 0x4;
- private static final int MESSAGE_ADD_CONTACT = 0x5;
- private static final int MESSAGE_CHANGE_STATUS = 0x7;
- private static final int MESSAGE_MUC_JOIN = 0x8;
- private static final int MESSAGE_MUC_SEND_MSG = 0x9;
- private static final int MESSAGE_ADD_MUC = 0xA;
+
+ //private Map<String, XmppConnectionAdapter> mConnection = new HashMap<String, XmppConnectionAdapter>();
- public static final String MUC_NAME = "muc_name";
- public static final String MUC_NICKNAME = "muc_nickname";
- public static final String MUC_PASSWORD = "muc_password";
- public static final String MUC_AUTOJOIN = "muc_autojoin";
-
- private Map<String, XmppConnectionAdapter> mConnection = new HashMap<String, XmppConnectionAdapter>();
- private Map<String, BeemConnection> mBeemConnection = new HashMap<String, BeemConnection>();
-
- private boolean mOnOffReceiverIsRegistered;
- private Handler mHandler;
- private Looper mServiceLooper;
+ private BeemServiceHandler mHandler;
private BeemBroadcastReceiver mReceiver = new BeemBroadcastReceiver();
- private BeemServicePreferenceListener mPreferenceListener = new BeemServicePreferenceListener();
- private BeemServiceBroadcastReceiver mOnOffReceiver = new BeemServiceBroadcastReceiver();
+ private final BeemServicePreferenceListener mPreferenceListener = new BeemServicePreferenceListener();
/**
* Constructor.
@@ -146,13 +108,14 @@
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent != null) {
- handleIntent(intent);
+ mHandler.handleIntent(intent);
}
return Service.START_STICKY;
}
/**
* {@inheritDoc}
+ * @return return always null. Instead of bind, use intent.
*/
@Override
public IBinder onBind(Intent intent) {
@@ -162,14 +125,14 @@
@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();
- }
+ // boolean isConnected = true;
+ // for (XmppConnectionAdapter connection : mConnection.values()) {
+ // if (!connection.getAdaptee().isConnected())
+ // isConnected = false;
+ // }
+ // if (!isConnected) {
+ // this.stopSelf();
+ // }
return true;
}
@@ -182,14 +145,27 @@
Log.d(TAG, "ONCREATE");
HandlerThread thread = new HandlerThread("BeemServiceThread");
thread.start();
- mServiceLooper = thread.getLooper();
- mHandler = new BeemServiceHandler(mServiceLooper);
+ mHandler = new BeemServiceHandler(thread.getLooper(), this);
registerReceiver(mReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
+ //TODO: ADD AUTO AWAY OPTION DEPEND ON SCREEN OFF OR ON
+ // registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
+ // registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_SCREEN_ON));
configure(ProviderManager.getInstance());
BeemNotification.BindNotification(this);
Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
}
+ protected void onResume() {
+ //Initialize preference listener.
+ AccountManager am = AccountManager.get(this);
+ Account allAccount[] = am.getAccountsByType(BeemApplication.BEEM_PACKAGE);
+ for (Account account : allAccount) {
+ Log.e(TAG, " " + account.name);
+ getSharedPreferences(account.name, BeemService.MODE_PRIVATE).registerOnSharedPreferenceChangeListener(
+ mPreferenceListener);
+ }
+ }
+
/**
* {@inheritDoc}
*/
@@ -198,43 +174,12 @@
super.onDestroy();
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);
- }
-
- /**
- * 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();
- }
-
+ // if (mOnOffReceiverIsRegistered)
+ // unregisterReceiver(mOnOffReceiver);
+ // for (XmppConnectionAdapter connection : mConnection.values()) {
+ // if (connection.isAuthentificated() && BeemConnectivity.isConnected(this))
+ // connection.disconnect();
+ // }
}
/**
@@ -248,9 +193,9 @@
* Get the preference of the service.
* @return the preference
*/
- public SharedPreferences getServicePreference(String accountName) {
- return mBeemConnection.get(accountName).getSettings();
- }
+ // public SharedPreferences getServicePreference(String accountName) {
+ // return mBeemConnection.get(accountName).getSettings();
+ // }
/**
* A sort of patch from this thread: http://www.igniterealtime.org/community/thread/31118. Avoid ClassCastException
@@ -306,6 +251,10 @@
// Private Data Storage for Bookmarks
pm.addIQProvider("query", "jabber:iq:private", new PrivateDataManager.PrivateDataIQProvider());
+ // ping
+ pm.addIQProvider(BeemPacketListener.PingExtension.ELEMENT, BeemPacketListener.PingExtension.NAMESPACE, BeemPacketListener.PingExtension.class);
+
+
// Time
// try {
// pm.addIQProvider("query", "jabber:iq:time", Class.forName("org.jivesoftware.smackx.packet.Time"));
@@ -363,6 +312,7 @@
// pm.addExtensionProvider("bad-sessionid", COMMAND_NAMESPACE, new AdHocCommandDataProvider.BadSessionIDError());
// pm.addExtensionProvider("session-expired", COMMAND_NAMESPACE,
// new AdHocCommandDataProvider.SessionExpiredError());
+ XmppStreamHandler.addExtensionProviders();
}
/**
@@ -374,276 +324,74 @@
* ctor.
*/
public BeemServicePreferenceListener() {
+ Log.e(TAG, "CONSTRUCTOR");
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ Log.e(TAG, "OO" + 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);
- }
+ // 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);
+ // }
} else if (BeemApplication.STATUS_TEXT_KEY.equals(key)) {
- BeemNotification.BindNotification(BeemService.this);
- }
- }
- }
-
- /**
- * 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<String, XmppConnectionAdapter> 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);
- }
+ // BeemNotification.BindNotification(BeemService.this);
+ } else if (BeemApplication.NOTIFICATION_ENABLE_KEY.equals(key)) {
+ Log.e(TAG, "OO");
}
}
}
- 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_ISCONNECTED.equals(action)) {
- msg = mHandler.obtainMessage(MESSAGE_IS_CONNECTED, intent.getExtras());
- } else if (BeemIntent.ACTION_SEND_MESSAGE.equals(action)) {
- msg = mHandler.obtainMessage(MESSAGE_SEND_MSG, intent.getExtras());
- } else if (BeemIntent.ACTION_SYNC.equals(action)) {
- msg = mHandler.obtainMessage(MESSAGE_SYNC, intent.getExtras());
- } else if (BeemIntent.ACTION_ADD_CONTACT.equals(action)) {
- msg = mHandler.obtainMessage(MESSAGE_ADD_CONTACT, intent.getExtras());
- } else if (BeemIntent.ACTION_CHANGE_STATUS.equals(action)) {
- msg = mHandler.obtainMessage(MESSAGE_CHANGE_STATUS, intent.getExtras());
- } else if (BeemIntent.ACTION_MUC_JOIN.equals(action)) {
- msg = mHandler.obtainMessage(MESSAGE_MUC_JOIN, intent.getExtras());
- } else if (BeemIntent.ACTION_MUC_SEND_MESSAGE.equals(action)) {
- msg = mHandler.obtainMessage(MESSAGE_MUC_SEND_MSG, intent.getExtras());
- } else if (BeemIntent.ACTION_ADD_MUC.equals(action)) {
- msg = mHandler.obtainMessage(MESSAGE_ADD_MUC, intent.getExtras());
- } else {
- Log.w(TAG, "Unknown intent " + intent);
+ public static class StreamHandlingPacket extends UnknownPacket {
+ private String name;
+ private String namespace;
+ Map<String, String> attributes;
+
+ public StreamHandlingPacket(String name, String namespace) {
+ this.name = name;
+ this.namespace = namespace;
+ attributes = Collections.emptyMap();
}
- if (msg != null)
- mHandler.sendMessage(msg);
- }
- private class BeemServiceHandler extends Handler {
+ public void addAttribute(String name, String value) {
+ if (attributes == Collections.EMPTY_MAP)
+ attributes = new HashMap<String, String>();
+ attributes.put(name, value);
+ }
- public BeemServiceHandler(Looper looper) {
- super(looper);
+ public String getAttribute(String name) {
+ return attributes.get(name);
}
- @Override
- public void handleMessage(Message msg) {
- String accountName = null;
- XmppConnectionAdapter connection = null;
- Bundle b = (Bundle) msg.obj;
- if (b.containsKey(BeemIntent.EXTRA_ACCOUNT)) {
- accountName = b.getString(BeemIntent.EXTRA_ACCOUNT);
- connection = mConnection.get(accountName);
- }
- if (connection == null && msg.what != MESSAGE_CONNECT && msg.what != MESSAGE_SYNC
- && msg.what != MESSAGE_IS_CONNECTED && msg.what != MESSAGE_CHANGE_STATUS) {
- Toast.makeText(BeemService.this, getString(R.string.BeemServiceNotConnected, accountName),
- Toast.LENGTH_LONG).show();
- return;
- }
- switch (msg.what) {
- case MESSAGE_CONNECT:
- handleConnect(accountName);
- break;
- case MESSAGE_DISCONNECT:
- handleDisconnect(accountName);
- break;
- case MESSAGE_IS_CONNECTED:
- Intent res = new Intent(BeemIntent.ACTION_DISCONNECTED);
- //res.putExtra(BeemIntent.EXTRA_MESSAGE, R.string.contact_status_msg_offline);
- res.putExtra(BeemIntent.EXTRA_ACCOUNT, accountName);
- if (mConnection.containsKey(accountName))
- res.setAction(BeemIntent.ACTION_CONNECTED);
- sendBroadcast(res);
- break;
- case MESSAGE_SEND_MSG:
- connection.handleMessage(accountName, msg);
- break;
- case MESSAGE_SYNC:
- BeemNotification.StartSyncNotification(getBaseContext());
- //TODO: Connect with option to not show status
- handleConnect(accountName);
- if (!mConnection.containsKey(accountName))
- connection = mConnection.get(accountName);
- if (connection != null) {
- BeemSync sync = new BeemSync(getBaseContext());
- XMPPConnection xmppCo = connection.getAdaptee();
- if (xmppCo != null) {
- sync.manageRoster(xmppCo.getRoster(), accountName);
- sync.syncMUC(xmppCo, accountName);
- }
- }
- BeemNotification.StopSyncNotification(getBaseContext());
- break;
- case MESSAGE_ADD_CONTACT:
- String jid = b.getString(BeemIntent.EXTRA_JID);
+ public String getNamespace() {
+ return namespace;
+ }
- XMPPConnection xmppCo = connection.getAdaptee();
- if (xmppCo != null) {
- Roster r = xmppCo.getRoster();
- if (r == null) {
- Log.e(TAG, "Has not logged in yet : " + accountName);
- return;
- }
- try {
- r.createEntry(jid, jid, null);
- } catch (XMPPException e) {
- Log.e(TAG, "AddContact", e);
- }
- }
- break;
- case MESSAGE_CHANGE_STATUS:
- int status = b.getInt(BeemIntent.EXTRA_MESSAGE);
- if (status == Status.CONTACT_STATUS_DISCONNECT) {
- handleDisconnect(accountName);
- } else {
- handleConnect(accountName);
- if (mConnection.containsKey(accountName)) {
- mConnection.get(accountName).changeStatus(status, "");
- }
- }
- break;
- case MESSAGE_MUC_JOIN:
- String mucjid = b.getString(BeemIntent.EXTRA_JID);
- MultiUserChat muc = new MultiUserChat(connection.getAdaptee(), mucjid);
+ public String getElementName() {
+ return name;
+ }
+
+ public String toXML() {
+ StringBuilder buf = new StringBuilder();
+ buf.append("<").append(getElementName());
- DiscussionHistory history = new DiscussionHistory();
- history.setMaxStanzas(5);
- Cursor c = getContentResolver().query(MUCs.CONTENT_URI,
- new String[] { MUCs.NICKNAME, MUCs.PASSWORD },
- MUCs.ACCOUNT_NAME + "=? AND " + MUCs.ACCOUNT_TYPE + "=? AND " + MUCs.JID + "=?",
- new String[] { accountName, BeemApplication.BEEM_PACKAGE, mucjid }, null);
- if (c.moveToFirst()) {
- try {
- muc.join(c.getString(c.getColumnIndex(MUCs.NICKNAME)),
- c.getString(c.getColumnIndex(MUCs.PASSWORD)), history,
- SmackConfiguration.getPacketReplyTimeout());
- } catch (XMPPException e) {
- Log.e(TAG, "MUC Join Problem", e);
- }
- }
- break;
- case MESSAGE_MUC_SEND_MSG:
- MultiUserChat mucmsg = new MultiUserChat(connection.getAdaptee(), b.getString(BeemIntent.EXTRA_JID));
- try {
- mucmsg.sendMessage(b.getString(BeemIntent.EXTRA_MESSAGE));
- } catch (XMPPException e) {
- Log.e(TAG, "Error send message to muc", e);
- }
- break;
- case MESSAGE_ADD_MUC:
- Bundle extra = b.getBundle(BeemIntent.EXTRA_MESSAGE);
-
- String mucName = extra.getString(MUC_NAME);
- String mucNickname = extra.getString(MUC_NICKNAME);
- String mucPassword = extra.getString(MUC_PASSWORD);
- boolean mucAutojoin = extra.getBoolean(MUC_AUTOJOIN);
- BookmarkManager bm;
- try {
- bm = BookmarkManager.getBookmarkManager(connection.getAdaptee());
- bm.addBookmarkedConference(mucName, b.getString(BeemIntent.EXTRA_JID), mucAutojoin,
- mucNickname, mucPassword);
- } catch (XMPPException e) {
- Log.e(TAG, "Error add muc", e);
- }
- break;
- default:
- Log.w(TAG, "Unknown message " + msg);
+ // TODO Xmlns??
+ if (getNamespace() != null) {
+ buf.append(" xmlns=\"").append(getNamespace()).append("\"");
}
+ for (String key : attributes.keySet()) {
+ buf.append(" ").append(key).append("=\"").append(StringUtils.escapeForXML(attributes.get(key)))
+ .append("\"");
+ }
+ buf.append("/>");
+ return buf.toString();
}
- }
- 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);
-
- 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);
-
- try {
- Log.i(TAG, "Starting connection of " + accountName);
- if (beemcoAdapter.connectSync()) {
- mConnection.put(accountName, 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);
- }
-
- }
- }
- //Bookmark : Muc
- if (mConnection.containsKey(accountName)) {
- //TODO AutoConnect
- }
- //TODO: ADD MESSAGE || TOAST TO CONFIRM CONNECTION OF THE ACCOUNT
- sendBroadcast(res);
- }
-
- private void handleDisconnect(String accountName) {
- Intent res = new Intent(BeemIntent.ACTION_DISCONNECTED);
- res.putExtra(BeemIntent.EXTRA_ACCOUNT, accountName);
- //TODO: ADD MESSAGE TO CONFIRM DECONNECTION OF THE ACCOUNT
- mConnection.remove(accountName);
- sendBroadcast(res);
}
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/BeemServiceHandler.java Mon Jul 16 11:43:10 2012 +0200
@@ -0,0 +1,215 @@
+/*
+ BEEM is a videoconference application on the Android Platform.
+
+ Copyright (C) 2009 by Frederic-Charles Barthelery,
+ Jean-Manuel Da Silva,
+ Nikita Kozlov,
+ Philippe Lago,
+ Jean Baptiste Vergely,
+ Vincent Veronis.
+
+ This file is part of BEEM.
+
+ BEEM is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ BEEM is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with BEEM. If not, see <http://www.gnu.org/licenses/>.
+
+ Please send bug reports with examples or suggestions to
+ contact@beem-project.com or http://dev.beem-project.com/
+
+ */
+
+package com.beem.project.beem;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.util.Log;
+import android.widget.Toast;
+
+import com.beem.project.beem.ui.Notification.BeemNotification;
+import com.beem.project.beem.utils.Status;
+
+/**
+ * Class for managing intent receive.
+ * @author marseille
+ */
+public class BeemServiceHandler extends Handler {
+
+ private static final String TAG = BeemServiceHandler.class.getName();
+
+ private enum IMESSAGE {
+ CONNECT, DISCONNECT, IS_CONNECTED, SEND_MSG, SYNC, ADD_CONTACT, CHANGE_STATUS, MUC_JOIN, MUC_SEND_MSG, ADD_MUC
+ };
+
+ private Map<String, BeemConnection> mBeemConnection = new HashMap<String, BeemConnection>();
+
+ private final Context mContext;
+
+ public BeemServiceHandler(Looper looper, Context context) {
+ super(looper);
+ mContext = context;
+ }
+
+ public void handleIntent(Intent intent) {
+ Message msg = null;
+ String action = intent.getAction();
+ if (BeemIntent.ACTION_CONNECT.equals(action)) {
+ msg = obtainMessage(IMESSAGE.CONNECT.ordinal(), intent.getExtras());
+ } else if (BeemIntent.ACTION_DISCONNECT.equals(action)) {
+ msg = obtainMessage(IMESSAGE.DISCONNECT.ordinal(), intent.getExtras());
+ } else if (BeemIntent.ACTION_ISCONNECTED.equals(action)) {
+ msg = obtainMessage(IMESSAGE.IS_CONNECTED.ordinal(), intent.getExtras());
+ } else if (BeemIntent.ACTION_SEND_MESSAGE.equals(action)) {
+ msg = obtainMessage(IMESSAGE.SEND_MSG.ordinal(), intent.getExtras());
+ } else if (BeemIntent.ACTION_SYNC.equals(action)) {
+ msg = obtainMessage(IMESSAGE.SYNC.ordinal(), intent.getExtras());
+ } else if (BeemIntent.ACTION_ADD_CONTACT.equals(action)) {
+ msg = obtainMessage(IMESSAGE.ADD_CONTACT.ordinal(), intent.getExtras());
+ } else if (BeemIntent.ACTION_CHANGE_STATUS.equals(action)) {
+ msg = obtainMessage(IMESSAGE.CHANGE_STATUS.ordinal(), intent.getExtras());
+ } else if (BeemIntent.ACTION_MUC_JOIN.equals(action)) {
+ msg = obtainMessage(IMESSAGE.MUC_JOIN.ordinal(), intent.getExtras());
+ } else if (BeemIntent.ACTION_MUC_SEND_MESSAGE.equals(action)) {
+ msg = obtainMessage(IMESSAGE.MUC_SEND_MSG.ordinal(), intent.getExtras());
+ } else if (BeemIntent.ACTION_ADD_MUC.equals(action)) {
+ msg = obtainMessage(IMESSAGE.ADD_MUC.ordinal(), intent.getExtras());
+ } else {
+ Log.w(TAG, "Unknown intent " + intent);
+ }
+ if (msg != null)
+ sendMessage(msg);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ String accountName = null;
+ BeemConnection connection = null;
+ Bundle b = (Bundle) msg.obj;
+ if (b.containsKey(BeemIntent.EXTRA_ACCOUNT)) {
+ accountName = b.getString(BeemIntent.EXTRA_ACCOUNT);
+ connection = mBeemConnection.get(accountName);
+ }
+ if (connection == null && msg.what != IMESSAGE.CONNECT.ordinal() && msg.what != IMESSAGE.SYNC.ordinal()
+ && msg.what != IMESSAGE.IS_CONNECTED.ordinal() && msg.what != IMESSAGE.CHANGE_STATUS.ordinal()) {
+ Toast.makeText(mContext, mContext.getString(R.string.BeemServiceNotConnected, accountName),
+ Toast.LENGTH_LONG).show();
+ return;
+ }
+
+ if (msg.what == IMESSAGE.CONNECT.ordinal()) {
+ handleConnect(accountName);
+ } else if (msg.what == IMESSAGE.DISCONNECT.ordinal()) {
+ handleDisconnect(accountName);
+ } else if (msg.what == IMESSAGE.IS_CONNECTED.ordinal()) {
+ Intent res = new Intent(BeemIntent.ACTION_DISCONNECTED);
+ res.putExtra(BeemIntent.EXTRA_MESSAGE, R.string.contact_status_msg_offline);
+ res.putExtra(BeemIntent.EXTRA_ACCOUNT, accountName);
+ if (mBeemConnection.containsKey(accountName))
+ res.setAction(BeemIntent.ACTION_CONNECTED);
+ mContext.sendBroadcast(res);
+ } else if (msg.what == IMESSAGE.SEND_MSG.ordinal()) {
+ connection.handleXMPPMessage(accountName, msg);
+ } else if (msg.what == IMESSAGE.SYNC.ordinal()) {
+ BeemNotification.StartSyncNotification(mContext);
+ //TODO: Connect with option to not show status
+ handleConnect(accountName);
+ connection = mBeemConnection.get(accountName);
+ if (connection != null)
+ connection.syncRoster();
+ BeemNotification.StopSyncNotification(mContext);
+ } else if (msg.what == IMESSAGE.ADD_CONTACT.ordinal()) {
+ String jid = b.getString(BeemIntent.EXTRA_JID);
+ if (connection.addContact(jid) == false) {
+ Toast.makeText(mContext, connection.getErrorMessage(), Toast.LENGTH_LONG).show();
+ }
+ } else if (msg.what == IMESSAGE.CHANGE_STATUS.ordinal()) {
+ Bundle extraBundle = b.getBundle(BeemIntent.EXTRA_MESSAGE);
+ int status = extraBundle.getInt(BeemApplication.STATUS_KEY);
+ if (status == Status.CONTACT_STATUS_DISCONNECT) {
+ handleDisconnect(accountName);
+ } else {
+ handleConnect(accountName);
+ connection = mBeemConnection.get(accountName);
+ if (connection != null) {
+ String sStatus = extraBundle.getString(BeemApplication.STATUS_TEXT_KEY);
+ connection.changeStatus(status, sStatus, 0);
+ Toast.makeText(mContext, R.string.ChangeStatusOk, Toast.LENGTH_LONG).show();
+ }
+ }
+ } else if (msg.what == IMESSAGE.MUC_JOIN.ordinal()) {
+ String mucjid = b.getString(BeemIntent.EXTRA_JID);
+ if (connection.mucJoin(mucjid) == false) {
+ Toast.makeText(mContext, connection.getErrorMessage(), Toast.LENGTH_LONG).show();
+ }
+ } else if (msg.what == IMESSAGE.MUC_SEND_MSG.ordinal()) {
+ String mucjid = b.getString(BeemIntent.EXTRA_JID);
+ String mucmsg = b.getString(BeemIntent.EXTRA_MESSAGE);
+ connection.mucSendMsg(mucjid, mucmsg);
+
+ } else if (msg.what == IMESSAGE.ADD_MUC.ordinal()) {
+ String mucjid = b.getString(BeemIntent.EXTRA_JID);
+ Bundle extra = b.getBundle(BeemIntent.EXTRA_MESSAGE);
+ connection.mucAdd(mucjid, extra);
+ } else {
+ Log.w(TAG, "Unknown message " + msg);
+ }
+ }
+
+ 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);
+
+ if (mBeemConnection.containsKey(accountName)) {
+ res.setAction(BeemIntent.ACTION_CONNECTED);
+ } else {
+ if (accountName == null) {
+ ;//connect all
+ } else {
+ BeemConnection connection = new BeemConnection(mContext, accountName);
+ if (connection.connect()) {
+ mBeemConnection.put(accountName, connection);
+ res.setAction(BeemIntent.ACTION_CONNECTED);
+ Log.i(TAG, "Account connection : " + accountName + " DONE");
+ } else {
+ Log.w(TAG, "Unable to connect " + accountName);
+ res.putExtra(BeemIntent.EXTRA_MESSAGE, connection.getErrorMessage());
+ }
+
+ }
+
+ }
+ //Bookmark : Muc
+ // if (mConnection.containsKey(accountName)) {
+ // //TODO AutoConnect
+ // }
+ //TODO: ADD MESSAGE || TOAST TO CONFIRM CONNECTION OF THE ACCOUNT
+ mContext.sendBroadcast(res);
+ }
+
+ private void handleDisconnect(String accountName) {
+ Intent res = new Intent(BeemIntent.ACTION_DISCONNECTED);
+ res.putExtra(BeemIntent.EXTRA_ACCOUNT, accountName);
+ //TODO: ADD MESSAGE TO CONFIRM DECONNECTION OF THE ACCOUNT
+ mBeemConnection.get(accountName).finalize();
+ mBeemConnection.remove(accountName);
+ mContext.sendBroadcast(res);
+ }
+
+}
\ No newline at end of file
--- a/src/com/beem/project/beem/BeemSync.java Sun May 06 12:28:38 2012 +0200
+++ b/src/com/beem/project/beem/BeemSync.java Mon Jul 16 11:43:10 2012 +0200
@@ -135,7 +135,7 @@
for (RosterEntry entry : r.getEntries()) {
if (entry != null) {
long rawContactID = manageEntry(ops, account, entry);
- addUpdateStatus(ops, entry, r.getPresence(entry.getUser()), rawContactID);
+ addUpdateStatus(ops, account, entry, r.getPresence(entry.getUser()), rawContactID);
}
if (ops.size() > NB_DB_OPERATION)
executeOperation(ops);
@@ -304,7 +304,7 @@
* @param isInsert Insert boolean
* @return
*/
- private void addUpdateStatus(ArrayList<ContentProviderOperation> ops, RosterEntry entry, Presence p,
+ private void addUpdateStatus(ArrayList<ContentProviderOperation> ops, Account a, 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()
@@ -314,8 +314,9 @@
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.IM_ACCOUNT, a.name);
+ if (p.getStatus() != null)
+ 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
@@ -349,10 +350,10 @@
values.put(MUCs.ACCOUNT_TYPE, BeemApplication.BEEM_PACKAGE);
if (c.getCount() == 0) {
mContext.getContentResolver().insert(MUCs.CONTENT_URI, values);
- } else if (c.getCount() == 1){
+ } else if (c.getCount() == 1) {
c.moveToFirst();
String id = c.getString(c.getColumnIndex(MUCs._ID));
- mContext.getContentResolver().update(MUCs.CONTENT_URI, values, MUCs._ID + "=?", new String[]{id});
+ mContext.getContentResolver().update(MUCs.CONTENT_URI, values, MUCs._ID + "=?", new String[] { id });
} else {
//TODO: Error problem sync -> throw toast ! Should not happend
}
--- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java Sun May 06 12:28:38 2012 +0200
+++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java Mon Jul 16 11:43:10 2012 +0200
@@ -189,8 +189,7 @@
return true;
else {
try {
- mAdaptee.connect();
- //mAdaptee.addConnectionListener(mConListener);
+ mAdaptee.connect();
return true;
} catch (XMPPException e) {
Log.e(TAG, "Error while connecting", e);
@@ -239,6 +238,11 @@
mAdaptee.addPacketListener(mSubscribePacketListener, filter);
mAdaptee.login(mLogin, mPassword, mResource);
+
+ BeemService.StreamHandlingPacket enablePacket = new BeemService.StreamHandlingPacket("enable", "urn:xmpp:sm:2");
+ enablePacket.addAttribute("resume", "true");
+ mAdaptee.sendPacket(enablePacket);
+
//mChatManager = new BeemChatManager(mAdaptee.getChatManager(), mService);
//nikita: I commented this line because of the logs provided in http://www.beem-project.com/issues/321
//Also, since the privacylistmanager isn't finished and used, it will be safer to not initialize it
@@ -405,41 +409,7 @@
return mErrorMsg;
}
- public void handleMessage(String accountName, android.os.Message msg) {
-
- Bundle b = (Bundle) msg.obj;
- String to = b.getString(BeemIntent.EXTRA_JID);
- String body = b.getString(BeemIntent.EXTRA_MESSAGE);
-
- Message send = new Message();
- send.setFrom(accountName);
- send.setThread(""); //TODO: set ThreadID
- send.setTo(to);
- send.setBody(body);
- send.setType(Message.Type.chat);
- // TODO gerer les messages contenant des XMPPError
- try {
- mAdaptee.sendPacket(send);
- } catch (IllegalStateException e) {
- Log.e(TAG, "Message not send", e);
- }
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- ContentValues values = new ContentValues();
- values.put(Messages.FROM, "me"); //TODO: Get current account name
- values.put(Messages.MESSAGE_ID, "message id");
- values.put(Messages.TO, to);
- values.put(Messages.TYPE, Message.Type.chat.toString());
- values.put(Messages.SUBJECT, "SUBJECT");
- values.put(Messages.BODY, body);
- values.put(Messages.THREAD, "");
- values.put(Messages.EXTRAS, "");
- values.put(Messages.IS_RECEIVE, true);
- values.put(Messages.DATE_RECEIVE, dateFormat.format(new Date()));
- values.put(Messages.DATE_READ, dateFormat.format(new Date()));
- mService.getContentResolver().insert(Messages.CONTENT_URI, values);
-
- }
-
+
/**
* Initialize the features provided by beem.
*/
@@ -712,6 +682,7 @@
@Override
public void processPacket(Packet packet) {
+ Log.e(TAG, "suscribe packet" + packet.getClass().toString());
if (packet instanceof Presence) {
Presence p = (Presence) packet;
if (p.getType() != Presence.Type.subscribe)
--- a/src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl Sun May 06 12:28:38 2012 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,88 +0,0 @@
-/*
- BEEM is a videoconference application on the Android Platform.
-
- Copyright (C) 2009 by Frederic-Charles Barthelery,
- Jean-Manuel Da Silva,
- Nikita Kozlov,
- Philippe Lago,
- Jean Baptiste Vergely,
- Vincent Veronis.
-
- This file is part of BEEM.
-
- BEEM is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- BEEM is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with BEEM. If not, see <http://www.gnu.org/licenses/>.
-
- Please send bug reports with examples or suggestions to
- contact@beem-project.com or http://dev.beem-project.com/
-
- Epitech, hereby disclaims all copyright interest in the program "Beem"
- written by Frederic-Charles Barthelery,
- Jean-Manuel Da Silva,
- Nikita Kozlov,
- Philippe Lago,
- Jean Baptiste Vergely,
- Vincent Veronis.
-
- Nicolas Sadirac, November 26, 2009
- President of Epitech.
-
- Flavien Astraud, November 26, 2009
- Head of the EIP Laboratory.
-
-*/
-package com.beem.project.beem.service.aidl;
-
-/**
- * Interface to listen for connection events
- * @author Da Risk <barthe_f@epitech.eu>
- */
-interface IBeemConnectionListener {
-
- /**
- * Callback to call when the connection is closed
- */
- void connectionClosed();
-
- /**
- * Callback to call when the connection occurs
- * @Deprecated
- */
- //void onConnect();
-
- //void connectionClosedOnError(in Exception e);
- /**
- * Callback to call when the connection is closed on error
- */
- void connectionClosedOnError();
-
- /**
- * Callback to call when trying to reconnecting
- */
- void reconnectingIn(in int seconds);
-
- /**
- * Callback to call when the reconnection has failed
- */
- void reconnectionFailed();
-
- /**
- * Callback to call when the reconnection is successfull
- */
- void reconnectionSuccessful();
-
- /**
- * Callback to call when the connection Failed
- */
- void connectionFailed(in String errorMsg);
-}
--- a/src/com/beem/project/beem/service/aidl/IBeemRosterListener.aidl Sun May 06 12:28:38 2012 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-/*
- BEEM is a videoconference application on the Android Platform.
-
- Copyright (C) 2009 by Frederic-Charles Barthelery,
- Jean-Manuel Da Silva,
- Nikita Kozlov,
- Philippe Lago,
- Jean Baptiste Vergely,
- Vincent Veronis.
-
- This file is part of BEEM.
-
- BEEM is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- BEEM is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with BEEM. If not, see <http://www.gnu.org/licenses/>.
-
- Please send bug reports with examples or suggestions to
- contact@beem-project.com or http://dev.beem-project.com/
-
- Epitech, hereby disclaims all copyright interest in the program "Beem"
- written by Frederic-Charles Barthelery,
- Jean-Manuel Da Silva,
- Nikita Kozlov,
- Philippe Lago,
- Jean Baptiste Vergely,
- Vincent Veronis.
-
- Nicolas Sadirac, November 26, 2009
- President of Epitech.
-
- Flavien Astraud, November 26, 2009
- Head of the EIP Laboratory.
-
-*/
-package com.beem.project.beem.service.aidl;
-
-interface IBeemRosterListener {
- void onEntriesAdded(in List<String> addresses);
- void onEntriesUpdated(in List<String> addresses);
- void onEntriesDeleted(in List<String> addresses);
-}
--- a/src/com/beem/project/beem/service/aidl/IXmppConnection.aidl Sun May 06 12:28:38 2012 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,77 +0,0 @@
-/*
- BEEM is a videoconference application on the Android Platform.
-
- Copyright (C) 2009 by Frederic-Charles Barthelery,
- Jean-Manuel Da Silva,
- Nikita Kozlov,
- Philippe Lago,
- Jean Baptiste Vergely,
- Vincent Veronis.
-
- This file is part of BEEM.
-
- BEEM is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- BEEM is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with BEEM. If not, see <http://www.gnu.org/licenses/>.
-
- Please send bug reports with examples or suggestions to
- contact@beem-project.com or http://dev.beem-project.com/
-
- Epitech, hereby disclaims all copyright interest in the program "Beem"
- written by Frederic-Charles Barthelery,
- Jean-Manuel Da Silva,
- Nikita Kozlov,
- Philippe Lago,
- Jean Baptiste Vergely,
- Vincent Veronis.
-
- Nicolas Sadirac, November 26, 2009
- President of Epitech.
-
- Flavien Astraud, November 26, 2009
- Head of the EIP Laboratory.
-
-*/
-package com.beem.project.beem.service.aidl;
-
-import com.beem.project.beem.service.aidl.IBeemConnectionListener;
-
-
-interface IXmppConnection {
-
- boolean connect();
-
- boolean login();
-
- boolean connectSync();
-
- void connectAsync();
-
- boolean disconnect();
-
- //IRoster getRoster();
-
- void addConnectionListener(in IBeemConnectionListener listen);
- void removeConnectionListener(in IBeemConnectionListener listen);
-
- boolean isAuthentificated();
-
- //IChatManager getChatManager();
-
- void changeStatusAndPriority(in int status, in String msg, in int priority);
-
- void changeStatus(in int status, in String msg);
-
- //IPrivacyListManager getPrivacyListManager();
-
- String getErrorMessage();
-}
--- a/src/com/beem/project/beem/smack/pep/PepSubManager.java Sun May 06 12:28:38 2012 +0200
+++ b/src/com/beem/project/beem/smack/pep/PepSubManager.java Mon Jul 16 11:43:10 2012 +0200
@@ -47,6 +47,7 @@
import java.util.List;
import org.jivesoftware.smack.Connection;
+import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketExtensionFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.PacketListener;
@@ -58,21 +59,23 @@
import org.jivesoftware.smackx.pubsub.PubSubManager;
import org.jivesoftware.smackx.pubsub.LeafNode;
+import android.util.Log;
+
/**
* Little extension of {@link PubSubManager} which allows to add {@link PEPListener}.
*
*/
-public class PepSubManager extends PubSubManager {
+public class PepSubManager {
private List<PEPListener> mPepListeners = new ArrayList<PEPListener>();
private PacketFilter mPacketFilter = new PacketExtensionFilter("event", "http://jabber.org/protocol/pubsub#event");
-
+ private PubSubManager mPubSubManager;
/**
* Create a PepSubManager.
*
* @param connection the connection
*/
public PepSubManager(final Connection connection) {
- super(connection);
+ mPubSubManager = new PubSubManager(connection);
init(connection);
}
@@ -84,7 +87,7 @@
* @param toAddress The pubsub specific to address (required for some servers)
*/
public PepSubManager(final Connection connection, final String toAddress) {
- super(connection, toAddress);
+ mPubSubManager = new PubSubManager(connection, toAddress);
init(connection);
}
@@ -115,8 +118,12 @@
* @return the node
*/
public LeafNode getPEPNode(String nodeName) {
- LeafNode node = new LeafNode(con, nodeName);
- node.setTo(to);
+ LeafNode node = null;
+ try {
+ node = (LeafNode) mPubSubManager.getNode(nodeName);
+ } catch (XMPPException e) {
+ Log.e("beem pubsubmanger", "GETPEPNODE", e);
+ }
return node;
}
--- a/src/com/beem/project/beem/ui/AddMuc.java Sun May 06 12:28:38 2012 +0200
+++ b/src/com/beem/project/beem/ui/AddMuc.java Mon Jul 16 11:43:10 2012 +0200
@@ -141,11 +141,11 @@
Log.e(TAG, "Account : " + mAccount);
String mucJid = getWidgetText(R.id.addm_jid);
Bundle b = new Bundle();
- b.putString(BeemService.MUC_NAME, getWidgetText(R.id.addm_name));
- b.putString(BeemService.MUC_NICKNAME, getWidgetText(R.id.addm_nickname));
- b.putString(BeemService.MUC_PASSWORD, getWidgetText(R.id.addm_password));
+ b.putString(BeemApplication.MUC_NAME, getWidgetText(R.id.addm_name));
+ b.putString(BeemApplication.MUC_NICKNAME, getWidgetText(R.id.addm_nickname));
+ b.putString(BeemApplication.MUC_PASSWORD, getWidgetText(R.id.addm_password));
CheckBox checkboxWidget = (CheckBox) findViewById(R.id.addm_autojoin);
- b.putBoolean(BeemService.MUC_AUTOJOIN, checkboxWidget.isChecked());
+ b.putBoolean(BeemApplication.MUC_AUTOJOIN, checkboxWidget.isChecked());
Intent intent = new Intent(BeemIntent.ACTION_ADD_MUC);
intent.putExtra(BeemIntent.EXTRA_ACCOUNT, mAccount);
--- a/src/com/beem/project/beem/ui/BeemNotification.java Sun May 06 12:28:38 2012 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,97 +0,0 @@
-/*
- BEEM is a videoconference application on the Android Platform.
-
- Copyright (C) 2009 by Frederic-Charles Barthelery,
- Jean-Manuel Da Silva,
- Nikita Kozlov,
- Philippe Lago,
- Jean Baptiste Vergely,
- Vincent Veronis.
-
- This file is part of BEEM.
-
- BEEM is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- BEEM is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with BEEM. If not, see <http://www.gnu.org/licenses/>.
-
- Please send bug reports with examples or suggestions to
- contact@beem-project.com or http://dev.beem-project.com/
- */
-
-package com.beem.project.beem.ui;
-
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.content.Context;
-import android.content.Intent;
-import android.widget.RemoteViews;
-
-import com.beem.project.beem.R;
-
-/**
- * SingletonClass notification.
- * @author Vincent V. <marseille@beem-project.com>
- */
-public class BeemNotification extends Notification {
-
- private static Context mContext;
- private NotificationManager mNotificationManager;
-
- private static BeemNotification instance = null;
-
- /**
- * Constructor.
- */
- protected BeemNotification(Context c) {
- super();
- mContext = c;
- mNotificationManager = (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE);
- Intent notificationIntent = new Intent();
- contentIntent = PendingIntent.getActivity(c, (int) System.currentTimeMillis(), notificationIntent,
- PendingIntent.FLAG_UPDATE_CURRENT);
- icon = R.drawable.beem_status_icon;
- flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
- contentView = new RemoteViews(mContext.getPackageName(), R.layout.notification);
- contentView.setTextViewText(R.id.pseudo, "Beem");
- }
-
- public static void BindNotification(Context c) {
- if (instance == null) {
- instance = new BeemNotification(c);
- }
- instance.contentView.setTextViewText(R.id.msgstatus, "TODO: X messages unread");
- instance.mNotificationManager.notify(R.string.app_name, instance);
-
- }
-
- public static void StartSyncNotification(Context c) {
- if (instance == null) {
- instance = new BeemNotification(c);
- }
- instance.icon = R.drawable.ic_menu_sync;
- instance.mNotificationManager.notify(R.string.app_name, instance);
- }
-
- public static void StopSyncNotification(Context c) {
- if (instance == null) {
- instance = new BeemNotification(c);
- }
- instance.icon = R.drawable.beem_status_icon;
- instance.mNotificationManager.notify(R.string.app_name, instance);
- }
-
- public void deleteNotification(int id) {
- mNotificationManager.cancel(id);
- }
-
-}
--- a/src/com/beem/project/beem/ui/ChangeStatus.java Sun May 06 12:28:38 2012 +0200
+++ b/src/com/beem/project/beem/ui/ChangeStatus.java Mon Jul 16 11:43:10 2012 +0200
@@ -25,45 +25,26 @@
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.ui;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
-import android.content.IntentFilter;
import android.content.SharedPreferences;
-import android.content.SharedPreferences.Editor;
import android.os.Bundle;
-import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
-import android.widget.Toast;
import com.beem.project.beem.BeemApplication;
-import com.beem.project.beem.BeemService;
+import com.beem.project.beem.BeemIntent;
import com.beem.project.beem.R;
-import com.beem.project.beem.utils.BeemBroadcastReceiver;
+import com.beem.project.beem.ui.wizard.AccountConfigure;
import com.beem.project.beem.utils.Status;
/**
@@ -85,7 +66,6 @@
private static final int DISCONNECTED_IDX = 5;
private EditText mStatusMessageEditText;
- private Toast mToast;
private Button mOk;
private Button mClear;
private Button mContact;
@@ -94,7 +74,7 @@
private SharedPreferences mSettings;
private ArrayAdapter<CharSequence> mAdapter;
private final OnClickListener mOnClickOk = new MyOnClickListener();
- private final BeemBroadcastReceiver mReceiver = new BeemBroadcastReceiver();
+ private String mAccount;
/**
* Constructor.
@@ -108,9 +88,18 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
setContentView(R.layout.changestatus);
-
+ Bundle b = getIntent().getExtras();
+ if (b == null) {
+ //TODO: Add toast to advice need to configure at least 1 beem account (Should not happend)
+ startActivity(new Intent(ChangeStatus.this, AccountConfigure.class));
+ }
+ mAccount = b.getString(BeemIntent.EXTRA_ACCOUNT);
+ if (mAccount == null) {
+ //TODO: Add toast to advice need to configure at least 1 beem account (Should not happend)
+ startActivity(new Intent(ChangeStatus.this, AccountConfigure.class));
+ }
+ mSettings = getSharedPreferences(mAccount, MODE_PRIVATE);
mOk = (Button) findViewById(R.id.ChangeStatusOk);
mOk.setOnClickListener(mOnClickOk);
@@ -120,7 +109,6 @@
mContact = (Button) findViewById(R.id.OpenContactList);
mContact.setOnClickListener(mOnClickOk);
- mSettings = PreferenceManager.getDefaultSharedPreferences(this);
mStatusMessageEditText = (EditText) findViewById(R.id.ChangeStatusMessage);
mStatusMessageEditText.setText(mSettings.getString(BeemApplication.STATUS_TEXT_KEY, ""));
@@ -128,60 +116,16 @@
mAdapter = ArrayAdapter.createFromResource(this, R.array.status_types, android.R.layout.simple_spinner_item);
mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSpinner.setAdapter(mAdapter);
+ mSpinner.setSelection(fillSpinnerFromSettings(mSettings.getInt(BeemApplication.STATUS_KEY, AVAILABLE_IDX)));
- mToast = Toast.makeText(this, R.string.ChangeStatusOk, Toast.LENGTH_LONG);
- mSpinner.setSelection(getPreferenceStatusIndex());
-
- this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
}
- /**
- * {@inheritDoc}
- */
@Override
protected void onResume() {
super.onResume();
-// if (!BeemConnectivity.isConnected(getApplicationContext())) {
-// Intent i = new Intent(this, Login.class);
-// startActivity(i);
-// finish();
-// }
-// bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onPause() {
- super.onPause();
-// unbindService(mServConn);
- }
-
- /* (non-Javadoc)
- * @see android.app.Activity#onDestroy()
- */
- @Override
- protected void onDestroy() {
- super.onDestroy();
- this.unregisterReceiver(mReceiver);
- }
-
- /**
- * Return the status index from status the settings.
- * @return the status index from status the settings.
- */
- private int getPreferenceStatusIndex() {
- return mSettings.getInt(BeemApplication.STATUS_KEY, AVAILABLE_IDX);
- }
-
- /**
- * Return the status text from status the settings.
- * @param id status text id.
- * @return the status text from status the settings.
- */
- private String getPreferenceString(int id) {
- return mSettings.getString(getString(id), "");
+ Bundle b = getIntent().getExtras();
+ if (b != null && b.containsKey(BeemIntent.EXTRA_ACCOUNT))
+ mAccount = b.getString(BeemIntent.EXTRA_ACCOUNT);
}
/**
@@ -218,6 +162,39 @@
}
/**
+ * convert settings to spinner.
+ * @param item selected item text.
+ * @return item position in the array.
+ */
+ private int fillSpinnerFromSettings(int status) {
+ int result;
+ switch (status) {
+ case Status.CONTACT_STATUS_DISCONNECT:
+ result = DISCONNECTED_IDX;
+ break;
+ case Status.CONTACT_STATUS_UNAVAILABLE:
+ result = UNAVAILABLE_IDX;
+ break;
+ case Status.CONTACT_STATUS_AWAY:
+ result = AWAY_IDX;
+ break;
+ case Status.CONTACT_STATUS_BUSY:
+ result = BUSY_IDX;
+ break;
+ case Status.CONTACT_STATUS_AVAILABLE:
+ result = AVAILABLE_IDX;
+ break;
+ case Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT:
+ result = AVAILABLE_FOR_CHAT_IDX;
+ break;
+ default:
+ result = UNAVAILABLE_IDX;
+ break;
+ }
+ return result;
+ }
+
+ /**
* User have clicked on ok.
* @author nikita
*/
@@ -234,20 +211,13 @@
if (v == mOk) {
String msg = mStatusMessageEditText.getText().toString();
int status = getStatusForService((String) mSpinner.getSelectedItem());
- Editor edit = mSettings.edit();
- edit.putString(BeemApplication.STATUS_TEXT_KEY, msg);
- if (status == Status.CONTACT_STATUS_DISCONNECT) {
- stopService(new Intent(ChangeStatus.this, BeemService.class));
- } else {
-// try {
-// mXmppFacade.changeStatus(status, msg.toString());
-// edit.putInt(BeemApplication.STATUS_KEY, mSpinner.getSelectedItemPosition());
-// } catch (RemoteException e) {
-// e.printStackTrace();
-// }
- mToast.show();
- }
- edit.commit();
+ Bundle b = new Bundle();
+ b.putInt(BeemApplication.STATUS_KEY, status);
+ b.putString(BeemApplication.STATUS_TEXT_KEY, msg);
+ Intent intent = new Intent(BeemIntent.ACTION_CHANGE_STATUS);
+ intent.putExtra(BeemIntent.EXTRA_ACCOUNT, mAccount);
+ intent.putExtra(BeemIntent.EXTRA_MESSAGE, b);
+ startService(intent);
ChangeStatus.this.finish();
} else if (v == mClear) {
mStatusMessageEditText.setText(null);
--- a/src/com/beem/project/beem/ui/Chat.java Sun May 06 12:28:38 2012 +0200
+++ b/src/com/beem/project/beem/ui/Chat.java Mon Jul 16 11:43:10 2012 +0200
@@ -206,7 +206,7 @@
@Override
public void bindView(View view, Context context, Cursor cursor) {
- String jid = cursor.getString(cursor.getColumnIndex(Messages.TO));
+ String jid = cursor.getString(cursor.getColumnIndex(Messages.FROM));
if (jid.length() == 0)
jid = cursor.getString(cursor.getColumnIndex(Messages.FROM));
String date = cursor.getString(cursor.getColumnIndex(Messages.DATE_READ));
--- a/src/com/beem/project/beem/ui/ContactList.java Sun May 06 12:28:38 2012 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java Mon Jul 16 11:43:10 2012 +0200
@@ -181,21 +181,23 @@
switch (item.getItemId()) {
case R.id.contact_list_menu_settings:
Intent i = new Intent(this, Settings.class);
- i.putExtra("account_name", mAccountName);
+ i.putExtra(BeemIntent.EXTRA_ACCOUNT, mAccountName);
startActivity(i);
return true;
case R.id.contact_list_menu_add_contact:
Intent addContactIntent = new Intent(ContactList.this, AddContact.class);
- addContactIntent.putExtra("account_name", mAccountName);
+ addContactIntent.putExtra(BeemIntent.EXTRA_ACCOUNT, mAccountName);
startActivity(addContactIntent);
return true;
case R.id.contact_list_menu_muc_add_contact:
Intent addMUCIntent = new Intent(ContactList.this, AddMuc.class);
- addMUCIntent.putExtra("account_name", mAccountName);
+ addMUCIntent.putExtra(BeemIntent.EXTRA_ACCOUNT, mAccountName);
startActivity(addMUCIntent);
return true;
case R.id.menu_change_status:
- startActivity(new Intent(ContactList.this, ChangeStatus.class));
+ Intent changeStatusIntent = new Intent(ContactList.this, ChangeStatus.class);
+ changeStatusIntent.putExtra(BeemIntent.EXTRA_ACCOUNT, mAccountName);
+ startActivity(changeStatusIntent);
return true;
case R.id.contact_list_menu_chatlist:
// List<Contact> openedChats;
--- a/src/com/beem/project/beem/ui/Login.java Sun May 06 12:28:38 2012 +0200
+++ b/src/com/beem/project/beem/ui/Login.java Mon Jul 16 11:43:10 2012 +0200
@@ -56,6 +56,7 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
@@ -65,7 +66,6 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
-import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
@@ -79,6 +79,7 @@
import com.beem.project.beem.R;
import com.beem.project.beem.ui.dialogs.builders.ChangeStatus;
import com.beem.project.beem.ui.wizard.AccountConfigure;
+import com.beem.project.beem.utils.Status;
/**
* This class is the main Activity for the Beem project.
@@ -282,9 +283,10 @@
@Override
public boolean onLongClick(View v) {
+ //TODO: Long Click
TextView accountName = (TextView) mView.findViewById(R.id.accountname);
Intent i = new Intent(Login.this, ChangeStatus.class);
- i.putExtra("beem_account", accountName.getText());
+ i.putExtra(BeemIntent.EXTRA_ACCOUNT, accountName.getText());
startActivity(i);
return true;
}
@@ -340,10 +342,12 @@
ImageButton logo = (ImageButton) v.findViewById(R.id.loginanim_logo_anim);
if (BeemIntent.ACTION_CONNECTED.equals(action)) {
+ SharedPreferences settings = getSharedPreferences(account, MODE_PRIVATE);
if (text != null)
- text.setText(R.string.contact_status_msg_available);
+ text.setText(settings
+ .getString(BeemApplication.STATUS_TEXT_KEY, getString(R.string.contact_status_msg_available)));
if (logo != null) {
- logo.setImageResource(R.drawable.beem_launcher_icon_color);
+ logo.setImageResource(Status.getIconBarFromStatus(settings.getInt(BeemApplication.STATUS_KEY, 0)));
logo.clearAnimation();
}
} else if (BeemIntent.ACTION_DISCONNECTED.equals(action)) {
@@ -351,7 +355,7 @@
if (text != null)
text.setText(message);
if (logo != null) {
- logo.setImageResource(R.drawable.beem_launcher_icon_silver);
+ logo.setImageResource(R.drawable.beem_status_icon_offline);
logo.clearAnimation();
}
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/ui/Notification/BeemAccountNotification.java Mon Jul 16 11:43:10 2012 +0200
@@ -0,0 +1,12 @@
+package com.beem.project.beem.ui.Notification;
+
+import android.content.Context;
+
+public class BeemAccountNotification extends BeemNotification {
+
+ protected BeemAccountNotification(Context c, String accountName) {
+ super(c);
+
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/ui/Notification/BeemNotification.java Mon Jul 16 11:43:10 2012 +0200
@@ -0,0 +1,97 @@
+/*
+ BEEM is a videoconference application on the Android Platform.
+
+ Copyright (C) 2009 by Frederic-Charles Barthelery,
+ Jean-Manuel Da Silva,
+ Nikita Kozlov,
+ Philippe Lago,
+ Jean Baptiste Vergely,
+ Vincent Veronis.
+
+ This file is part of BEEM.
+
+ BEEM is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ BEEM is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with BEEM. If not, see <http://www.gnu.org/licenses/>.
+
+ Please send bug reports with examples or suggestions to
+ contact@beem-project.com or http://dev.beem-project.com/
+ */
+
+package com.beem.project.beem.ui.Notification;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.widget.RemoteViews;
+
+import com.beem.project.beem.R;
+
+/**
+ * SingletonClass notification.
+ * @author Vincent V. <marseille@beem-project.com>
+ */
+public class BeemNotification extends Notification {
+
+ private static Context mContext;
+ private NotificationManager mNotificationManager;
+
+ private static BeemNotification instance = null;
+
+ /**
+ * Constructor.
+ */
+ protected BeemNotification(Context c) {
+ super();
+ mContext = c;
+ mNotificationManager = (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE);
+ Intent notificationIntent = new Intent();
+ contentIntent = PendingIntent.getActivity(c, (int) System.currentTimeMillis(), notificationIntent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+ icon = R.drawable.beem_status_icon;
+ flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
+ contentView = new RemoteViews(mContext.getPackageName(), R.layout.notification);
+ contentView.setTextViewText(R.id.pseudo, "Beem");
+ }
+
+ public static void BindNotification(Context c) {
+ if (instance == null) {
+ instance = new BeemNotification(c);
+ }
+ instance.contentView.setTextViewText(R.id.msgstatus, "TODO: X messages unread");
+ instance.mNotificationManager.notify(R.string.app_name, instance);
+
+ }
+
+ public static void StartSyncNotification(Context c) {
+ if (instance == null) {
+ instance = new BeemNotification(c);
+ }
+ instance.icon = R.drawable.ic_menu_sync;
+ instance.mNotificationManager.notify(R.string.app_name, instance);
+ }
+
+ public static void StopSyncNotification(Context c) {
+ if (instance == null) {
+ instance = new BeemNotification(c);
+ }
+ instance.icon = R.drawable.beem_status_icon;
+ instance.mNotificationManager.notify(R.string.app_name, instance);
+ }
+
+ public void deleteNotification(int id) {
+ mNotificationManager.cancel(id);
+ }
+
+}
--- a/src/com/beem/project/beem/ui/Settings.java Sun May 06 12:28:38 2012 +0200
+++ b/src/com/beem/project/beem/ui/Settings.java Mon Jul 16 11:43:10 2012 +0200
@@ -40,7 +40,7 @@
Flavien Astraud, November 26, 2009
Head of the EIP Laboratory.
-*/
+ */
package com.beem.project.beem.ui;
import android.accounts.Account;
@@ -70,15 +70,14 @@
super.onCreate(savedInstanceState);
Account account = getIntent().getParcelableExtra("account");
PreferenceManager pn = getPreferenceManager();
- if (account != null) { // if we come from android.account interface
- pn.setSharedPreferencesName(account.name);
- }
- else if (getIntent().getExtras() != null) { // if we come from beem interface
+ if (account != null) { // if we come from android.account interface
+ pn.setSharedPreferencesName(account.name);
+ } else if (getIntent().getExtras() != null) { // if we come from beem interface
pn.setSharedPreferencesName(getIntent().getExtras().getString("account_name"));
} else {
-
+
}
-
+
addPreferencesFromResource(R.layout.preferences);
}
@@ -102,7 +101,7 @@
case R.id.settings_menu_create_account:
i = new Intent(this, CreateAccount.class);
startActivity(i);
- return true;
+ return true;
default:
return false;
}
--- a/src/com/beem/project/beem/ui/dialogs/builders/ChangeStatus.java Sun May 06 12:28:38 2012 +0200
+++ b/src/com/beem/project/beem/ui/dialogs/builders/ChangeStatus.java Mon Jul 16 11:43:10 2012 +0200
@@ -32,11 +32,13 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.os.Bundle;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.ImageButton;
import android.widget.TextView;
+import com.beem.project.beem.BeemApplication;
import com.beem.project.beem.BeemIntent;
import com.beem.project.beem.R;
import com.beem.project.beem.utils.Status;
@@ -76,9 +78,11 @@
ImageButton logo = (ImageButton) v.findViewById(R.id.loginanim_logo_anim);
logo.startAnimation(AnimationUtils.loadAnimation(context, R.anim.rotate_and_scale));
+ Bundle b = new Bundle();
+ b.putInt(BeemApplication.STATUS_KEY, getStatusForService(item));
Intent intent = new Intent(BeemIntent.ACTION_CHANGE_STATUS);
- intent.putExtra(BeemIntent.EXTRA_ACCOUNT, account);
- intent.putExtra(BeemIntent.EXTRA_MESSAGE, getStatusForService(item));
+ intent.putExtra(BeemIntent.EXTRA_ACCOUNT, account);
+ intent.putExtra(BeemIntent.EXTRA_MESSAGE, b);
context.startService(intent);
}
});
--- a/src/com/beem/project/beem/utils/Status.java Sun May 06 12:28:38 2012 +0200
+++ b/src/com/beem/project/beem/utils/Status.java Mon Jul 16 11:43:10 2012 +0200
@@ -40,12 +40,14 @@
Flavien Astraud, November 26, 2009
Head of the EIP Laboratory.
-*/
+ */
package com.beem.project.beem.utils;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Mode;
+import com.beem.project.beem.R;
+
/**
* Utility class to deal with status and presence value.
* @author marseille
@@ -153,4 +155,32 @@
return status != Status.CONTACT_STATUS_DISCONNECT;
}
+ /**
+ * Get icon resource from status.
+ * @param status the status
+ * @return the resource icon
+ */
+ public static int getIconBarFromStatus(final int status) {
+ int icon = R.drawable.beem_status_icon;
+ switch (status) {
+ case Status.CONTACT_STATUS_AVAILABLE:
+ icon = R.drawable.beem_status_icon_available;
+ break;
+ case Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT:
+ icon = R.drawable.beem_status_icon_chat;
+ break;
+ case Status.CONTACT_STATUS_AWAY:
+ icon = R.drawable.beem_status_icon_away;
+ break;
+ case Status.CONTACT_STATUS_BUSY:
+ icon = R.drawable.beem_status_icon_busy;
+ break;
+ case Status.CONTACT_STATUS_UNAVAILABLE:
+ icon = R.drawable.beem_status_icon_gray;
+ break;
+ default:
+ icon = R.drawable.beem_status_icon_offline;
+ }
+ return icon;
+ }
}