Contacts模块中的QuickContacts

2024-01-12 03:32

本文主要是介绍Contacts模块中的QuickContacts,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在ContactsLIstActiviry中的newView()和bindView()函数中都使用了ContactListItemCache类型的Cache:

    final static class ContactListItemCache {

        public View header;

        public TextView headerText;

        public View divider;

        public TextView nameView;

        public View callView;

        public ImageView callButton;

        public CharArrayBuffer nameBuffer = new CharArrayBuffer(128);

        public TextView labelView;

        public CharArrayBuffer labelBuffer = new CharArrayBuffer(128);

        public TextView dataView;

        public CharArrayBuffer dataBuffer = new CharArrayBuffer(128);

        public ImageView presenceView;

        public QuickContactBadge photoView;

        public ImageView nonQuickContactPhotoView;

}

 

其中QuickContactBadge类型的photoView,就是指的图片,点击图片之后会弹出QuickContacts框。

 

 

 

 

 

看一下QuickContactBadge的代码:

public void onClick(View v) {

…………..……

} else if (mContactEmail != null) {

mQueryHandler.startQuery(TOKEN_EMAIL_LOOKUP_AND_TRIGGER, mContactEmail,

Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(mContactEmail)),

EMAIL_LOOKUP_PROJECTION, null, null, null);

…………..……

//在相应点击时触发一个startQuery()方法,这个方法执行完毕之后自动调用mQueryHandler的//onQueryComplete()方法

}

 

protected void onQueryComplete(int token, Object cookie, Cursor cursor) {

…………………………………….

 

if (trigger && lookupUri != null) {

trigger(lookupUri);//在调用trigger()方法。

…………………………………..

}

 

 

}

    private void trigger(Uri lookupUri) {

        QuickContact.showQuickContact(getContext(), this, lookupUri, mMode, mExcludeMimes);

    }

 

对于showQuickContact方法来说,它是ContactsContract类中的一个函数。下面是代码:

 

 

public static void showQuickContact(Context context, Rect target, Uri lookupUri, int mode,

                String[] excludeMimes) {

            // Launch pivot dialog through intent for now

            final Intent intent = new Intent(ACTION_QUICK_CONTACT);//这个就是.UI.QuickContactsActivity的IntentFilter的Action

            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP

                    | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

 

            intent.setData(lookupUri);

            intent.putExtra(EXTRA_TARGET_RECT, target);

            intent.putExtra(EXTRA_MODE, mode);

            intent.putExtra(EXTRA_EXCLUDE_MIMES, excludeMimes);

            context.startActivity(intent);//此时就会启动.UI.QuickContactsActivity

}

 

QuickContactsActivity类中的代码比较少。它继承了QuickContactWindow.OnDismissListener,使用onDismiss()函数来把QuickContact框dismiss掉。

QuickContactsActivity类在onNewIntent()函数中先将Intent解析出来,再调用show()方法将QuickContactWindow显示出来。

    public void onNewIntent(Intent intent) {

        super.onNewIntent(intent);

                   ……………

        mQuickContact.show(lookupUri, target, mode, excludeMimes);//show()方法是QuickContactWindow类中的函数

    }

 

.UI.QuickContactsActivity界面的绘制就是在QuickContactWindow类中完成的。

 

 

 

首先,在Show()方法中调用mHandler.startQuery()方法

 

   

public synchronized void show(Uri lookupUri, Rect anchor, int mode, String[] excludeMimes) {

                   ………………………………….

        if (mMode == QuickContact.MODE_LARGE) {

            // Select photos, but only super-primary

            mHandler.startQuery(TOKEN_DATA, lookupUri, dataUri, DataQuery.PROJECTION, Data.MIMETYPE

                + "!=? OR (" + Data.MIMETYPE + "=? AND " + Data._ID + "=" + Contacts.PHOTO_ID

                + ")", new String[] { Photo.CONTENT_ITEM_TYPE, Photo.CONTENT_ITEM_TYPE }, null);

        } else {

            // Exclude all photos from cursor

            mHandler.startQuery(TOKEN_DATA, lookupUri, dataUri, DataQuery.PROJECTION, Data.MIMETYPE

                    + "!=?", new String[] { Photo.CONTENT_ITEM_TYPE }, null);

        }

    }

 

然后在onQueryComplete()方法中调用handleData()

   

    public synchronized void onQueryComplete(int token, Object cookie, Cursor cursor) {

        if (cookie != mLookupUri) return;

 

        if (cursor == null) {

            // Problem while running query, so bail without showing

            Log.w(TAG, "Missing cursor for token=" + token);

            this.dismiss();

            return;

        }

                   //绘制QuickContact框的过程基本都在此函数中完成。

        handleData(cursor);

        mHasData = true;

 

        if (!cursor.isClosed()) {

            cursor.close();

        }

 

        considerShowing();

}

再来看handleData()的代码:

 

   

    private void handleData(Cursor cursor) {

        if (cursor == null) return;

…………………………………………………………

        // 使用一个while循环,将从onQueryComplete()方法中得到的cursor遍历。

        while (cursor.moveToNext()) {

            // 将cursor中的数据解出来。

            final long dataId = cursor.getLong(DataQuery._ID);

            final String accountType = cursor.getString(DataQuery.ACCOUNT_TYPE);

            final String resPackage = cursor.getString(DataQuery.RES_PACKAGE);

            final String mimeType = cursor.getString(DataQuery.MIMETYPE);

           

…………………………………………………………

// 中间通过判断mimeType的类型,生成DataAction类的实例,然后使用函数considerAdd()将

// DataAction类型的action以mimeType为键存储在mActions中。

…………………………………………………………

}//end while

        // 将mActions的键取出。

        final Set<String> containedTypes = mActions.keySet();

       

        String[] temp = containedTypes.toArray(new String[containedTypes.size()]);

        int length = temp.length;

       

        // 在此循环中调用inflateAction()函数,将QuickContact框中的图标生成。        

for (String mimeType : ORDERED_MIMETYPES) {

            if (containedTypes.contains(mimeType)) {

                final int index = mTrack.getChildCount() - 1;

                mTrack.addView(inflateAction(mimeType), index); // 将快速联系人的小图标add到mTrack中,在showInternal()函数中会调用startAnimation()将其动画效果显示出来

                containedTypes.remove(mimeType);

            }

        }

…………………………………………………………

 

    }

 

 

   

    private void considerAdd(Action action, String mimeType) {

        if (mResolveCache.hasResolve(action)) {

            mActions.collect(mimeType, action);

        }

}

 

 

 

   

    private View inflateAction(String mimeType) {

……………………………….

        ActionList children = mActions.get(mimeType);

        Action firstInfo = children.get(0);

        if (children.size() == 1) {

            view.setTag(firstInfo);

        } else {

            for (Action action : children) {

                if (action.isPrimary()) {

                    view.setTag(action);

                    isActionSet = true;

                    break;

                }

            }

            if (!isActionSet) {

                view.setTag(children);

            }

        }

 

        // Set icon and listen for clicks

        final CharSequence descrip = mResolveCache.getDescription(firstInfo);

        final Drawable icon = mResolveCache.getIcon(firstInfo);

        view.setChecked(false);

        view.setContentDescription(descrip);

        view.setImageDrawable(icon);

        view.setOnClickListener(this);

        return view;

    }

 

此时,handleData()函数已经完成,接着调用considerShowing(),由considerShowing()调用showInternal()函数来完成绘制工作。

 

 

   

    private void considerShowing() {

        if (mHasData && !mShowing && !mDismissed) {

            if (mMode == QuickContact.MODE_MEDIUM && !mHasValidSocial) {

                // Missing valid social, swap medium for small header

                mHeader.setVisibility(View.GONE);

                mHeader = getHeaderView(QuickContact.MODE_SMALL);

            }

 

            // All queries have returned, pull curtain

            showInternal();

        }

    }

 

 

 

   

    private void showInternal() {

        mDecor = mWindow.getDecorView();

        mDecor.getViewTreeObserver().addOnGlobalLayoutListener(this);

        WindowManager.LayoutParams l = mWindow.getAttributes();

 

        l.width = mScreenWidth + mShadowHoriz + mShadowHoriz;

        l.height = WindowManager.LayoutParams.WRAP_CONTENT;

 

        // Force layout measuring pass so we have baseline numbers

        mDecor.measure(l.width, l.height);

        final int blockHeight = mDecor.getMeasuredHeight();

 

        l.gravity = Gravity.TOP | Gravity.LEFT;

        l.x = -mShadowHoriz;

 

        if (mAnchor.top > blockHeight) {

            // Show downwards callout when enough room, aligning bottom block

            // edge with top of anchor area, and adjusting to inset arrow.

            showArrow(R.id.arrow_down, mAnchor.centerX());

            l.y = mAnchor.top - blockHeight + mShadowVert;

            l.windowAnimations = R.style.QuickContactAboveAnimation;

 

        } else {

            // Otherwise show upwards callout, aligning block top with bottom of

            // anchor area, and adjusting to inset arrow.

            showArrow(R.id.arrow_up, mAnchor.centerX());

            l.y = mAnchor.bottom - mShadowVert;

            l.windowAnimations = R.style.QuickContactBelowAnimation;

 

        }

 

        l.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN

                | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;

 

        mRequestedY = l.y;

        mWindowManager.addView(mDecor, l);

        mShowing = true;

        mQuerying = false;

        mDismissed = false;

 

        mTrack.startAnimation(mTrackAnim);// 调用动画效果

 

        if (TRACE_LAUNCH) {

            android.os.Debug.stopMethodTracing();

            Log.d(TAG, "Window recycled " + mWindowRecycled + " times, chiclets "

                    + mActionRecycled + " times");

        }

    }

 

到此,完了。

若有错,欢迎指正。

这篇关于Contacts模块中的QuickContacts的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/596664

相关文章

Python logging模块使用示例详解

《Pythonlogging模块使用示例详解》Python的logging模块是一个灵活且强大的日志记录工具,广泛应用于应用程序的调试、运行监控和问题排查,下面给大家介绍Pythonlogging模... 目录一、为什么使用 logging 模块?二、核心组件三、日志级别四、基本使用步骤五、快速配置(bas

Python datetime 模块概述及应用场景

《Pythondatetime模块概述及应用场景》Python的datetime模块是标准库中用于处理日期和时间的核心模块,本文给大家介绍Pythondatetime模块概述及应用场景,感兴趣的朋... 目录一、python datetime 模块概述二、datetime 模块核心类解析三、日期时间格式化与

Python如何调用指定路径的模块

《Python如何调用指定路径的模块》要在Python中调用指定路径的模块,可以使用sys.path.append,importlib.util.spec_from_file_location和exe... 目录一、sys.path.append() 方法1. 方法简介2. 使用示例3. 注意事项二、imp

Python中模块graphviz使用入门

《Python中模块graphviz使用入门》graphviz是一个用于创建和操作图形的Python库,本文主要介绍了Python中模块graphviz使用入门,具有一定的参考价值,感兴趣的可以了解一... 目录1.安装2. 基本用法2.1 输出图像格式2.2 图像style设置2.3 属性2.4 子图和聚

Python的time模块一些常用功能(各种与时间相关的函数)

《Python的time模块一些常用功能(各种与时间相关的函数)》Python的time模块提供了各种与时间相关的函数,包括获取当前时间、处理时间间隔、执行时间测量等,:本文主要介绍Python的... 目录1. 获取当前时间2. 时间格式化3. 延时执行4. 时间戳运算5. 计算代码执行时间6. 转换为指

Python正则表达式语法及re模块中的常用函数详解

《Python正则表达式语法及re模块中的常用函数详解》这篇文章主要给大家介绍了关于Python正则表达式语法及re模块中常用函数的相关资料,正则表达式是一种强大的字符串处理工具,可以用于匹配、切分、... 目录概念、作用和步骤语法re模块中的常用函数总结 概念、作用和步骤概念: 本身也是一个字符串,其中

Python中的getopt模块用法小结

《Python中的getopt模块用法小结》getopt.getopt()函数是Python中用于解析命令行参数的标准库函数,该函数可以从命令行中提取选项和参数,并对它们进行处理,本文详细介绍了Pyt... 目录getopt模块介绍getopt.getopt函数的介绍getopt模块的常用用法getopt模

python logging模块详解及其日志定时清理方式

《pythonlogging模块详解及其日志定时清理方式》:本文主要介绍pythonlogging模块详解及其日志定时清理方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录python logging模块及日志定时清理1.创建logger对象2.logging.basicCo

Qt spdlog日志模块的使用详解

《Qtspdlog日志模块的使用详解》在Qt应用程序开发中,良好的日志系统至关重要,本文将介绍如何使用spdlog1.5.0创建满足以下要求的日志系统,感兴趣的朋友一起看看吧... 目录版本摘要例子logmanager.cpp文件main.cpp文件版本spdlog版本:1.5.0采用1.5.0版本主要

Python使用date模块进行日期处理的终极指南

《Python使用date模块进行日期处理的终极指南》在处理与时间相关的数据时,Python的date模块是开发者最趁手的工具之一,本文将用通俗的语言,结合真实案例,带您掌握date模块的六大核心功能... 目录引言一、date模块的核心功能1.1 日期表示1.2 日期计算1.3 日期比较二、六大常用方法详