summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorDmitri Plotnikov <dplotnikov@google.com>2010-08-31 15:05:18 -0700
committerDmitri Plotnikov <dplotnikov@google.com>2010-08-31 15:05:18 -0700
commit55f04311fb40ccadb224f1a4dc1b8ff473dfdf03 (patch)
treebdc67226c58473bfd667a7edfb66e76dd06cb176 /common
parent950b496faf3cbae2a4d08b957cbf6708d2dee8bd (diff)
downloadandroid_frameworks_ex-55f04311fb40ccadb224f1a4dc1b8ff473dfdf03.tar.gz
android_frameworks_ex-55f04311fb40ccadb224f1a4dc1b8ff473dfdf03.tar.bz2
android_frameworks_ex-55f04311fb40ccadb224f1a4dc1b8ff473dfdf03.zip
Correct formating of an email when name is unknown
Also, reducing the number of change notifications Change-Id: If075fee9a96dc8191c264fc34162969afe4027b6
Diffstat (limited to 'common')
-rw-r--r--common/java/com/android/common/contacts/BaseEmailAddressAdapter.java49
-rw-r--r--common/java/com/android/common/widget/CompositeCursorAdapter.java23
2 files changed, 58 insertions, 14 deletions
diff --git a/common/java/com/android/common/contacts/BaseEmailAddressAdapter.java b/common/java/com/android/common/contacts/BaseEmailAddressAdapter.java
index 0892851..f592633 100644
--- a/common/java/com/android/common/contacts/BaseEmailAddressAdapter.java
+++ b/common/java/com/android/common/contacts/BaseEmailAddressAdapter.java
@@ -267,6 +267,10 @@ public abstract class BaseEmailAddressAdapter extends CompositeCursorAdapter imp
} else {
String displayName = cursor.getString(EmailQuery.NAME);
String emailAddress = cursor.getString(EmailQuery.ADDRESS);
+ if (TextUtils.isEmpty(displayName) || TextUtils.equals(displayName, emailAddress)) {
+ displayName = emailAddress;
+ emailAddress = null;
+ }
bindView(v, directoryType, directoryName, displayName, emailAddress);
}
}
@@ -348,23 +352,36 @@ public abstract class BaseEmailAddressAdapter extends CompositeCursorAdapter imp
}
}
- // The filter has loaded results for the default partition too.
- if (defaultPartitionCursor != null && getPartitionCount() > 0) {
- changeCursor(0, defaultPartitionCursor);
+ int count = getPartitionCount();
+
+ // Since we will be changing several partitions at once, hold the data change
+ // notifications
+ setNotificationsEnabled(false);
+ try {
+ // The filter has loaded results for the default partition too.
+ if (defaultPartitionCursor != null && getPartitionCount() > 0) {
+ changeCursor(0, defaultPartitionCursor);
+ }
+
+ // Show non-default directories as "loading"
+ // Note: skipping the default partition (index 0), which has already been loaded
+ for (int i = 1; i < count; i++) {
+ DirectoryPartition partition = (DirectoryPartition) getPartition(i);
+ partition.constraint = constraint;
+
+ if (!partition.loading) {
+ partition.loading = true;
+ changeCursor(i, createLoadingCursor());
+ }
+ }
+ } finally {
+ setNotificationsEnabled(true);
}
// Start search in other directories
- int count = getPartitionCount();
// Note: skipping the default partition (index 0), which has already been loaded
for (int i = 1; i < count; i++) {
DirectoryPartition partition = (DirectoryPartition) getPartition(i);
- partition.constraint = constraint;
-
- if (!partition.loading) {
- partition.loading = true;
- changeCursor(i, createLoadingCursor());
- }
-
if (partition.filter == null) {
partition.filter = new DirectoryPartitionFilter(i, partition.directoryId);
}
@@ -408,8 +425,12 @@ public abstract class BaseEmailAddressAdapter extends CompositeCursorAdapter imp
return "";
}
- String name = cursor.getString(EmailQuery.NAME);
- String address = cursor.getString(EmailQuery.ADDRESS);
- return new Rfc822Token(name, address, null).toString();
+ String displayName = cursor.getString(EmailQuery.NAME);
+ String emailAddress = cursor.getString(EmailQuery.ADDRESS);
+ if (TextUtils.isEmpty(displayName) || TextUtils.equals(displayName, emailAddress)) {
+ return emailAddress;
+ } else {
+ return new Rfc822Token(displayName, emailAddress, null).toString();
+ }
}
}
diff --git a/common/java/com/android/common/widget/CompositeCursorAdapter.java b/common/java/com/android/common/widget/CompositeCursorAdapter.java
index 5a2a281..d0c248f 100644
--- a/common/java/com/android/common/widget/CompositeCursorAdapter.java
+++ b/common/java/com/android/common/widget/CompositeCursorAdapter.java
@@ -59,6 +59,8 @@ public abstract class CompositeCursorAdapter extends BaseAdapter {
private int mSize = 0;
private int mCount = 0;
private boolean mCacheValid = true;
+ private boolean mNotificationsEnabled = true;
+ private boolean mNotificationNeeded;
public CompositeCursorAdapter(Context context) {
this(context, INITIAL_CAPACITY);
@@ -505,4 +507,25 @@ public abstract class CompositeCursorAdapter extends BaseAdapter {
protected boolean isEnabled(int partition, int position) {
return true;
}
+
+ /**
+ * Enable or disable data change notifications. It may be a good idea to
+ * disable notifications before making changes to several partitions at once.
+ */
+ public void setNotificationsEnabled(boolean flag) {
+ this.mNotificationsEnabled = flag;
+ if (mNotificationNeeded) {
+ notifyDataSetChanged();
+ }
+ }
+
+ @Override
+ public void notifyDataSetChanged() {
+ if (mNotificationsEnabled) {
+ mNotificationNeeded = false;
+ super.notifyDataSetChanged();
+ } else {
+ mNotificationNeeded = true;
+ }
+ }
}