Android短彩信收件人的实现

来源:互联网 发布:电信云计算公司地址 编辑:程序博客网 时间:2024/06/05 01:36

最近因为项目需要开始研究短彩信的收件人这块,因为这块涉及到的东西比较多,所以还是静下心来一点一点啃,希望早日成佛啊。。。

首先从收件人的布局开始说,信息的编辑界面布局文件compose_message_activity.xml,

<ViewStub android:id="@+id/recipients_editor_stub"            android:layout="@layout/recipients_editor"            android:layout_width="match_parent"            android:layout_height="wrap_content"        />

从上边能看出收件人的具体内容还是在recipient_editor.xml中,接着看这个布局文件,文件内容不多,由一个自定义的view和ImageButton组成:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="horizontal">    <com.android.mms.ui.RecipientsEditor        android:id="@+id/recipients_editor"        android:hint="@string/to_hint"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:inputType="textFilter"        android:layout_weight="1"        android:textColor="@color/compose_message_edit_text"    />    <ImageButton android:id="@+id/recipients_picker"        android:src="@mipmap/ic_launcher_contacts"        android:layout_marginLeft="5dip"        android:layout_width="50dip"        android:layout_height="fill_parent"        android:layout_weight="0"        android:background="@null"    /></LinearLayout>

上面只是简单的布局文件,下面进入主题,讲解下收件人框的自定义布局com.android.mms.ui.RecipientsEditor


RecipientsEditor.java继承了RecipientEditTextView,通过进一步查看代码可知RecipientsEditor其实就是继承了MultiAutoCompleteTextView,在MultiAutoCompleteTextView里其实已经定义好了收件人自动匹配的的基本功能,在RecipientEditor只是重新对它又做了一些封装而已。

下面首先讲下收件人的显示:

Bitmap.createBitmap()创建点击图片
handlePendingChips-->createReplacementChip()-->constructChipSpan()-->createUnselectedChip()-->Bitmap.createBitmap()

expand()和shrink()方法比较经常被调用,当点中RecipientsEditor的时候,其获得焦点,调用expand()方法,将chips展开,而RecipientsEditor失去焦点的时候,调用shrink(),将chips收缩,只显示最开始的两个联系人

点击删除按钮:

RecipientEditTextView.java

onTouchEvent()方法中onClick()-->removeChip()

0 0