Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display QuickContact card from widget

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.

like image 854
alejom99 Avatar asked Aug 08 '10 17:08

alejom99


3 Answers

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);
}  
like image 103
Sofi Software LLC Avatar answered Nov 14 '22 20:11

Sofi Software LLC


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);
like image 26
Pentium10 Avatar answered Nov 14 '22 20:11

Pentium10


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

like image 1
stfn Avatar answered Nov 14 '22 19:11

stfn