简易的记事本android课程设计.doc_第1页
简易的记事本android课程设计.doc_第2页
简易的记事本android课程设计.doc_第3页
简易的记事本android课程设计.doc_第4页
简易的记事本android课程设计.doc_第5页
免费预览已结束,剩余21页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

河南科技学院物联网移动应用开发课程设计报告设 计 题 目: 简易的记事本 班 级: 物联网131班 学 号: 20131554119 姓 名: 指 导 教 师: 徐睿 成 绩: 信 息 工 程 学 院课程设计报告说明一、写报告前,请认真阅读课程设计报告说明。二、打印装订要求1、一律用A4纸,双面打印,并左侧装订。报告正文部分均采用宋体小四。课程设计报告说明页也打印。2、课程设计概述部分占一页;课程设计内容长度根据实际需要填写;结论和指导教师评语及成绩单独占一页。保证打印格式工整。3、指导教师评语及成绩部分由指导教师填写。三、报告内容要求1、课程设计目的结合实际自己写,不要雷同。2、课程设计原理简要说明所完成课程设计项目所涉及的理论知识。3、课程设计内容 这是课程设计报告极其重要的内容。概括整个课程设计过程。(最好在上述内容基础上画出相应的流图、设计思路和设计方法,再配以相应的文字进行说明。)一、课程设计概述1、课程设计目的Window操作系统的诞生成就了微软帝国,同时也造就了PC时代的繁荣,然而如今,以Android和iPhone手机为代表的智能移动设备的发明与互联网云技术的兴起却敲响了PC时代的丧钟!这也预示着移动互联网时代(3G)已经来临。 在这个互联网繁荣的时代,有一颗超新星,以它独特性能优势与人性化的UI设计使它在短短的几年迅速的占领了智能移动设备的市场份额,它就是Google的Android!这也意味着Google在移动互联网时代开始抢跑并领跑。 通过调查显示,大部分消费者都会使用手机记事本功能。随着手机记事本功能的不断加强与完善,手机记事本对于人们的意义,已不仅仅像一般记事簿一样简单记录,而是向着更个性化人性化的方向发展。Android1系统是开源的,它以迅猛的姿势已经占领了全球一半多的市场。记事本在生活和工作也日益凸显出它的重要性,它能更好地帮助人们更好地管理自己的工作和生活,极大的方便了人们的生活。因其开源,我们可以在之上开发安卓记事本软件,同时这也符合广大的市场需求。2、课程设计要求设计的最终作品包括设计报告和能成功运行的程序,能够达到设计指标的要求。每个小组在设计完成后,要经指导教师检查。课程设计报告每个学生一份,由学习委员收齐后统一交给指导教师。按照课程设计的进程,认真完成各个环节,保证质量,达到目标。3、课程设计原理(1) 设计实现添加事件、保存事件、删除事件、导出事件、添加图片等主功能。(2)利用Android中的一些组件和事件监听解决功能的实现问题。(3)利用mysql语句来实现数据库的设计为用户保存数据。(4)使用debug调试来解决程序运行时遇到的问题二、课程设计内容1、软件功能规划(1)软件功能能够提示用户是否有已写记事本,能够进行记事本的标题填写和内容填写,确定后保存。(2) 界面设计进入程序提示“您还没有开始写日记呢!点击下边的Menu按钮开始写日记吧!”,点击图片按钮后进入标题和内容的填写界面。2、程序设计 (1)记事本组件的设计 本项目涉及到以下组件:TextView:“记事本”,“新建记事”,“编辑记事”等标题。EditView:“记事本的标题”,“内容”等。ImageButton:“写事件”,“保存”,“加图片”按钮。Menu:“编译内容”,“删除当前记事”,“修改当前记事”,“导出当前记事”“帮助”,“关于”等。(2)记事本逻辑设计(i)添加新记事如果当前没有记事,点击“listview中的事件”后只有一个菜单选项“添加新记事”,写完记事之后,点击“确定”进行保存。(ii)编辑内容选中要编辑的那一个记事,然后点击“listview中的事件”菜单,会出现三个选项“新建记事”,“编辑内容”,“删除当前记事”,点击“编辑内容”对被选中的记事进行编辑,然后点击“确定”加以保存。(iii)删除记事点击上下键,选中要删除的记事,然后点击“listview中的事件”菜单,然后点击“删除当前记事”,对选中的记事加以删除。(3)记事本存储实现 Android 中一共提供了5种数据存储方式,但是由于存储的这些数据都是其应用程序私有的,所以如果需要在其他应用程序中使用这些数据,就要使用Android提供的Content Providers。 Content Providers:Android提供的一个特殊的存储数据的类型,它提供了一套标准的接口来获取,操作数据。 Shared Preference:用来存储“key-value paires”格式的数据,它是一个轻量级的键值存储机制,只可以存储基本数据类型。Files:它通过File Input Stream 和 File Output Stream对文件进行操作,但是在Android中,文件是一个应用程序私有的,一个应用程序无法读写其他应用程序的文件。SQL ite:Android提供的一个标准的数据库,支持SQL语句。Network:通过网络来存储和获得数据。(i)数据存储之SQLite通过sqlite中的增删改查方法来保存、删除、修改、查找数据。来实现对数据的操作。代码:public class DBManage private Context mContext = null;private SQLiteDatabase mSQLiteDatabase = null;/用于操作数据库的对象private DBHelper dh = null;/用于创建数据库的对象Cursor namecursor=null;private String dbName = notepad.db;private int dbVersion = 1;public DBManage(Context context)mContext = context;/* * 打开数据库 */public void open()try dh = new DBHelper(mContext, dbName, null, dbVersion); if(dh = null) return ;mSQLiteDatabase = dh.getWritableDatabase();/dh.onOpen(mSQLiteDatabase);Log.i(log, DB is opened);catch(SQLiteException se)se.printStackTrace();Log.i(log, open DB faile);/* 关闭数据库 */public void close()mSQLiteDatabase.close();dh.close();Log.i(log, DB is closed);/获取列表public Cursor selectAll()Cursor cursor = null;tryString sql = select * from travels;cursor = mSQLiteDatabase.rawQuery(sql, null);catch(Exception ex)ex.printStackTrace();cursor = null;return cursor;public Cursor selectById(int id)Cursor cursor = null;tryString sql = select * from travels where _id= + id +;cursor = mSQLiteDatabase.rawQuery(sql, null);catch(Exception ex)ex.printStackTrace();cursor = null;return cursor;public Cursor selcetPathByName(String name)Cursor cursor=null;tryString sql = select path from icons where filename=+ name +;cursor=mSQLiteDatabase.rawQuery(sql, null);Log.i(log, sql);catch(Exception ex)ex.printStackTrace();Log.i(log, select faile);return cursor;/插入数据public long insert(String title, String content)Log.i(log, readyto insert);long datetime = System.currentTimeMillis();Log.i(log, time-+datetime);long l = -1;tryContentValues cv = new ContentValues();cv.put(title, title);cv.put(content, content);cv.put(time, datetime);Log.i(log, data-+title+content+datetime);l = mSQLiteDatabase.insert(travels, null, cv);Log.i(log, cv.toString();Log.i(log, datetime+l);catch(Exception ex)ex.printStackTrace();l = -1;return l;public long inserticonpath(String filename,String iconpath)long l=-1;tryLog.i(log, ready to insert icon);ContentValues cv = new ContentValues();cv.put(filename,filename);cv.put(path, iconpath);l = mSQLiteDatabase.insert(icons, null, cv);Log.i(log, insert iconname success);catch(Exception ex)ex.printStackTrace();l = -1;return l;/删除数据public int delete(long id)int affect = 0;tryLog.i(log,try to delete the data in databases);affect=mSQLiteDatabase.delete(travels,_id=?,new Stringid+);Log.i(log, delete success);catch(Exception ex)ex.printStackTrace();affect = -1;Log.i(log, delete faile);return affect;/修改数据public int update(int id, String title, String content)int affect = 0;tryContentValues cv = new ContentValues();cv.put(title, title);cv.put(content, content);affect=mSQLiteDatabase.update(travels,cv,_id=?,new Stringid+);catch(Exception ex)ex.printStackTrace();affect = -1;return affect;(ii)数据存储之Files我们可以通过自定义的copyfile()方法来复制数据代码:/复制文件public int copyfile(String from,String into)try copyfrom=new FileInputStream(from); copyinto=new FileOutputStream(into); Log.i(log, fuck you); byte bt = new byte1024; int c; while(c=copyfrom.read(bt) 0) copyinto.write(bt,0,c); copyfrom.close(); copyinto.close(); Log.i(log, copy success); return 1; catch (FileNotFoundException e) e.printStackTrace(); return -1; catch (IOException e) e.printStackTrace(); return -1; 3、程序开发(1)主activity的设计当选择“新建记事本”,“编辑内容”,“删除当前记事”等菜单选项时对应的操作代码:public void initAdapter() dm.open();/打开数据库操作对象 cursor = dm.selectAll();/获取所有数据 cursor.moveToFirst();/将游标移动到第一条数据,使用前必须调用 int count = cursor.getCount();/个数 ArrayList items = new ArrayList(); ArrayList times = new ArrayList(); for(int i= 0; i +item.getItemId();tryLog.i(log, cursor ready move );Log.i(log, menuInfo position +menuInfo.position);cursor.moveToPosition(menuInfo.position);Log.i(log, cursor move success);adapter.removeListItem(menuInfo.position);/删除数据adapter.notifyDataSetChanged();/通知数据源,数据已经改变,刷新界面dm.close();catch(Exception ex)ex.printStackTrace();break; case 1:/修改 try cursor.moveToPosition(menuInfo.position); /用于Activity之间的通讯 Intent intent = new Intent(); /通讯时的数据传送 intent.putExtra(id, cursor.getString(cursor.getColumnIndex(_id); intent.putExtra(state, ALERT_STATE); intent.putExtra(title, cursor.getString(cursor.getColumnIndex(title); intent.putExtra(time, cursor.getString(cursor.getColumnIndex(time); intent.putExtra(content, cursor.getString(cursor.getColumnIndex(content); /设置并启动另一个指定的Activity intent.setClass(MainActivity.this, EditTravels.class); MainActivity.this.startActivity(intent); finish(); catch(Exception ex) ex.printStackTrace(); break; case 2:/查看 try cursor.moveToPosition(menuInfo.position); Intent intent = new Intent(); intent.putExtra(id, cursor.getString(cursor.getColumnIndex(_id); intent.putExtra(title, cursor.getString(cursor.getColumnIndex(title); intent.putExtra(time, cursor.getString(cursor.getColumnIndex(time); intent.putExtra(content, cursor.getString(cursor.getColumnIndex(content); intent.setClass(MainActivity.this, CheckTravels.class); MainActivity.this.startActivity(intent); catch(Exception ex) ex.printStackTrace(); break; case 3:/导出 try cursor.moveToPosition(menuInfo.position); String title=cursor.getString(cursor.getColumnIndex(title); String content=cursor.getString(cursor.getColumnIndex(content); HM.htmlmanager(title, content); copyicon(title,content); Toast.makeText(MainActivity.this, 导出成功,快去SD卡的 记事本 里找出来分享吧!, Toast.LENGTH_LONG).show(); catch(Exception ex) Toast.makeText(MainActivity.this, Sorry!导出失败!, Toast.LENGTH_LONG).show(); ex.printStackTrace(); break; default:; dm.close();return super.onContextItemSelected(item); (2)修改内容代码:public class EditTravels extends Activityprivate static final int SELECT_IMAGE =123;int rotate = 0; private EditText titleedit;private EditText travelsedit;private ImageButton save;private ImageButton insertimage;private ImageButton takephoto;private String idString;private int id2;private String title=;private String travelsdata = ;private String timeText = ;public Cursor cursor=null;public String namestr=;private DBManage dm=null;private Bitmap bitmap = null;private String path = null;private int state =-1;Overrideprotected void onCreate(Bundle savedInstanceState) / TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.edittravels);titleedit=(EditText)findViewById(R.id.titleedit);travelsedit=(EditText)findViewById(R.sedit);save=(ImageButton)findViewById(R.id.save);save.setOnClickListener(new saveListener();insertimage=(ImageButton)findViewById(R.id.insertimage);insertimage.setOnClickListener(new insertimageListener();dm=new DBManage(this);Intent intent = getIntent();state = Integer.parseInt(intent.getStringExtra(state);Log.i(log, state-+state);if (state=2)idString =intent.getStringExtra(id);Log.i(log, id-+idString);id2 = Integer.parseInt(idString);title = intent.getStringExtra(title);travelsdata = intent.getStringExtra(content);timeText = intent.getStringExtra(time);titleedit.setText(title);dm.open();int i=0;int start=0;int end=0;String str1=null;String str2=;String str4=;String iconname=null;SpannableString travelsSpan =new SpannableString(travelsdata);for(i=0;i+count);BitmapFactory.Options options =new BitmapFactory.Options();options.inJustDecodeBounds =true;bitmap =BitmapFactory.decodeFile(path, options); /此时返回bm为空options.inJustDecodeBounds =false;int be = (int)(options.outHeight/ (float)100);if (be +title);Log.i(log, travels-+travelsdata);trydm.open();if(state=1)dm.insert(title, travelsdata);if (state=2)Log.i(log, ready to alter);dm.update(id2, title, travelsdata);dm.close();catch(Exception ex)ex.printStackTrace();Intent gobackIntent=new Intent(EditTravels.this,MainActivity.class);EditTravels.this.startActivity(gobackIntent);finish();/插入图片点击事件class insertimageListener implements OnClickListenerpublic void onClick(View v) Intent intent=new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType(image/*); intent.putExtra(return-data, true); startActivityForResult(intent, SELECT_IMAGE);Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) super.onActivityResult(requestCode, resultCode, data);if (resultCode = RESULT_OK)path=getpath(data.getData();BitmapFactory.Options options =new BitmapFactory.Options(); options.inJustDecodeBounds =true; /获取这个图片的宽和高 bitmap =BitmapFactory.decodeFile(path, options); /此时返回bm为空 options.inJustDecodeBounds =false; /计算缩放比 int be = (int)(options.outHeight/ (float)100); if (be +be); /重新读入图片 bitmap=BitmapFactory.decodeFile(path,options); int bitmapwidth=options.outWidth; int bitmapheight=options.outHeight; /检查图片是否要翻转 try ExifInterface exifInterface = new ExifInterface(path); int result = exifInterface.getAttributeInt( ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); switch(result) case ExifInterface.ORIENTATION_ROTATE_90: rotate = 90; Log.i(log, rotate-+rotate); break; case ExifInterface.ORIENTATION_ROTATE_180: rotate = 180; Log.i(log, rotate-+rotate); break; case ExifInterface.ORIENTATION_ROTATE_270: rotate = 270; Log.i(log, rotate-+rotate); break; default: break; catch (IOException e) e.printStackTrace(); if (rotate!=0&bitmap!=null) Matrix matrix=new Matrix(); matrix.reset(); matrix.setRotate(rotate); Bitmap bitmap1=Bitmap.createBitmap(bitmap,0,0, options.outWidth, options.outHeight, matrix, true); bitmap = bitmap1; rotate=0; bitmapwidth=options.outHeight; bitmapheight=options.outWidth; Drawable drawable = new BitmapDrawable(bitmap);drawable.setBounds(0, 0,bitmapwidth*2,bitmapheight*2);String iconname = path.substring(path.lastIndexOf(/)+1);String iconimfo=+iconname+;SpannableString spannable = new SpannableString(iconimfo);ImageSpan span = new ImageSpan(drawable,ImageSpan.ALIGN_BOTTOM);spannable.setSpan(span, 0,iconimfo.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);int select=travelsedit.getSelectionStart();Editable edit = travelsedit.getEditableText();edit.insert(select, spannable);trydm.open();dm.inserticonpath(iconname, path);dm.close();catch(Exception ex)ex.printStackTrace();String getpath(Uri uri) String projection = MediaColumns.DATA;Cursor cursor = managedQuery(uri, projection, null, null, null);startManagingCursor(cursor);int column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA);/ 记录图片的位置Log.i(log,column_index-+column_index);cursor.moveToFirst();return cursor.getString(column_index);int poi = 0;Overrideprotected void onDestroy() / TODO Auto-generated method stubsuper.onDestroy();public boolean onKeyDown(int KeyCode,KeyEvent event)if (KeyCode=KeyEvent.KEYCODE_BACK)Intent goBackToMainIntent=new I

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论