# HG changeset patch # User Nikita Kozlov # Date 1253989147 -7200 # Node ID 3c8ca2a1a32738da03ea8b96ac14a697cf56853f # Parent 4684a42ae0add109527dc24b5b107b2a61d53d28 changement de la gestion des settings. pleins de trucs a traduire dedans. diff -r 4684a42ae0ad -r 3c8ca2a1a327 .classpath --- a/.classpath Sat Sep 26 01:15:19 2009 +0200 +++ b/.classpath Sat Sep 26 20:19:07 2009 +0200 @@ -2,17 +2,17 @@ - + - - + + - + diff -r 4684a42ae0ad -r 3c8ca2a1a327 AndroidManifest.xml --- a/AndroidManifest.xml Sat Sep 26 01:15:19 2009 +0200 +++ b/AndroidManifest.xml Sat Sep 26 20:19:07 2009 +0200 @@ -15,6 +15,12 @@ android:name="com.beem.project.beem.service.XmppConnectionAdapter.CONNECTION_CLOSED" /> + + + + + diff -r 4684a42ae0ad -r 3c8ca2a1a327 res/layout/preferences.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/res/layout/preferences.xml Sat Sep 26 20:19:07 2009 +0200 @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 4684a42ae0ad -r 3c8ca2a1a327 src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Sat Sep 26 01:15:19 2009 +0200 +++ b/src/com/beem/project/beem/BeemService.java Sat Sep 26 20:19:07 2009 +0200 @@ -17,8 +17,8 @@ import android.content.SharedPreferences.Editor; import android.os.IBinder; import android.os.RemoteException; +import android.preference.PreferenceManager; import android.util.Log; -import android.widget.ArrayAdapter; import com.beem.project.beem.jingle.JingleService; import com.beem.project.beem.service.XmppConnectionAdapter; @@ -62,16 +62,13 @@ */ private void initConnectionConfig() { java.security.Security.addProvider(new com.sun.security.sasl.Provider()); - mUseProxy = mSettings.getBoolean(getString(R.string.settings_key_proxy_use), false); + mUseProxy = mSettings.getBoolean("settings_key_proxy_use", false); if (mUseProxy) { - ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.proxy_types, - android.R.layout.simple_spinner_item); - int pos = mSettings.getInt(getString(R.string.settings_key_proxy_type), 0); - String stype = adapter.getItem(pos).toString(); - String phost = mSettings.getString(getString(R.string.settings_key_proxy_server), ""); - String puser = mSettings.getString(getString(R.string.settings_key_proxy_username), ""); - String ppass = mSettings.getString(getString(R.string.settings_key_proxy_password), ""); - int pport = Integer.parseInt(mSettings.getString(getString(R.string.settings_key_proxy_port), "1080")); + String stype = mSettings.getString("settings_key_proxy_type", "HTTP"); + String phost = mSettings.getString("settings_key_proxy_server", ""); + String puser = mSettings.getString("settings_key_proxy_username", ""); + String ppass = mSettings.getString("settings_key_proxy_password", ""); + int pport = Integer.parseInt(mSettings.getString("settings_key_proxy_port", "1080")); ProxyInfo.ProxyType type = ProxyType.valueOf(stype); mProxyInfo = new ProxyInfo(type, phost, pport, puser, ppass); if (mService != null) @@ -84,7 +81,7 @@ else mConnectionConfiguration = new ConnectionConfiguration(mHost, mPort); } - if (mSettings.getBoolean(getString(R.string.settings_key_xmpp_tls_use), false)) { + if (mSettings.getBoolean("settings_key_xmpp_tls_use", false)) { mConnectionConfiguration.setSecurityMode(SecurityMode.required); } mConnectionConfiguration.setDebuggerEnabled(false); @@ -107,21 +104,19 @@ public void onCreate() { super.onCreate(); - mSettings = getSharedPreferences(getString(R.string.settings_filename), MODE_PRIVATE); - mLogin = mSettings.getString(getString(R.string.settings_key_account_username), ""); - mPassword = mSettings.getString(getString(R.string.settings_key_account_password), ""); - mHost = mSettings.getString(getString(R.string.settings_key_xmpp_server), ""); - mPort = Integer.parseInt(mSettings.getString(getString(R.string.settings_key_xmpp_port), "5222")); + mSettings = PreferenceManager.getDefaultSharedPreferences(this); + mLogin = mSettings.getString("settings_key_account_username", ""); + mPassword = mSettings.getString("settings_key_account_password", ""); + mHost = mSettings.getString("settings_key_xmpp_server", ""); + mPort = Integer.parseInt(mSettings.getString("settings_key_xmpp_port", "5222")); + mService = StringUtils.parseServer(mLogin); - /* - * Gestion pour gmail. - */ - if ("".equals(mHost)) { - mHost = StringUtils.parseServer(mLogin); + if (mSettings.getBoolean("settings_key_gmail", false)) { + mHost = "talk.google.com"; mService = null; mLogin = StringUtils.parseName(mLogin); - } else - mService = StringUtils.parseServer(mLogin); + } + initConnectionConfig(); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mConnection = new XmppConnectionAdapter(mConnectionConfiguration, mLogin, mPassword, this); diff -r 4684a42ae0ad -r 3c8ca2a1a327 src/com/beem/project/beem/ui/AddContact.java --- a/src/com/beem/project/beem/ui/AddContact.java Sat Sep 26 01:15:19 2009 +0200 +++ b/src/com/beem/project/beem/ui/AddContact.java Sat Sep 26 20:19:07 2009 +0200 @@ -31,13 +31,13 @@ */ public class AddContact extends Activity { + private static final Intent SERVICE_INTENT = new Intent(); private static final String TAG = "AddContact"; private final List mGroup = new ArrayList(); private IXmppFacade mXmppFacade; private final ServiceConnection mServConn = new BeemServiceConnection(); private BroadcastReceiver mReceiver; - private static final Intent SERVICE_INTENT = new Intent(); static { SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService")); } @@ -67,7 +67,7 @@ super.onStop(); unbindService(mServConn); } - + /** * {@inheritDoc} */ @@ -77,7 +77,7 @@ this.registerReceiver(mReceiver, new IntentFilter(XmppConnectionAdapter.BEEM_CONNECTION_CLOSED)); bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE); } - + /** * {@inheritDoc} */ diff -r 4684a42ae0ad -r 3c8ca2a1a327 src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Sat Sep 26 01:15:19 2009 +0200 +++ b/src/com/beem/project/beem/ui/ContactList.java Sat Sep 26 20:19:07 2009 +0200 @@ -36,7 +36,6 @@ import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemLongClickListener; -import com.beem.project.beem.BeemService; import com.beem.project.beem.R; import com.beem.project.beem.service.Contact; import com.beem.project.beem.service.PresenceAdapter; @@ -53,6 +52,7 @@ public class ContactList extends Activity { //private static final String TAG = "CONTACTLIST_ACT"; + private static final Intent SERVICE_INTENT = new Intent(); private static final int REQUEST_CODE = 1; private BeemContactList mAdapterContactList; private BeemBanner mAdapterBanner; @@ -66,7 +66,6 @@ private final ServiceConnection mServConn = new BeemServiceConnection(); private BroadcastReceiver mReceiver; - private static final Intent SERVICE_INTENT = new Intent(); static { SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService")); } @@ -131,7 +130,7 @@ public final boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.contact_list_menu_settings: - startActivityForResult(new Intent(this, EditSettings.class), REQUEST_CODE); + startActivityForResult(new Intent(this, Settings.class), REQUEST_CODE); return true; case R.id.contact_list_menu_add_contact: startActivity(new Intent(ContactList.this, AddContact.class)); @@ -146,6 +145,7 @@ super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE) { if (resultCode == 69) { + stopService(SERVICE_INTENT); finish(); startActivity(new Intent(this, Login.class)); } @@ -158,7 +158,7 @@ @Override protected void onStart() { super.onStart(); - bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE); + bindService(SERVICE_INTENT, mServConn, BIND_AUTO_CREATE); } /** @@ -217,8 +217,6 @@ /** * Contact List construction. - * @param listContact Contact list. - * @param listGroup Group list. */ private void buildContactList() { if (mCurGroup != null) { @@ -231,6 +229,9 @@ listView.setAdapter(mAdapterContactList); } + /** + * buildBanner. + */ private void buildBanner() { Gallery g = (Gallery) findViewById(R.id.gallery); g.setOnItemClickListener(new OnItemClickGroupName()); @@ -289,6 +290,12 @@ */ private class OnItemClickGroupName implements OnItemClickListener { + /** + * Constructor. + */ + public OnItemClickGroupName() { + } + @Override public void onItemClick(AdapterView arg0, View v, int i, long l) { mCurGroup = mListGroup.get(i); @@ -512,7 +519,7 @@ break; default: imageDrawable = getResources().getDrawable(R.drawable.error); - break; + break; } imgV.setImageDrawable(imageDrawable); diff -r 4684a42ae0ad -r 3c8ca2a1a327 src/com/beem/project/beem/ui/Login.java --- a/src/com/beem/project/beem/ui/Login.java Sat Sep 26 01:15:19 2009 +0200 +++ b/src/com/beem/project/beem/ui/Login.java Sat Sep 26 20:19:07 2009 +0200 @@ -12,6 +12,7 @@ import android.os.Handler; import android.os.IBinder; import android.os.RemoteException; +import android.preference.PreferenceManager; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; @@ -32,6 +33,7 @@ public class Login extends Activity { private static final String TAG = "LOG_AS"; + private static final int REQUEST_CODE = 1; private static final Intent SERVICE_INTENT = new Intent(); static { SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService")); @@ -75,11 +77,24 @@ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mSettings = getSharedPreferences(getString(R.string.settings_filename), MODE_PRIVATE); + mSettings = PreferenceManager.getDefaultSharedPreferences(this); setContentView(R.layout.login); mProgressDialog = new ProgressDialog(this); } + /** + * {@inheritDoc} + */ + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == REQUEST_CODE) { + if (resultCode == 69) { + stopService(SERVICE_INTENT); + } + } + } + @Override protected void onDestroy() { super.onDestroy(); @@ -94,11 +109,9 @@ @Override public void onStart() { super.onStart(); - mIsConfigured = mSettings.getBoolean(getString(R.string.PreferenceIsConfigured), false); - + mIsConfigured = mSettings.getBoolean("PreferenceIsConfigured", false); if (mIsConfigured) bindService(Login.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE); - } /** @@ -121,7 +134,7 @@ public final boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.login_menu_settings: - startActivity(new Intent(Login.this, EditSettings.class)); + startActivity(new Intent(Login.this, Settings.class)); return true; case R.id.login_menu_about: createAboutDialog(); diff -r 4684a42ae0ad -r 3c8ca2a1a327 src/com/beem/project/beem/ui/Settings.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/ui/Settings.java Sat Sep 26 20:19:07 2009 +0200 @@ -0,0 +1,127 @@ +package com.beem.project.beem.ui; + +import android.content.BroadcastReceiver; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.preference.PreferenceActivity; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; + +import com.beem.project.beem.R; +import com.beem.project.beem.service.XmppConnectionAdapter; + +/** + * This class represents an activity which allows the user to change his account or proxy parameters. + * @author nikita + */ +public class Settings extends PreferenceActivity { + + private static final Intent SERVICE_INTENT = new Intent(); + private BeemBroadcastReceiver mReceiver; + + static { + SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService")); + } + + /** + * Constructor. + */ + public Settings() { + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.layout.preferences); + mReceiver = new BeemBroadcastReceiver(); + } + + /** + * {@inheritDoc} + */ + @Override + protected void onPause() { + super.onPause(); + this.unregisterReceiver(mReceiver); + } + + /** + * {@inheritDoc} + */ + @Override + public void onResume() { + super.onResume(); + this.registerReceiver(mReceiver, new IntentFilter(XmppConnectionAdapter.BEEM_CONNECTION_CLOSED)); + } + + /** + * {@inheritDoc} + */ + @Override + public void onStop() { + super.onStop(); + SharedPreferences settings = getPreferenceManager().getSharedPreferences(); + settings.edit().putBoolean("PreferenceIsConfigured", + !"".equals(settings.getString("settings_key_account_username", "")) + || !"".equals(settings.getString("settings_key_account_password", ""))).commit(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater mInflater = getMenuInflater(); + mInflater.inflate(R.menu.edit_settings, menu); + return true; + } + + + + /** + * {@inheritDoc} + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + Intent i = null; + switch (item.getItemId()) { + case R.id.settings_menu_create_account: + i = new Intent(this, CreateAccount.class); + startActivity(i); + return true; + case R.id.settings_menu_login: + setResult(69); + SharedPreferences settings = getPreferenceManager().getSharedPreferences(); + settings.edit().putBoolean("PreferenceIsConfigured", + !"".equals(settings.getString("settings_key_account_username", "")) + || !"".equals(settings.getString("settings_key_account_password", ""))).commit(); + this.stopService(SERVICE_INTENT); + finish(); + return true; + default: + return false; + } + } + + /** + * disconnect Broadcast receiver. + */ + private class BeemBroadcastReceiver extends BroadcastReceiver { + + /** + * Constructor. + */ + public BeemBroadcastReceiver() { + } + + @Override + public void onReceive(Context context, Intent intent) { + Settings.this.setResult(69); + } + } +}