Don't show the buddy's offline status in Contacts

Bug: 2164303
Change-Id: Ida1e417b2f4654a5b018b4215f4fa445754a0a06
diff --git a/src/com/android/contacts/ContactPresenceIconUtil.java b/src/com/android/contacts/ContactPresenceIconUtil.java
new file mode 100644
index 0000000..1a2d58e
--- /dev/null
+++ b/src/com/android/contacts/ContactPresenceIconUtil.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2010 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.graphics.drawable.Drawable;
+import android.provider.ContactsContract.StatusUpdates;
+
+/**
+ * Define the contact present show policy in Contacts
+ */
+public class ContactPresenceIconUtil {
+    /**
+     * Get the presence icon resource according the status.
+     * 
+     * @return null means don't show the status icon.
+     */
+    public static Drawable getPresenceIcon (Context context, int status) {
+        // We don't show the offline status in Contacts
+        switch(status) {
+            case StatusUpdates.AVAILABLE:
+            case StatusUpdates.IDLE:
+            case StatusUpdates.AWAY:
+            case StatusUpdates.DO_NOT_DISTURB:
+            case StatusUpdates.INVISIBLE:
+                return context.getResources().getDrawable(
+                        StatusUpdates.getPresenceIconResourceId(status));
+            case StatusUpdates.OFFLINE:
+            // The undefined status is treated as OFFLINE in getPresenceIconResourceId();
+            default:
+                return null;
+        }
+    }
+}
diff --git a/src/com/android/contacts/ContactsListActivity.java b/src/com/android/contacts/ContactsListActivity.java
index d0b064b..c7d158d 100644
--- a/src/com/android/contacts/ContactsListActivity.java
+++ b/src/com/android/contacts/ContactsListActivity.java
@@ -3067,9 +3067,13 @@
                 int serverStatus;
                 if (!cursor.isNull(SUMMARY_PRESENCE_STATUS_COLUMN_INDEX)) {
                     serverStatus = cursor.getInt(SUMMARY_PRESENCE_STATUS_COLUMN_INDEX);
-                    presenceView.setImageResource(
-                            Presence.getPresenceIconResourceId(serverStatus));
-                    presenceView.setVisibility(View.VISIBLE);
+                    Drawable icon = ContactPresenceIconUtil.getPresenceIcon(mContext, serverStatus);
+                    if (icon != null) {
+                        presenceView.setImageDrawable(icon);
+                        presenceView.setVisibility(View.VISIBLE);
+                    } else {
+                        presenceView.setVisibility(View.GONE);
+                    }
                 } else {
                     presenceView.setVisibility(View.GONE);
                 }
diff --git a/src/com/android/contacts/ViewContactActivity.java b/src/com/android/contacts/ViewContactActivity.java
index 168da46..ee86ef9 100644
--- a/src/com/android/contacts/ViewContactActivity.java
+++ b/src/com/android/contacts/ViewContactActivity.java
@@ -978,7 +978,6 @@
         public int collapseCount = 0;
 
         public int presence = -1;
-        public int presenceIcon = -1;
 
         public CharSequence footerLine = null;
 
@@ -1019,9 +1018,6 @@
          */
         public ViewEntry applyStatus(DataStatus status, boolean fillData) {
             presence = status.getPresence();
-            presenceIcon = (presence == -1) ? -1 :
-                    StatusUpdates.getPresenceIconResourceId(this.presence);
-
             if (fillData && status.isValid()) {
                 this.data = status.getStatus().toString();
                 this.footerLine = status.getTimestampLabel(context);
@@ -1208,13 +1204,8 @@
             }
 
             // Set the presence icon
-            Drawable presenceIcon = null;
-            if (entry.presenceIcon != -1) {
-                presenceIcon = resources.getDrawable(entry.presenceIcon);
-            } else if (entry.presence != -1) {
-                presenceIcon = resources.getDrawable(
-                        StatusUpdates.getPresenceIconResourceId(entry.presence));
-            }
+            Drawable presenceIcon = ContactPresenceIconUtil.getPresenceIcon(
+                    mContext, entry.presence);
             ImageView presenceIconView = views.presenceIcon;
             if (presenceIcon != null) {
                 presenceIconView.setImageDrawable(presenceIcon);
diff --git a/src/com/android/contacts/ui/QuickContactWindow.java b/src/com/android/contacts/ui/QuickContactWindow.java
index 0d1eb2c..4ac787c 100644
--- a/src/com/android/contacts/ui/QuickContactWindow.java
+++ b/src/com/android/contacts/ui/QuickContactWindow.java
@@ -17,6 +17,7 @@
 package com.android.contacts.ui;
 
 import com.android.contacts.Collapser;
+import com.android.contacts.ContactPresenceIconUtil;
 import com.android.contacts.ContactsUtils;
 import com.android.contacts.R;
 import com.android.contacts.model.ContactsSource;
@@ -617,30 +618,6 @@
     }
 
     /**
-     * Find the presence icon for showing in summary header.
-     */
-    private Drawable getPresenceIcon(int status) {
-        int resId = -1;
-        switch (status) {
-            case StatusUpdates.AVAILABLE:
-                resId = android.R.drawable.presence_online;
-                break;
-            case StatusUpdates.IDLE:
-            case StatusUpdates.AWAY:
-                resId = android.R.drawable.presence_away;
-                break;
-            case StatusUpdates.DO_NOT_DISTURB:
-                resId = android.R.drawable.presence_busy;
-                break;
-        }
-        if (resId != -1) {
-            return mContext.getResources().getDrawable(resId);
-        } else {
-            return null;
-        }
-    }
-
-    /**
      * Find the QuickContact-specific presence icon for showing in chiclets.
      */
     private Drawable getTrackPresenceIcon(int status) {
@@ -1215,7 +1192,7 @@
             // Read contact information from last data row
             final String name = cursor.getString(DataQuery.DISPLAY_NAME);
             final int presence = cursor.getInt(DataQuery.CONTACT_PRESENCE);
-            final Drawable statusIcon = getPresenceIcon(presence);
+            final Drawable statusIcon = ContactPresenceIconUtil.getPresenceIcon(mContext, presence);
 
             setHeaderText(R.id.name, name);
             setHeaderImage(R.id.presence, statusIcon);