1、 河南科技学院 《物联网移动应用开发》课程设计汇报 设 计 题 目: 简易记事本 班 级: 物联网131班 学 号: 1554119 姓 名: 指 导 教 师: 徐睿 成 绩: 信 息 工 程 学 院 课程设计汇报说明 一、写汇报前,请认真阅读《课程设计汇报说明》。
2、 二、打印装订要求 1、一律用A4纸,双面打印,并左侧装订。汇报正文部分均采取宋体小四。《课程设计汇报说明》页也打印。 2、课程设计概述部分占一页;课程设计内容长度依据实际需要填写;结论和指导老师评语及成绩单独占一页。确保打印格式工整。 3、指导老师评语及成绩部分由指导老师填写。 三、汇报内容要求 1、课程设计目标结合实际自己写,不要雷同。 2、课程设计原理简明说明所完成课程设计项目所包含理论知识。 3、课程设计内容 这是课程设计汇报极其关键内容。概括整个课程设计过程。(最好在上述内容基础上画出对应流图、设计思绪和设计方法,再配以对应文字进行说明。) 一、
3、课程设计概述 1、课程设计目标 Window操作系统诞生成就了微软帝国,同时也造就了PC时代繁荣,然而现在,以Android和iPhone手机为代表智能移动设备发明和互联网云技术兴起却敲响了PC时代丧钟!这也预示着移动互联网时代(3G)已经来临。 在这个互联网繁荣时代,有一颗超新星,以它独特征能优势和人性化UI设计使它在短短几年快速占领了智能移动设备市场份额,它就是谷歌Android!这也意味着谷歌在移动互联网时代开始抢跑并领跑。 经过调查显示,大部分消费者全部会使用手机记事本功效。伴随手机记事本功效不停加强和完善,手机记事本对于大家意义,已不仅仅像通常记事
4、簿一样简单统计,而是向着更个性化人性化方向发展。Android[1]系统是开源,它以迅猛姿势已经占领了全球二分之一多市场。记事本在生活和工作也日益凸显出它关键性,它能愈加好地帮助大家愈加好地管理自己工作和生活,极大方便了大家生活。因其开源,我们能够在之上开发安卓记事本软件,同时这也符合广大市场需求。 2、课程设计要求 设计最终作品包含设计汇报和能成功运行程序,能够达成设计指标要求。每个小组在设计完成后,要经指导老师检验。课程设计汇报每个学生一份,由学习委员收齐后统一交给指导老师。 根据课程设计进程,认真完成各个步骤,确保质量,达成目标。 3、课程设计原理 (1) 设计实现
5、添加事件、保留事件、删除事件、导出事件、添加图片等主功效。 (2)利用Android中部分组件和事件监听处理功效实现问题。 (3)利用mysql语句来实现数据库设计为用户保留数据。 (4)使用debug调试来处理程序运行时碰到问题 二、课程设计内容 1、软件功效计划 (1)软件功效 能够提醒用户是否有已写记事本,能够进行记事本标题填写和内容填写,确定后保留。 (2) 界面设计 进入程序提醒“您还没有开始写日志呢!点击下边Menu按钮开始写日志吧!”,点击图片按钮后进入标题和内容填写界面。 2、程序设计 (1)记事本组件设计 本项目包含到以下组件:
6、 TextView:“记事本”,“新建记事”,“编辑记事”等标题。 EditView:“记事本标题”,“内容”等。 ImageButton:“写事件”,“保留”,“加图片”按钮。 Menu:“编译内容”,“删除目前记事”,“修改目前记事”,“导出目前记事” “帮助”,“相关”等。 (2)记事本逻辑设计 (i)添加新记事 假如目前没有记事,点击“listview中事件”后只有一个菜单选项“添加新记事”,写完记事以后,点击“确定”进行保留。 (ii)编辑内容 选中要编辑那一个记事,然后点击“listview中事件”菜单,会出现三个选项“新建记事”,“编辑内容”,“删除目前
7、记事”,点击“编辑内容”对被选中记事进行编辑,然后点击“确定”加以保留。 (iii)删除记事 点击上下键,选中要删除记事,然后点击“listview中事件”菜单,然后点击“删除目前记事”,对选中记事加以删除。 (3)记事本存放实现 Android 中一共提供了5种数据存放方法,不过因为存放这些数据全部是其应用程序私有,所以假如需要在其它应用程序中使用这些数据,就要使用Android提供Content Providers。 Content Providers:Android提供一个特殊存放数据类型,它提供了一套标准接口来获取,操作数据。 Shared Preferen
8、ce:用来存放“key-value paires”格式数据,它是一个轻量级键值存放机制,只能够存放基础数据类型。 Files:它经过File Input Stream 和 File Output Stream对文件进行操作,不过在Android中,文件是一个应用程序私有,一个应用程序无法读写其它应用程序文件。 SQL ite:Android提供一个标准数据库,支持SQL语句。 Network:经过网络来存放和取得数据。 (i)数据存放之SQLite 经过sqlite中增删改查方法来保留、删除、修改、查找数据。来实现对数据操作。 代码: public class DBMana
9、ge { 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; } /*
10、 * 打开数据库 */ 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
11、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; try{ String sql = "select * from travels"; cursor = mSQLiteDa
12、tabase.rawQuery(sql, null); }catch(Exception ex){ ex.printStackTrace(); cursor = null; } return cursor; } public Cursor selectById(int id){ Cursor cursor = null; try{ String sql = "select * from travels where _id='" + id +"'"; cursor = mSQLiteDatabase.rawQuery(sql, null); }catch(E
13、xception ex){ ex.printStackTrace(); cursor = null;} return cursor; } public Cursor selcetPathByName(String name){ Cursor cursor=null; try{ String sql = "select path from icons where filename='"+ name +"'"; cursor=mSQLiteDatabase.rawQuery(sql, null); Log.i("log", sql); }catch(Exception ex)
14、{ 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; try{ ContentValues cv = new Co
15、ntentValues(); 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
16、); l = -1; } return l; } public long inserticonpath(String filename,String iconpath){ long l=-1; try{ Log.i("log", "ready to insert icon"); ContentValues cv = new ContentValues(); cv.put("filename",filename); cv.put("path", iconpath); l = mSQLiteDatabase.insert("icons", null, cv);
17、Log.i("log", "insert iconname success"); }catch(Exception ex){ ex.printStackTrace(); l = -1; } return l; } //删除数据 public int delete(long id){ int affect = 0; try{ Log.i("log","try to delete the data in databases"); affect=mSQLiteDatabase.delete("travels","_id=?",new String[]{id+""}); Lo
18、g.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; try{ ContentValues cv = new ContentValues(); cv.put("title", tit
19、le); cv.put("content", content); affect=mSQLiteDatabase.update("travels",cv,"_id=?",new String[]{id+""}); }catch(Exception ex){ ex.printStackTrace(); affect = -1; } return affect; } } (ii)数据存放之Files 我们能够经过自定义copyfile()方法来复制数据 代码: //复制文件 public int copyfile(String from,String into){
20、 try { copyfrom=new FileInputStream(from); copyinto=new FileOutputStream(into); Log.i("log", "fuck you"); byte[] bt = new byte[1024]; int c; while((c=copyfrom.read(bt)) > 0){ copyinto.write(bt,0,c); } cop
21、yfrom.close(); copyinto.close(); Log.i("log", "copy success"); return 1; }catch (FileNotFoundException e) { e.printStackTrace(); return -1; } catch (IOException e) { e.printStackTrace(); return -1; }
22、
}
3、程序开发
(1)主activity设计
当选择“新建记事本”,“编辑内容”,“删除目前记事”等菜单选项时对应操作
代码:
public void initAdapter(){
dm.open();//打开数据库操作对象
cursor = dm.selectAll();//获取全部数据
cursor.moveToFirst();//将游标移动到第一条数据,使用前必需调用
int count = cursor.getCount();//个数
ArrayList
23、rayList
24、dm.close();//关闭数据操作对象 adapter = new ListViewAdd(this,items,times);//创建数据源 } public class myOnCreateContextMenuListener implements OnCreateContextMenuListener{ public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) { menu.setHeaderTitle(""); //设置选项
25、 Log.i("log", "chooseing menu"); menu.add(0,0,0,"删除"); menu.add(0,1,0,"修改"); menu.add(0,2,0,"查看"); menu.add(0,3,0,"导出到SD卡"); } } public boolean onContextItemSelected(MenuItem item){ AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo)ite
26、m.getMenuInfo(); dm.open(); switch(item.getItemId()){ case 0://删除 Log.i("log", "selectItem---->"+item.getItemId()); try{ Log.i("log", "cursor ready move "); Log.i("log", "menuInfo position "+menuInfo.position); cursor.moveToPosition(menuInfo.position); Log.i("
27、log", "cursor move success"); adapter.removeListItem(menuInfo.position);//删除数据 adapter.notifyDataSetChanged();//通知数据源,数据已经改变,刷新界面 dm.close(); }catch(Exception ex){ ex.printStackTrace(); } break; case 1://修改 try{ cursor.moveToPosition(menuInf
28、o.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("t
29、itle"))); intent.putExtra("time", cursor.getString(cursor.getColumnIndex("time"))); intent.putExtra("content", cursor.getString(cursor.getColumnIndex("content"))); //设置并开启另一个指定Activity intent.setClass(MainActivity.this, EditTravels.class); MainActivity.th
30、is.startActivity(intent); finish(); }catch(Exception ex){ ex.printStackTrace(); } break; case 2://查看 try{ cursor.moveToPosition(menuInfo.position); Intent intent = new Intent(); intent.putExtra("id", cursor.
31、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")));
32、 intent.setClass(MainActivity.this, CheckTravels.class); MainActivity.this.startActivity(intent); }catch(Exception ex){ ex.printStackTrace(); } break; case 3://导出 try{ cursor.moveToPosition(menuInfo.position);
33、 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卡\" 记事本 \"里找出来分享吧!!", To
34、ast.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
35、修改内容 代码: public class EditTravels extends Activity{ private 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 idStr
36、ing; 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; @Overrid
37、e protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.edittravels); titleedit=(EditText)findViewById(R.id.titleedit); travelsedit=(EditText)findViewById(R.id.travelsedit); save=(ImageB
38、utton)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.getStr
39、ingExtra("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"); t
40、imeText = 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;
41、i 42、tPathByName(namestr);
cursor.moveToFirst();
path=cursor.getString(cursor.getColumnIndex("path"));
cursor.close();
namestr=null;
Log.i("log", path);
if(!(cursor==null))
{
int count=cursor.getCount();
Log.i("log", "count----->"+count);
BitmapFactory 43、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 <= 0)
be = 1;
options.inSam 44、pleSize = be;
bitmap=BitmapFactory.decodeFile(path,options);
Drawable drawable = new BitmapDrawable(bitmap);
drawable.setBounds(0, 0, 360, 280);
ImageSpan span = new ImageSpan(drawable,ImageSpan.ALIGN_BOTTOM);
travelsSpan.setSpan(span, start-1,end+1, Spannable.SPAN_EXCL 45、USIVE_EXCLUSIVE);
}
else
{
Log.i("log", "insert icon faile");
}
}
}
dm.close();
travelsedit.setText(travelsSpan);
}
}
//保留按钮点击事件
class saveListener implements OnClickListener{
public void onClick(View v) {
// TODO Auto-genera 46、ted method stub
title = titleedit.getText().toString();
travelsdata= travelsedit.getText().toString();
Log.i("log","title---->"+title);
Log.i("log", "travels---->"+travelsdata);
try{
dm.open();
if(state==1)
dm.insert(title, travelsdata);
if (state==2 47、)
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() 48、
}
}
//插入图片点击事件
class insertimageListener implements OnClickListener{
public 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);
49、 startActivityForResult(intent, SELECT_IMAGE);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK)
{
path=getpath(data.getData());
BitmapFa 50、ctory.Options options =new BitmapFactory.Options();
options.inJustDecodeBounds =true;
//获取这个图片宽和高
bitmap =BitmapFactory.decodeFile(path, options); //此时返回bm为空
options.inJustDecodeBounds =false;
//计算缩放比
int be = (in






