I have a widget that displays the picture of some of my contacts and I would like to display the QuickContact card when the user taps on one of the pictures. I know I should be using the method ContactsContract.QuickContact.showQuickContact(), but it requires a View or a Rect as one of the input parameters. My problem is that Widgets only have RemoteViews, so I'm no sure what to pass as the View or Rect parameter. Any ideas would be appreciated.
To show the QuickContact UI over a widget, you can make a callback PendingIntent using the technique illustrated here:
http://advback.com/android/working-with-app-widgets-android/
In your widget onUpdate(), create the intent and associate it with the RemoteView:
intent = new Intent(context, MyWidget.class);
intent.setAction(ACTION_WIDGET_RECEIVER);
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
intent.setData(uri);
pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.my_widget_view, pendingIntent);
When the view is clicked, you'll get an onReceive() notification in your widget. Use Intent.getSourceBounds() to retrieve the rect, and show the QuickContact:
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) {
Uri uri = intent.getData();
if ( uri != null ) {
QuickContact.showQuickContact(context, intent.getSourceBounds(), uri, ContactsContract.QuickContact.MODE_SMALL, null);
}
}
super.onReceive(context, intent);
}
You can reference the badge in the XML
I have this in the XML file:
<QuickContactBadge
android:id="@+id/photo"
android:layout_width="54dip"
android:layout_height="57dip"
android:layout_marginLeft="5dip"
android:background="@drawable/quickcontact_photo_frame"
style="?android:attr/quickContactBadgeStyleWindowSmall"
/>
and this code:
private QuickContactBadge mPhotoView;
mPhotoView = (QuickContactBadge) findViewById(R.id.photo);
mPhotoView.assignContactUri(objItem.getUri());
mPhotoView.setMode(QuickContact.MODE_MEDIUM);
and this is the calling mode (but the click on the badge is handling this popup, this call too popup the chooser is made by clicking on something else)
QuickContact.showQuickContact(viewContactQuick.this, mPhotoView,objItem.getLookupUri() , QuickContact.MODE_MEDIUM, null);
I've been looking for this as well. Maybe the source of the Contacts app will be helpful. I'm trying to digg in: link text
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With