# HG changeset patch # User "Vincent Veronis" # Date 1311377287 -7200 # Node ID 965a9876c37a22f57c7120493be962c3e37f0a56 # Parent 07de7eb304b6e11e804ff3c58b9fd3ed2731098e UI login now can connect to multi account diff -r 07de7eb304b6 -r 965a9876c37a res/drawable/beem_launcher_icon_color.png Binary file res/drawable/beem_launcher_icon_color.png has changed diff -r 07de7eb304b6 -r 965a9876c37a res/layout/login.xml --- a/res/layout/login.xml Thu Jul 21 23:03:26 2011 +0200 +++ b/res/layout/login.xml Sat Jul 23 01:28:07 2011 +0200 @@ -1,13 +1,18 @@ - - - - + \ No newline at end of file diff -r 07de7eb304b6 -r 965a9876c37a src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Thu Jul 21 23:03:26 2011 +0200 +++ b/src/com/beem/project/beem/BeemService.java Sat Jul 23 01:28:07 2011 +0200 @@ -155,15 +155,7 @@ @Override public IBinder onBind(Intent intent) { Log.d(TAG, "ONBIND()"); - String accountName = intent.getStringExtra("account_name"); - Log.e(TAG, accountName); - // try { - // for (XmppConnectionAdapter connection : mConnection.values()) - // connection.connect(); - // } catch (RemoteException e) { - // Log.w(TAG, "Error while connecting", e); - // } - return (IBinder) mBind.get(accountName); + return null;//(IBinder) mBind.get(accountName); } @Override @@ -526,15 +518,18 @@ private void handleConnect(Bundle b) { Intent res = new Intent(BeemIntent.ACTION_DISCONNECTED); + String account = null; - if (b != null) + if (b != null) { + Log.e("VIEW", "ID"+b.getInt("VIEW")); account = b.getString(BeemIntent.EXTRA_ACCOUNT); + res.putExtra(BeemIntent.EXTRA_ACCOUNT, account); + } if (account == null) //TODO temporary account = "dummy"; if (account == null) { //connect all } else { - BeemConnection beemco = new BeemConnection(BeemService.this.getSharedPreferences(account, MODE_PRIVATE), mPreferenceListener); if (beemco.getSettings().getBoolean("settings_away_chk", false)) { @@ -550,8 +545,7 @@ Log.i(TAG, "Starting connection of " + account); if (beemcoAdapter.connectSync()) { mConnection.put(account, beemcoAdapter); - mBind.put(account, new XmppFacade(beemcoAdapter)); - + mBind.put(account, new XmppFacade(beemcoAdapter)); res.setAction(BeemIntent.ACTION_CONNECTED); Log.e(TAG, "Account configuration : " + account.toString() + " DONE"); } else { @@ -560,36 +554,6 @@ } catch (RemoteException e) { Log.e(TAG, "Unable to connect " + account, e); } - - // res.putExtra(BeemIntent.EXTRA_ACCOUNT, account); - // XmppConnectionAdapter con = mConnections.get(account); - // if (con != null && con.isAuthentificated()) - // return; - // if (con == null ) { - // ConnectionConfiguration config = initConnectionConfig(account); - // String login = StringUtils.parseName(account); - // String password = mSettings.getString(BeemApplication.ACCOUNT_PASSWORD_KEY, ""); - // - // if (mSettings.getBoolean(BeemApplication.FULL_JID_LOGIN_KEY, false) || - // "gmail.com".equals(mService) || "googlemail.com".equals(mService)) { - // login = account; - // } - // con = new XmppConnectionAdapter(config, login, password, this); - // try { - // Log.i(TAG, "Starting connection of " + account); - // if(con.connectSync()){ - // mConnections.put(account, con); - // mConnection = con; - // - // //TODO - // mBind = new XmppFacade(con); - // } else { - // Log.w(TAG, "Unable to connect " + account); - // } - // } catch (RemoteException e) { - // Log.e(TAG, "Unable to connect " + account, e); - // } - // } sendBroadcast(res); } } diff -r 07de7eb304b6 -r 965a9876c37a src/com/beem/project/beem/account/CheckBoxPreference_Custom.java --- a/src/com/beem/project/beem/account/CheckBoxPreference_Custom.java Thu Jul 21 23:03:26 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +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 . - - 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.account; - -import android.content.Context; -import android.preference.CheckBoxPreference; -import android.util.AttributeSet; -import android.util.Log; -import android.widget.CompoundButton; -import android.widget.CompoundButton.OnCheckedChangeListener; - -/** - * Custom CheckBoxPreference for Android accountPreferences xml - * @author marseille - */ -public class CheckBoxPreference_Custom extends CheckBoxPreference implements OnCheckedChangeListener { - - private static final String TAG = "CheckBoxPreference_Custom"; - - /** - * Constructor - */ - public CheckBoxPreference_Custom(Context context) { - super(context); - } - - /** - * Constructor - */ - public CheckBoxPreference_Custom(Context context, AttributeSet attrs) { - super(context, attrs); - } - - /** - * Constructor - */ - public CheckBoxPreference_Custom(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - /** - * {@inheritDoc} - */ - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - Log.e(TAG, "Checked : " + isChecked); - - } - -} diff -r 07de7eb304b6 -r 965a9876c37a src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Thu Jul 21 23:03:26 2011 +0200 +++ b/src/com/beem/project/beem/ui/ContactList.java Sat Jul 23 01:28:07 2011 +0200 @@ -79,6 +79,7 @@ import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; +import com.beem.project.beem.BeemIntent; import com.beem.project.beem.R; import com.beem.project.beem.service.Contact; import com.beem.project.beem.service.aidl.IChatManager; @@ -138,6 +139,7 @@ setContentView(R.layout.contactlist); mInflater = getLayoutInflater(); + getIntent().getExtras().getString(BeemIntent.EXTRA_ACCOUNT); //Get Groups list final Cursor cursorGroup = getContentResolver().query(ContactsContract.Groups.CONTENT_URI, diff -r 07de7eb304b6 -r 965a9876c37a src/com/beem/project/beem/ui/Login.java --- a/src/com/beem/project/beem/ui/Login.java Thu Jul 21 23:03:26 2011 +0200 +++ b/src/com/beem/project/beem/ui/Login.java Sat Jul 23 01:28:07 2011 +0200 @@ -50,23 +50,20 @@ import android.accounts.AccountManager; import android.app.Activity; import android.app.AlertDialog; -import android.content.ComponentName; +import android.content.BroadcastReceiver; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.content.ServiceConnection; +import android.content.IntentFilter; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; -import android.os.AsyncTask; import android.os.Bundle; -import android.os.IBinder; -import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.AdapterView; import android.widget.BaseAdapter; @@ -75,32 +72,18 @@ import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener; -import com.beem.project.beem.BeemApplication; +import com.beem.project.beem.BeemIntent; import com.beem.project.beem.R; -import com.beem.project.beem.service.LoginAsyncTask; -import com.beem.project.beem.service.aidl.IXmppFacade; /** * This class is the main Activity for the Beem project. - * @author Da Risk + * @author Vincent V. */ public class Login extends Activity { - private static final Intent SERVICE_INTENT = new Intent(); - static { - SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService")); - } - private static final int LOGIN_REQUEST_CODE = 1; - private TextView mTextView; - private BeemApplication mBeemApplication; - private String mAccountName; - private final ServiceConnection mServConn = new LoginServiceConnection(); - private IXmppFacade mXmppFacade; - private AsyncTask mTask; - private Animation mAnimationLogo; - - List mListAccount = new ArrayList(); + private BroadcastReceiver mReceiver; private BeemAccountList mAdapterAccountList; + private List mListAccount = new ArrayList(); private final BeemAccountListOnClick mOnAccountClick = new BeemAccountListOnClick(); /** @@ -112,23 +95,40 @@ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.login); - mTextView = (TextView) findViewById(R.id.log_as_msg); ListView listView = (ListView) findViewById(R.id.accountlist); mAdapterAccountList = new BeemAccountList(getLayoutInflater()); listView.setClickable(true); listView.setOnItemClickListener(mOnAccountClick); listView.setAdapter(mAdapterAccountList); - mAnimationLogo = AnimationUtils.loadAnimation(Login.this, R.anim.rotate_and_scale); - Intent i = new Intent(Login.SERVICE_INTENT); - startService(i); - } + + mReceiver = new BroadcastReceiver() { + public void onReceive(Context ctx, Intent intent) { + String action = intent.getAction(); + String account = intent.getExtras().getString(BeemIntent.EXTRA_ACCOUNT); + int hash = account.hashCode(); + if (hash < 0 ) hash = hash - 2 * hash; + + View v = findViewById(hash); + TextView text = (TextView) v.findViewById(R.id.accountstatus); + ImageButton logo = (ImageButton) v.findViewById(R.id.loginanim_logo_anim); - @Override - protected void onStart() { - super.onStart(); - mTextView.setText(R.string.login_start_msg); + if (BeemIntent.ACTION_CONNECTED.equals(action)) { + if (text != null) text.setText(R.string.contact_status_msg_available); + if (logo != null) { + logo.setImageResource(R.drawable.beem_launcher_icon_color); + logo.clearAnimation(); + } + } else if (BeemIntent.ACTION_DISCONNECTED.equals(action)) { + if (text != null) text.setText(R.string.contact_status_msg_offline); + if (logo != null) { + logo.setImageResource(R.drawable.beem_launcher_icon_silver); + logo.clearAnimation(); + } + } + } + }; + } @Override @@ -138,19 +138,12 @@ inflater.inflate(R.menu.login, menu); return true; } - - @Override - protected void onDestroy() { - super.onDestroy(); - //unbindService(mServConn); - } @Override public final boolean onOptionsItemSelected(MenuItem item) { boolean result; switch (item.getItemId()) { case R.id.login_menu_settings: - mTextView.setText(""); startActivity(new Intent(Login.this, Settings.class)); result = true; break; @@ -193,6 +186,9 @@ aboutDialog.show(); } + /** + * Populate row account. + */ private class BeemAccountList extends BaseAdapter { private LayoutInflater mInflater; @@ -229,35 +225,49 @@ } ImageButton logo = (ImageButton) v.findViewById(R.id.loginanim_logo_anim); logo.setFocusable(false); - logo.setOnClickListener(new BeemConnectionOnClick()); + logo.setOnClickListener(new BeemConnectionOnClick(v)); TextView name = (TextView) v.findViewById(R.id.accountname); name.setText(mListAccount.get(position)); + int hash = mListAccount.get(position).hashCode(); + if (hash < 0 ) hash = hash - 2 * hash; + v.setId(hash); return v; } } + /** + * Event simple click on item of the bitton of account list. + */ private class BeemConnectionOnClick implements android.view.View.OnClickListener { - + private View mView; + /** + * Constructor. + */ + public BeemConnectionOnClick(View v) { + mView = v; + } @Override public void onClick(View v) { //TODO: Check if already connected -> disconnect - TextView accountStatus = (TextView) findViewById(R.id.accountstatus); - accountStatus.setText(R.string.login_pending); - ImageButton logo = (ImageButton) findViewById(R.id.loginanim_logo_anim); - logo.startAnimation(mAnimationLogo); - TextView accountName = (TextView) findViewById(R.id.accountname); - Intent i = new Intent(Login.SERVICE_INTENT); - i.putExtra("account_name", accountName.getText()); - bindService(i, mServConn, BIND_AUTO_CREATE); - mTask = new LoginTask(v.getRootView()); + TextView accountStatus = (TextView) mView.findViewById(R.id.accountstatus); + accountStatus.setText(R.string.login_pending); + + ImageButton logo = (ImageButton) mView.findViewById(R.id.loginanim_logo_anim); + logo.startAnimation(AnimationUtils.loadAnimation(mView.getContext(), R.anim.rotate_and_scale)); + TextView accountName = (TextView) mView.findViewById(R.id.accountname); + Intent intent = new Intent(BeemIntent.ACTION_CONNECT); + intent.putExtra(BeemIntent.EXTRA_ACCOUNT, accountName.getText()); + IntentFilter filter = new IntentFilter(BeemIntent.ACTION_CONNECTED); + filter.addAction(BeemIntent.ACTION_DISCONNECTED); + registerReceiver(mReceiver, filter); + startService(intent); } - } /** - * Event simple click on item of the contact list. + * Event simple click on item of the account list. */ private class BeemAccountListOnClick implements OnItemClickListener { /** @@ -272,73 +282,9 @@ @Override public void onItemClick(AdapterView arg0, View v, int pos, long lpos) { Intent i = new Intent(Login.this, ContactList.class); + TextView accountName = (TextView)v.findViewById(R.id.accountname); + i.putExtra(BeemIntent.EXTRA_ACCOUNT, accountName.getText()); startActivity(i); } - } - - /** - * Asynchronous class for connection. - */ - private class LoginTask extends LoginAsyncTask { - - private View mView; - - /** - * Constructor. - */ - LoginTask(View v) { - mView = v; - } - - @Override - protected void onPostExecute(Boolean result) { - ImageButton logo = (ImageButton) mView.findViewById(R.id.loginanim_logo_anim); - if (result == null || !result) { // Task cancelled or exception - unbindService(mServConn); - logo.setBackgroundResource(R.drawable.beem_launcher_icon_silver); - } else { // Connection OK - logo.setBackgroundResource(R.drawable.beem_icon_launcher_color); - } - logo.clearAnimation(); - } - - @Override - protected void onProgressUpdate(Integer... values) { - TextView status = (TextView) mView.findViewById(R.id.accountstatus); - status.setText(getResources().getStringArray(R.array.loganim_state)[values[0]]); - } - - @Override - protected void onCancelled() { - super.onCancelled(); - Login.this.stopService(Login.SERVICE_INTENT); - } - - } - - /** - * The service connection used to connect to the Beem service. - */ - private class LoginServiceConnection implements ServiceConnection { - - /** - * Constructor. - */ - public LoginServiceConnection() { - } - - @Override - public void onServiceConnected(ComponentName name, IBinder service) { - Log.e("BEEMSERVICECONNECTION", "CONNECTED"); - mXmppFacade = IXmppFacade.Stub.asInterface(service); - mTask.execute(mXmppFacade); - } - - @Override - public void onServiceDisconnected(ComponentName name) { - Log.e("BEEMSERVICECONNECTION", "DISCONNECTED"); - mXmppFacade = null; - } - } - + } } diff -r 07de7eb304b6 -r 965a9876c37a src/com/beem/project/beem/ui/LoginAnim.java --- a/src/com/beem/project/beem/ui/LoginAnim.java Thu Jul 21 23:03:26 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,253 +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 . - - 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.ServiceConnection; -import android.os.AsyncTask; -import android.os.Bundle; -import android.os.IBinder; -import android.util.Log; -import android.view.KeyEvent; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.animation.Animation; -import android.view.animation.AnimationUtils; -import android.widget.Button; -import android.widget.ImageView; -import android.widget.TextView; - -import com.beem.project.beem.R; -import com.beem.project.beem.service.LoginAsyncTask; -import com.beem.project.beem.service.aidl.IXmppFacade; - -/** - * This class is an activity which display an animation during the connection with the server. - * @author Da Risk - */ -public class LoginAnim extends Activity { - - private static final String TAG = "LoginAnim"; - private static final Intent SERVICE_INTENT = new Intent(); - static { - SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService")); - } - private ImageView mLogo; - private Animation mRotateAnim; - private final ServiceConnection mServConn = new LoginServiceConnection(); - private IXmppFacade mXmppFacade; - private AsyncTask mTask; - private Button mCancelBt; - private TextView mLoginState; - - /** - * Constructor. - */ - public LoginAnim() { - } - - /* (non-Javadoc) - * @see android.app.Activity#onCreate(android.os.Bundle) - */ - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.login_anim); - mLoginState = (TextView) findViewById(R.id.loginanim_status_text); - mLogo = (ImageView) findViewById(R.id.loginanim_logo_anim); - mRotateAnim = AnimationUtils.loadAnimation(this, R.anim.rotate_and_scale); - mCancelBt = (Button) findViewById(R.id.loginanim_cancel_button); - mCancelBt.setOnClickListener(new ClickListener()); - } - - /* (non-Javadoc) - * @see android.app.Activity#onStart() - */ - @Override - protected void onStart() { - super.onStart(); - mLogo.startAnimation(mRotateAnim); - } - - /* (non-Javadoc) - * @see android.app.Activity#onResume() - */ - @Override - protected void onResume() { - super.onResume(); - if (mTask == null) - mTask = new LoginTask(); - if (mXmppFacade == null) { - Intent i = new Intent(LoginAnim.SERVICE_INTENT); - i.putExtras(getIntent()); - bindService(i, mServConn, BIND_AUTO_CREATE); - } - } - - /* (non-Javadoc) - * @see android.app.Activity#onPause() - */ - @Override - protected void onPause() { - super.onPause(); - if (mXmppFacade != null) { // and async task not en cours - unbindService(mServConn); - mXmppFacade = null; - } - } - - /* (non-Javadoc) - * @see android.app.Activity#onKeyDown(int, android.view.KeyEvent) - */ - @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - // TODO use onBackPressed on Eclair (2.0) - if (keyCode == KeyEvent.KEYCODE_BACK && mTask.getStatus() != AsyncTask.Status.FINISHED) { - if (!mTask.cancel(true)) { - Log.d(TAG, "Can't interrupt the connection"); - } - setResult(Activity.RESULT_CANCELED); - } - return super.onKeyDown(keyCode, event); - } - - /** - * Click event listener on cancel button. - */ - private class ClickListener implements OnClickListener { - - /** - * Constructor. - */ - ClickListener() { - } - - @Override - public void onClick(View v) { - if (v == mCancelBt) { - if (!mTask.cancel(true)) { - Log.d(TAG, "Can't interrupt the connection"); - } - setResult(Activity.RESULT_CANCELED); - finish(); - } - } - } - - /** - * Asynchronous class for connection. - */ - private class LoginTask extends LoginAsyncTask { - - /** - * Constructor. - */ - LoginTask() { - } - - /* (non-Javadoc) - * @see android.os.AsyncTask#onPostExecute(java.lang.Object) - */ - @Override - protected void onPostExecute(Boolean result) { - - if (result == null || !result) { // Task cancelled or exception - if (!result) { - Intent i = new Intent(); - i.putExtra("message", getErrorMessage()); - LoginAnim.this.setResult(Activity.RESULT_CANCELED, i); - } else - LoginAnim.this.setResult(Activity.RESULT_CANCELED); - LoginAnim.this.finish(); - } else { - mCancelBt.setEnabled(false); - LoginAnim.this.startService(LoginAnim.SERVICE_INTENT); - LoginAnim.this.setResult(Activity.RESULT_OK); - LoginAnim.this.finish(); - } - } - - @Override - protected void onProgressUpdate(Integer ... values) { - mLoginState.setText(getResources().getStringArray(R.array.loganim_state)[values[0]]); - } - - /* (non-Javadoc) - * @see android.os.AsyncTask#onCancelled() - */ - @Override - protected void onCancelled() { - super.onCancelled(); - LoginAnim.this.stopService(LoginAnim.SERVICE_INTENT); - } - - } - - /** - * The service connection used to connect to the Beem service. - */ - private class LoginServiceConnection implements ServiceConnection { - - /** - * Constructor. - */ - public LoginServiceConnection() { - } - - @Override - public void onServiceConnected(ComponentName name, IBinder service) { - mXmppFacade = IXmppFacade.Stub.asInterface(service); - if (mTask.getStatus() == AsyncTask.Status.PENDING) - mTask = mTask.execute(mXmppFacade); - - } - - @Override - public void onServiceDisconnected(ComponentName name) { - mXmppFacade = null; - } - } -}