- 浏览: 1065628 次
- 性别:
- 来自: 南昌
文章分类
- 全部博客 (276)
- 生活 (1)
- 代码之美 (22)
- Media (7)
- Android Widget (3)
- Android Intent (1)
- Android Activity (4)
- UI event handle--UI事件处理机制 (2)
- Java基础知识 (12)
- android Databases (5)
- Android 系统知识 (70)
- 平常遇到的问题与解决方法 (38)
- Android TextView/EditView (2)
- Thinking Java (1)
- android webkit (6)
- JSON (1)
- XML (4)
- HTTP (1)
- Google Weather API (1)
- android 2.3 NFC (10)
- android app (20)
- android framework (7)
- C++ (2)
- android System (5)
- Pthread (1)
- Wifi (8)
- Unix/Linux C (8)
- Android 4.0 (1)
- Mail (1)
- Smack 源码学习 (4)
- iOS (4)
- Android (1)
- git (1)
- Gallery3d (2)
- React-Natice (1)
最新评论
-
dd18349182956:
你是用的smack哪个版本?我用的smack4.1.3和sma ...
关于socket长连接的心跳包 -
xukaiyin:
全英文
getApplicationContext()与this,getBaseContext() -
裂风矢:
...
<category android:name="android.intent.category.DEFAULT" /> 惹的祸 -
xanthodont:
mark一下
XMPP——Smack -
Evilover3:
mark一下,学习了
XMPP——Smack
参考文章:http://mobile.tutsplus.com/tutorials/android/android-sdk_contact-badge/
If you’ve spent any time on an Android device, you may have noticed how you can click on little Contact images to launch a toolbar with lots of different actions, such as call, text or email that person. In this Quick Tip, you learn how to build this great functionality—called the Quick Contact Badge—into your own applications.
In order to have easy access to contacts, we’ll start with our existing open source code here. We enhance this project, which initially allowed the user to simply choose a contact from a list, and create several different quick contact badges for that contact to illustrate how they work.
Note: This tutorial requires Android 2.0 or higher.
Step 1: Adding an Activity
Start with a new Activity called QuickContactBadgeActivity. Inside the onCreate() method, add a setContentView() method call for a new layout called badge (e.g. R.id.badge).
view plaincopy to clipboardprint?
public class QuickContactBadgeActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.badge);
}
}
Step 2: Creating the Layout
Now you need to create a layout using QuickContactBadge controls. The QuickContactBadge control was introduced in Android 2.0 (API Level 5). The following layout creates two QuickContactBadge controls and provides a holder for a third (a FrameLayout control). The QuickContactBadge control is derived from an ImageView control. Thus, you can set the image displayed by the QuickContactBadge control just as you would an ImageView, using the src attribute.
Here’s the final layout we’re using:
view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:text="Sample Quick Contact Badges"
android:id="@+id/TextView01"
android:layout_width="match_parent"
android:layout_height="wrap_content"></TextView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/pick_contact"
android:onClick="onPickContact"
android:text="@string/pick_contact_for_badge"></Button>
<QuickContactBadge
android:id="@+id/badge_small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/droid_small"></QuickContactBadge>
<QuickContactBadge
android:id="@+id/badge_medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></QuickContactBadge>
<FrameLayout
android:id="@+id/badge_holder_large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></FrameLayout>
</LinearLayout>
QuickContactBadge controls can launch the contact action bar (as we’re calling it) in three different sizes: small, medium (default), and large. The small action bar contains only the action buttons and minimal details. The medium action bar contains the action buttons and some additional contact info. The large action bar contains lots of actions, contact info and graphics.
Note: The current ADT plug-in for Eclipse allows you to set the window size of the contact action bar in XML. An error is shown when you try to set a value, though. Unfortunately, this means you can’t actually set this attribute in the XML layout file. Instead, you must set the window size programmatically using the setMode() method of the QuickContactBadge class. You will see how in the next step.
Step 2: Configuring the Badges
Within the onCreate() method of the Activity, add the following code, replacing the email address with one in your contacts (add it ahead of time if you need to).
view plaincopy to clipboardprint?
QuickContactBadge badgeSmall = (QuickContactBadge) findViewById(R.id.badge_small);
badgeSmall.assignContactFromEmail("any@gmail.com", true);
badgeSmall.setMode(ContactsContract.QuickContact.MODE_SMALL);
The more information that is associated with the contact tied to the badge, the more action items will be available for use in the contact action bar. For instance, here’s one using my own email address:
And here’s another with a contact that has a web address assigned:
You can use the setExcludeMimeTypes() method of the QuickContactBadge class to remove any actions or information you don’t want to display.
Step 3: Working with Unknown Contacts
The previous example worked well because you already knew your own address or added a contact you knew to exist. What if the contact doesn’t yet exist within your Contacts database? Try it!
Add the following code, this time to look up a phone number that you probably don’t have in your address book:
view plaincopy to clipboardprint?
QuickContactBadge badgeMedium = (QuickContactBadge) findViewById(R.id.badge_medium);
badgeMedium.assignContactFromPhone("831-555-1212", true);
badgeMedium.setImageResource(R.drawable.droid_small);
Note also that this time we are using a medium sized QuickContactBadge. When clicking on the QuickContactBadge for an unknown entry, something interesting happens. The user is asked if they want to add the contact. If they choose yes, they’ll get the option to add the email or phone number to an existing contact or create a new contact. Then, on subsequent presses of this QuickContactBadge, the contact will exist and be found. This can be quite handy.
Step 4: Creating a QuickContactBadge From an Existing Contact
Generally speaking, you don’t know what contacts are on someone’s device. You do, however, have access to the Contacts content provider and can retrieve URIs for each contact as needed. You learned how to launch the contact picker in this previous tutorial.
Here’s an example of how we can use a contact URI to supply the contact information for a QuickContactBadge:
view plaincopy to clipboardprint?
public void onPickContact(View view) {
Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,
Contacts.CONTENT_URI);
startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
switch (requestCode) {
case CONTACT_PICKER_RESULT:
Uri contactUri = data.getData();
FrameLayout badgeLargeHolder = (FrameLayout) findViewById(R.id.badge_holder_large);
QuickContactBadge badgeLarge = new QuickContactBadge(this);
badgeLarge.assignContactUri(contactUri);
badgeLarge.setMode(ContactsContract.QuickContact.MODE_LARGE);
badgeLarge.setImageResource(R.drawable.droid_small);
badgeLargeHolder.addView(badgeLarge);
break;
}
}
}
Here you use the Contact Uri chosen by the user to configure a QuickContactBadge that the user can click on. In addition, this shows the final, and largest, contact action bar mode.
Using the QuickContactBadge
When might you want to use the QuickContactBadge? Use the QuickContactBadge anywhere that displays friends or lists of contacts, enabling the user to interact with these individuals in other ways. You could also add your email and phone number to the Contacts and provide a QuickContactBadge within your application to give users a quick way to email, call, or message you (or your support team).
Conclusion
In this Quick Tip, you learned how to use the QuickContactBadge control to quickly bring up the contact action bar (available in various sizes) and enable various actions to be taken. The QuickContactBadge is a standard view control available in Android 2.0 and higher, so users should be familiar with its purpose, and therefore appreciate it when developers take advantage of its powerful features. The QuickContactBadge can also save you, the developer, valuable time in creating all of the possible Intent actions that this control provides with ease.
除此之外,还可以看APIDemo-->app->QuickContactsDemo的例子
If you’ve spent any time on an Android device, you may have noticed how you can click on little Contact images to launch a toolbar with lots of different actions, such as call, text or email that person. In this Quick Tip, you learn how to build this great functionality—called the Quick Contact Badge—into your own applications.
In order to have easy access to contacts, we’ll start with our existing open source code here. We enhance this project, which initially allowed the user to simply choose a contact from a list, and create several different quick contact badges for that contact to illustrate how they work.
Note: This tutorial requires Android 2.0 or higher.
Step 1: Adding an Activity
Start with a new Activity called QuickContactBadgeActivity. Inside the onCreate() method, add a setContentView() method call for a new layout called badge (e.g. R.id.badge).
view plaincopy to clipboardprint?
public class QuickContactBadgeActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.badge);
}
}
Step 2: Creating the Layout
Now you need to create a layout using QuickContactBadge controls. The QuickContactBadge control was introduced in Android 2.0 (API Level 5). The following layout creates two QuickContactBadge controls and provides a holder for a third (a FrameLayout control). The QuickContactBadge control is derived from an ImageView control. Thus, you can set the image displayed by the QuickContactBadge control just as you would an ImageView, using the src attribute.
Here’s the final layout we’re using:
view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:text="Sample Quick Contact Badges"
android:id="@+id/TextView01"
android:layout_width="match_parent"
android:layout_height="wrap_content"></TextView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/pick_contact"
android:onClick="onPickContact"
android:text="@string/pick_contact_for_badge"></Button>
<QuickContactBadge
android:id="@+id/badge_small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/droid_small"></QuickContactBadge>
<QuickContactBadge
android:id="@+id/badge_medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></QuickContactBadge>
<FrameLayout
android:id="@+id/badge_holder_large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></FrameLayout>
</LinearLayout>
QuickContactBadge controls can launch the contact action bar (as we’re calling it) in three different sizes: small, medium (default), and large. The small action bar contains only the action buttons and minimal details. The medium action bar contains the action buttons and some additional contact info. The large action bar contains lots of actions, contact info and graphics.
Note: The current ADT plug-in for Eclipse allows you to set the window size of the contact action bar in XML. An error is shown when you try to set a value, though. Unfortunately, this means you can’t actually set this attribute in the XML layout file. Instead, you must set the window size programmatically using the setMode() method of the QuickContactBadge class. You will see how in the next step.
Step 2: Configuring the Badges
Within the onCreate() method of the Activity, add the following code, replacing the email address with one in your contacts (add it ahead of time if you need to).
view plaincopy to clipboardprint?
QuickContactBadge badgeSmall = (QuickContactBadge) findViewById(R.id.badge_small);
badgeSmall.assignContactFromEmail("any@gmail.com", true);
badgeSmall.setMode(ContactsContract.QuickContact.MODE_SMALL);
The more information that is associated with the contact tied to the badge, the more action items will be available for use in the contact action bar. For instance, here’s one using my own email address:
And here’s another with a contact that has a web address assigned:
You can use the setExcludeMimeTypes() method of the QuickContactBadge class to remove any actions or information you don’t want to display.
Step 3: Working with Unknown Contacts
The previous example worked well because you already knew your own address or added a contact you knew to exist. What if the contact doesn’t yet exist within your Contacts database? Try it!
Add the following code, this time to look up a phone number that you probably don’t have in your address book:
view plaincopy to clipboardprint?
QuickContactBadge badgeMedium = (QuickContactBadge) findViewById(R.id.badge_medium);
badgeMedium.assignContactFromPhone("831-555-1212", true);
badgeMedium.setImageResource(R.drawable.droid_small);
Note also that this time we are using a medium sized QuickContactBadge. When clicking on the QuickContactBadge for an unknown entry, something interesting happens. The user is asked if they want to add the contact. If they choose yes, they’ll get the option to add the email or phone number to an existing contact or create a new contact. Then, on subsequent presses of this QuickContactBadge, the contact will exist and be found. This can be quite handy.
Step 4: Creating a QuickContactBadge From an Existing Contact
Generally speaking, you don’t know what contacts are on someone’s device. You do, however, have access to the Contacts content provider and can retrieve URIs for each contact as needed. You learned how to launch the contact picker in this previous tutorial.
Here’s an example of how we can use a contact URI to supply the contact information for a QuickContactBadge:
view plaincopy to clipboardprint?
public void onPickContact(View view) {
Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,
Contacts.CONTENT_URI);
startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
switch (requestCode) {
case CONTACT_PICKER_RESULT:
Uri contactUri = data.getData();
FrameLayout badgeLargeHolder = (FrameLayout) findViewById(R.id.badge_holder_large);
QuickContactBadge badgeLarge = new QuickContactBadge(this);
badgeLarge.assignContactUri(contactUri);
badgeLarge.setMode(ContactsContract.QuickContact.MODE_LARGE);
badgeLarge.setImageResource(R.drawable.droid_small);
badgeLargeHolder.addView(badgeLarge);
break;
}
}
}
Here you use the Contact Uri chosen by the user to configure a QuickContactBadge that the user can click on. In addition, this shows the final, and largest, contact action bar mode.
Using the QuickContactBadge
When might you want to use the QuickContactBadge? Use the QuickContactBadge anywhere that displays friends or lists of contacts, enabling the user to interact with these individuals in other ways. You could also add your email and phone number to the Contacts and provide a QuickContactBadge within your application to give users a quick way to email, call, or message you (or your support team).
Conclusion
In this Quick Tip, you learned how to use the QuickContactBadge control to quickly bring up the contact action bar (available in various sizes) and enable various actions to be taken. The QuickContactBadge is a standard view control available in Android 2.0 and higher, so users should be familiar with its purpose, and therefore appreciate it when developers take advantage of its powerful features. The QuickContactBadge can also save you, the developer, valuable time in creating all of the possible Intent actions that this control provides with ease.
除此之外,还可以看APIDemo-->app->QuickContactsDemo的例子
发表评论
-
ACTIVITY的LAUNCH MODE详解 SINGLETASK正解
2012-05-30 08:58 1098转自:http://www.cnblogs.com/xiaoQ ... -
android的一些开源项目
2011-12-06 14:08 1179转自:http://www.iteye.com/problem ... -
修改StatusBar
2011-10-10 10:27 1245转自:http://iserveandroid.blogspo ... -
单独一个应用程序换语言
2011-09-29 15:16 1436转自http://blog.csdn.net/sodino/a ... -
通过代码设置live wall paper
2011-09-02 09:17 25081. The code is: private Wall ... -
Android camera 默认显示黑白的问题
2011-06-08 16:18 2525转自:http://tassardge.blog. ... -
关于Activity切换动画——overridePendingTransition
2011-05-25 14:33 5756Activity的切换动画指的是从一个activity跳转到另 ... -
sendBroadcast和sendStickyBroadcast的区别
2011-04-28 13:39 9699我们平时最经常使用的是sendBroadcast,就是把一个I ... -
Settings.System.getInt获取Setting里面的一些设置
2011-04-28 10:29 7020好久没有更新博客了,其实这期间我都在研究android如何换皮 ... -
Service 启动Activity
2011-03-11 11:06 25162我想我们一般在Service里想启动Activity一定会这样 ... -
Android Windows
2011-03-11 09:45 2042转自:http://elsila.blog.163.com/b ... -
IntentService
2011-03-11 09:23 3435看android的源码可以发现很多很多有趣有用的代码,今天在看 ... -
AsyncQueryHandler
2011-03-02 15:10 6788在QuickContactBadge里面我 ... -
QuickContactBadge如何实现
2011-03-02 11:52 4909从前一篇,我们知道了如何使用了QuikcContactBadg ... -
QuickSearcheBox---SearchManager获取search列表
2011-02-25 14:05 1849在android 2.2之后加入了SearchManager, ... -
QuickSearcheBox---SearchWidgetConfigActivity
2011-02-24 10:48 1630再把QuickSearchBox放到桌面前,会先触发它的Con ... -
RemoteView总结
2011-02-23 11:15 2325我最初认识RemoteView是在AppWidget里面的,但 ... -
Google Search Widget, Google Search ap, Globe Search ap
2011-02-23 10:39 1282http://blog.csdn.net/Judy889/ar ... -
调用android system Search UI须注意的问题
2011-02-23 10:38 1535http://blog.csdn.net/Judy889/ar ...
相关推荐
`ch06_QuickContactBadge`则可能包含使用QuickContactBadge的实例;`ch06_ucweb_menu`可能是针对特定场景(如UCWeb浏览器)的自定义菜单实现;而`ch06_menu`则可能是基础的菜单资源文件。 总的来说,自定义菜单和...
#### 二、使用QuickContactBadge实现基本通讯录弹窗 1. **布局文件创建**: 在`res/layout`目录下创建布局文件`main.xml`,包含一个`QuickContactBadge`组件。该组件用于显示联系人的图片,并支持点击后弹出一系列...
- **权限需求**:使用 `QuickContactBadge` 需要申请 `android.permission.READ_CONTACTS` 权限,因为该控件涉及访问设备上的联系人信息。 #### 知识点二:QuickContactBadge 的构造与初始化 - **初始化方法**:在...
在这个场景中,`QuickContactBadge` 和 `ListView` 是两个关键组件,它们共同构建了一个高效且用户友好的交互体验。 首先,`QuickContactBadge` 是一个Android SDK提供的视图组件,它主要用于显示联系人头像,并...
7. **绑定QuickContactBadge**: 将查询到的联系人ID绑定到QuickContactBadge上,通常使用`setContactUri()`方法。这样在点击QuickContactBadge时,系统会自动弹出对应联系人的QuickContact窗口。 8. **事件监听**: ...
此外,还可以使用ValueAnimator或ObjectAnimator实现更复杂的动画效果,如平滑过渡或基于时间的比例变化。 除了动画,自定义ListView还需要注意滚动同步问题。因为ListView在滚动时会复用View,所以我们需要确保在...
- **使用**:开发者可以通过设置`android:uiOptions="splitActionBarWhenNarrow"`属性或使用`getSupportActionBar()`方法来实现Action Bar。 2. **Fragment** - **定义**:Fragment是Android 3.0引入的一个可重用...
本文档涵盖了 Android 2.2 版本的 API,包括 TextView、EditText、AccessibilityService、Manifest、View、ImageView、ImageButton、QuickContactBadge、ZoomButton、CheckBox、RadioButton、Button、ToggleButton、...
在Android中,这一功能通过`SectionIndexer`接口和`QuickContactBadge`组件共同实现。 `SectionIndexer`接口定义了三个方法:`getPositionForSection(int section)`用于获取指定分段(字母)的第一个索引位置;`...
4. **QuickContactBadge**:为了增强用户体验,可以在每个联系人项旁边添加QuickContactBadge,当用户点击时可以快速查看或编辑联系人信息。 5. **onSectionChanged()回调**:当用户选择字母栏上的某个字母时,系统...
在联系人应用中,我们可以使用`ACTION_PICK_CONTACT`或`ACTION_INSERT`等预定义Intent来选择或创建新的联系人。 4. **Permissions**:访问联系人数据通常需要`READ_CONTACTS`和`WRITE_CONTACTS`权限。在Android 4.0...
通过分析和学习这个文件,开发者可以更深入地理解自定义菜单的实现过程,包括布局设计、PopupWindow的使用以及动画的添加等。这个示例不仅适用于创建QuickContactBadge风格的菜单,还可以作为基础,根据需求调整样式...
10. QuickContactBadge:联系人控件,快速查看或编辑联系人信息。 11. DatePicker/TimePicker:日期和时间选择器,让用户选择日期或时间。 【资源和配置】 Android应用的结构包括界面程序、配置清单文件和资源...
它有两个已知的直接子类:ImageButton和QuickContactBadge,分别用于显示可点击的图像按钮和快速联系人徽章。除此之外,还有一些间接子类,如ZoomButton,用于处理缩放操作。 ImageView的重要属性包括: 1. `...
5. **QuickContactBadge**:这是一个可以快速查看联系人详细信息的小图标,常用于快速索引栏中,当用户点击特定字母时,显示与该字母相关的联系人。 6. **ListView/RecyclerView**:展示联系人列表的视图组件。...
这个"android项目代码"正是关于这一主题的实践案例,它使用了Qt库来辅助开发,并且具有实用性,适合学习和参考。Qt是一个跨平台的应用程序开发框架,支持包括Android在内的多种操作系统。 首先,我们要理解Android...
- **QuickContactBadge**:快速联系组件,常用于显示联系人头像和相关信息。 以上是《Android简明应用程序开发》前五章内容的总结,涵盖了Android应用开发的基础知识和技术要点。希望这些信息能够帮助读者更好地...
* QuickContactBadge:提供了快速联系人的方式。 * ZoomButton:提供了缩放按钮的方式。 * CheckBox:提供了复选框的方式。 * RadioButton:提供了单选框的方式。 * Button:提供了普通按钮的方式。 * ToggleButton...