实验报告 | ||||||||||||||
通讯录 | ||||||||||||||
| ||||||||||||||
实验项目名称 | 通讯录 | |
一、实验目的与要求: 目的:练习掌握 Android 软件开发基本编程技术、Android 系统 SQLite 数据库的使用、通话、短信的使用等,设计制作一 Android 通讯录软件。 要求: (1)每位同学独立设计软件功能、完成软件的开发与测试。 (2)软件完成后由任课教师检查、提问软件功能、软件的设计和开发的代码。(3)每位同学独立完成实验报告(包括学号、姓名,实验目的、实验内容、软件功能、设计思想、实验总结等),并将实验报告和开发软件的工程文件压缩包提交任课教师。 | ||
二、实验设备及软件: 一台电脑,Androidstudio2.3.3软件 | ||
三、实验方法(原理、流程图) 实现的通讯录功能和界面可在实验开发中由每位同学自己设计,但必须使用 SQLite 数据库保存通讯录信息。 以下功能和软件界面供参考:仿照一般手机通讯录的使用界面和功能,主要功能可包括: (1)可以添加、删减联系人 (2)联系人的信息包括:姓名、手机号码、工作单位、组、、手机铃声 (3)选择联系人后,可以快速进行操作,如:、查看详细、移出组、移动分组、删除联系人等。查看详细时显示手机号码、组、和设定的手机铃声以及同该联系人的通话记录。 (4)在联系人界面,可以查看各组。点击组,跳出对应联系人。 (5)有拨号键盘,点击数字将号码显示出来,并可以对手机号码进行删减 (6)可以发送信息,显示信息记录 (7)发送信息时,可以快速选择现有联系人。 | ||
四、实验过程、步骤及内容 通讯录界面要求布局合理简约,颜舒,控制按钮简单明了,让用户一眼就能看出各个按钮的作用及操方法。能实要求的功能,但又不重复。要考到不同手机屏幕大小可能不一样,应尽兼容大多数手机屏幕尺寸,使之显示无障碍。 实现思路与简单设计 1. 关于通讯录获取联系人信息以及联系人信息的存储结构的分析。 2. 解决添加联系人的表中添加数据以及读取已保存的数据 3. 实现通讯录的基本功能的具体实现。 4. 对通讯录界面的具体设计,给人一种方便的操作通道。 5. 灵活应用各种系统库函数实现完整的通讯录。 开发流程图: 主要功能分析: 1、增加、删除、编联系人 点击通信录界面中的增加按钮,入增加联系人面。输入联系人的基本信息,并可根据用户需求增加个性化信息如头像、姓名、手机号码、办室电话、家庭电话、职务职称、单位名称、地址、、Email、其他、备注这些信息,击确认返回主界面。点击通信录中一个已存在的联系人,进入联系人编辑界面,可修改系人的资料或进行删除联系人操作,完成后退回到主界面。对列表中联系人的标记,点mnu键弹出功能界面上的删除按键也可进行删除。还可以在菜单上选择删除全部联系人清空通讯录。在删除联系人的过程中,系统将提示用户是否继续操作,若放弃操作,则系人信息将继续保存。 2、查联系人 用户点击menu键打开底部菜单框,底部菜单框为查询系人提供入口,进入通讯录的缺省页面为联系人列表,在列表中看到所有联系人的姓名、电话息排列,用户点击查按键输入联系人基本信息,,通讯录显所有符合查询条件的联系人列表,用户选择一个联系人进入联系人基本信息页面进行其他操作;查询完成,用户按返回键返回主界面。 3、通功能 用户在通录选择联系人进入联系详细信息界面,这时点击menu键打开通信功能框,选择打电话、发信息的功能进行操作。 4、菜单能 通过对menu按的点击,显示底部菜框,包含有增加查、除、菜单、返回功能,菜单按键则包含显示所有、删除所有等实用功能。 增加联系人: 这个功能由ContactAdder类完成,具体实现不是比较麻烦,保存动作由ContentResolver类解决,但实现方式有所不同,可分为一次性批量增加与挨个增加。 由于界面设置繁琐,代码页过多,所以挑出其中的一部分进行说明 首先是DB数据库建库过程: package com._dels.db; import t.ContentValues; import android.database.Cursor; import android.database.sqlite.SQLiteOpenHelper; import t.Context; import android.database.sqlite.SQLiteDatabase; import _dels.Contact; import _dels.Sms; import java.util.ArrayList; import java.util.List; public class DBHandlerextends SQLiteOpenHelper {// Database Version private static final intDB_VERSION = 1;// Database Name private static final String DB_NAME = "DB";// Contacts table name private static final String CONTACTS_TABLE = "contacts";//通讯录 private static final String SMS_TABLE = "sms";// Shops Table Columns names private static final String KEY_ID = "id"; private static final String KEY_IMAGE = "image";//图片 private static final String KEY_NAME = "name";//姓名 private static final String KEY_PHONE = "phone";//电话号码 private static final String KEY_EMAIL = "email";//邮箱 private static final String KEY_ADDRESS = "address";//联系人地址 private static final String KEY_SMS_HEADER = "sms_header"; private static final String KEY_SMS_CONTENT = "sms_content"; private static final String KEY_CONTACT_ID = "contact_id"; private static final String KEY_SMS_TYPE = "sms_type"; private static final String CONTACTS_TABLE_CREATE = "CREATE TABLE " + CONTACTS_TABLE + " (" + KEY_ID + " INTEGER PRIMARY KEY, " + KEY_IMAGE + " BLOB, " + KEY_NAME + " TEXT, " + KEY_PHONE + " TEXT, " + KEY_EMAIL + " TEXT, " + KEY_ADDRESS + " TEXT)"; private static final String SMS_TABLE_CREATE = "CREATE TABLE " + SMS_TABLE + " (" + KEY_ID + " INTEGER PRIMARY KEY, " + KEY_SMS_HEADER + " TEXT, " + KEY_SMS_CONTENT + " TEXT, " + KEY_CONTACT_ID + " INTEGER," + KEY_SMS_TYPE + " INTEGER)"; private static DBHandlerdbInstance= null; public static DBHandlergetInstance(Context context) { if (dbInstance== null) { dbInstance= new DBHandler(context, DB_NAME, DB_VERSION); } return dbInstance; } DBHandler(Context context, String dbName, intdbVersion) { super(context, dbName, null, dbVersion); } @Override public void onCreate(SQLiteDatabasedb) { db.execSQL(CONTACTS_TABLE_CREATE); db.execSQL(SMS_TABLE_CREATE); } @Override public void onUpgrade(SQLiteDatabasedb, intoldVersion, intnewVersion) { // Drop older table if existed db.execSQL("DROP TABLE IF EXISTS " + CONTACTS_TABLE); db.execSQL("DROP TABLE IF EXISTS " + SMS_TABLE); // 重新创建表 onCreate(db); } //新增联系人 public void addContact(Contact contact) { SQLiteDatabasedb = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_IMAGE, Image()); values.put(KEY_NAME, Name()); values.put(KEY_PHONE, Phone()); values.put(KEY_EMAIL, Email()); values.put(KEY_ADDRESS, Address()); db.insert(CONTACTS_TABLE, null, values); } // Adding new sms public void addSms(Smssms) { SQLiteDatabasedb = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_SMS_HEADER, Header()); values.put(KEY_SMS_CONTENT, Content()); values.put(KEY_CONTACT_ID, ContactId()); values.put(KEY_SMS_TYPE, Type()); db.insert(SMS_TABLE, null, values); } // Getting one contact public Contact getContact(intid) { SQLiteDatabasedb = this.getReadableDatabase(); Cursor cursor = db.query(CONTACTS_TABLE, new String[] { KEY_ID, KEY_IMAGE, KEY_NAME, KEY_PHONE, KEY_EMAIL, KEY_ADDRESS }, KEY_ID + "=?", new String[] { String.valueOf(id) }, null, null, null, null); if (cursor != null) veToFirst(); Contact contact = new Blob(1), String(2), String(3), String(4), String(5)); contact.Int(0)); cursor.close(); return contact; } // Getting one contact by name public Contact getContactByName(String name) { SQLiteDatabasedb = this.getReadableDatabase(); Cursor cursor = db.query(CONTACTS_TABLE, new String[] { KEY_ID, KEY_IMAGE, KEY_NAME, KEY_PHONE, KEY_EMAIL, KEY_ADDRESS }, KEY_NAME + "=?", new String[] { name }, null, null, null, null); if (cursor != null) veToFirst(); Contact contact = new Blob(1), String(2), String(3), String(4), String(5)); contact.Int(0)); cursor.close(); return contact; } // Getting one contact by phone public Contact getContactByPhone(String phone) { SQLiteDatabasedb = this.getReadableDatabase(); Cursor cursor = db.query(CONTACTS_TABLE, new String[] { KEY_ID, KEY_IMAGE, KEY_NAME, KEY_PHONE, KEY_EMAIL, KEY_ADDRESS }, KEY_PHONE + "=?", new String[] { phone }, null, null, null, null); if (!veToFirst()) return null; Contact contact = new Blob(1), String(2), String(3), String(4), String(5)); contact.Int(0)); cursor.close(); return contact; } // Getting one sms by contact id public List<Sms>getSmsByContactId(Integer id) { SQLiteDatabasedb = this.getReadableDatabase(); Cursor cursor = db.query(SMS_TABLE, new String[] { KEY_ID, KEY_SMS_HEADER, KEY_SMS_CONTENT, KEY_CONTACT_ID, KEY_SMS_TYPE }, KEY_CONTACT_ID + "=?", new String[] { String.valueOf(id) }, null, null, null, null); List<Sms>allSms = new ArrayList<>(); if (veToFirst()) { do { Smssms = new Sms(); sms.setId(Integer.parseInt(String(0))); sms.String(1)); sms.String(2)); sms.Int(3)); sms.Int(4)); allSms.add(sms); } while (veToNext()); } cursor.close(); return allSms; } // Getting all contacts public List<Contact>getAllContacts() { String selectQuery = "SELECT * FROM " + CONTACTS_TABLE; SQLiteDatabasedb = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); List<Contact>allContacts = new ArrayList<>(); if (veToFirst()) { do { Contact contact = new Contact(); contact.setId(Integer.parseInt(String(0))); contact.Blob(1)); contact.String(2)); contact.String(3)); contact.String(4)); contact.String(5)); allContacts.add(contact); } while (veToNext()); } cursor.close(); return allContacts; } // Getting all sms public List<Sms>getAllSms() { String selectQuery = "SELECT * FROM " + SMS_TABLE; SQLiteDatabasedb = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); List<Sms>allSms = new ArrayList<>(); if (veToFirst()) { do { Smssms = new Sms(); sms.setId(Integer.parseInt制作android软件流程(String(0))); sms.String(1)); sms.String(2)); sms.Int(3)); sms.Int(4)); allSms.add(sms); } while (veToNext()); } cursor.close(); return allSms; } // Getting all sms from contact public List<Sms>getAllSmsFromContact(intid) { String selectQuery = "SELECT * FROM " + SMS_TABLE + " WHERE " + KEY_CONTACT_ID + " = " + id; SQLiteDatabasedb = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); List<Sms>allSms = new ArrayList<>(); if (veToFirst()) { do { Smssms = new Sms(); sms.setId(Integer.parseInt(String(0))); sms.String(1)); sms.String(2)); sms.Int(3)); sms.Int(4)); allSms.add(sms); } while (veToNext()); } cursor.close(); return allSms; } // Getting contacts count public Integer getContactsCount() { String countQuery = "SELECT * FROM " + CONTACTS_TABLE; SQLiteDatabasedb = this.getReadableDatabase(); Cursor cursor = db.rawQuery(countQuery, null); return Count(); } // Checking duplicates in table public booleanisDuplicate(DBHandlerdb, String name) { List<Contact> contacts = db.getAllContacts(); for (Contact cont : contacts) { if (Name().equals(name)) return true; } return false; } // Updating a contact public Integer updateContact(Contact contact) { SQLiteDatabasedb = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_IMAGE, Image()); values.put(KEY_NAME, Name()); values.put(KEY_PHONE, Phone()); values.put(KEY_EMAIL, Email()); values.put(KEY_ADDRESS, Address()); return db.update(CONTACTS_TABLE, values, KEY_ID + " = ?", new String[]{String.valueOf(Id())}); } // Updating a sms public Integer updateSms(Smssms) { SQLiteDatabasedb = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_SMS_HEADER, Header()); values.put(KEY_SMS_CONTENT, Content()); values.put(KEY_CONTACT_ID, ContactId()); values.put(KEY_SMS_TYPE, Type()); return db.update(SMS_TABLE, values, KEY_ID + " = ?", new String[]{String.valueOf(Id())}); } // Deleting a contact public void deleteContact(Contact contact) { SQLiteDatabasedb = this.getWritableDatabase(); db.delete(CONTACTS_TABLE, KEY_ID + " = ?", new String[] { String.valueOf(Id()) }); } // Deleting a contact public void deleteSms(Smssms) { SQLiteDatabasedb = this.getWritableDatabase(); db.delete(SMS_TABLE, KEY_ID + " = ?", new String[] { String.valueOf(Id()) }); } // Deleting all contacts public void deleteAllContacts(DBHandlerdb) { List<Contact> contacts = db.getAllContacts(); for (Contact cont : contacts) { db.deleteContact(cont); } } // Deleting all sms public void deleteAllSms(DBHandlerdb) { List<Sms>allSms = db.getAllSms(); for (Smssms : allSms) { db.deleteSms(sms); } } } 界面切换: package _contact_manager.views.activities; import android.app.Activity; import t.Intent; import android.os.Bundle; import android.view.WindowManager; import _contact_manager.R; import java.util.Timer; import java.util.TimerTask; public class SplashActivityextends Activity { private static final long DELAY = 1000; private booleanscheduled = false; private Timer splashTimer; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); splashTimer= new Timer(); splashTimer.schedule(new TimerTask() { @Override public void run() { Intent intent = new Intent(SplashActivity.this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(intent); overridePendingTransition(0, 0); SplashActivity.this.finish(); } }, DELAY); scheduled = true; } @Override protected void onDestroy() { super.onDestroy(); if (scheduled) { splashTimer.cancel(); } splashTimer.purge(); } } 按钮设计: package _contact_manager.views.fragments; import android.Manifest; import android.app.AlertDialog; import t.DialogInterface; import t.Intent; import t.pm.PackageManager; import aphics.Bitmap; import aphics.Color; import aphics.Typeface; import android.Uri; import android.os.Bundle; import android.support.annotation.Nullable; import android.t.ContextCompat; import android.t.res.ResourcesCompat; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.ScrollView; import android.widget.TextView; import android.widget.Toast; import android.support.v4.app.Fragment; import _contact_manager.R; import _dels.Contact; import _dels.Sms; import _dels.db.DBHandler; import _contact_manager.utilities.BitmapUtility; import _contact_manager.views.activities.ContactEditionActivity; import_contact_manager.views.activities.ContactSmsActivity; import_contact_manager.views.activities.MainActivity; importuzdev.circularfloatingactionmenu.library.FloatingActionMenu; importuzdev.circularfloatingactionmenu.library.SubActionButton; import java.util.List; public class ContactInfoFragmentextends Fragment implements View.OnClickListener, View.OnTouchListener { private TextViewname; private TextViewphone; public FloatingActionMenuactionMenu; private DBHandlerdb; @Nullable @Override public View onCreateView(LayoutInflaterinflater, @NullableViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_contact_info, container, false); setHasOptionsMenu(true); ActionBar ab = ((AppCompatActivity) getActivity()).getSupportActionBar(); if (ab != null) { ab.setTitle("Options"); ab.setDisplayHomeAsUpEnabled(true); } db= DBHandler.getInstance(getActivity()); Contact receivedContact = (Contact) getArguments().getSerializable("contact"); if (receivedContact != null) { ImageViewimageView = (ImageView) view.findViewById(R.id.info_image); name = (TextView) view.findViewById(R.id.info_name); phone = (TextView) view.findViewById(R.id.info_phone); TextView email = (TextView) view.findViewById(R.id.info_email); TextView address = (TextView) view.findViewById(R.id.info_address); if (Image() != null) { Bitmap imageBm = BitmapUtility.getImage(Image()); imageView.setImageBitmap(imageBm); } name.Name()); phone.Phone()); if (Email().equals("")) { email.setTypeface(null, Typeface.ITALIC); email.setTextColor(Color.GRAY); email.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18f); email.setText(R.string.placeholder_none); } else email.Email()); if (Address().equals("")) { address.setTypeface(null, Typeface.ITALIC); address.setTextColor(Color.GRAY); address.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18f); address.setText(R.string.placeholder_none); } else address.Address()); } return view; } @Override public void onViewCreated(View view, @NullableBundle savedInstanceState) { initInfoMenu(view); ScrollViewscrollView = (ScrollView) view.findViewById(R.id.scrollview_contact_info); scrollView.setOnTouchListener(this); super.onViewCreated(view, savedInstanceState); } @Override public booleanonTouch(View v, MotionEvent event) { actionMenu.close(true); return false; } @Override public void onClick(View v) { switch (v.getId()) { case R.id.itemId1: toSmsManager(); break; case R.id.itemId2: callContact(); break; case R.id.itemId3: editContact(); break; case R.id.itemId4: deleteContact(); break; } actionMenu.close(true); } @Override public void onCreateOptionsMenu(Menu menu, MenuInflaterinflater) { inflater.u.menu_main, menu); super.onCreateOptionsMenu(menu,inflater); } @Override public booleanonOptionsItemSelected(MenuItem item) { switch (ItemId()) { case android.R.id.home: actionMenu.close(true); getFragmentManager().popBackStack(); return true; default: return super.onOptionsItemSelected(item); } } private void initInfoMenu(View view) { ImageView menuIcon1 = new ImageView(getActivity()); ImageView menuIcon2 = new ImageView(getActivity()); ImageView menuIcon3 = new ImageView(getActivity()); ImageView menuIcon4 = new ImageView(getActivity()); menuIcon1.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_message_black_24dp, null)); menuIcon2.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_call_black_24dp, null)); menuIcon3.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_mode_edit_black_24dp, null)); menuIcon4.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_delete_black_24dp, null)); menuIcon1.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.circle_opacity, null)); menuIcon2.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.circle_opacity, null)); menuIcon3.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.circle_opacity, null)); menuIcon4.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.circle_opacity, null)); menuIcon1.setColorFilter(ContextCompat.getColor(getActivity(), lor.white)); menuIcon2.setColorFilter(ContextCompat.getColor(getActivity(), lor.white)); menuIcon3.setColorFilter(ContextCompat.getColor(getActivity(), lor.white)); menuIcon4.setColorFilter(ContextCompat.getColor(getActivity(), lor.white)); menuIcon1.setPadding(15,15,15,15); menuIcon2.setPadding(15,15,15,15); menuIcon3.setPadding(15,15,15,15); //设置的是各个控件之间的距离 menuIcon4.setPadding(15,15,15,15); SubActionButton.BuilderitemBuilder = new SubActionButton.Builder(getActivity()); itemBuilder.setLayoutParams(new FrameLayout.LayoutParams(160,160)); ImageViewmenuInfo = (ImageView) view.findViewById(R.id.info_menu); actionMenu= new FloatingActionMenu.Builder(getActivity()) .addSubActionView(itemBuilder.setContentView(menuIcon1).build()) .addSubActionView(itemBuilder.setContentView(menuIcon2).build()) .addSubActionView(itemBuilder.setContentView(menuIcon3).build()) .addSubActionView(itemBuilder.setContentView(menuIcon4).build()) .attachTo(menuInfo) .setStartAngle(100) .setEndAngle(260) .build(); menuIcon1.setId(R.id.itemId1); menuIcon1.setOnClickListener(this); menuIcon2.setId(R.id.itemId2); menuIcon2.setOnClickListener(this); menuIcon3.setId(R.id.itemId3); menuIcon3.setOnClickListener(this); menuIcon4.setId(R.id.itemId4); menuIcon4.setOnClickListener(this); } private void toSmsManager() { name = (TextView) getActivity().findViewById(R.id.info_name); phone = (TextView) getActivity().findViewById(R.id.info_phone); Intent intent = new Intent(getActivity(), ContactSmsActivity.class); intent.putExtra("name", name.getText().toString()); intent.putExtra("phone", phone.getText().toString()); startActivity(intent); } private void callContact() { phone = (TextView) getActivity().findViewById(R.id.info_phone); Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:" + phone.getText().toString())); if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) { startActivity(callIntent); } else { Toast toast = Toast.makeText(getActivity(), R.string.alert_no_call_perm, Toast.LENGTH_LONG); toast.show(); } } private void editContact() { name = (TextView) getActivity().findViewById(R.id.info_name); Contact contact = db.getContactByName(name.getText().toString()); Intent intent = new Intent(getActivity(), ContactEditionActivity.class); intent.putExtra("contact", contact); startActivity(intent); } private void deleteContact() { AlertDialog dialog = new AlertDialog.Builder(getActivity()) .setMessage(getResources().getString(R.string.alert_delete_message)) .setCancelable(false) .setPositiveButton(getResources().getString(R.string.alert_delete_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, intid) { TextViewtextView = (TextView) getActivity().findViewById(R.id.info_name); Contact contact = db.Text().toString()); db.deleteContact(contact); List<Sms>allSms = db.Id()); for (Smssms : allSms) { db.deleteSms(sms); } Intent intent = new Intent(getActivity(), MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } }) .setNegativeButton(getResources().getString(R.string.alert_delete_cancel), null) .show(); Button buttonPositive = Button(DialogInterface.BUTTON_POSITIVE); Button buttonNegative = Button(DialogInterface.BUTTON_NEGATIVE); buttonPositive.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary)); buttonNegative.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary)); } } Main程序: package _contact_manager.views.activities; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import _contact_manager.R; import _dels.Contact; import _contact_manager.utilities.Utility; import _contact_manager.views.fragments.ContactInfoFragment; import_contact_manager.views.fragments.ContactListFragment; public class MainActivityextends AppCompatActivityimplements ContactListFragment.DataPassListener { private ContactListFragmentfragmentA; private ContactInfoFragmentfragmentB; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); if (findViewById(R.id.fragment_holder) != null) { Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); if (savedInstanceState != null) { fragmentA= new ContactListFragment(); fragmentB= new ContactInfoFragment(); return; } fragmentA= new ContactListFragment(); fragmentB= new ContactInfoFragment(); getSupportFragmentManager().beginTransaction() .add(R.id.fragment_holder, fragmentA) mit(); Utility.changeStatusBarColor(this); } } @Override public void onBackPressed() { intcount = getSupportFragmentManager().getBackStackEntryCount(); if (count == 0) { super.onBackPressed(); } else { if (fragmentB.actionMenu!= null) { fragmentB.actionMenu.close(true); } getSupportFragmentManager().popBackStack(); } } @Override public void passData(Contact contact) { if (fragmentB!= null) { Bundle args = new Bundle(); args.putSerializable("contact", contact); fragmentB.setArguments(args); getSupportFragmentManager().beginTransaction() .setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right) .replace(R.id.fragment_holder, fragmentB) .addToBackStack(null) mit(); } } } | ||
五、实验数据(现象)处理分析 下面是程序的截图: 软件界面以及各个自文件目录示意图: 通讯录在Android手机功能界面上的显示图标以及图标在工程里存放的位置: 进入通讯录时的初界面以及图标的配置过程: 刚开始运行通讯录时,出现几个权限选择: 开始界面(按加号):创建一个新的联系人:会弹出键盘 创建联系人的过程中如果格式不规范会有错误提示:比如Email格式错误 创建好后的界面(多创建几个联系人),头像可以更改: 修改头像时出现的错误如下(照相机和相册里选择合适的头像): 接下来进行对通讯录的基本功能测试。基本功能有对已保存联系人信息的编辑(更新),删除,发短信和打电。下面是功能显示图: 编辑已存联系人信息(添加Email): 编辑的时候还有对Text部分的选择复制,粘贴功能: 删除联系人操作 短信功能 打电话功能 第而个联系人(llp)已经被删除。 | ||
六、实验结论 通过这次实验,学会了代码建立数据库,在编程时,将所用到的对数据库的操作封装到一个类里,只要调用这个类,就可以完成对数据库的,插入,更新,删除等功能。对控件的使用更加熟练,学会了添加点击事件的等基本用法。 还学会了各个组建的配置的另一种简便的方法,也就是不是以往的使用写代码代码来实现各个按钮等组建的配置,而是使用设计界面的手动添加并进行编辑。从而达到更合理的控制目的。以前的实验是运行出来的图标是系统自设的,这次自己添加图片,让应用标识图和打开页面变得个性化。各个组建的创建,测试,错误处理以及各式各样的条件处理过后对安卓开发有了很强的兴趣。虽然一个连一个出现的系统错误刚开始觉得很烦,甚至不到对应的解决方案,但是现在想都是一种收获,学会了不少系统配置的部分,对开发软件的理解更深了。希望以后的学习当中起到很好的作用。 | ||
七、教师批阅意见: 成绩评定: 教师签字: 年月日 | ||
八、备注: | ||
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论