Contacts解析
显示联系人
相关类
packages/apps/Contacts/src/com/android/contacts/activities/PeopleActivity.java
packages/apps/Contacts/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
packages/apps/Contacts/src/com/android/contacts/list/DefaultContactListAdapter.java
packages/apps/Contacts/src/com/android/contacts/list/ContactEntryListFragment.java
packages/apps/Contacts/src/com/android/contacts/list/ContactEntryListAdapter.java
packages/apps/Contacts/src/com/android/contacts/list/DirectoryPartition.java
packages/apps/Contacts/src/com/android/contacts/list/DirectoryListLoader.java
packages/apps/Contacts/src/com/android/contacts/quickcontact/QuickContactActivity.java
packages/apps/Contacts/src/com/android/contacts/model/ContactLoader.java
联系人列表数据加载流程
打开Contacts根目录下的AndroidManifest.xml文件查看PeopleActivity属性如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<activity
android:name=".activities.PeopleActivity"
android:alwaysRetainTaskState="true"
android:launchMode="singleTop"
android:resizeableActivity="true"
android:theme="@style/LaunchScreenTheme"
android:visibleToInstantApps="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.APP_CONTACTS"/>
</intent-filter>
PeopleActivity是Contacts应用的LAUNCHER界面,因此打开联系人应用,首先加载PeopleActivity,在createViewsAndFragments()方法中创建联系人界面
setUpListFragment()方法中创建DefaultContactBrowseListFragment所有联系人的Fragment
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
private void setUpListFragment(FragmentManager fragmentManager) {
mContactsListFragment = (DefaultContactBrowseListFragment)
fragmentManager.findFragmentByTag(TAG_ALL);
//判断mContactsListFragment为空则创建Fragment
if (mContactsListFragment == null) {
mContactsListFragment = new DefaultContactBrowseListFragment();
mContactsListFragment.setAnimateOnLoad(true);
fragmentManager.beginTransaction()
.add(R.id.contacts_list_container, mContactsListFragment, TAG_ALL)
.commit();
fragmentManager.executePendingTransactions();
}
//对Fragment进行初始化的一系列设置
mContactsListFragment.setContactsAvailable(areContactsAvailable());
mContactsListFragment.setListType(mContactListFilterController.getFilterListType());
mContactsListFragment.setParameters(/* ContactsRequest */ mRequest,
/* fromOnNewIntent */ false);
}
创建所有联系人界面以后进行数据加载,数据加载使用DirectoryListLoader,该加载器继承自系统的AsyncTaskLoader加载器
DirectoryListLoader加载数据的Uri并非来自DirectoryPartition.mContentUri,而是直接从ContactContacts中的Directory类中获取
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
private static final class DirectoryQuery {
//查询数据排序规则
public static final String ORDER_BY = Directory._ID;
//查询条件规则
public static final String[] PROJECTION = {
Directory._ID,
Directory.PACKAGE_NAME,
Directory.TYPE_RESOURCE_ID,
Directory.DISPLAY_NAME,
Directory.PHOTO_SUPPORT,
};
public static final int ID = 0;
public static final int PACKAGE_NAME = 1;
public static final int TYPE_RESOURCE_ID = 2;
public static final int DISPLAY_NAME = 3;
public static final int PHOTO_SUPPORT = 4;
//获取查询Uri,跟踪代码可知,Directory.ENTERPRISE_CONTENT_URI是Android 25版本之后才加入的
//ContactsUtils.java
//public static final boolean FLAG_N_FEATURE = Build.VERSION.SDK_INT >= 24;
public static Uri getDirectoryUri(int mode) {
if (mode == SEARCH_MODE_DATA_SHORTCUT || mode == SEARCH_MODE_CONTACT_SHORTCUT) {
return Directory.CONTENT_URI;
} else {
return DirectoryCompat.getContentUri();
}
}
}
DirectoryPartition类对联系人数据加载过程信息进行管理,联系人信息加载后在内存中的缓存的封装,内部提供了3种数据加载信息状态
1
2
3
public static final int STATUS_NOT_LOADED = 0; //还未加载数据
public static final int STATUS_LOADING = 1; //正在加载数据
public static final int STATUS_LOADED = 2; //数据已加载完毕
联系人详情页加载流程
联系人详情的界面类是QuickContactActivity,一般情况下联系人详情是通过其他入口启动的,启动时必须通过Intent传递lookupUri到QuickContactActivity,否则将调用finish()关闭界面
联系人详情数据加载流程中的加载器ContactLoader和列表一样都继承自AsyncTaskLoader,可查看代码了解
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
private void processIntent(Intent intent) {
//这里各种判断中调用finish(),就是对加载联系人合法性的判断失败后自己关闭界面
......
//使用oldLookupUri,对加载过的联系人进行缓存,以便再次打开能更快加载
mLookupUri = lookupUri;
mExcludeMimes = intent.getStringArrayExtra(QuickContact.EXTRA_EXCLUDE_MIMES);
if (oldLookupUri == null) {
// Should not log if only orientation changes.
mShouldLog = !mIsRecreatedInstance;
mContactLoader = (ContactLoader) getLoaderManager().initLoader(
LOADER_CONTACT_ID, null, mLoaderContactCallbacks);
} else if (oldLookupUri != mLookupUri) {
// Should log when reload happens, regardless of orientation change.
mShouldLog = true;
// After copying a directory contact, the contact URI changes. Therefore,
// we need to reload the new contact.
destroyInteractionLoaders(http://www.amjmh.com/v/BIBRGZ_558768/);
mContactLoader = (ContactLoader) (Loader<?>) getLoaderManager().getLoader(
LOADER_CONTACT_ID);
mContactLoader.setNewLookup(mLookupUri);
mCachedCp2DataCardModel = null;
}
//最后通过ContactLoader开启联系人数据加载
mContactLoader.forceLoad();
}
————————————————
Contacts解析的更多相关文章
- Sharepoint学习笔记—习题系列--70-576习题解析 -(Q105-Q108)
Question 105 You are designing a SharePoint 2010 application that contains a single list named Us ...
- Android:联系人Contacts之ContentResolver query 参数详解
注:本片整理自 http://blog.csdn.net/wssiqi/article/details/8132603 1.获取联系人姓名 一个简单的例子,这个函数获取设备上所有的联系人ID和联系人N ...
- android 获取系统联系人 完全解析
一.代码 1.ContactsEngine.java import java.util.ArrayList; import java.util.HashMap; import java.util.Li ...
- Sharepoint学习笔记—习题系列--70-576习题解析 -(Q6-Q8)
Question 6 You are designing a SharePoint 2010 solution that allows users to enter address informat ...
- getContentResolver()内容解析者查询联系人、插入联系人
首先,我们需要知道的两个Uri: 1.Uri uri = Uri.parse("content://com.android.contacts/raw_contacts");//查到 ...
- Google Android 6.0 权限完全解析
注:本文只针对Google原生Android系统有效, 小米魅族等手机有自己的权限机制, 可能不适用 一.运行时权限的变化及特点 新的权限机制更好的保护了用户的隐私,Google将权限分为两类,一类是 ...
- WCF 已知类型和泛型解析程序 KnownType
数据协定继承 已知类型和泛型解析程序 Juval Lowy 下载代码示例 自首次发布以来,Windows Communication Foundation (WCF) 开发人员便必须处理数据协定继承方 ...
- DOM综合案例、SAX解析、StAX解析、DOM4J解析
今日大纲 1.DOM技术对xml的增删操作 2.使用DOM技术完成联系人管理 3.SAX和StAX解析 4.DOM4J解析 5.XPATH介绍 1.DOM的增删操作 1.1.DOM的增加操作 /* * ...
- Intent的详细解析以及用法
Intent的详细解析以及用法 Android的四大组件分别为Activity .Service.BroadcastReceiver(广播接收器).ContentProvider(内容提供者 ...
随机推荐
- 接口测试-免费开放的api
归纳一些不错的免费开放的api 1.Apizza免费开放的Api接口 链接: https://www.jianshu.com/p/e6f072839282 接口文档:https://www.apiop ...
- gitlab操作笔记
基本命令 准备 1. 安装所需命令 sudo yum install curl openssh-server openssh-clients postfix cronie -y2. 安装SSH sud ...
- 给Repater增加等号
//不改变数据结构的情况下,增加行号.对Application服务器压力增大,减少DB服务器压力. protected void repShow_ItemDataBound(object sen ...
- vue cli更新
关于旧版本 Vue CLI 的包名称由 vue-cli 改成了 @vue/cli. 如果你已经全局安装了旧版本的 vue-cli (1.x 或 2.x),你需要先通过 npm uninstall vu ...
- PYTHON的程序在LINUX后台运行
1.nohup 命令 nohup nohup 命令 用途:LINUX命令用法,不挂断地运行命令. 语法:nohup Command [ Arg ... ] [ & ] 描述:nohup 命令运 ...
- redis集群启动和关闭脚本
创建startall.sh /usr/local/redis/bin/redis-server /usr/local/redis/redis-cluster/7001/redis.conf /usr/ ...
- ssh无密码访问设置(ssh-keygen 的详解)
[原文链接]http://blog.csdn.net/wh_19910525/article/details/7433164 为了让两个linux机器之间使用ssh不需要用户名和密码.所以采用了数字签 ...
- Oracle批量导出表数据到CSV文件
需求:把oracle数据库中符合条件的n多表,导出成csv文本文件,并以表名.csv为文件名存放. 实现:通过存储过程中utl_file函数来实现.导出的csv文件放入提前创建好的directory中 ...
- 【SDOI 2014】数表
题意 https://loj.ac/problem/2193 题解 显然就是求 $\sum\limits_{i=1}^{n} \sum\limits_{j=1}^{m} \sigma_1(\gcd{ ...
- k8s资源对象及API群组
REST是representational state transfer的缩写,意为“表征状态转移”,它是一种程序架构风格,基本元素为资源(resource).表征(representation)和行 ...