# HG changeset patch # User marseille@KungFuh # Date 1239141699 -7200 # Node ID 7b2a869e9ef89312a03ca5931cff88a80eda4484 # Parent 84cad8522aa65e26c1e35c18873763a322f728ec Changement du dialogsettings en activity. diff -r 84cad8522aa6 -r 7b2a869e9ef8 AndroidManifest.xml --- a/AndroidManifest.xml Tue Apr 07 20:14:42 2009 +0200 +++ b/AndroidManifest.xml Wed Apr 08 00:01:39 2009 +0200 @@ -9,6 +9,7 @@ + diff -r 84cad8522aa6 -r 7b2a869e9ef8 res/layout/contactlistdialogsettings.xml --- a/res/layout/contactlistdialogsettings.xml Tue Apr 07 20:14:42 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,89 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff -r 84cad8522aa6 -r 7b2a869e9ef8 res/layout/contactlistsettings.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/res/layout/contactlistsettings.xml Wed Apr 08 00:01:39 2009 +0200 @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 84cad8522aa6 -r 7b2a869e9ef8 src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Tue Apr 07 20:14:42 2009 +0200 +++ b/src/com/beem/project/beem/ui/ContactList.java Wed Apr 08 00:01:39 2009 +0200 @@ -13,7 +13,6 @@ import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Handler; -import android.os.IBinder; import android.os.RemoteException; import android.util.Log; import android.view.Menu; @@ -32,17 +31,17 @@ import com.beem.project.beem.service.Contact; import com.beem.project.beem.service.PresenceAdapter; import com.beem.project.beem.service.aidl.IBeemRosterListener; +import com.beem.project.beem.service.aidl.IRoster; import com.beem.project.beem.service.aidl.IXmppFacade; -import com.beem.project.beem.service.aidl.IRoster; public class ContactList extends ExpandableListActivity { private static final String TAG = "CONTACTLIST_ACT"; + private static final int PREFERENCECHANGED = 0; private IXmppFacade mService = null; private SharedPreferences mSettings; private Handler mHandler; private BeemApplication mBeemApplication; - private ContactListDialogSettings mDialog; private BeemRosterListener mRosterListener; private IRoster mRoster; @@ -66,23 +65,13 @@ mBeemApplication = BeemApplication.getApplication(this); mSettings = getSharedPreferences( getString(R.string.PreferenceFileName), MODE_PRIVATE); - mDialog = new ContactListDialogSettings(this, mSettings); mRosterListener = new BeemRosterListener(); - - mSettings - .registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() { - @Override - public void onSharedPreferenceChanged( - SharedPreferences sharedPreferences, String key) { - Log.i(TAG, "On Preference Changed"); - } - }); } @Override protected void onStart() { super.onStart(); - + mBeemApplication.startBeemService(); } @Override @@ -92,18 +81,21 @@ * @TODO: A ameliorer apres listener de nikita */ Log.i(TAG, "onResume"); - mBeemApplication.startBeemService(); mBeemApplication.callWhenConnectedToServer(mHandler, new Runnable() { @Override public void run() { mService = mBeemApplication.getXmppFacade(); try { - if (mRoster != null) { - mRoster = mService.getRoster(); + mRoster = mService.getRoster(); + } catch (RemoteException e1) { + e1.printStackTrace(); + } + if (mRoster != null) { + try { mRoster.addConnectionListener(mRosterListener); + } catch (RemoteException e) { + e.printStackTrace(); } - } catch (RemoteException e) { - e.printStackTrace(); } callbackShowContactList(); } @@ -149,7 +141,7 @@ public final boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.account_edit: - mDialog.show(); + startActivityForResult(new Intent(this, ContactListSettings.class), PREFERENCECHANGED); return true; case R.id.account_about: return true; @@ -157,6 +149,17 @@ return false; } } + + protected void onActivityResult(int requestCode, int resultCode, + Intent data) { + if (requestCode == PREFERENCECHANGED) { + if (resultCode == RESULT_OK) { + mBeemApplication.stopBeemService(); + mBeemApplication.startBeemService(); + } + } + } + private void showContactList(List listGroup, List listContact) { @@ -277,12 +280,10 @@ if (v != null) { v.setText(c.getJID()); } - /* - * @TODO: Rajouter le message perso du contact v = (TextView) - */ + v = (TextView) view.findViewById(to[2]); if (v != null) { - v.setText(c.getMsgState()); + v.setText(c.getMMsgState()); } /* diff -r 84cad8522aa6 -r 7b2a869e9ef8 src/com/beem/project/beem/ui/ContactListDialogSettings.java --- a/src/com/beem/project/beem/ui/ContactListDialogSettings.java Tue Apr 07 20:14:42 2009 +0200 +++ b/src/com/beem/project/beem/ui/ContactListDialogSettings.java Wed Apr 08 00:01:39 2009 +0200 @@ -33,7 +33,6 @@ setContentView(R.layout.contactlistdialogsettings); getWindow().setFlags(4, 4); setTitle("Jabber Account Settings"); - showSettings(); Button ok = (Button) findViewById(R.id.ok); ok.setOnClickListener(this); } @@ -58,21 +57,7 @@ dismiss(); } - private void showSettings() { - Context ctx = getContext(); - EditText e = (EditText) findViewById(R.id.host); - e.setText(mSettings.getString( - ctx.getString(R.string.PreferenceHostKey), "")); - e = (EditText) findViewById(R.id.port); - e.setText(mSettings.getString( - ctx.getString(R.string.PreferencePortKey), "")); - e = (EditText) findViewById(R.id.userid); - e.setText(mSettings.getString(ctx - .getString(R.string.PreferenceLoginKey), "")); - e = (EditText) findViewById(R.id.password); - e.setText(mSettings.getString(ctx - .getString(R.string.PreferencePasswordKey), "")); - } + private String getWidgetText(int id) { EditText widget = (EditText) this.findViewById(id); diff -r 84cad8522aa6 -r 7b2a869e9ef8 src/com/beem/project/beem/ui/ContactListSettings.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/ui/ContactListSettings.java Wed Apr 08 00:01:39 2009 +0200 @@ -0,0 +1,93 @@ +package com.beem.project.beem.ui; + +import android.app.Activity; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.view.View; +import android.util.Log; +import android.view.View.OnClickListener; +import android.widget.Button; +import android.widget.EditText; + +import com.beem.project.beem.R; + +public class ContactListSettings extends Activity { + + public static final int CHANGE = 1; + private SharedPreferences mSettings; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.contactlistsettings); + mSettings = getSharedPreferences( + getString(R.string.PreferenceFileName), MODE_PRIVATE); + showSettings(); + Button ok = (Button) findViewById(R.id.ok); + ok.setOnClickListener(mOkListener); + } + + private OnClickListener mOkListener = new OnClickListener() { + public void onClick(View v) { + boolean b = false; + SharedPreferences.Editor editor = mSettings.edit(); + + if (isChanged(R.id.host, R.string.PreferenceHostKey)) { + editor.putString( + getString(R.string.PreferenceHostKey), + getWidgetText(R.id.host)); + b = true; + } + if (isChanged(R.id.port, R.string.PreferencePortKey)) { + editor.putString( + getString(R.string.PreferencePortKey), + getWidgetText(R.id.port)); + b = true; + } + if (isChanged(R.id.userid, R.string.PreferenceLoginKey)) { + editor.putString( + getString(R.string.PreferenceLoginKey), + getWidgetText(R.id.userid)); + b = true; + } + if (isChanged(R.id.password, R.string.PreferencePasswordKey)) { + editor.putString( + getString(R.string.PreferencePasswordKey), + getWidgetText(R.id.password)); + b = true; + } + + if (b == true) { + editor.commit(); + setResult(RESULT_OK); + } else + setResult(RESULT_CANCELED); + finish(); + } + }; + + private boolean isChanged(int idEdit, int idPreference) { + return (!getWidgetText(idEdit).equals(getPreferenceString(idPreference))); + } + + private void showSettings() { + EditText e = (EditText) findViewById(R.id.host); + e.setText(getPreferenceString(R.string.PreferenceHostKey)); + e = (EditText) findViewById(R.id.port); + e.setText(getPreferenceString(R.string.PreferencePortKey)); + e = (EditText) findViewById(R.id.userid); + e.setText(getPreferenceString(R.string.PreferenceLoginKey)); + e = (EditText) findViewById(R.id.password); + e.setText(getPreferenceString(R.string.PreferencePasswordKey)); + } + + private String getWidgetText(int id) { + EditText widget = (EditText) this.findViewById(id); + return widget.getText().toString(); + } + + private String getPreferenceString(int id) { + return mSettings.getString(getString(id), ""); + } + +}