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

Commit ad2eaf20 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Added long-press hooks to Contact header widget.

To match Contacts edit UI mocks, the user long-presses on
the photo or display name to select a new primary.  This
change provides the hooks needed over in Contacts.
parent 6c30a711
Loading
Loading
Loading
Loading
+41 −1
Original line number Diff line number Diff line
@@ -52,7 +52,8 @@ import com.android.internal.R;


/* Widget that is used across system apps for displaying a header banner with contact info */
public class ContactHeaderWidget extends FrameLayout implements View.OnClickListener {
public class ContactHeaderWidget extends FrameLayout implements View.OnClickListener,
        View.OnLongClickListener {

    private static final String TAG = "ContactHeaderWidget";

@@ -71,6 +72,13 @@ public class ContactHeaderWidget extends FrameLayout implements View.OnClickList

    protected ContentResolver mContentResolver;

    public interface ContactHeaderListener {
        public void onPhotoLongClick(View view);
        public void onDisplayNameLongClick(View view);
    }

    private ContactHeaderListener mListener;

    //Projection used for the summary info in the header.
    protected static final String[] HEADER_PROJECTION = new String[] {
        Contacts.DISPLAY_NAME,
@@ -125,6 +133,8 @@ public class ContactHeaderWidget extends FrameLayout implements View.OnClickList
        inflater.inflate(R.layout.contact_header, this);

        mDisplayNameView = (TextView) findViewById(R.id.name);
        mDisplayNameView.setOnLongClickListener(this);

        mPhoneticNameView = (TextView) findViewById(R.id.phonetic_name);

        mStarredView = (CheckBox)findViewById(R.id.star);
@@ -132,6 +142,7 @@ public class ContactHeaderWidget extends FrameLayout implements View.OnClickList

        mPhotoView = (ImageView)findViewById(R.id.photo);
        mPhotoView.setOnClickListener(this);
        mPhotoView.setOnLongClickListener(this);

        mStatusView = (TextView)findViewById(R.id.status);

@@ -152,6 +163,35 @@ public class ContactHeaderWidget extends FrameLayout implements View.OnClickList
        mQueryHandler = new QueryHandler(mContentResolver);
    }

    public void setContactHeaderListener(ContactHeaderListener listener) {
        mListener = listener;
    }

    /** {@inheritDoc} */
    public boolean onLongClick(View v) {
        switch (v.getId()) {
            case R.id.photo:
                performPhotoLongClick();
                return true;
            case R.id.name:
                performDisplayNameLongClick();
                return true;
        }
        return false;
    }

    private void performPhotoLongClick() {
        if (mListener != null) {
            mListener.onPhotoLongClick(mPhotoView);
        }
    }

    private void performDisplayNameLongClick() {
        if (mListener != null) {
            mListener.onDisplayNameLongClick(mDisplayNameView);
        }
    }

    private class QueryHandler extends AsyncQueryHandler {

        public QueryHandler(ContentResolver cr) {