【Android课程设计】邵利娟20xx42605

信息科学与工程学院

课程设计报告书

课程名称:   智能终端软件开发   

             通讯录              

专业班级:    信息管理与信息系统一班  

姓    名          邵利娟                                       

    号:         201142605          

指导教师:           孙兴华          

2014   7    5 

基于Android平台的通讯录

1设计题目

题目:基于Android平台的通讯录

本项目是一款基于Android手机平台的通讯录,包含拨号功能,联系人功能、信息功能、备份功能。

2设计思想

拨号功能:将通话记录显示出来,可以选择多种方式显示(例如按照时间排序、拨出电话排序等)

联系人功能:将所有联系人显示出来,可以添加、删除、查看联系人,并且可以将联系人进行分组。

信息功能:查看所有短信呢,可以对短信进行发送、删除等操作

备份功能:可以本地备份

3系统结构

图 3-1系统功能结构图

4通讯录的详细设计与实现

首先是创建一个主界面HomeTabHostActivity,它使用自定义的动画TabHost布局,这里面的TabWidget控件控制着四个个Activity的互相切换:

一个是HomeDialActivity,这个Activity是拨号的界面,如下:

4-1 HomeDialActivity

另一个是HomeContactActivity(图4-2),这个Activity是联系人模块,如下图:

   4-2 HomeContactActivity

第三个是HomeSMSActivity(图4-3),这个Activity是信息模块,如下图:

4-3 HomeSMSActivity

第四个是HomeSettinActivity(图4-4),这个Activity是设置模块,如下图:

4-4 HomeSettinActivity

5、运行结果和分析

5.1拨号键盘显示和分类显示结果:

listView = (ListView) findViewById(R.id.contact_list);// 联系人列表

       in_btn = (Button) findViewById(R.id.in_btn);// 拨出电话

       miss_btn = (Button) findViewById(R.id.miss_btn);// 未接来电

       out_btn = (Button) findViewById(R.id.out_btn);// 已接来电

       bohaopan = (LinearLayout) findViewById(R.id.bohaopan);// 拨号键盘

       keyboard_show_ll = (LinearLayout) findViewById(R.id.keyboard_show_ll);// 出键盘图标,已接,未接图标

       keyboard_show = (Button) findViewById(R.id.keyboard_show);// 键盘控制button

       callLogList = (ListView) findViewById(R.id.call_log_list);// 通话标志列表

application = (MyApplication) getApplication();// 得到数据库信息,并且联系人的信息

       spinner = (Spinner) findViewById(R.id.spin);

       adapter2 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,sort);

       adapter2.setDropDownViewResource(R.layout.spinnertext);

       spinner.setAdapter(adapter2);

       asyncQuery = new MyAsyncQueryHandler(getContentResolver());// 异步的查询操作帮助

       keyboard_show.setOnClickListener(new OnClickListener() {

           publicvoid onClick(View v) {

              dialPadShow();// 显示或者隐藏拨号键盘

              Toast.makeText(HomeDialActivity.this, "拨号键盘", 1).show();

          

5.2联系人添加界面结果:

publicvoid add(){

    ContentValues values = new ContentValues();

    ContentResolver resolver=getContentResolver();

    //得到新纪录的rawContentUri

    Uri rawContentUri = resolver.insert(RawContacts.CONTENT_URI, values);

    //通过解析得到新纪录的Id

    long rawContentId = ContentUris.parseId(rawContentUri);

    Log.i(TAG, rawContentId+"+-+-");

    //插入名字

    values.clear();

    values.put(Data.RAW_CONTACT_ID, rawContentId);

    values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);

    values.put(StructuredName.DISPLAY_NAME, name);

    resolver.insert(ContactsContract.Data.CONTENT_URI, values);

    if(photo != null) {

    values.put(Data.RAW_CONTACT_ID, rawContentId);

    values.put(Data.MIMETYPE, Photo.CONTENT_ITEM_TYPE);

    values.put(Photo.PHOTO, Bitmap2Bytes(photo));

    Log.i("photo",Bitmap2Bytes(photo)+"");

    resolver.insert(ContactsContract.Data.CONTENT_URI, values);

    }

    //插入号码

    if(phoneNumber != null) {

        values.clear();

        values.put(Data.RAW_CONTACT_ID, rawContentId);

        values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);

        values.put(Phone.NUMBER, phoneNumber);

        values.put(Phone.TYPE, Phone.TYPE_MOBILE);

        resolver.insert(ContactsContract.Data.CONTENT_URI, values);

    }

    if(homeNumber != null) {

        values.clear();

        values.put(Data.RAW_CONTACT_ID, rawContentId);

        values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);

        values.put(Phone.NUMBER, homeNumber);

        values.put(Phone.TYPE, Phone.TYPE_HOME);

        resolver.insert(ContactsContract.Data.CONTENT_URI, values);

    }

   插入公司、地址、邮箱、备注的代码如上

  

5.3联系人分组界面结果:

menuBtn.setOnClickListener(new OnClickListener() {

           publicvoid onClick(View v) {

              scrollView.clickMenuBtn(HomeContactActivity.this);

           }

       });

       View leftView = new View(this);

       leftView.setBackgroundColor(Color.TRANSPARENT);

       children = new View[] { leftView, acbuwaPage };

       scrollView.initViews(children, new SizeCallBackForMenu(this.menuBtn),

              this.menuList);

       scrollView.setMenuBtn(this.menuBtn);

5.4联系人备份界面结果:

导入代码:

//得到ContentValues对象

                    ContentValues values = new ContentValues();

                    //得到新纪录的rawContentUri

                    Uri rawContentUri = resolver.insert(RawContacts.CONTENT_URI, values);

                    //通过解析得到新纪录的Id

                    long rawContentId = ContentUris.parseId(rawContentUri);

                    //插入名字

                    values.clear();

                    values.put(Data.RAW_CONTACT_ID, rawContentId);

                    values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);

                    values.put(StructuredName.DISPLAY_NAME, displayName);

                    resolver.insert(ContactsContract.Data.CONTENT_URI, values);

导出代码:

Label labelName = new Label(0, row, name); // 姓名

Label labelPhotoId = new Label(1, row,people.getPhotoId()); // 头像

Label labelMobileNum = new Label(2, row,people.getMobilePhone()); // 住宅号码

Label labelHomeNum = new Label(3, row,people.getHomePhone()); // 手机号码

Label labelCompany = new Label(4, row, people.getCompany()); // 单位

Label labelStreet = new Label(5, row,people.getStreet()); // 住址

Label labelEmail = new Label(6, row,people.getEmailValue()); // 邮箱

Label labelNoteinfo = new Label(7, row,people.getNoteinfo()); // 备注

ws.addCell(labelName);

ws.addCell(labelPhotoId);

ws.addCell(labelMobileNum);

ws.addCell(labelHomeNum);

ws.addCell(labelCompany);

ws.addCell(labelStreet);

ws.addCell(labelEmail);

ws.addCell(labelNoteinfo);

6、自我评价与总结

(1) 通过对Android手机平台的通讯录的开发,使我对通讯录的整体设计有一个深入的了解,对整个流程也会有一个清晰的认识。开发通讯录,要抓住开发的核心部分,通讯录由联系人、拨号、备份、信息四部分组成,只要掌握了这四部分的开发,通讯录就能初具规模。

(2) 通讯录实现了拨打电话、查询通话记录、查看联系人、添加联系人、发送短信、备份等基本功能,运用的系统平台是现今最热门的Android系统,是一个开源的基于Linux系统的手机平台。是以Java语言编写+SQLite数据库支持的组合方式进行数据管理。实现了通讯录的系统编程。

7、附录:程序清单,注意加注释(包括关键字、方法、变量等),在每个模块前加注释;

  主界面代码:

<lab.b509.contacts.ui.AnimationTabHost xmlns:android="http://schemas.android.com/apk/res/android"

    android:id="@android:id/tabhost"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:background="#000000" >

    <LinearLayout

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:orientation="vertical" >

        <FrameLayout

            android:id="@android:id/tabcontent"

            android:layout_width="fill_parent"

            android:layout_height="wrap_content"

            android:layout_weight="1.0"

            android:gravity="center" />

        <RelativeLayout

            android:layout_width="fill_parent"

            android:layout_height="wrap_content" >

            <TabWidget

                android:id="@android:id/tabs"

                android:layout_width="fill_parent"

                android:layout_height="wrap_content"

                android:layout_weight="0.0"

                android:background="@drawable/main_tab_bg" />

            <ImageView

                android:id="@+id/cursor"

                android:layout_width="fill_parent"

                android:layout_height="wrap_content"

                android:scaleType="matrix"

                android:src="@drawable/main_tab_anim_light" />

        </RelativeLayout>

    </LinearLayout>

</lab.b509.contacts.ui.AnimationTabHost>

  联系人代码:

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:background="#000000" >

    <RelativeLayout

        android:id="@+id/carol_topbar"

        style="@style/topbar_bg"

        android:layout_width="fill_parent"

        android:layout_height="46.0dip" >

        <Button

            android:id="@+id/menuBtn"

            style="@style/topbar_left_btn"

            android:background="@drawable/menu_unfold" />

    </RelativeLayout>

    <RelativeLayout

        android:layout_width="fill_parent"

        android:layout_height="fill_parent" >

        <ListView

            android:id="@+id/menuList"

            android:layout_width="fill_parent"

            android:layout_height="fill_parent"

            android:background="@drawable/menu_bg"

            android:cacheColorHint="#000000"

            android:divider="#00000000"

            android:fadingEdge="none"

            android:scrollingCache="false"

            android:visibility="invisible" />

        <Button

            android:id="@+id/add_menu"

            android:layout_width="fill_parent"

            android:layout_height="wrap_content"

            android:layout_alignParentBottom="true"

            android:layout_alignParentLeft="true"

            android:background="@drawable/add_group_bg"

            android:drawableLeft="@drawable/create_new_group"

            android:gravity="center_vertical|left"

            android:text="创建群组"

            android:textAppearance="?android:attr/textAppearanceSmall"

            android:textColor="#ffffff" />

    </RelativeLayout>

    <lab.b509.contacts.ui.MenuHorizontalScrollView

        android:id="@+id/mScrollView"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:background="#00ffffff"

        android:fadingEdge="none"

        android:scrollbars="none" >

        <LinearLayout

            android:id="@+id/top"

            android:layout_width="fill_parent"

            android:layout_height="fill_parent"

            android:background="#00ffffff"

            android:orientation="horizontal" >

        </LinearLayout>

    </lab.b509.contacts.ui.MenuHorizontalScrollView>

</FrameLayout> 

相关推荐