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

Commit 13a90abc authored by Dmitri Plotnikov's avatar Dmitri Plotnikov
Browse files

Adding status update attribution to ContactHeaderWidget

Change-Id: I677f8a8d805c68d95ee56cd1119cc3e97c6ae073
parent 6e98f7e3
Loading
Loading
Loading
Loading
+68 −13
Original line number Diff line number Diff line
@@ -24,22 +24,26 @@ import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.net.Uri;
import android.os.SystemClock;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.PhoneLookup;
import android.provider.ContactsContract.Presence;
import android.provider.ContactsContract.RawContacts;
import android.provider.ContactsContract.StatusUpdates;
import android.provider.ContactsContract.CommonDataKinds.Email;
import android.provider.ContactsContract.CommonDataKinds.Photo;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
@@ -67,7 +71,7 @@ public class ContactHeaderWidget extends FrameLayout implements View.OnClickList
    private FasttrackBadgeWidget mPhotoView;
    private ImageView mPresenceView;
    private TextView mStatusView;
    private TextView mStatusDateView;
    private TextView mStatusAttributionView;
    private int mNoPhotoResource;
    private QueryHandler mQueryHandler;

@@ -99,6 +103,8 @@ public class ContactHeaderWidget extends FrameLayout implements View.OnClickList
            Contacts.CONTACT_PRESENCE,
            Contacts.CONTACT_STATUS,
            Contacts.CONTACT_STATUS_TIMESTAMP,
            Contacts.CONTACT_STATUS_RES_PACKAGE,
            Contacts.CONTACT_STATUS_LABEL,
        };
        int _ID = 0;
        int LOOKUP_KEY = 1;
@@ -110,6 +116,8 @@ public class ContactHeaderWidget extends FrameLayout implements View.OnClickList
        int CONTACT_PRESENCE_STATUS = 5;
        int CONTACT_STATUS = 6;
        int CONTACT_STATUS_TIMESTAMP = 7;
        int CONTACT_STATUS_RES_PACKAGE = 8;
        int CONTACT_STATUS_LABEL = 9;
    }

    //Projection used for looking up contact id from phone number
@@ -168,7 +176,7 @@ public class ContactHeaderWidget extends FrameLayout implements View.OnClickList
        mPresenceView = (ImageView) findViewById(R.id.presence);

        mStatusView = (TextView)findViewById(R.id.status);
        mStatusDateView = (TextView)findViewById(R.id.status_date);
        mStatusAttributionView = (TextView)findViewById(R.id.status_date);

        // Set the photo with a random "no contact" image
        long now = SystemClock.elapsedRealtime();
@@ -287,7 +295,7 @@ public class ContactHeaderWidget extends FrameLayout implements View.OnClickList
     * Manually set the presence.
     */
    public void setPresence(int presence) {
        mPresenceView.setImageResource(Presence.getPresenceIconResourceId(presence));
        mPresenceView.setImageResource(StatusUpdates.getPresenceIconResourceId(presence));
    }

    /**
@@ -432,7 +440,7 @@ public class ContactHeaderWidget extends FrameLayout implements View.OnClickList
        //Set the presence status
        if (!c.isNull(ContactQuery.CONTACT_PRESENCE_STATUS)) {
            int presence = c.getInt(ContactQuery.CONTACT_PRESENCE_STATUS);
            mPresenceView.setImageResource(Presence.getPresenceIconResourceId(presence));
            mPresenceView.setImageResource(StatusUpdates.getPresenceIconResourceId(presence));
            mPresenceView.setVisibility(View.VISIBLE);
        } else {
            mPresenceView.setVisibility(View.GONE);
@@ -444,6 +452,8 @@ public class ContactHeaderWidget extends FrameLayout implements View.OnClickList
            mStatusView.setText(status);
            mStatusView.setVisibility(View.VISIBLE);

            CharSequence timestamp = null;

            if (!c.isNull(ContactQuery.CONTACT_STATUS_TIMESTAMP)) {
                long date = c.getLong(ContactQuery.CONTACT_STATUS_TIMESTAMP);

@@ -451,18 +461,63 @@ public class ContactHeaderWidget extends FrameLayout implements View.OnClickList
                // times.
                int flags = DateUtils.FORMAT_ABBREV_RELATIVE;

                mStatusDateView.setText(DateUtils.getRelativeTimeSpanString(date, System
                        .currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, flags));
                mStatusDateView.setVisibility(View.VISIBLE);
                timestamp = DateUtils.getRelativeTimeSpanString(date,
                        System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, flags);
            }

            String label = null;

            if (!c.isNull(ContactQuery.CONTACT_STATUS_LABEL)) {
                String resPackage = c.getString(ContactQuery.CONTACT_STATUS_RES_PACKAGE);
                int labelResource = c.getInt(ContactQuery.CONTACT_STATUS_LABEL);
                Resources resources;
                if (TextUtils.isEmpty(resPackage)) {
                    resources = getResources();
                } else {
                mStatusDateView.setVisibility(View.GONE);
                    PackageManager pm = getContext().getPackageManager();
                    try {
                        resources = pm.getResourcesForApplication(resPackage);
                    } catch (NameNotFoundException e) {
                        Log.w(TAG, "Contact status update resource package not found: "
                                + resPackage);
                        resources = null;
                    }
                }

                if (resources != null) {
                    try {
                        label = resources.getString(labelResource);
                    } catch (NotFoundException e) {
                        Log.w(TAG, "Contact status update resource not found: " + resPackage + "@"
                                + labelResource);
                    }
                }
            }

            CharSequence attribution;
            if (timestamp != null && label != null) {
                attribution = getContext().getString(
                        R.string.contact_status_update_attribution_with_date,
                        timestamp, label);
            } else if (timestamp == null && label != null) {
                attribution = getContext().getString(
                        R.string.contact_status_update_attribution,
                        label);
            } else if (timestamp != null) {
                attribution = timestamp;
            } else {
                attribution = null;
            }
            if (attribution != null) {
                mStatusAttributionView.setText(attribution);
                mStatusAttributionView.setVisibility(View.VISIBLE);
            } else {
                mStatusAttributionView.setVisibility(View.GONE);
            }
        } else {
            mStatusView.setVisibility(View.GONE);
            mStatusDateView.setVisibility(View.GONE);
            mStatusAttributionView.setVisibility(View.GONE);
        }

        // TODO add support for status update source, e.g. "via Google Talk"
    }

    public void onClick(View view) {
+6 −1
Original line number Diff line number Diff line
@@ -1300,6 +1300,12 @@
    <!-- Custom organization type -->
    <string name="orgTypeCustom">Custom</string>
    
    <!-- Attbution of a contact status update, when the time of update is unknown -->
    <string name="contact_status_update_attribution">Via <xliff:g id="source" example="Google Talk">%1$s</xliff:g></string>

    <!-- Attbution of a contact status update, when the time of update is known -->
    <string name="contact_status_update_attribution_with_date"><xliff:g id="date" example="3 hours ago">%1$s</xliff:g> via <xliff:g id="source" example="Google Talk">%2$s</xliff:g></string>

    <!-- Instructions telling the user to enter their pin to unlock the keyguard.
         Displayed in one line in a large font.  -->
    <string name="keyguard_password_enter_pin_code">Enter PIN code</string>
@@ -2082,5 +2088,4 @@

    <!-- Do Not Translate: Alternate eri.xml -->
    <string name="alternate_eri_file">/data/eri.xml</string>

</resources>