# HG changeset patch # User Da Risk # Date 1266542781 -3600 # Node ID 03d61b8faa0d83b1c426621c812c9111ce921a78 # Parent bd5bddda04ddcd2badb9896e479582c403fe7826# Parent 99931d858ac0910ebf6230044337855d836028ef Merge diff -r 99931d858ac0 -r 03d61b8faa0d AndroidManifest.xml --- a/AndroidManifest.xml Fri Feb 19 00:49:37 2010 +0100 +++ b/AndroidManifest.xml Fri Feb 19 02:26:21 2010 +0100 @@ -4,7 +4,7 @@ android:versionName="0.1.2"> + android:debuggable="true" android:name=".BeemApplication"> @@ -13,7 +13,7 @@ + android:launchMode="singleTop" android:screenOrientation="portrait" /> . + + 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 android.app.Application; + +/** + * 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 + */ +public class BeemApplication extends Application { + + private boolean mIsConnected; + + @Override + public void onCreate() { + super.onCreate(); + } + + /** + * Tell if Beem is connected to a XMPP server. + * @return false if not connected. + */ + public boolean isConnected() { + return mIsConnected; + } + + /** + * Set the status of the connection to a XMPP server of BEEM. + * @param isConnected + */ + public void setConnected(boolean isConnected) { + mIsConnected = isConnected; + } + +} diff -r 99931d858ac0 -r 03d61b8faa0d src/com/beem/project/beem/service/BeemChatManager.java --- a/src/com/beem/project/beem/service/BeemChatManager.java Fri Feb 19 00:49:37 2010 +0100 +++ b/src/com/beem/project/beem/service/BeemChatManager.java Fri Feb 19 02:26:21 2010 +0100 @@ -92,6 +92,7 @@ @Override public void chatCreated(Chat chat, boolean locally) { IChat newchat = getChat(chat); + Log.d(TAG, "Chat" + chat.toString() + " created locally " + locally + "with " + chat.getParticipant()); try { newchat.addMessageListener(mChatListener); final int n = mRemoteChatCreationListeners.beginBroadcast(); diff -r 99931d858ac0 -r 03d61b8faa0d src/com/beem/project/beem/service/XmppConnectionAdapter.java --- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java Fri Feb 19 00:49:37 2010 +0100 +++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java Fri Feb 19 02:26:21 2010 +0100 @@ -59,6 +59,7 @@ import android.app.Notification; import android.app.PendingIntent; +import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.RemoteCallbackList; @@ -67,6 +68,7 @@ import com.beem.project.beem.BeemService; import com.beem.project.beem.R; +import com.beem.project.beem.BeemApplication; import com.beem.project.beem.service.aidl.IBeemConnectionListener; import com.beem.project.beem.service.aidl.IChatManager; import com.beem.project.beem.service.aidl.IRoster; @@ -101,6 +103,7 @@ private String mPreviousStatus; private PrivacyListManagerAdapter mPrivacyListManager; private final BeemService mService; + private BeemApplication mApplication; private final RemoteCallbackList mRemoteConnListeners = new RemoteCallbackList(); private final SubscribePacketListener mSubscribePacketListener = new SubscribePacketListener(); @@ -144,6 +147,10 @@ mLogin = login; mPassword = password; mService = service; + Context ctx = mService.getApplicationContext(); + if (ctx instanceof BeemApplication) { + mApplication = (BeemApplication) ctx; + } SharedPreferences pref = mService.getServicePreference(); try { mPreviousPriority = Integer.parseInt(pref.getString("settings_key_priority", "0")); @@ -221,7 +228,7 @@ mService.resetStatus(); mService.initJingle(mAdaptee); - // triggerAsynchronousConnectEvent(); + mApplication.setConnected(true); changeStatus(Status.CONTACT_STATUS_AVAILABLE, mService.getServicePreference().getString("status_text", "")); return true; } catch (XMPPException e) { @@ -369,7 +376,7 @@ Roster adap = mAdaptee.getRoster(); if (adap == null) return null; - mRoster = new RosterAdapter(adap, mService.getApplicationContext()); + mRoster = new RosterAdapter(adap, mService); return mRoster; } @@ -403,13 +410,6 @@ } /** - * Trigger Connection event. - */ - private void triggerAsynchronousConnectEvent() { - mConListener.onConnect(); - } - - /** * PrivacyListManagerAdapter mutator. * @param privacyListManager the privacy list manager */ @@ -457,6 +457,7 @@ intent.putExtra("normally", true); mService.sendBroadcast(intent); mService.stopSelf(); + mApplication.setConnected(false); } /** @@ -470,6 +471,7 @@ intent.putExtra("message", exception.getMessage()); mService.sendBroadcast(intent); mService.stopSelf(); + mApplication.setConnected(false); } /** @@ -493,61 +495,7 @@ } mRemoteConnListeners.finishBroadcast(); mService.stopSelf(); - } - - /** - * Method to execute when a connection event occurs. - */ - public void onConnect() { - PacketFilter filter = new PacketFilter() { - - @Override - public boolean accept(Packet packet) { - if (packet instanceof Presence) { - Presence pres = (Presence) packet; - if (pres.getType() == Presence.Type.subscribe) - return true; - } - return false; - } - }; - - mAdaptee.addPacketListener(new PacketListener() { - - @Override - public void processPacket(Packet packet) { - String from = packet.getFrom(); - Notification notif = new Notification(android.R.drawable.stat_notify_more, mService.getString( - R.string.AcceptContactRequest, from), System.currentTimeMillis()); - notif.defaults = Notification.DEFAULT_ALL; - notif.flags = Notification.FLAG_AUTO_CANCEL; - Intent intent = new Intent(mService, Subscription.class); - intent.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); - } - }, filter); - - mService.resetStatus(); - mService.initJingle(mAdaptee); - - final int n = mRemoteConnListeners.beginBroadcast(); - - for (int i = 0; i < n; i++) { - IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i); - try { - if (listener != null) - listener.onConnect(); - } catch (RemoteException e) { - // The RemoteCallbackList will take care of removing the - // dead listeners. - Log.w(TAG, "Error while triggering remote connection listeners", e); - } - } - mRemoteConnListeners.finishBroadcast(); + mApplication.setConnected(false); } /** @@ -600,6 +548,7 @@ @Override public void reconnectionSuccessful() { Log.d(TAG, "reconnectionSuccessful"); + mApplication.setConnected(true); PacketFilter filter = new PacketFilter() { @Override diff -r 99931d858ac0 -r 03d61b8faa0d src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl --- a/src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl Fri Feb 19 00:49:37 2010 +0100 +++ b/src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl Fri Feb 19 02:26:21 2010 +0100 @@ -56,8 +56,9 @@ /** * Callback to call when the connection occurs + * @Deprecated */ - void onConnect(); + //void onConnect(); //void connectionClosedOnError(in Exception e); /** diff -r 99931d858ac0 -r 03d61b8faa0d src/com/beem/project/beem/ui/Login.java --- a/src/com/beem/project/beem/ui/Login.java Fri Feb 19 00:49:37 2010 +0100 +++ b/src/com/beem/project/beem/ui/Login.java Fri Feb 19 02:26:21 2010 +0100 @@ -45,6 +45,7 @@ import android.app.Activity; import android.app.AlertDialog; +import android.app.Application; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; @@ -60,6 +61,7 @@ import com.beem.project.beem.R; import com.beem.project.beem.utils.BeemConnectivity; +import com.beem.project.beem.BeemApplication; /** * This class is the main Activity for the Beem project. @@ -72,6 +74,7 @@ private TextView mTextView; private boolean mIsConfigured; private boolean mIsResult; + private BeemApplication mBeemApplication; /** * Constructor. @@ -82,6 +85,14 @@ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + Application app = getApplication(); + if (app instanceof BeemApplication) { + BeemApplication mBeemApplication = (BeemApplication) app; + if (mBeemApplication.isConnected()) { + startActivity(new Intent(this, ContactList.class)); + finish(); + } + } setContentView(R.layout.login); mTextView = (TextView) findViewById(R.id.log_as_msg); mSettings = PreferenceManager.getDefaultSharedPreferences(this);