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.
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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,12 +126,14 @@ 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 = (CheckBox)findViewById(R.id.star);
|
||||
mStarredView.setOnClickListener(this);
|
||||
// Don't show start by default.
|
||||
mStarredView.setVisibility(View.GONE);
|
||||
mPhotoView = (ImageView) findViewById(R.id.photo);
|
||||
mStatusView = (TextView) findViewById(R.id.status);
|
||||
|
||||
mPhotoView = (ImageView)findViewById(R.id.photo);
|
||||
mPhotoView.setOnClickListener(this);
|
||||
|
||||
mStatusView = (TextView)findViewById(R.id.status);
|
||||
|
||||
// Set the photo with a random "no contact" image
|
||||
long now = SystemClock.elapsedRealtime();
|
||||
@@ -310,13 +315,38 @@ public class ContactHeaderWidget extends FrameLayout implements View.OnClickList
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
if (view.getId() == R.id.star) {
|
||||
ContentValues values = new ContentValues(1);
|
||||
values.put(Contacts.STARRED, mStarredView.isChecked());
|
||||
mContentResolver.update(mContactUri, values, null, null);
|
||||
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;
|
||||
Bitmap photoBm = null;
|
||||
|
||||
@@ -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>
|
||||
</LinearLayout>
|
||||
|
||||
Reference in New Issue
Block a user