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

Commit 6bfe14de authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Add SHOW_OR_CREATE size modes, trigger from contact header.

Added constants so that apps triggering SHOW_OR_CREATE can
request a desired size through EXTRA_MODE.  Also added hooks
to internal ContactHeaderWidget to launch SHOW_OR_CREATE
when user taps on photo.
parent e397a88e
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -1411,6 +1411,28 @@ public final class ContactsContract {
         */
        public static final String EXTRA_TARGET_RECT = "target_rect";

        /**
         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
         * desired dialog style, usually a variation on size. One of
         * {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or {@link #MODE_LARGE}.
         */
        public static final String EXTRA_MODE = "mode";

        /**
         * Value for {@link #EXTRA_MODE} to show a small-sized dialog.
         */
        public static final int MODE_SMALL = 1;

        /**
         * Value for {@link #EXTRA_MODE} to show a medium-sized dialog.
         */
        public static final int MODE_MEDIUM = 2;

        /**
         * Value for {@link #EXTRA_MODE} to show a large-sized dialog.
         */
        public static final int MODE_LARGE = 3;

        /**
         * Intents related to the Contacts app UI.
         */
+39 −9
Original line number Diff line number Diff line
@@ -21,9 +21,11 @@ import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
@@ -31,6 +33,7 @@ import android.os.SystemClock;
import android.provider.SocialContract;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.Intents;
import android.provider.ContactsContract.PhoneLookup;
import android.provider.ContactsContract.RawContacts;
import android.provider.ContactsContract.CommonDataKinds.Photo;
@@ -123,11 +126,13 @@ public class ContactHeaderWidget extends FrameLayout implements View.OnClickList

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

        mStarredView = (CheckBox)findViewById(R.id.star);
        mStarredView.setOnClickListener(this);
        // Don't show start by default.
        mStarredView.setVisibility(View.GONE);

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

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

        // Set the photo with a random "no contact" image
@@ -310,12 +315,37 @@ public class ContactHeaderWidget extends FrameLayout implements View.OnClickList
    }

    public void onClick(View view) {
        if (view.getId() == R.id.star) {
            ContentValues values = new ContentValues(1);
        switch (view.getId()) {
            case R.id.star: {
                // Toggle "starred" state
                final ContentValues values = new ContentValues(1);
                values.put(Contacts.STARRED, mStarredView.isChecked());
                mContentResolver.update(mContactUri, values, null, null);
                break;
            }
            case R.id.photo: {
                // Photo launches contact detail action
                final Intent intent = new Intent(Intents.SHOW_OR_CREATE_CONTACT, mContactUri);
                final Rect target = getTargetRect(view);
                intent.putExtra(Intents.EXTRA_TARGET_RECT, target);
                intent.putExtra(Intents.EXTRA_MODE, Intents.MODE_SMALL);
                mContext.startActivity(intent);
                break;
            }
        }
    }

    private Rect getTargetRect(View anchor) {
        final int[] location = new int[2];
        anchor.getLocationOnScreen(location);

        final Rect rect = new Rect();
        rect.left = location[0];
        rect.top = location[1];
        rect.right = rect.left + anchor.getWidth();
        rect.bottom = rect.top + anchor.getHeight();
        return rect;
    }

    private Bitmap loadContactPhoto(long photoId, BitmapFactory.Options options) {
        Cursor photoCursor = null;
+6 −4
Original line number Diff line number Diff line
@@ -48,9 +48,11 @@
                
    </LinearLayout>

    <CheckBox android:id="@+id/star"
        style="?android:attr/starStyle"
    <CheckBox
        android:id="@+id/star"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
        android:layout_height="wrap_content"
        android:visibility="gone"
        style="?android:attr/starStyle" />

</LinearLayout>