/soc/2012/michael/android: 929026441e6b: Added the classes that ...
Michael Zangl
michael at soc.pidgin.im
Sat Jul 7 03:34:13 EDT 2012
Changeset: 929026441e6b350b519edf200b15eea190373dcf
Author: Michael Zangl <michael at soc.pidgin.im>
Date: 2012-06-17 12:20 +0200
Branch: soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/929026441e6b
Description:
Added the classes that control the account edit dialog and the account list view.
diffstat:
android/workspace/im.pidgin.libpurple.testclient/res/layout/accountedit.xml | 8 +-
android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/PurpleTestClient.java | 52 ++-
android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/account/AccountEditView.java | 54 +++
android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/accountlist/AccountListAdapter.java | 180 ++++++++++
android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/accountlist/AccountListView.java | 41 ++
android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/core/ViewController.java | 7 +-
6 files changed, 336 insertions(+), 6 deletions(-)
diffs (truncated from 424 to 300 lines):
diff --git a/android/workspace/im.pidgin.libpurple.testclient/res/layout/accountedit.xml b/android/workspace/im.pidgin.libpurple.testclient/res/layout/accountedit.xml
--- a/android/workspace/im.pidgin.libpurple.testclient/res/layout/accountedit.xml
+++ b/android/workspace/im.pidgin.libpurple.testclient/res/layout/accountedit.xml
@@ -10,21 +10,21 @@
android:layout_gravity="right" >
<TextView
- android:id="@+id/accountlist_headline"
+ android:id="@+id/accountedit_headline"
style="@style/headline"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
- android:text="@string/accountedit_title" />
+ android:text="" />
<Button
- android:id="@+id/accountlist_newButton"
+ android:id="@+id/accountedit_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="@dimen/padding_button"
- android:text="@string/accountedit_ok" />
+ android:text="" />
</LinearLayout>
<TableLayout
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
@@ -2,14 +2,18 @@
import java.util.LinkedList;
+import im.pidgin.libpurple.account.PurpleAccount;
import im.pidgin.libpurple.core.PurpleInstance;
+import im.pidgin.libpurple.testclient.about.AboutView;
+import im.pidgin.libpurple.testclient.accountlist.AccountListView;
import im.pidgin.libpurple.testclient.core.TestClientView;
+import im.pidgin.libpurple.testclient.core.ViewController;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
-public class PurpleTestClient extends Activity {
+public class PurpleTestClient extends Activity implements ViewController {
private PurpleInstance instance;
private final LinkedList<DisplayedView> viewStack = new LinkedList<DisplayedView>();
@@ -23,6 +27,7 @@
getFilesDir());
}
+ displayAccountList();
}
private void showView(TestClientView view) {
@@ -61,4 +66,49 @@
view.removed(androidView);
}
}
+
+ @Override
+ public void onBackPressed() {
+ goBack();
+ }
+
+ @Override
+ public void displayAbout() {
+ showView(new AboutView(this));
+ }
+
+ @Override
+ public void displayAccountList() {
+ showView(new AccountListView(this));
+ }
+
+ @Override
+ public void displayAccountEdit(PurpleAccount account) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void displayNewAccountDialog() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void displayBuddylist() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void displayConversation() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public PurpleInstance getPurple() {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
\ 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
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/account/AccountEditView.java
@@ -0,0 +1,54 @@
+package im.pidgin.libpurple.testclient.account;
+
+import im.pidgin.libpurple.account.PurpleAccount;
+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.widget.Button;
+import android.widget.TextView;
+
+public class AccountEditView implements TestClientView {
+ private final ViewController viewController;
+ private final PurpleAccount account;
+
+ /**
+ * 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);
+
+ 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);
+ }
+
+ return root;
+ }
+
+ @Override
+ public void removed(View view) {
+ }
+
+}
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
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/accountlist/AccountListAdapter.java
@@ -0,0 +1,180 @@
+package im.pidgin.libpurple.testclient.accountlist;
+
+import im.pidgin.libpurple.account.PurpleAccount;
+import im.pidgin.libpurple.account.PurpleAccountList;
+import im.pidgin.libpurple.account.PurpleAccountListListener;
+import im.pidgin.libpurple.account.PurpleAccountListener;
+import im.pidgin.libpurple.testclient.R;
+import im.pidgin.libpurple.testclient.core.ViewController;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+import android.widget.CompoundButton.OnCheckedChangeListener;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+/**
+ * An adapter that displays the account list on an Android GUI. It can be
+ * displayed with or without checkboxes to enable the account.
+ *
+ * @author michaelz
+ *
+ */
+public class AccountListAdapter extends BaseAdapter implements
+ PurpleAccountListListener, PurpleAccountListener {
+
+ private final class NotifyDataChanged implements Runnable {
+ private final List<PurpleAccount> newAccounts;
+
+ public NotifyDataChanged(List<PurpleAccount> newAccounts) {
+ this.newAccounts = newAccounts;
+ }
+
+ @Override
+ public void run() {
+ allAccounts = newAccounts;
+ notifyDataSetChanged();
+ }
+ }
+
+ private List<PurpleAccount> allAccounts;
+ private final boolean withActiveSelector;
+ private final ViewController viewController;
+
+ public AccountListAdapter(ViewController viewController,
+ boolean withActiveSelector) {
+ this.viewController = viewController;
+ if (viewController == null) {
+ throw new NullPointerException();
+ }
+ this.withActiveSelector = withActiveSelector;
+ PurpleAccountList list = viewController.getPurple().getAccountList();
+ this.allAccounts = new ArrayList<PurpleAccount>(list.getAllAccounts());
+
+ list.addAccountListener(this);
+ list.addAccountListListener(this);
+ }
+
+ @Override
+ public int getCount() {
+ return allAccounts.size();
+ }
+
+ @Override
+ public Object getItem(int arg0) {
+ return allAccounts.get(arg0);
+ }
+
+ @Override
+ public long getItemId(int arg0) {
+ return allAccounts.get(arg0).hashCode();
+ }
+
+ @Override
+ public int getItemViewType(int arg0) {
+ return 0;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ final PurpleAccount account = getAccount(position);
+
+ View view;
+ if (convertView == null) {
+ view = viewController.getLayoutInflater().inflate(
+ R.layout.accountlist_item, null);
+ } else {
+ view = convertView;
+ }
+
+ CheckBox active = (CheckBox) view
+ .findViewById(R.id.accountitem_accountIsActive);
+ if (withActiveSelector) {
+ active.setChecked(account.isEnabled());
+ active.setOnCheckedChangeListener(new OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView,
+ final boolean isChecked) {
+ account.setEnabled(isChecked);
+ }
+ });
+ } else {
+ active.setVisibility(View.GONE);
+ }
+
+ ImageView icon = (ImageView) view
+ .findViewById(R.id.accountlist_item_icon);
+ //TODO icon.setImageResource(IconGenerator.getIconFor(account.getProtocol()));
+
+ TextView username = (TextView) view
+ .findViewById(R.id.accountlist_item_username);
+ if (username != null) {
+ username.setText(account.getUsername());
+ }
+
+ TextView protocol = (TextView) view
+ .findViewById(R.id.accountlist_item_protocol);
+ if (protocol != null) {
+//TODO protocol.setText(account.getProtocol().getId());
+ }
More information about the Commits
mailing list