Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 107736c5 authored by Bai Tao's avatar Bai Tao
Browse files

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

Bug: 2164303
Change-Id: Ida1e417b2f4654a5b018b4215f4fa445754a0a06
parent d0037fd8
Loading
Loading
Loading
Loading
+48 −0
Original line number Diff line number Diff line
/*
 * 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;
        }
    }
}
+7 −3
Original line number Diff line number Diff line
@@ -3067,8 +3067,9 @@ public class ContactsListActivity extends ListActivity implements View.OnCreateC
                int serverStatus;
                if (!cursor.isNull(SUMMARY_PRESENCE_STATUS_COLUMN_INDEX)) {
                    serverStatus = cursor.getInt(SUMMARY_PRESENCE_STATUS_COLUMN_INDEX);
                    presenceView.setImageResource(
                            Presence.getPresenceIconResourceId(serverStatus));
                    Drawable icon = ContactPresenceIconUtil.getPresenceIcon(mContext, serverStatus);
                    if (icon != null) {
                        presenceView.setImageDrawable(icon);
                        presenceView.setVisibility(View.VISIBLE);
                    } else {
                        presenceView.setVisibility(View.GONE);
@@ -3076,6 +3077,9 @@ public class ContactsListActivity extends ListActivity implements View.OnCreateC
                } else {
                    presenceView.setVisibility(View.GONE);
                }
            } else {
                presenceView.setVisibility(View.GONE);
            }

            // TODO: make sure that when mShowSearchSnippets is true, the
            // snippet views are available
+2 −11
Original line number Diff line number Diff line
@@ -978,7 +978,6 @@ public class ViewContactActivity extends Activity
        public int collapseCount = 0;

        public int presence = -1;
        public int presenceIcon = -1;

        public CharSequence footerLine = null;

@@ -1019,9 +1018,6 @@ public class ViewContactActivity extends Activity
         */
        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 @@ public class ViewContactActivity extends Activity
            }

            // 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);
+2 −25
Original line number Diff line number Diff line
@@ -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;
@@ -616,30 +617,6 @@ public class QuickContactWindow implements Window.Callback,
        }
    }

    /**
     * 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.
     */
@@ -1215,7 +1192,7 @@ public class QuickContactWindow implements Window.Callback,
            // 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);