Add status message to contact list
Bug: 5070817
Change-Id: I230c7cf7c4f0f6931fa6ddac4cddc9d3741835e9
diff --git a/src/com/android/contacts/ContactStatusUtil.java b/src/com/android/contacts/ContactStatusUtil.java
new file mode 100644
index 0000000..4aa24b0
--- /dev/null
+++ b/src/com/android/contacts/ContactStatusUtil.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.contacts;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.provider.ContactsContract.StatusUpdates;
+
+/**
+ * Provides static function to get default contact status message.
+ */
+public class ContactStatusUtil {
+
+ private static final String TAG = "ContactStatusUtil";
+
+ public static String getStatusString(Context context, int presence) {
+ Resources resources = context.getResources();
+ switch (presence) {
+ case StatusUpdates.AVAILABLE:
+ return resources.getString(R.string.status_available);
+ case StatusUpdates.IDLE:
+ case StatusUpdates.AWAY:
+ return resources.getString(R.string.status_away);
+ case StatusUpdates.DO_NOT_DISTURB:
+ return resources.getString(R.string.status_busy);
+ case StatusUpdates.OFFLINE:
+ case StatusUpdates.INVISIBLE:
+ default:
+ return null;
+ }
+ }
+
+}
diff --git a/src/com/android/contacts/list/ContactListAdapter.java b/src/com/android/contacts/list/ContactListAdapter.java
index e51fd5c..7322fc6 100644
--- a/src/com/android/contacts/list/ContactListAdapter.java
+++ b/src/com/android/contacts/list/ContactListAdapter.java
@@ -45,12 +45,13 @@
Contacts.STARRED, // 4
Contacts.CONTACT_PRESENCE, // 5
Contacts.CONTACT_CHAT_CAPABILITY, // 6
- Contacts.PHOTO_ID, // 7
- Contacts.PHOTO_THUMBNAIL_URI, // 8
- Contacts.LOOKUP_KEY, // 9
- Contacts.PHONETIC_NAME, // 10
- Contacts.HAS_PHONE_NUMBER, // 11
- Contacts.IS_USER_PROFILE, // 12
+ Contacts.CONTACT_STATUS, // 7
+ Contacts.PHOTO_ID, // 8
+ Contacts.PHOTO_THUMBNAIL_URI, // 9
+ Contacts.LOOKUP_KEY, // 10
+ Contacts.PHONETIC_NAME, // 11
+ Contacts.HAS_PHONE_NUMBER, // 12
+ Contacts.IS_USER_PROFILE, // 13
};
protected static final String[] PROJECTION_DATA = new String[] {
@@ -61,11 +62,12 @@
Data.STARRED, // 4
Data.CONTACT_PRESENCE, // 5
Data.CONTACT_CHAT_CAPABILITY, // 6
- Data.PHOTO_ID, // 7
- Data.PHOTO_THUMBNAIL_URI, // 8
- Data.LOOKUP_KEY, // 9
- Data.PHONETIC_NAME, // 10
- Data.HAS_PHONE_NUMBER, // 11
+ Data.CONTACT_STATUS, // 7
+ Data.PHOTO_ID, // 8
+ Data.PHOTO_THUMBNAIL_URI, // 9
+ Data.LOOKUP_KEY, // 10
+ Data.PHONETIC_NAME, // 11
+ Data.HAS_PHONE_NUMBER, // 12
};
protected static final String[] FILTER_PROJECTION = new String[] {
@@ -76,13 +78,14 @@
Contacts.STARRED, // 4
Contacts.CONTACT_PRESENCE, // 5
Contacts.CONTACT_CHAT_CAPABILITY, // 6
- Contacts.PHOTO_ID, // 7
- Contacts.PHOTO_THUMBNAIL_URI, // 8
- Contacts.LOOKUP_KEY, // 9
- Contacts.PHONETIC_NAME, // 10
- Contacts.HAS_PHONE_NUMBER, // 11
- Contacts.IS_USER_PROFILE, // 12
- SearchSnippetColumns.SNIPPET, // 13
+ Contacts.CONTACT_STATUS, // 7
+ Contacts.PHOTO_ID, // 8
+ Contacts.PHOTO_THUMBNAIL_URI, // 9
+ Contacts.LOOKUP_KEY, // 10
+ Contacts.PHONETIC_NAME, // 11
+ Contacts.HAS_PHONE_NUMBER, // 12
+ Contacts.IS_USER_PROFILE, // 13
+ SearchSnippetColumns.SNIPPET, // 14
};
protected static final int CONTACT_ID_COLUMN_INDEX = 0;
@@ -92,13 +95,14 @@
protected static final int CONTACT_STARRED_COLUMN_INDEX = 4;
protected static final int CONTACT_PRESENCE_STATUS_COLUMN_INDEX = 5;
protected static final int CONTACT_CHAT_CAPABILITY_COLUMN_INDEX = 6;
- protected static final int CONTACT_PHOTO_ID_COLUMN_INDEX = 7;
- protected static final int CONTACT_PHOTO_URI_COLUMN_INDEX = 8;
- protected static final int CONTACT_LOOKUP_KEY_COLUMN_INDEX = 9;
- protected static final int CONTACT_PHONETIC_NAME_COLUMN_INDEX = 10;
- protected static final int CONTACT_HAS_PHONE_COLUMN_INDEX = 11;
- protected static final int CONTACT_IS_USER_PROFILE = 12;
- protected static final int CONTACT_SNIPPET_COLUMN_INDEX = 13;
+ protected static final int CONTACT_CONTACT_STATUS_COLUMN_INDEX = 7;
+ protected static final int CONTACT_PHOTO_ID_COLUMN_INDEX = 8;
+ protected static final int CONTACT_PHOTO_URI_COLUMN_INDEX = 9;
+ protected static final int CONTACT_LOOKUP_KEY_COLUMN_INDEX = 10;
+ protected static final int CONTACT_PHONETIC_NAME_COLUMN_INDEX = 11;
+ protected static final int CONTACT_HAS_PHONE_COLUMN_INDEX = 12;
+ protected static final int CONTACT_IS_USER_PROFILE = 13;
+ protected static final int CONTACT_SNIPPET_COLUMN_INDEX = 14;
private CharSequence mUnknownNameText;
private int mDisplayNameColumnIndex;
@@ -304,9 +308,9 @@
view.showPhoneticName(cursor, CONTACT_PHONETIC_NAME_COLUMN_INDEX);
}
- protected void bindPresence(final ContactListItemView view, Cursor cursor) {
- view.showPresence(cursor, CONTACT_PRESENCE_STATUS_COLUMN_INDEX,
- CONTACT_CHAT_CAPABILITY_COLUMN_INDEX);
+ protected void bindPresenceAndStatusMessage(final ContactListItemView view, Cursor cursor) {
+ view.showPresenceAndStatusMessage(cursor, CONTACT_PRESENCE_STATUS_COLUMN_INDEX,
+ CONTACT_CHAT_CAPABILITY_COLUMN_INDEX, CONTACT_CONTACT_STATUS_COLUMN_INDEX);
}
protected void bindSearchSnippet(final ContactListItemView view, Cursor cursor) {
diff --git a/src/com/android/contacts/list/ContactListItemView.java b/src/com/android/contacts/list/ContactListItemView.java
index 4fb6f1d..d69f880 100644
--- a/src/com/android/contacts/list/ContactListItemView.java
+++ b/src/com/android/contacts/list/ContactListItemView.java
@@ -17,6 +17,7 @@
package com.android.contacts.list;
import com.android.contacts.ContactPresenceIconUtil;
+import com.android.contacts.ContactStatusUtil;
import com.android.contacts.R;
import com.android.contacts.format.DisplayNameFormatter;
import com.android.contacts.format.PrefixHighlighter;
@@ -916,7 +917,7 @@
mStatusView.setSingleLine(true);
mStatusView.setEllipsize(getTextEllipsis());
mStatusView.setTextAppearance(mContext, android.R.style.TextAppearance_Small);
- mStatusView.setText("Put Status here"); // Temporary
+ mStatusView.setTextColor(Color.GRAY);
addView(mStatusView);
}
return mStatusView;
@@ -996,20 +997,33 @@
}
/**
- * Sets the proper icon (star or presence or nothing)
+ * Sets the proper icon (star or presence or nothing) and/or status message.
*/
- public void showPresence(Cursor cursor, int presenceColumnIndex, int capabilityColumnIndex) {
+ public void showPresenceAndStatusMessage(Cursor cursor, int presenceColumnIndex,
+ int capabilityColumnIndex, int contactStatusColumnIndex) {
Drawable icon = null;
+ int presence = 0;
+ int chatCapability = 0;
if (!cursor.isNull(presenceColumnIndex)) {
- int status = cursor.getInt(presenceColumnIndex);
- int chatCapability = 0;
+ presence = cursor.getInt(presenceColumnIndex);
if (capabilityColumnIndex != 0 && !cursor.isNull(presenceColumnIndex)) {
chatCapability = cursor.getInt(capabilityColumnIndex);
}
icon = ContactPresenceIconUtil.getChatCapabilityIcon(
- getContext(), status, chatCapability);
+ getContext(), presence, chatCapability);
}
setPresence(icon);
+
+ String statusMessage = null;
+ if (contactStatusColumnIndex != 0 && !cursor.isNull(contactStatusColumnIndex)) {
+ statusMessage = cursor.getString(contactStatusColumnIndex);
+ }
+ // If there is no status message from the contact, but there was a presence value, then use
+ // the default status message string
+ if (statusMessage == null && presence != 0) {
+ statusMessage = ContactStatusUtil.getStatusString(getContext(), presence);
+ }
+ setStatus(statusMessage);
}
/**
diff --git a/src/com/android/contacts/list/ContactTileView.java b/src/com/android/contacts/list/ContactTileView.java
index 715c331..6374c23 100644
--- a/src/com/android/contacts/list/ContactTileView.java
+++ b/src/com/android/contacts/list/ContactTileView.java
@@ -16,6 +16,7 @@
package com.android.contacts.list;
import com.android.contacts.ContactPhotoManager;
+import com.android.contacts.ContactStatusUtil;
import com.android.contacts.R;
import com.android.contacts.list.ContactTileAdapter.ContactEntry;
@@ -90,7 +91,8 @@
statusText = null;
} else {
statusText =
- (entry.status == null ? getStatusString(entry.presence) : entry.status);
+ (entry.status != null ? entry.status :
+ ContactStatusUtil.getStatusString(mContext, entry.presence));
}
mStatus.setText(statusText);
}
@@ -119,23 +121,6 @@
}
}
- private String getStatusString(int presence) {
- Resources resources = getResources();
- switch (presence) {
- case StatusUpdates.AVAILABLE:
- return resources.getString(R.string.status_available);
- case StatusUpdates.IDLE:
- case StatusUpdates.AWAY:
- return resources.getString(R.string.status_away);
- case StatusUpdates.DO_NOT_DISTURB:
- return resources.getString(R.string.status_busy);
- case StatusUpdates.OFFLINE:
- case StatusUpdates.INVISIBLE:
- default:
- return null;
- }
- }
-
public Uri getLookupUri() {
return mLookupUri;
}
diff --git a/src/com/android/contacts/list/DefaultContactListAdapter.java b/src/com/android/contacts/list/DefaultContactListAdapter.java
index c93b544..8b93888 100644
--- a/src/com/android/contacts/list/DefaultContactListAdapter.java
+++ b/src/com/android/contacts/list/DefaultContactListAdapter.java
@@ -234,7 +234,7 @@
}
bindName(view, cursor);
- bindPresence(view, cursor);
+ bindPresenceAndStatusMessage(view, cursor);
if (isSearchMode()) {
bindSearchSnippet(view, cursor);
diff --git a/src/com/android/contacts/list/LegacyContactListAdapter.java b/src/com/android/contacts/list/LegacyContactListAdapter.java
index ffc8fc3..b3ab2af 100644
--- a/src/com/android/contacts/list/LegacyContactListAdapter.java
+++ b/src/com/android/contacts/list/LegacyContactListAdapter.java
@@ -91,6 +91,6 @@
}
protected void bindPresence(final ContactListItemView view, Cursor cursor) {
- view.showPresence(cursor, PERSON_PRESENCE_STATUS_COLUMN_INDEX, 0);
+ view.showPresenceAndStatusMessage(cursor, PERSON_PRESENCE_STATUS_COLUMN_INDEX, 0, 0);
}
}