Login add features to change status on logo icon
authorVincent V. <marseille@beem-project.com>
Thu, 29 Dec 2011 22:40:40 +0100
changeset 924 5aece2c91bef
parent 923 60061b3719fb
child 925 6a4029cc7882
Login add features to change status on logo icon
AndroidManifest.xml
res/menu/contactlist_context.xml
src/com/beem/project/beem/BeemIntent.java
src/com/beem/project/beem/BeemService.java
src/com/beem/project/beem/ui/Login.java
src/com/beem/project/beem/ui/dialogs/builders/ChangeStatus.java
--- a/AndroidManifest.xml	Thu Dec 29 19:20:05 2011 +0100
+++ b/AndroidManifest.xml	Thu Dec 29 22:40:40 2011 +0100
@@ -191,6 +191,7 @@
                 <action android:name="com.beem.project.beem.intent.action.IS_CONNECTED" />
                 <action android:name="com.beem.project.beem.intent.action.SEND_MESSAGE" />
                 <action android:name="com.beem.project.beem.intent.action.ADD_CONTACT" />
+                <action android:name="com.beem.project.beem.intent.action.CHANGE_STATUS" />
             </intent-filter>
         </service>
     </application>
--- a/res/menu/contactlist_context.xml	Thu Dec 29 19:20:05 2011 +0100
+++ b/res/menu/contactlist_context.xml	Thu Dec 29 22:40:40 2011 +0100
@@ -1,34 +1,36 @@
-<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_call_item"
-		android:title="@string/CDCall"
-		android:visible="false" />
-	<item
-		android:id="@+id/contact_list_context_menu_user_info"
-		android:title="@string/CDInfos">
-		<menu>
-			<item
-				android:id="@+id/contact_list_context_menu_userinfo_alias"
-				android:title="@string/userinfo_label_alias" />
-			<item
-				android:id="@+id/contact_list_context_menu_userinfo_group"
-				android:title="@string/userinfo_label_chg_group" />
-			<item	
-				android:id="@+id/contact_list_context_menu_userinfo_subscription"
-				android:title="@string/userinfo_label_re_subscription" />
-			<item
-				android:id="@+id/contact_list_context_menu_userinfo_block"
-				android:title="@string/userinfo_label_block"
-				android:visible="false" />
-			<item
-				android:id="@+id/contact_list_context_menu_userinfo_delete"
-				android:title="@string/userinfo_label_delete" />
-		</menu>
-	</item>
+<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_call_item"
+        android:title="@string/CDCall"
+        android:visible="false"/>
+    <item
+        android:id="@+id/contact_list_context_menu_user_info"
+        android:title="@string/CDInfos">
+        <menu>
+            <item
+                android:id="@+id/contact_list_context_menu_userinfo_alias"
+                android:title="@string/userinfo_label_alias"/>
+            <item
+                android:id="@+id/contact_list_context_menu_userinfo_group"
+                android:title="@string/userinfo_label_chg_group"/>
+            <item
+                android:id="@+id/contact_list_context_menu_userinfo_subscription"
+                android:title="@string/userinfo_label_re_subscription"/>
+            <item
+                android:id="@+id/contact_list_context_menu_userinfo_block"
+                android:title="@string/userinfo_label_block"
+                android:visible="false"/>
+            <item
+                android:id="@+id/contact_list_context_menu_userinfo_delete"
+                android:title="@string/userinfo_label_delete"/>
+        </menu>
+    </item>
+
 </menu>
\ No newline at end of file
--- a/src/com/beem/project/beem/BeemIntent.java	Thu Dec 29 19:20:05 2011 +0100
+++ b/src/com/beem/project/beem/BeemIntent.java	Thu Dec 29 22:40:40 2011 +0100
@@ -1,47 +1,46 @@
+/*
+ BEEM is a videoconference application on the Android Platform.
 
-/*
-    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.
 
-    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.
 
-    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 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.
 
-    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/>.
 
-    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/
+ 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.
+ 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.
+ Nicolas Sadirac, November 26, 2009
+ President of Epitech.
 
-    Flavien Astraud, November 26, 2009
-    Head of the EIP Laboratory.
+ Flavien Astraud, November 26, 2009
+ Head of the EIP Laboratory.
 
-*/
+ */
 package com.beem.project.beem;
 
 public class BeemIntent {
@@ -49,16 +48,18 @@
     public static final String ACTION_CONNECT = "com.beem.project.beem.intent.action.CONNECT";
 
     public static final String ACTION_DISCONNECT = "com.beem.project.beem.intent.action.DISCONNECT";
-    
+
     public static final String ACTION_ISCONNECTED = "com.beem.project.beem.intent.action.IS_CONNECTED";
 
     public static final String ACTION_SEND_MESSAGE = "com.beem.project.beem.intent.action.SEND_MESSAGE";
-    
+
     public static final String ACTION_SYNC = "com.beem.project.beem.intent.action.SYNC";
-    
+
     public static final String ACTION_ADD_CONTACT = "com.beem.project.beem.intent.action.ADD_CONTACT";
 
-    /*Broadcast Receiver's action */
+    public static final String ACTION_CHANGE_STATUS = "com.beem.project.beem.intent.action.CHANGE_STATUS";
+
+    /* Broadcast Receiver's action */
     public static final String ACTION_CONNECTED = "com.beem.project.beem.intent.action.CONNECTED";
 
     public static final String ACTION_DISCONNECTED = "com.beem.project.beem.intent.action.DISCONNECTED";
@@ -72,4 +73,3 @@
     public static final String EXTRA_MESSAGE = "com.beem.project.beem.intent.extra.MESSAGE";
 
 }
-
--- a/src/com/beem/project/beem/BeemService.java	Thu Dec 29 19:20:05 2011 +0100
+++ b/src/com/beem/project/beem/BeemService.java	Thu Dec 29 22:40:40 2011 +0100
@@ -105,6 +105,8 @@
     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;
+    //Next = 0x8;
 
     private Map<String, XmppConnectionAdapter> mConnection = new HashMap<String, XmppConnectionAdapter>();
     private Map<String, BeemConnection> mBeemConnection = new HashMap<String, BeemConnection>();
@@ -400,6 +402,8 @@
 	    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 {
 	    Log.w(TAG, "Unknown intent " + intent);
 	}
@@ -423,7 +427,7 @@
 		connection = mConnection.get(accountName);
 	    }
 	    if (connection == null && msg.what != MESSAGE_CONNECT && msg.what != MESSAGE_SYNC
-		&& msg.what != MESSAGE_IS_CONNECTED) {
+		&& msg.what != MESSAGE_IS_CONNECTED && msg.what != MESSAGE_CHANGE_STATUS) {
 		Toast.makeText(BeemService.this, getString(R.string.BeemServiceNotConnected, accountName),
 		    Toast.LENGTH_LONG).show();
 		return;
@@ -477,6 +481,15 @@
 			}
 		    }
 		    break;
+		case MESSAGE_CHANGE_STATUS:
+		    int status = b.getInt(BeemIntent.EXTRA_MESSAGE);
+		    if (status == Status.CONTACT_STATUS_DISCONNECT) {
+			handleDisconnect(accountName);
+		    } else {
+			handleConnect(accountName);
+			mConnection.get(accountName).changeStatus(status, "");
+		    }
+		    break;
 		default:
 		    Log.w(TAG, "Unknown message " + msg);
 	    }
@@ -522,12 +535,16 @@
 
 	    }
 	}
+	//TODO: ADD MESSAGE 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);
     }
+
 }
--- a/src/com/beem/project/beem/ui/Login.java	Thu Dec 29 19:20:05 2011 +0100
+++ b/src/com/beem/project/beem/ui/Login.java	Thu Dec 29 22:40:40 2011 +0100
@@ -50,6 +50,7 @@
 import android.accounts.AccountManager;
 import android.app.Activity;
 import android.app.AlertDialog;
+import android.app.Dialog;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.DialogInterface;
@@ -58,7 +59,6 @@
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
 import android.os.Bundle;
-import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuInflater;
@@ -77,6 +77,7 @@
 import com.beem.project.beem.BeemIntent;
 import com.beem.project.beem.BeemService;
 import com.beem.project.beem.R;
+import com.beem.project.beem.ui.dialogs.builders.ChangeStatus;
 import com.beem.project.beem.ui.wizard.AccountConfigure;
 
 /**
@@ -107,7 +108,7 @@
 	}
 
 	setContentView(R.layout.login);
-	
+
 	Intent intent = new Intent(this, BeemService.class);
 	startService(intent);
 
@@ -120,8 +121,6 @@
 	listView.setClickable(true);
 	listView.setOnItemClickListener(mOnAccountClick);
 	listView.setAdapter(mAdapterAccountList);
-	
-
     }
 
     @Override
@@ -136,7 +135,6 @@
     public void onStart() {
 	super.onStart();
 	//TODO: Option autostart connect account
-	//TODO: Check if already connected : BindService ? Database ?
     }
 
     @Override
@@ -221,28 +219,28 @@
 	    if (convertView == null) {
 		v = mInflater.inflate(R.layout.login_row_account, null);
 	    }
-	    
+
 	    String accountName = mListAccount.get(position);
-	    
+
 	    //Check if already connected
 	    Intent intent = new Intent(BeemIntent.ACTION_ISCONNECTED);
 	    intent.putExtra(BeemIntent.EXTRA_ACCOUNT, accountName);
 	    startService(intent);
-	    
+
 	    ImageButton logo = (ImageButton) v.findViewById(R.id.loginanim_logo_anim);
-	    
+
 	    logo.setFocusable(false);
 	    logo.setOnClickListener(new BeemConnectionOnClick(v));
 	    logo.setOnLongClickListener(new BeemConnectionOnLongClick(v));
-	    
+
 	    TextView name = (TextView) v.findViewById(R.id.accountname);
 	    name.setText(accountName);
-	    
+
 	    int hash = accountName.hashCode();
 	    if (hash < 0)
 		hash = hash * -1;
 	    v.setId(hash);
-	    	    	        
+
 	    return v;
 	}
 
@@ -263,17 +261,9 @@
 
 	@Override
 	public void onClick(View v) {
-	    //TODO: Check if already connected -> disconnect
-	    TextView accountStatus = (TextView) mView.findViewById(R.id.accountstatus);
-	    accountStatus.setText(R.string.login_pending);
-
-	    ImageButton logo = (ImageButton) mView.findViewById(R.id.loginanim_logo_anim);
-	    logo.startAnimation(AnimationUtils.loadAnimation(mView.getContext(), R.anim.rotate_and_scale));
-
 	    TextView accountName = (TextView) mView.findViewById(R.id.accountname);
-	    Intent intent = new Intent(BeemIntent.ACTION_CONNECT);
-	    intent.putExtra(BeemIntent.EXTRA_ACCOUNT, accountName.getText());
-	    startService(intent);
+	    Dialog status = new ChangeStatus(Login.this, accountName.getText().toString(), mView).create();
+	    status.show();
 	}
     }
 
@@ -341,7 +331,6 @@
 	public void onReceive(Context context, Intent intent) {
 	    String action = intent.getAction();
 	    String account = intent.getExtras().getString(BeemIntent.EXTRA_ACCOUNT);
-	    Log.e("DEBUG", "ACTION " + action + " ACCOUNT " + account);
 	    int hash = account.hashCode();
 	    if (hash < 0)
 		hash = hash * -1;
@@ -359,7 +348,6 @@
 		}
 	    } else if (BeemIntent.ACTION_DISCONNECTED.equals(action)) {
 		String message = intent.getExtras().getString(BeemIntent.EXTRA_MESSAGE);
-		Log.e("DEBUG", "OO " + message);
 		if (text != null)
 		    text.setText(message);
 		if (logo != null) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/ui/dialogs/builders/ChangeStatus.java	Thu Dec 29 22:40:40 2011 +0100
@@ -0,0 +1,120 @@
+/*
+    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.dialogs.builders;
+
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.view.View;
+import android.view.animation.AnimationUtils;
+import android.widget.ImageButton;
+import android.widget.TextView;
+
+import com.beem.project.beem.BeemIntent;
+import com.beem.project.beem.R;
+import com.beem.project.beem.utils.Status;
+
+/**
+ * Create the change chat dialog.
+ */
+public class ChangeStatus extends AlertDialog.Builder {
+
+    private static final String TAG = "Dialogs.Builders > Status";
+
+    private static final int AVAILABLE_FOR_CHAT_IDX = 0;
+    private static final int AVAILABLE_IDX = 1;
+    private static final int BUSY_IDX = 2;
+    private static final int AWAY_IDX = 3;
+    private static final int UNAVAILABLE_IDX = 4;
+    private static final int DISCONNECTED_IDX = 5;
+
+    /**
+     * Constructor.
+     * @param context context activity.
+     * @param openedChats A list containing the JID of participants of the opened chats.
+     */
+
+    public ChangeStatus(final Context context, final String account, final View v) {
+	super(context);
+
+	setTitle(context.getString(R.string.ChangeStatusType));
+	final CharSequence[] items = context.getResources().getStringArray(R.array.status_types);	
+	
+	setItems(items, new DialogInterface.OnClickListener() {
+	    public void onClick(DialogInterface dialog, int item) {
+
+		TextView accountStatus = (TextView) v.findViewById(R.id.accountstatus);
+		accountStatus.setText(R.string.login_pending);
+
+		ImageButton logo = (ImageButton) v.findViewById(R.id.loginanim_logo_anim);
+		logo.startAnimation(AnimationUtils.loadAnimation(context, R.anim.rotate_and_scale));
+
+		Intent intent = new Intent(BeemIntent.ACTION_CHANGE_STATUS);
+		intent.putExtra(BeemIntent.EXTRA_ACCOUNT, account);
+		intent.putExtra(BeemIntent.EXTRA_MESSAGE, getStatusForService(item));
+		context.startService(intent);
+	    }
+	});
+    }
+
+    /**
+     * convert status text to.
+     * @param item selected item text.
+     * @return item position in the array.
+     */
+    private int getStatusForService(int item) {
+	int result;
+
+	switch (item) {
+	    case ChangeStatus.DISCONNECTED_IDX:
+		result = Status.CONTACT_STATUS_DISCONNECT;
+		break;
+	    case ChangeStatus.AVAILABLE_FOR_CHAT_IDX:
+		result = Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT;
+		break;
+	    case ChangeStatus.AVAILABLE_IDX:
+		result = Status.CONTACT_STATUS_AVAILABLE;
+		break;
+	    case ChangeStatus.AWAY_IDX:
+		result = Status.CONTACT_STATUS_AWAY;
+		break;
+	    case ChangeStatus.BUSY_IDX:
+		result = Status.CONTACT_STATUS_BUSY;
+		break;
+	    case ChangeStatus.UNAVAILABLE_IDX:
+		result = Status.CONTACT_STATUS_UNAVAILABLE;
+		break;
+	    default:
+		result = Status.CONTACT_STATUS_AVAILABLE;
+		break;
+	}
+	return result;
+    }
+}