/soc/2012/michael/android: 6faae45535d3: Added a protocol list (...

Michael Zangl michael at soc.pidgin.im
Sat Jul 7 03:34:15 EDT 2012


Changeset: 6faae45535d3abf06aaff9cb4f6b3bda41eac9d6
Author:	 Michael Zangl <michael at soc.pidgin.im>
Date:	 2012-06-24 10:24 +0200
Branch:	 soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/6faae45535d3

Description:

Added a protocol list (for the account edit dialog spinner) and made account edit dialog display/change the properties of the account.

diffstat:

 android/workspace/im.pidgin.libpurple.testclient/res/layout/protocollist_item.xml                                       |  18 ++
 android/workspace/im.pidgin.libpurple.testclient/res/values/strings.xml                                                 |   1 +
 android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/PurpleTestClient.java               |  12 +-
 android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/account/AccountEditView.java        |  88 +++++++--
 android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/account/ProtocolListAdapter.java    |  61 ++++++
 android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/accountlist/AccountListAdapter.java |   5 +
 android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/core/ViewController.java            |   2 +
 7 files changed, 165 insertions(+), 22 deletions(-)

diffs (298 lines):

diff --git a/android/workspace/im.pidgin.libpurple.testclient/res/layout/protocollist_item.xml b/android/workspace/im.pidgin.libpurple.testclient/res/layout/protocollist_item.xml
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple.testclient/res/layout/protocollist_item.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent" >
+
+    <TextView
+        android:id="@+id/protocollist_item_name"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content" />
+
+    <TextView
+        android:id="@+id/protocollist_item_summary"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_below="@+id/protocollist_item_name"/>
+
+</RelativeLayout>
\ No newline at end of file
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
@@ -19,5 +19,6 @@
     <string name="accountedit_alias">Alias</string>
     <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>
 
 </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
@@ -13,6 +13,7 @@
 import android.app.Activity;
 import android.os.Bundle;
 import android.view.View;
+import android.widget.Toast;
 
 public class PurpleTestClient extends Activity implements ViewController {
 	private PurpleInstance instance;
@@ -23,7 +24,7 @@
 	@Override
 	public void onCreate(Bundle savedInstanceState) {
 		super.onCreate(savedInstanceState);
-		if (instance != null) {
+		if (instance == null) {
 			instance = PurpleInstance.createInstance("testclient",
 					getFilesDir());
 		}
@@ -108,7 +109,12 @@
 
 	@Override
 	public PurpleInstance getPurple() {
-		// TODO Auto-generated method stub
-		return null;
+		return instance;
+	}
+
+	@Override
+	public void toast(String string) {
+		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/account/AccountEditView.java b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/account/AccountEditView.java
--- a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/account/AccountEditView.java
+++ b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/account/AccountEditView.java
@@ -1,57 +1,87 @@
 package im.pidgin.libpurple.testclient.account;
 
 import im.pidgin.libpurple.account.PurpleAccount;
+import im.pidgin.libpurple.plugin.PurplePluginList;
+import im.pidgin.libpurple.plugin.PurpleProtocolPlugin;
 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.EditText;
+import android.widget.Spinner;
 import android.widget.TextView;
 
 public class AccountEditView implements TestClientView {
 	private final ViewController viewController;
 	private final PurpleAccount account;
 
+	private Spinner protocol;
+	private EditText username;
+	private EditText alias;
+	private EditText password;
+	private ProtocolListAdapter protocolList;
+
 	/**
 	 * Creates a new Account edit view for a new account.
+	 * 
 	 * @param viewController
 	 */
 	public AccountEditView(ViewController viewController) {
 		this(viewController, null);
 	}
-	
+
 	public AccountEditView(ViewController viewController, PurpleAccount account) {
 		if (viewController == null) {
 			throw new NullPointerException();
 		}
-		
+
 		this.viewController = viewController;
 		this.account = account;
 	}
 
 	@Override
 	public View createView() {
-		View root = viewController.getLayoutInflater().inflate(R.layout.accountedit, null);
+		View root = viewController.getLayoutInflater().inflate(
+				R.layout.accountedit, null);
+
+		registerTitlebar(root);
+
+		username = (EditText) root.findViewById(R.id.accountedit_username);
+		alias = (EditText) root.findViewById(R.id.accountedit_alias);
+		password = (EditText) root.findViewById(R.id.accountedit_password);
+		protocol = (Spinner) root.findViewById(R.id.accountedit_protocol);
 		
-        registerTitlebar(root);
-        
-        return root;
+		PurplePluginList pluginList = viewController.getPurple().getPluginList();
+		protocolList = new ProtocolListAdapter(viewController.getLayoutInflater(), pluginList);
+		protocol.setAdapter(protocolList);
+
+		if (account != null) {
+			username.setText(account.getUsername());
+			alias.setText(account.getAlias());
+			password.setText(account.getPassword());
+			protocol.setEnabled(false);
+		}
+
+		return root;
 	}
 
 	private void registerTitlebar(View root) {
-		TextView title = (TextView) root.findViewById(R.id.accountedit_headline);
-        Button okButton = (Button) root.findViewById(R.id.accountedit_ok);
-        
-        if (account == null) {
-        	title.setText(R.string.accountedit_title_new);
-        	okButton.setText(R.string.accountedit_ok_new);
-        } else {
-        	title.setText(viewController.getResources().getString(R.string.accountedit_title, account.getAlias()));
-        	okButton.setText(R.string.accountedit_ok);
-        }
-        
-        okButton.setOnClickListener(new OnClickListener() {
+		TextView title = (TextView) root
+				.findViewById(R.id.accountedit_headline);
+		Button okButton = (Button) root.findViewById(R.id.accountedit_ok);
+
+		if (account == null) {
+			title.setText(R.string.accountedit_title_new);
+			okButton.setText(R.string.accountedit_ok_new);
+		} else {
+			title.setText(viewController.getResources().getString(
+					R.string.accountedit_title, account.getAlias()));
+			okButton.setText(R.string.accountedit_ok);
+		}
+
+		okButton.setOnClickListener(new OnClickListener() {
 			@Override
 			public void onClick(View v) {
 				saveAndExit();
@@ -60,7 +90,27 @@
 	}
 
 	protected void saveAndExit() {
-		//TODO: save
+		if (protocol == null  || protocolList == null|| username == null || password == null
+				|| alias == null) {
+			throw new IllegalStateException(
+					"No view was created but saveAndExit was called.");
+		}
+		PurpleProtocolPlugin prpl = protocolList.getProtocol(protocol.getSelectedItemPosition());
+
+		PurpleAccount account;
+			String userText = username.getText().toString();
+		if (this.account == null) {
+			account = viewController.getPurple().getAccountList()
+					.addAccount(userText, prpl);
+		} else {
+			account = this.account;
+			account.setUsername(userText);
+		}
+		account.setAlias(alias.getText().toString());
+		account.setPassword(password.getText().toString());
+
+		viewController.toast(viewController.getResources().getString(
+				R.string.account_saved, account.getAlias()));
 		viewController.goBack();
 	}
 
diff --git a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/account/ProtocolListAdapter.java b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/account/ProtocolListAdapter.java
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/account/ProtocolListAdapter.java
@@ -0,0 +1,61 @@
+package im.pidgin.libpurple.testclient.account;
+
+import im.pidgin.libpurple.plugin.PurplePluginList;
+import im.pidgin.libpurple.plugin.PurpleProtocolPlugin;
+import im.pidgin.libpurple.testclient.R;
+
+import java.util.ArrayList;
+
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.TextView;
+
+public class ProtocolListAdapter extends BaseAdapter {
+
+	private final ArrayList<PurpleProtocolPlugin> protocols;
+	private final LayoutInflater inflater;
+
+	public ProtocolListAdapter(LayoutInflater inflater, PurplePluginList pluginList) {
+		this.inflater = inflater;
+		protocols = new ArrayList<PurpleProtocolPlugin>(
+				pluginList.getProtocolPlugins());
+	}
+
+	@Override
+	public int getCount() {
+		return protocols.size();
+	}
+
+	@Override
+	public Object getItem(int arg0) {
+		return getProtocol(arg0);
+	}
+
+	@Override
+	public long getItemId(int arg0) {
+		return getProtocol(arg0).hashCode();
+	}
+
+	@Override
+	public View getView(int arg0, View arg1, ViewGroup arg2) {
+		View root;
+		if (arg1 != null) {
+			root = arg1;
+		} else {
+			root = inflater.inflate(R.layout.protocollist_item, arg2);
+			root.setPadding(2, 2, 2, 2);
+		}
+		TextView name = (TextView) root.findViewById(R.id.protocollist_item_name);
+		name.setText(getProtocol(arg0).getName());
+		TextView summary = (TextView) root.findViewById(R.id.protocollist_item_name);
+		summary.setText(getProtocol(arg0).getSummary());
+		return root;
+	}
+
+	public PurpleProtocolPlugin getProtocol(int arg0) {
+		return protocols.get(arg0);
+	}
+
+}
diff --git a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/accountlist/AccountListAdapter.java b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/accountlist/AccountListAdapter.java
--- a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/accountlist/AccountListAdapter.java
+++ b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/accountlist/AccountListAdapter.java
@@ -177,4 +177,9 @@
 		notifyDataChangeAsync();
 	}
 
+	@Override
+	public void accountRemoved(PurpleAccount account) {
+		notifyDataChangeAsync();
+	}
+
 }
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
@@ -28,4 +28,6 @@
 	void runOnUiThread(Runnable runnable);
 
 	Resources getResources();
+
+	void toast(String string);
 }



More information about the Commits mailing list