/soc/2012/michael/android: 86d5aee9f060: Added a dialog to add b...

Michael Zangl michael at soc.pidgin.im
Wed Jul 25 07:23:38 EDT 2012


Changeset: 86d5aee9f060e15ca39d6db87fdcc97aa8ffd87c
Author:	 Michael Zangl <michael at soc.pidgin.im>
Date:	 2012-07-21 11:24 +0200
Branch:	 soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/86d5aee9f060

Description:

Added a dialog to add buddies.

diffstat:

 android/workspace/im.pidgin.libpurple.testclient/res/layout/addbuddy.xml                                             |  74 ++++++++++
 android/workspace/im.pidgin.libpurple.testclient/res/layout/blist.xml                                                |  20 ++
 android/workspace/im.pidgin.libpurple.testclient/res/values/strings.xml                                              |   8 +
 android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/PurpleTestClient.java            |  11 +-
 android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/accountlist/AccountListView.java |   2 +-
 android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/AddBuddyView.java          |  51 ++++++
 android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/BlistView.java             |  11 +-
 android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/core/ViewController.java         |  19 +-
 8 files changed, 182 insertions(+), 14 deletions(-)

diffs (truncated from 305 to 300 lines):

diff --git a/android/workspace/im.pidgin.libpurple.testclient/res/layout/addbuddy.xml b/android/workspace/im.pidgin.libpurple.testclient/res/layout/addbuddy.xml
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple.testclient/res/layout/addbuddy.xml
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical" >
+
+    <TextView
+        android:id="@+id/textView1"
+        style="@style/headline"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/addbuddy_title" />
+
+    <TableLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content" >
+
+        <TableRow
+            android:id="@+id/tableRow1"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content" >
+
+            <TextView
+                android:id="@+id/textView2"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="@string/addbuddy_account" />
+
+            <Spinner
+                android:id="@+id/addbuddy_account"
+                android:layout_width="0dp"
+                android:layout_height="wrap_content"
+                android:layout_weight="1" />
+        </TableRow>
+
+        <TableRow
+            android:id="@+id/tableRow2"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content" >
+
+            <TextView
+                android:id="@+id/textView3"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="@string/addbuddy_username" />
+
+            <EditText
+                android:id="@+id/addbuddy_username"
+                android:layout_width="0dp"
+                android:layout_height="wrap_content"
+                android:layout_weight="1"
+                android:ems="10" />
+        </TableRow>
+
+        <TableRow
+            android:id="@+id/tableRow3"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content" >
+        </TableRow>
+
+        <TableRow
+            android:id="@+id/tableRow4"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content" >
+        </TableRow>
+    </TableLayout>
+
+    <Button
+        android:id="@+id/addbuddy_ok"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/addbuddy_ok" />
+
+</LinearLayout>
\ No newline at end of file
diff --git a/android/workspace/im.pidgin.libpurple.testclient/res/layout/blist.xml b/android/workspace/im.pidgin.libpurple.testclient/res/layout/blist.xml
--- a/android/workspace/im.pidgin.libpurple.testclient/res/layout/blist.xml
+++ b/android/workspace/im.pidgin.libpurple.testclient/res/layout/blist.xml
@@ -4,6 +4,26 @@
     android:layout_height="match_parent"
     android:orientation="vertical" >
 
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content" >
+
+        <TextView
+            android:id="@+id/textView1"
+            style="@style/headline"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_weight="1"
+            android:text="@string/blist_title" />
+
+        <Button
+            android:id="@+id/blist_new"
+            style="?android:attr/buttonStyleSmall"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/blist_new" />
+    </LinearLayout>
+
     <ListView
         android:id="@+id/blist_list"
         android:layout_width="match_parent"
diff --git a/android/workspace/im.pidgin.libpurple.testclient/res/values/strings.xml b/android/workspace/im.pidgin.libpurple.testclient/res/values/strings.xml
--- a/android/workspace/im.pidgin.libpurple.testclient/res/values/strings.xml
+++ b/android/workspace/im.pidgin.libpurple.testclient/res/values/strings.xml
@@ -20,5 +20,13 @@
     <string name="accountedit_username_hint">Username on Server</string>
     <string name="accountedit_alias_hint">(Optional)</string>
     <string name="account_saved">Account %s was saved</string>
+    <string name="blist_title">My Buddies</string>
+    <string name="blist_new">New…</string>
+    
+    <string name="addbuddy_title">Add Buddy</string>
+    <string name="addbuddy_ok">Add Buddy</string>
+    <string name="addbuddy_account">Account</string>
+    <string name="addbuddy_username">Username</string>
+    <string name="addbuddy_added">Added buddy %s</string>
 
 </resources>
\ No newline at end of file
diff --git a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/PurpleTestClient.java b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/PurpleTestClient.java
--- a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/PurpleTestClient.java
+++ b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/PurpleTestClient.java
@@ -6,6 +6,7 @@ import im.pidgin.libpurple.plugin.Purple
 import im.pidgin.libpurple.testclient.about.AboutView;
 import im.pidgin.libpurple.testclient.account.AccountEditView;
 import im.pidgin.libpurple.testclient.accountlist.AccountListView;
+import im.pidgin.libpurple.testclient.blist.AddBuddyView;
 import im.pidgin.libpurple.testclient.blist.BlistView;
 import im.pidgin.libpurple.testclient.core.TestClientView;
 import im.pidgin.libpurple.testclient.core.ViewController;
@@ -115,15 +116,18 @@ public class PurpleTestClient extends Ac
 	}
 
 	@Override
-	public void displayBuddylist() {
+	public void displayBlist() {
 		showView(new BlistView(this));
-
 	}
 
 	@Override
+	public void displayAddBuddyDialog() {
+		showView(new AddBuddyView(this));
+	}
+	
+	@Override
 	public void displayConversation() {
 		// TODO Auto-generated method stub
-
 	}
 
 	@Override
@@ -136,4 +140,5 @@ public class PurpleTestClient extends Ac
 		Toast t = Toast.makeText(this, string, Toast.LENGTH_SHORT);
 		t.show();
 	}
+
 }
\ No newline at end of file
diff --git a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/accountlist/AccountListView.java b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/accountlist/AccountListView.java
--- a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/accountlist/AccountListView.java
+++ b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/accountlist/AccountListView.java
@@ -42,7 +42,7 @@ public class AccountListView implements 
 			toBlistButton.setOnClickListener(new OnClickListener() {
 				@Override
 				public void onClick(View v) {
-					viewController.displayBuddylist();
+					viewController.displayBlist();
 				}
 			});
 		} else {
diff --git a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/AddBuddyView.java b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/AddBuddyView.java
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/AddBuddyView.java
@@ -0,0 +1,51 @@
+package im.pidgin.libpurple.testclient.blist;
+
+import im.pidgin.libpurple.account.PurpleAccount;
+import im.pidgin.libpurple.buddy.PurpleBuddy;
+import im.pidgin.libpurple.testclient.R;
+import im.pidgin.libpurple.testclient.accountlist.AccountListAdapter;
+import im.pidgin.libpurple.testclient.core.TestClientView;
+import im.pidgin.libpurple.testclient.core.ViewController;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.Spinner;
+
+public class AddBuddyView implements TestClientView {
+
+	private final ViewController viewController;
+
+	public AddBuddyView(ViewController viewController) {
+		this.viewController = viewController;
+	}
+
+	@Override
+	public View createView() {
+		View view = viewController.getLayoutInflater().inflate(R.layout.addbuddy, null);
+		final Spinner list = (Spinner) view.findViewById(R.id.addbuddy_account);
+		final AccountListAdapter accountListAdapter = new AccountListAdapter(viewController, false);
+		final EditText username = (EditText) view.findViewById(R.id.addbuddy_username);
+
+		Button okButton = (Button) view.findViewById(R.id.addbuddy_ok);
+		okButton.setOnClickListener(new OnClickListener() {
+			@Override
+			public void onClick(View arg0) {
+				String name = username.getText().toString();
+				PurpleAccount account = accountListAdapter.getAccount(list.getSelectedItemPosition());
+				PurpleBuddy buddy = account.newBuddy(name, null);
+				viewController.toast(viewController.getResources().getString(R.string.addbuddy_added, buddy.getName()));
+				viewController.goBack();
+			}
+		});
+		
+		list.setAdapter(accountListAdapter);
+		
+		return view;
+	}
+
+	@Override
+	public void removed(View view) {
+	}
+
+}
diff --git a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/BlistView.java b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/BlistView.java
--- a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/BlistView.java
+++ b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/BlistView.java
@@ -4,6 +4,8 @@ import im.pidgin.libpurple.testclient.R;
 import im.pidgin.libpurple.testclient.core.TestClientView;
 import im.pidgin.libpurple.testclient.core.ViewController;
 import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
 import android.widget.ListView;
 
 public class BlistView implements TestClientView {
@@ -22,10 +24,17 @@ public class BlistView implements TestCl
 			
 			ListView list = (ListView) view.findViewById(R.id.blist_list);
 			list.setAdapter(new BlistAdapter(viewController));
+			
+			Button newButton = (Button) view.findViewById(R.id.blist_new);
+			newButton.setOnClickListener(new OnClickListener() {
+				@Override
+				public void onClick(View arg0) {
+					viewController.displayAddBuddyDialog();
+				}
+			});
 		}
 		
 		return view;
-		
 	}
 
 	@Override
diff --git a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/core/ViewController.java b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/core/ViewController.java
--- a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/core/ViewController.java
+++ b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/core/ViewController.java
@@ -7,24 +7,25 @@ import android.view.LayoutInflater;
 
 public interface ViewController {
 	void displayAbout();
-	
+
 	void displayAccountList();
-	
+
 	void displayAccountEdit(PurpleAccount account);
-	
+
 	void displayNewAccountDialog();
-	
-	void displayBuddylist();
-	
-	//TODO...
+
+	void displayBlist();
+
+	void displayAddBuddyDialog();
+
 	void displayConversation();
-	
+
 	LayoutInflater getLayoutInflater();
 
 	PurpleInstance getPurple();
 
 	void goBack();



More information about the Commits mailing list