来电呼入时的各种信息显示都是在CallCard.java中实现的,其中的updateDisplayForPerson是主角。updateDisplayForPerson会根据电话的当前状态来更改名字号码等信息的显示。图片的替换代码如下:

ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(info, 0, this, call, getContext(), mPhoto, personUri, R.drawable.picture_unknown);

该方法可以传入CallerInfo信息以及各种参数,然后根据personUri将加载后获得的大头贴图片显示在mPhoto,picture_unknown是mPhoto的默认值。personUri的获取代码如下:

personUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, info.person_id);

R.drawable.picture_unknown则是系统默认的显示图片,如果查询不到相应personUri的大头贴信息,就会使用该图片。图片的加载是在ContactsAsynHelper.java中实现的。updateImageViewWithContactPhotoAsync方法的参数比较多,主要用于参数设定,消息发送:

public static final void updateImageViewWithContactPhotoAsync(CallerInfo info, int token,OnImageLoadCompleteListener listener, Object cookie, Context context,ImageView imageView, Uri person, int placeholderImageResource) {if (person == null) {if (DBG) Log.d(LOG_TAG, "target image is null, just display placeholder.");imageView.setVisibility(View.VISIBLE);imageView.setImageResource(placeholderImageResource);return;}// Added additional Cookie field in the callee to handle arguments// sent to the callback function.// setup argumentsWorkerArgs args = new WorkerArgs();args.cookie = cookie;args.context = context;args.view = imageView;args.uri = person;args.defaultResource = placeholderImageResource;args.listener = listener;args.info = info;// setup message argumentsMessage msg = sThreadHandler.obtainMessage(token);msg.arg1 = EVENT_LOAD_IMAGE;msg.obj = args;if (DBG) Log.d(LOG_TAG, "Begin loading image: " + args.uri +", displaying default image for now.");// set the default image first, when the query is complete, we will// replace the image with the correct one.if (placeholderImageResource != -1) {imageView.setVisibility(View.VISIBLE);imageView.setImageResource(placeholderImageResource);} else {imageView.setVisibility(View.INVISIBLE);}// notify the thread to begin workingsThreadHandler.sendMessage(msg);}

当这个方法被执行完毕时,会发送一个包含各种信息的msg,相应的处理handler是在WorkerHandler的handleMessage方法中进行的:

private class WorkerHandler extends Handler {
        public WorkerHandler(Looper looper) {
            super(looper);
        }

@Override
        public void handleMessage(Message msg) {
            WorkerArgs args = (WorkerArgs) msg.obj;

switch (msg.arg1) {
                case EVENT_LOAD_IMAGE:
                    InputStream inputStream = null;
                    try {
                        inputStream = Contacts.openContactPhotoInputStream(
                                args.context.getContentResolver(), args.uri, true);
                    } catch (Exception e) {
                        Log.e(LOG_TAG, "Error opening photo input stream", e);
                    }

if (inputStream != null) {
                        args.result = Drawable.createFromStream(inputStream, args.uri.toString());

if (DBG) Log.d(LOG_TAG, "Loading image: " + msg.arg1 +
                                " token: " + msg.what + " image URI: " + args.uri);
                    } else {
                        args.result = null;
                        if (DBG) Log.d(LOG_TAG, "Problem with image: " + msg.arg1 +
                                " token: " + msg.what + " image URI: " + args.uri +
                                ", using default image.");
                    }
                    break;
                default:
            }

// send the reply to the enclosing class.
            Message reply = ContactsAsyncHelper.this.obtainMessage(msg.what);
            reply.arg1 = msg.arg1;
            reply.obj = msg.obj;
            reply.sendToTarget();
        }
    }

根据参数中的uri获得输入流,然后根据该输入流查询得到图片,并将图片赋值给result。然后当reply.sendToTarget()方法执行后,会跳转到WorkerHandler类外部的handleMessage方法,此方法和类内部的handleMessage方法完全不同。最后在外部的handleMessage方法中设定图片资源:

 if (args.result != null) {args.view.setVisibility(View.VISIBLE);args.view.setImageDrawable((Drawable) args.result);// make sure the cached photo data is updated.if (args.info != null) {args.info.cachedPhoto = (Drawable) args.result;}

最后,在CallCard文件中会根据cachedPhoto来最终显示图片:

private static final boolean showCachedImage(ImageView view, CallerInfo ci) {if ((ci != null) && ci.isCachedPhotoCurrent) {if (ci.cachedPhoto != null) {log("person id is " + ci.person_id);log("showCachedImage: using the cachedPhoto!");showImage(view, ci.cachedPhoto);} else {log("showCachedImage: using picture_unknown!");showImage(view, R.drawable.picture_unknown);}return true;}log("showCachedImage: return false!");return false;}

android学习日记:来电大头贴显示流程相关推荐

  1. android 来电大头贴显示流程

    来电呼入时的各种信息显示都是在CallCard.java中实现的,其中的updateDisplayForPerson是主角.updateDisplayForPerson会根据电话的当前状态来更改名字号 ...

  2. android学习日记 RecyclerView的简单使用

    android学习日记 RecyclerView的简单使用 文章目录 android学习日记 RecyclerView的简单使用 一.如何使用RecyclerView? 二.使用步骤 1.首先在bui ...

  3. Android学习日记 Notification 通知

    Android学习日记 Notification 通知 文章目录 Android学习日记 Notification 通知 前言 使用步骤 总结 前言 下拉状态栏显示的通知功能 使用步骤 代码如下: p ...

  4. Android 7.0来电全屏显示 如何修改

    在Android 7.0来电全屏显示 如何修改呢? 1.alps/frameworks\base\packages\SystemUI\src\com\android\systemui\statusba ...

  5. Android图形显示系统——一张图片的显示流程

    Android设备上一张图片的显示过程 应用示例 假如我们现在有一张这样的风景照 想在Android设备(比如一个小米pad)上显示出来.首先想到的是写一个应用,用一个ImageView,把这张照片附 ...

  6. android学习日记一

    这几天在公司实习,公司主要是做android项目,以前在学校也学习过android,但是就学了点皮毛,在这里我准备把自己当做android一无所知的人,但是java会点的人,来系统的学习一下andro ...

  7. Android学习日记

    2021.2.27 星期六 // TODO 2/27 // 标识符 字母数字下划线$组成 不能数字开头 区分大小写 // 关键字 // 变量 变量类型 变量名 驼峰法 变量值 // 类 Pascal ...

  8. 【转】android学习日记01--综述

    转自:http://www.cnblogs.com/aiguozhe/p/3541941.html 一.总体框架 先上一张google提供官方的Android框架图: Android系统架构由5部分组 ...

  9. android学习日记16--GridView(网格视图)

    一.GridView 1.简述 GridView按照行列来显示图片或文本的一种视图,排列其实有点类似TableLayout布局, 不过和TableLayout还是差别很大的,倒比较像二维的ListVi ...

最新文章

  1. 8188无线网卡驱动linux,rtl8188eu linux驱动
  2. 成功解决You are using pip version 9.0.1, however version 9.0.3 is available. You should consider upgra
  3. MQTT再学习 -- 交叉编译与移植
  4. 650服务器raid配置_DELL R730服务器配置RAID及安装服务器系统
  5. python可以用来编写计算机网络程序吗_不必熟悉python或R编程语言,6步执行计算机视觉应用程序...
  6. 手写call,apply和bind(分析三者的用法与区别)
  7. 你必须了解Spring的生态
  8. zeppelin连接数据源_使用开放源代码合同(open-zeppelin)创建以太坊令牌
  9. STM32中C语言知识点:初学者必看,老鸟复习(长文总结)
  10. html倾斜变形,深入理解CSS变形transform(2d)_html/css_WEB-ITnose
  11. Unity Editor 查找资源依赖、反向查找资源依赖Dependencies
  12. 洞察药监局数据,挖掘万亿价值
  13. Trilateration三边测量定位算法
  14. Informatic学习总结_day03
  15. 企信下载的文件在哪里_Foobar2000(无损音乐播放器下载)(软件篇)
  16. CGArt 2008 Issue
  17. 微信小程序之CSS实现图片遮罩
  18. 班得瑞[Bandari]音乐介绍
  19. 创业公司技术总监出去面试,被拒后的感悟
  20. 阿里天池大数据竞赛(一)用ODPS提取特征

热门文章

  1. redis解决商品秒杀问题
  2. Problem 95 Prime Palindromes
  3. ld.lld: error: undefined symbol: android::CallStack::CallStack()
  4. 客控系统服务器,关于 客控系统厂家 的客控系统 您了解多少
  5. 类的默认成员函数、赋值运算符重载
  6. linux 脚本 杀进程,shell脚本实现杀死进程并启动程序(重启程序)【显哥出品,必为精品】...
  7. 公安机关对自己本辖区需要管理的人员叫做“实有人口“
  8. 使用 VXAPI ProtoBuf 工具抓取iPad微信Protobuf
  9. 计算机网络空间安全大赛报道,网络空间安全学院成功举办第十三届全国大学生信息安全竞赛线上宣讲会...
  10. PhotoshopCS5 第七篇 调整全局图像色彩