From 11d89599ef7cf949bfe0048d1352f264ee0f6a34 Mon Sep 17 00:00:00 2001 From: Megha Joshi Date: Fri, 13 Nov 2009 11:45:19 -0800 Subject: [PATCH] Add QuickContactsBadge widget sample to ApiDemos --- samples/ApiDemos/AndroidManifest.xml | 8 ++ .../res/drawable-hdpi/ic_contact_picture.png | Bin 0 -> 1487 bytes .../res/drawable-mdpi/ic_contact_picture.png | Bin 0 -> 1719 bytes .../ApiDemos/res/layout/quick_contacts.xml | 47 ++++++++ samples/ApiDemos/res/values/strings.xml | 3 +- .../android/apis/app/QuickContactsDemo.java | 106 ++++++++++++++++++ 6 files changed, 163 insertions(+), 1 deletion(-) create mode 100755 samples/ApiDemos/res/drawable-hdpi/ic_contact_picture.png create mode 100644 samples/ApiDemos/res/drawable-mdpi/ic_contact_picture.png create mode 100644 samples/ApiDemos/res/layout/quick_contacts.xml create mode 100644 samples/ApiDemos/src/com/example/android/apis/app/QuickContactsDemo.java diff --git a/samples/ApiDemos/AndroidManifest.xml b/samples/ApiDemos/AndroidManifest.xml index 01361ddb3..aba330a68 100644 --- a/samples/ApiDemos/AndroidManifest.xml +++ b/samples/ApiDemos/AndroidManifest.xml @@ -82,6 +82,14 @@ + + + + + + + diff --git a/samples/ApiDemos/res/drawable-hdpi/ic_contact_picture.png b/samples/ApiDemos/res/drawable-hdpi/ic_contact_picture.png new file mode 100755 index 0000000000000000000000000000000000000000..7c34f5c94bced4278508f594ef898b7ff6cf8b68 GIT binary patch literal 1487 zcmV;=1u*)FP)+9=wyRC6v z$+Ox3W;|T0)hHVW2M0>9xl^T5X=PoPdca2U3T(X1Ef|(&gznbX*6QkN zcHFk=8R2$&dppqQ#%h&#o614NN~lL8d2@5~^z<}Sz`nr_CnqPBN(H*fus%blz$U1o zuvx*`*%?{KM|ldh?d|Qu!^05s8(smh334B{NF^@JIr%m&xpsVf3{z&P!vr?cWUomLcb9&qjWkN(R?vf*JNA zs&k;LX0v&JfB*CI137PaHu5Ly>+6LqI3pjxP{!Te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X=@!~9i0TUq6fygK0+PD3A zRiN=q>v@8xG zoe{c}8*y;zE6+rLn|bvod2OxT1(GBekCLcnS%ENFFUrqOnu0&lpp}EUZYb)k7}5=&oi~LD0^B** zh|B_uSpXrnRpE=BRDY4&Ck#FG2l2cGiy-$c zghYcT$V;Ib);RjM!6 zts+3Mq}XNYqG{0% zO+7jU6no#~r7(dJAN#}PC0GipT81@;!TocpY{w$p;4vy7^d&V@l9#~wO$(`B(KN^_ z`+HS$(}G3iU$rT~!hG^aV3~9zFWHgBSSuZL64>$qJX6@t(6Gfjlrtc+y+GszAWUhy zB3@p(X32GAF_jOP05AJP@|x}sU?DFEvl6Ci3nh!JraH_Kw?(~3r9)_y9c{(F{LW$0 zD=#}-E=r0?tDB=V3?VGoqL!A2S|tHQ{3cfn_5D;$K+VtlvaMif47a|%j$7CZ$d0<7 z(wa-)(hcQEluNH-W03ojBA5BR>-Xljx3@v*yHB|6^?GVhpcBN}yYU3nXPTnOLPuNQ zM*gX~VF*)(eMrHjWx-*=mpA`%6P>HTssgN-S91~GF}9Fk&W~Cm%<-#i9pqI!`c9=u z(yH3-`O>@KC5mcQY%6XP6vG~7vBoa8p~YsUrg@Eq#!vCzs*k}gKF%_p`@^fpqx2&u z^bksXJj(gdFXPYtxLVBOj+>lGO2uiyW5HE(k?V2))t^G2`o&$SolJ|FODH7&nyr19 z4Z;nLW>vwPL;BzU8lo~NJ{@+kR5}!cPIjaGYhHYKGQ@{35HX@0HhkOmOqKf3gXEZd zrD8(MyHI&ICpVVQxGw{0>tDN$<@aq!~oPo3~Ig#tzle=qvil&tla zZ&f-jx@U3!vq~7=Z@L)HKY%^> literal 0 HcmV?d00001 diff --git a/samples/ApiDemos/res/layout/quick_contacts.xml b/samples/ApiDemos/res/layout/quick_contacts.xml new file mode 100644 index 000000000..ffb19ed83 --- /dev/null +++ b/samples/ApiDemos/res/layout/quick_contacts.xml @@ -0,0 +1,47 @@ + + + + + + + + + + diff --git a/samples/ApiDemos/res/values/strings.xml b/samples/ApiDemos/res/values/strings.xml index f4e895e4d..6f91b3476 100644 --- a/samples/ApiDemos/res/values/strings.xml +++ b/samples/ApiDemos/res/values/strings.xml @@ -32,12 +32,13 @@ Example of how you can use the Theme.Dialog theme to make an activity that looks like a dialog. - App/Activity/Custom Dialog Example of how you can use a custom Theme.Dialog theme to make an activity that looks like a customized dialog, here with an ugly frame. + App/Activity/QuickContactsDemo + App/Activity/Wallpaper App/Activity/SetWallpaper Set Wallpaper diff --git a/samples/ApiDemos/src/com/example/android/apis/app/QuickContactsDemo.java b/samples/ApiDemos/src/com/example/android/apis/app/QuickContactsDemo.java new file mode 100644 index 000000000..1ee574299 --- /dev/null +++ b/samples/ApiDemos/src/com/example/android/apis/app/QuickContactsDemo.java @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.apis.app; + +import com.example.android.apis.R; + +import android.app.ListActivity; +import android.content.Context; +import android.database.CharArrayBuffer; +import android.database.Cursor; +import android.os.Bundle; +import android.provider.ContactsContract.Contacts; +import android.view.View; +import android.view.ViewGroup; +import android.widget.QuickContactBadge; +import android.widget.ResourceCursorAdapter; +import android.widget.TextView; + +public class QuickContactsDemo extends ListActivity { + static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] { + Contacts._ID, // 0 + Contacts.DISPLAY_NAME, // 1 + Contacts.STARRED, // 2 + Contacts.TIMES_CONTACTED, // 3 + Contacts.CONTACT_PRESENCE, // 4 + Contacts.PHOTO_ID, // 5 + Contacts.LOOKUP_KEY, // 6 + Contacts.HAS_PHONE_NUMBER, // 7 + }; + + static final int SUMMARY_ID_COLUMN_INDEX = 0; + static final int SUMMARY_NAME_COLUMN_INDEX = 1; + static final int SUMMARY_STARRED_COLUMN_INDEX = 2; + static final int SUMMARY_TIMES_CONTACTED_COLUMN_INDEX = 3; + static final int SUMMARY_PRESENCE_STATUS_COLUMN_INDEX = 4; + static final int SUMMARY_PHOTO_ID_COLUMN_INDEX = 5; + static final int SUMMARY_LOOKUP_KEY = 6; + static final int SUMMARY_HAS_PHONE_COLUMN_INDEX = 7; + + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND (" + + Contacts.HAS_PHONE_NUMBER + "=1) AND (" + + Contacts.DISPLAY_NAME + " != '' ))"; + Cursor c = + getContentResolver().query(Contacts.CONTENT_URI, CONTACTS_SUMMARY_PROJECTION, select, + null, Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC"); + startManagingCursor(c); + ContactListItemAdapter adapter = new ContactListItemAdapter(this, R.layout.quick_contacts, c); + setListAdapter(adapter); + + } + + private final class ContactListItemAdapter extends ResourceCursorAdapter { + public ContactListItemAdapter(Context context, int layout, Cursor c) { + super(context, layout, c); + } + + @Override + public void bindView(View view, Context context, Cursor cursor) { + final ContactListItemCache cache = (ContactListItemCache) view.getTag(); + TextView nameView = cache.nameView; + QuickContactBadge photoView = cache.photoView; + // Set the name + cursor.copyStringToBuffer(SUMMARY_NAME_COLUMN_INDEX, cache.nameBuffer); + int size = cache.nameBuffer.sizeCopied; + cache.nameView.setText(cache.nameBuffer.data, 0, size); + final long contactId = cursor.getLong(SUMMARY_ID_COLUMN_INDEX); + final String lookupKey = cursor.getString(SUMMARY_LOOKUP_KEY); + cache.photoView.assignContactUri(Contacts.getLookupUri(contactId, lookupKey)); + } + + @Override + public View newView(Context context, Cursor cursor, ViewGroup parent) { + View view = super.newView(context, cursor, parent); + ContactListItemCache cache = new ContactListItemCache(); + cache.nameView = (TextView) view.findViewById(R.id.name); + cache.photoView = (QuickContactBadge) view.findViewById(R.id.badge); + view.setTag(cache); + + return view; + } + } + + final static class ContactListItemCache { + public TextView nameView; + public QuickContactBadge photoView; + public CharArrayBuffer nameBuffer = new CharArrayBuffer(128); + } +}