merge
authormarseille@KungFuh
Wed, 08 Apr 2009 12:07:49 +0200
changeset 91 d8c5c3191491
parent 90 c2b22b565ef9 (diff)
parent 85 7d0e36aa1be5 (current diff)
child 93 a4501bbd1549
merge
--- a/AndroidManifest.xml	Wed Apr 08 00:12:24 2009 +0200
+++ b/AndroidManifest.xml	Wed Apr 08 12:07:49 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	Wed Apr 08 00:12:24 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 12:07:49 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	Wed Apr 08 00:12:24 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java	Wed Apr 08 12:07:49 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,33 +65,12 @@
 	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) {
-			/*
-			 * TODO : A faire apres listener nikita
-			 * 
-			 * mBeemApplication.stopBeemService();
-			 * mBeemApplication.startBeemService();
-			 * mBeemApplication.callWhenServiceConnected(mHandler,
-			 * new Runnable() {
-			 * 
-			 * @Override public void run() {
-			 * callbackShowContactList(); } });
-			 */
-		    }
-		});
     }
 
     @Override
     protected void onStart() {
 	super.onStart();
-	Log.i(TAG, "onStart");
 	mBeemApplication.startBeemService();
     }
 
@@ -103,18 +81,22 @@
 	 * @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 {
 		    mRoster = mService.getRoster();
-		    mRoster.addConnectionListener(mRosterListener);
-		    Log.i(TAG, "ROSTERLISTENER OK");
-		} catch (RemoteException e) {
-		    e.printStackTrace();
-		}		
+		} catch (RemoteException e1) {
+		    e1.printStackTrace();
+		}
+		if (mRoster != null) {
+		    try {
+			mRoster.addConnectionListener(mRosterListener);
+		    } catch (RemoteException e) {
+			e.printStackTrace();
+		    }
+		}
 		callbackShowContactList();
 	    }
 	});
@@ -126,10 +108,11 @@
 	 */
 	if (mRoster != null)
 	    try {
-		showContactList(mRoster.getGroupsNames(), mRoster.getContactList());
+		showContactList(mRoster.getGroupsNames(), mRoster
+			.getContactList());
 	    } catch (RemoteException e) {
 		e.printStackTrace();
-	    }	
+	    }
     }
 
     /**
@@ -158,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;
@@ -166,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) {
@@ -186,7 +180,7 @@
 		Map<String, Contact> curChildMap = new HashMap<String, Contact>();
 		children.add(curChildMap);
 		Contact c = listContact.get(j);
-		Log.i(TAG, c.getID() + " " +c.getJID());
+		Log.i(TAG, c.getID() + " " + c.getJID());
 		curChildMap.put("CHILD", c);
 	    }
 	    childData.add(children);
@@ -278,7 +272,7 @@
 		    default:
 			imageDrawable = (Drawable) getResources().getDrawable(
 				R.drawable.error);
-		    	break;
+			break;
 		}
 		imgV.setImageDrawable(imageDrawable);
 
@@ -286,9 +280,7 @@
 		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());
@@ -314,26 +306,29 @@
 	public void onEntriesAdded(List<String> addresses)
 		throws RemoteException {
 	    Log.i(TAG, "ENTRIES ADDED");
-	    
+
 	}
+
 	@Override
 	public void onEntriesDeleted(List<String> addresses)
 		throws RemoteException {
 	    Log.i(TAG, "ENTRIES DEL");
-	    
+
 	}
+
 	@Override
 	public void onEntriesUpdated(List<String> addresses)
 		throws RemoteException {
 	    Log.i(TAG, "ENTRIES UPD");
-	    
+
 	}
+
 	@Override
 	public void onPresenceChanged(PresenceAdapter presence)
 		throws RemoteException {
 	    Log.i(TAG, "PRESENCE CHANGED");
-	    
+
 	}
-	
+
     }
 }
\ No newline at end of file
--- a/src/com/beem/project/beem/ui/ContactListDialogSettings.java	Wed Apr 08 00:12:24 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,81 +0,0 @@
-package com.beem.project.beem.ui;
-
-import android.app.Activity;
-import android.app.Dialog;
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.os.RemoteException;
-import android.util.Log;
-import android.view.View;
-import android.widget.Button;
-import android.widget.EditText;
-
-import com.beem.project.beem.BeemApplication;
-import com.beem.project.beem.R;
-
-/**
- *
- */
-public class ContactListDialogSettings extends Dialog implements
-	android.view.View.OnClickListener {
-
-    private SharedPreferences mSettings;
-
-    public ContactListDialogSettings(Activity activity,
-	    SharedPreferences settings) {
-	super(activity);
-	this.mSettings = settings;
-    }
-
-    @Override
-    protected void onStart() {
-	super.onStart();
-	setContentView(R.layout.contactlistdialogsettings);
-	getWindow().setFlags(4, 4);
-	setTitle("Jabber Account Settings");
-	showSettings();
-	Button ok = (Button) findViewById(R.id.ok);
-	ok.setOnClickListener(this);
-    }
-
-    @Override
-    public void onClick(View v) {
-	SharedPreferences.Editor editor = mSettings.edit();
-	Context ctx = getContext();
-	editor.putString(ctx.getString(R.string.PreferenceHostKey),
-		getWidgetText(R.id.host));
-	editor.putString(ctx.getString(R.string.PreferencePortKey),
-		getWidgetText(R.id.port));
-	editor.putString(ctx.getString(R.string.PreferenceLoginKey),
-		getWidgetText(R.id.userid));
-	editor.putString(ctx.getString(R.string.PreferencePasswordKey),
-		getWidgetText(R.id.password));
-	String JID = ctx.getString(R.string.PreferenceLoginKey) + "@"
-		+ ctx.getString(R.string.PreferenceHostKey);
-	editor.putString(ctx.getString(R.string.PreferenceJID), JID);
-	editor.putBoolean("ACCOUNT_CONFIGURED", true);
-	editor.commit();
-	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);
-	return widget.getText().toString();
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/ui/ContactListSettings.java	Wed Apr 08 12:07:49 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), "");
+    }
+
+}