Changement du dialogsettings en activity.
authormarseille@KungFuh
Wed, 08 Apr 2009 00:01:39 +0200
changeset 88 7b2a869e9ef8
parent 87 84cad8522aa6
child 89 3f6eb9233987
Changement du dialogsettings en activity.
AndroidManifest.xml
res/layout/contactlistdialogsettings.xml
res/layout/contactlistsettings.xml
src/com/beem/project/beem/ui/ContactList.java
src/com/beem/project/beem/ui/ContactListDialogSettings.java
src/com/beem/project/beem/ui/ContactListSettings.java
--- 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 @@
 				<category android:name="android.intent.category.LAUNCHER" />
 			</intent-filter>
 		</activity>
+		<activity android:name=".ui.ContactListSettings" android:label="@string/app_name" />
 		<activity android:name=".ui.SendIM" android:label="@string/app_name" />
 		<service android:name="BeemService" android:enabled="true"
 			android:label="Beem Service" android:permission="com.beem.project.beem.BEEM_SERVICE">
--- 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 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-              android:orientation="vertical"
-              android:layout_width="fill_parent"
-              android:layout_height="fill_parent"
-        >
-    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-                  android:orientation="horizontal"
-                  android:layout_width="fill_parent"
-                  android:layout_height="wrap_content"
-            >
-        <TextView
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:text="Host/Port:"
-                android:minWidth="70dp"
-                />
-                
-        <EditText android:id="@+id/host"
-                  android:layout_width="wrap_content"
-                  android:layout_height="wrap_content"
-                  android:singleLine="true"
-                  android:textSize="16sp"
-                  android:autoText="false"
-                  android:capitalize="none"
-                  android:minWidth="150dp"
-                  android:scrollHorizontally="true"/>
-        <EditText android:id="@+id/port"
-                  android:layout_width="wrap_content"
-                  android:layout_height="wrap_content"
-                  android:singleLine="true"
-                  android:textSize="16sp"
-                  android:autoText="false"
-                  android:minWidth="80dp"
-                  android:capitalize="none"
-                  android:scrollHorizontally="true"/>
-    </LinearLayout>
-
-    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-                  android:orientation="horizontal"
-                  android:layout_width="fill_parent"
-                  android:layout_height="wrap_content"
-            >
-        <TextView
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:text="Userid:"
-                android:minWidth="70dp"
-                />
-        <EditText android:id="@+id/userid"
-                  android:layout_width="wrap_content"
-                  android:layout_height="wrap_content"
-                  android:singleLine="true"
-                  android:textSize="16sp"
-                  android:autoText="false"
-                  android:minWidth="250dp"
-                  android:capitalize="none"
-                  android:scrollHorizontally="true"/>
-    </LinearLayout>
-    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-                  android:orientation="horizontal"
-                  android:layout_width="fill_parent"
-                  android:layout_height="wrap_content"
-            >
-        <TextView
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:text="Password:"
-                android:minWidth="70dp"
-                />
-        <EditText android:id="@+id/password"
-                  android:layout_width="wrap_content"
-                  android:layout_height="wrap_content"
-                  android:singleLine="true"
-                  android:password="true"
-                  android:textSize="16sp"
-                  android:autoText="false"
-                  android:minWidth="250dp"
-                  android:capitalize="none"
-                  android:scrollHorizontally="true"/>
-    </LinearLayout>
-
-    <Button android:id="@+id/ok"
-            android:layout_width="fill_parent"
-            android:layout_height="fill_parent"
-            android:text="OK">
-        <requestFocus/>
-    </Button>
-</LinearLayout>
\ No newline at end of file
--- /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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:orientation="vertical"
+              android:layout_width="fill_parent"
+              android:layout_height="fill_parent"
+        >
+    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+                  android:orientation="horizontal"
+                  android:layout_width="fill_parent"
+                  android:layout_height="wrap_content"
+            >
+        <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="Host/Port:"
+                android:minWidth="70dp"
+                />
+                
+        <EditText android:id="@+id/host"
+                  android:layout_width="wrap_content"
+                  android:layout_height="wrap_content"
+                  android:singleLine="true"
+                  android:textSize="16sp"
+                  android:autoText="false"
+                  android:capitalize="none"
+                  android:minWidth="150dp"
+                  android:scrollHorizontally="true"/>
+        <EditText android:id="@+id/port"
+                  android:layout_width="wrap_content"
+                  android:layout_height="wrap_content"
+                  android:singleLine="true"
+                  android:textSize="16sp"
+                  android:autoText="false"
+                  android:minWidth="80dp"
+                  android:capitalize="none"
+                  android:scrollHorizontally="true"/>
+    </LinearLayout>
+
+    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+                  android:orientation="horizontal"
+                  android:layout_width="fill_parent"
+                  android:layout_height="wrap_content"
+            >
+        <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="Userid:"
+                android:minWidth="70dp"
+                />
+        <EditText android:id="@+id/userid"
+                  android:layout_width="wrap_content"
+                  android:layout_height="wrap_content"
+                  android:singleLine="true"
+                  android:textSize="16sp"
+                  android:autoText="false"
+                  android:minWidth="250dp"
+                  android:capitalize="none"
+                  android:scrollHorizontally="true"/>
+    </LinearLayout>
+    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+                  android:orientation="horizontal"
+                  android:layout_width="fill_parent"
+                  android:layout_height="wrap_content"
+            >
+        <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="Password:"
+                android:minWidth="70dp"
+                />
+        <EditText android:id="@+id/password"
+                  android:layout_width="wrap_content"
+                  android:layout_height="wrap_content"
+                  android:singleLine="true"
+                  android:password="true"
+                  android:textSize="16sp"
+                  android:autoText="false"
+                  android:minWidth="250dp"
+                  android:capitalize="none"
+                  android:scrollHorizontally="true"/>
+    </LinearLayout>
+
+    <Button android:id="@+id/ok"
+            android:layout_width="fill_parent"
+            android:layout_height="fill_parent"
+            android:text="OK">
+        <requestFocus/>
+    </Button>
+</LinearLayout>
\ No newline at end of file
--- 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<String> listGroup,
 	    List<Contact> 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());
 		}
 
 		/*
--- 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);
--- /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), "");
+    }
+
+}