版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
-.z****大學智能終端開發(fā)課程設計說明書課題名稱:姓名:學號:專業(yè):班級:指導教師:2014年12月25日目錄第一章概述----------------------------------------------------------------------------第二章需求分析------------------------------------------------------------------------------2.1系統(tǒng)主要內容--------------------------------------------------------------------------2.2根本要求--------------------------------------------------------------2.3設計需要結合使用的技術---------------------------------------------2.4模塊的功能性概述---------------------------------------------第三章概要設計---------------------------------------------------------------------3.1系統(tǒng)的功能構造------------------------------------------------------------------3.2系統(tǒng)的模塊構造------------------------------------------------------------------------3.3各模塊的活動圖------------------------------------------------------------------------第四章詳細設計----------------------------------------------------------------------4.1布局文件------------------------------------------------------4.2備忘錄數(shù)據(jù)存儲的實現(xiàn)--------------------------------------------------------------------4.3備忘錄的列表展示--------------------------------------------------------------------------4.4備忘錄的維護-------------------------------------------------------------4.5備忘錄的定時提醒-------------------------------------------------------------調試分析------------------------------------------------------------------------------第六章設計總結--------------------------------------------------------------------------------第七章參考文獻----------------------------------------------------------------------------第八章附錄----------------------------------------------------------------------------第一章概述對于很多人來說,隨時帶個小本子記錄一些事情是很有必要的事情,從而出現(xiàn)了備忘錄。有了備忘錄,可以將自己的工作和生活安排的更有條理,在有限的時間內完成最重要、最緊急的事情。隨著智能手機逐漸走進普通人的生活,它正在成為人們獲取信息的主要設備,而且智能手機是他們獲取信息最方便、最快捷的途徑。因此,對于所有擁有的手機的用戶來說,可以隨時隨地便捷的通過手機備忘錄來實現(xiàn)重要事情的記錄與提醒,省去了隨身攜帶紙筆的麻煩。現(xiàn)如今搭載Android系統(tǒng)平臺的手機已占有超過70%的市場份額,所以,在Android系統(tǒng)下的備忘錄軟件中,用戶可以非常方便的查詢事件備忘,為工作、出游、生活雜碎事提供整理記錄功能。開發(fā)一款能在Android系統(tǒng)上使用,且性能卓越的備忘錄是非常有必要且前途光明。第二章需求分析2.1、系統(tǒng)主要內容:〔1〕、基于Android系統(tǒng)平臺研發(fā)出備忘錄;〔2〕、通過安裝備忘錄,防止手機用戶遺忘*個時間的重要工作,進展記錄并在特定時間通過聲音,文字或振動提醒用戶;〔3〕、主要模塊有:備忘錄數(shù)據(jù)存儲、列表瀏覽、數(shù)據(jù)維護和定時提醒等模塊。2.2、根本要求:〔1〕、基于Android系統(tǒng)平臺研發(fā)出備忘錄,以防止手機用戶遺忘*個時間的重要工作,進展記錄并在特定時間通過聲音,文字或振動提醒用戶?!?〕、主要設計出備忘錄數(shù)據(jù)存儲、列表瀏覽、數(shù)據(jù)維護和定時提醒等模塊。已學習掌握Android系統(tǒng)平臺和Java編程技術,并要求軟件界面簡潔專業(yè),功能完善,真正為用戶提供重要工作備忘功能。2.3、設計需要結合使用的技術:〔1〕、Eclipse平臺:Eclipse是一個運行插件的平臺??梢韵螺d安裝EclipseClassic的最新版本?!?〕、AndroidDeveloperTools:按照安裝說明安裝AndroidDeveloperTools〔Eclipse插件〕。2.4、模塊的功能性概述:〔1〕、備忘錄數(shù)據(jù)存儲實現(xiàn):備忘錄的最重要功能就是記錄和保存用戶容易遺忘的日期和事件,為了持久地將用戶的備忘錄信息保存下來,需要將這些信息存儲在數(shù)據(jù)庫中。備忘錄需要保存的信息有:編號〔ID〕、提醒日期(Date1)、提醒時間(Time1)、提醒內容(Content)、是否啟用(ON_OFF)、是否聲音提醒(ALARM)、創(chuàng)立時間(CREATED)等.〔2〕、備忘錄列表展示:用戶可能需要創(chuàng)立很多條備忘錄信息,并且需要維護這些備忘錄信息,例如刪除、修改等功能。備忘錄的列表展示能使用戶界面更加簡潔清晰,并帶給用戶使用方便〔3〕、備忘錄維護:備忘錄維護是該應用程序的核心局部,提供了添加、修改、刪除備忘錄信息的功能,提供備忘錄動態(tài)更新的功能。〔4〕、備忘錄定時提醒:備忘錄的第一需求是能夠有效提醒用戶置辦已記錄的事件,從而到達真正防止遺忘的效果,為了更好的提醒用戶在特定時間做*項工作,要設置語音和震動等功能。第三章概要設計3.1、系統(tǒng)的功能構造:開場開場設置是否開啟設置日期時間備忘錄內容完畢開啟鬧鐘3.2、系統(tǒng)的模塊構造:3.3、各模塊的活動圖:3.3.1、添加備忘錄添加日期、時間、鬧鈴:添加內容:3.3.2、查看備忘錄3.3.3修改備忘錄修改日期、時間、鬧鈴:修改內容:3.3.4刪除備忘錄第四章詳細設計4.1、布局文件main.*mlfill_parent:使視圖元素占滿可用的空間。也可以認為這就是“拉伸〞。4.2、備忘錄數(shù)據(jù)存儲的實現(xiàn)為了使備忘錄數(shù)據(jù)表具有通用的數(shù)據(jù)共享機制,需要通過ContentProvider來實現(xiàn)。這里定義一個TaskListProvider類,該類繼承ContentProvider,實現(xiàn)了onCreat、query、getType、insert、delete、update等方法,來支持數(shù)據(jù)的增、刪、查、改等操作。在該類內部還定義了一個DatabaseHelper內部類繼承SQLiteHelper,該類提供了常見或翻開數(shù)據(jù)庫、創(chuàng)立或刪除表的功能。4.3、備忘錄的列表展示:這里通過一個ListActivity來展示備忘錄列表,通過選項菜單提供維護數(shù)據(jù)接口。4.4、備忘錄的維護:當用戶單擊主界面的一個列表時會在上述列表展示中提到的setOnItemClickListener方法中響應,此方法體中定義一個Intent對象,使用setClass方法實現(xiàn)界面跳轉到此TaskDetailActivity所對應的界面4.5、備忘錄的定時提醒:此功能通過定義Activity發(fā)出播送,BroadcastReceiver接收播送,并通過Notification提醒用戶。4.5.1定義提醒播送接收器當用戶選擇了備忘錄信息中的“開啟鬧鐘〞選項時,便通過播送的方式啟動一個定時鬧鐘,之后定義一個播送接收器接收播送。4.5.2播送接收器實現(xiàn)如下顯示提醒Activity:第五章調試分析程序運行:列表展示:備忘錄維護:備忘錄定時提醒:總體來說,調試過程中根本沒有出現(xiàn)系統(tǒng)性錯誤,軟件強健性良好,測試數(shù)據(jù)隨機采用,根本實現(xiàn)軟件要實現(xiàn)的需求。第六章設計總結經過一個多月的學習和研究,本次課程設計終于圓滿完成,雖然消耗了許多精力和時間,設計過程中也出現(xiàn)了許多問題,但通過網上資料的查詢、圖書館圖書的借閱以及同學們的幫助,最終也逐一得到了解決。通過本次課程設計,我了解到實踐經歷對于學生的重要性。備忘錄軟件的開發(fā)使我對書本上的知識點和理論有了更深一層的了解,使我學會了如何利用所學的知識,把理論結合于實踐中,進一步掌握了開發(fā)基于Android平臺的軟件的流程。本次課程設計主要研究了Android平臺的架構以及在Android平臺上開發(fā)備忘錄軟件,此應用除了具備簡單備忘功能外,還具備簡單數(shù)據(jù)處理功能以及鬧鐘提醒相對高級點的功能。本次課程設計在Android平臺以及在該平臺上開發(fā)手機備忘錄軟件上做了大量的工作,但仍有許多地方值得進一步探討研究,如:界面設計如何更加美觀簡潔,軟件的移植性、兼容性如何等。Android開發(fā)是一個開放的平臺,需要不斷進展內容添加和補充,這也就要求我們學生不斷學習新知識,從而使軟件功能不斷擴展。同時,本次課程設計讓我對?智能終端開發(fā)?這門課程有了更深層次的了解,也讓我發(fā)現(xiàn)了自我存在的缺乏,今后,在Android開發(fā)的學習之路上,我必須更加重視實踐與理論的結合,在系統(tǒng)的擴展性方面花費更多的精力去學習。第七章參考文獻【1】?零點起飛學Android開發(fā)?*誠著,清華大學[2]?Android根底教程?〔美〕伯內特著,*波等譯/2009年11月/人民郵電[3]?Android應用程序開發(fā)?,王向輝,*國印,沈潔編著/2010年3月/清華大學[4]?Java寶典?,*瀏毅等編著/2009年8月/電子工業(yè)大學[5]?*ML程序設計使用教程?,*亞飛,湯桂風編著/2010年8月/師*大學[6]?Java編程思想?(美)BruceEckel著,陳昊鵬譯/2011年4月/機械工業(yè)[7]?Android程序設計根底?郝玉龍/2011年1月/清華大學第八章附錄AlarmActivity.java文件package.amaker.ch17.app;importandroid.app.*;importandroid.content.Conte*t;.Uri;importandroid.os.Bundle;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.Button;importandroid.widget.Te*tView;publicclassAlarmActivitye*tendsActivity{ publicstaticfinalintID=1; protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.alarm); //獲得Button、Te*tView實例 Buttonbtn=(Button)findViewById(R.id.cancelButton01); Te*tViewtv=(Te*tView)findViewById(R.id.msgTe*tView01); //獲得NotificationManager實例 Stringservice=Conte*t.NOTIFICATION_SERVICE; finalNotificationManagernm=(NotificationManager)getSystemService(service); //實例化NotificationNotificationn=newNotification(); //設置顯示提示信息,該信息也會在狀態(tài)欄顯示Stringmsg=getIntent().getStringE*tra("msg"); n.tickerTe*t=msg;//顯示時間 tv.setTe*t(msg); //設置聲音提示n.sound=Uri.parse("file:///sdcard/fallbackring.ogg"); nm.notify(ID,n);//發(fā)出通知 //取消通知 btn.setOnClickListener(newOnClickListener(){ publicvoidonClick(Viewv){ nm.cancel(ID); finish(); } }); }}TaskDetailActivity.java文件-.zpackage.amaker.ch17.app;importjava.util.Calendar;importandroid.app.*;importandroid.content.*;.Uri;importandroid.os.Bundle;importandroid.view.LayoutInflater;importandroid.view.View;importandroid.view.ViewGroup;importandroid.widget.*;import.amaker.ch17.app.TaskList.Tasks;publicclassTaskDetailActivitye*tendsListActivity{ //備忘錄信息列表privateListViewlistView=null; privateintmYear;//提醒日期 privateintmMonth; privateintmDay; privateintmHour;//提醒時間 privateintmMinute; //日期顯示Te*tViewprivateTe*tViewdateName,dateDesc; //時間顯示Te*tViewprivateTe*tViewtimeName,timeDesc; //提醒內容Te*tViewprivateTe*tViewcontentName,contentDesc; privateinton_off=0;//是否開啟提醒 privateintalarm=0;//是否聲音警告 //顯示日期、時間對話框常量staticfinalintDATE_DIALOG_ID=0; staticfinalintTIME_DIALOG_ID=1; //保存內容、日期、時間字符串privateStringcontent,date1,time1; privateintid1;//備忘錄ID privateCheckedTe*tViewctv1,ctv2;//多項選擇框 privateLayoutInflaterli;//布局實例 //初始化方法privatevoidinit(Intentintent){Bundleb=intent.getBundleE*tra("b"); if(b!=null){id1=b.getInt("id");content=b.getString("content"); date1=b.getString("date1"); time1=b.getString("time1"); on_off=b.getInt("on_off"); alarm=b.getInt("alarm");if(date1!=null&&date1.length()>0){String[]strs=date1.split("/");mYear=Integer.parseInt(strs[0]);mMonth=Integer.parseInt(strs[1]);mDay=Integer.parseInt(strs[2]);}if(time1!=null&&time1.length()>0){String[]strs=time1.split(":");mHour=Integer.parseInt(strs[0]);mMinute=Integer.parseInt(strs[1]);}}}publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); //獲得ListView listView=getListView(); //實例化LayoutInflater li=getLayoutInflater(); //設置ListViewAdapterlistView.setAdapter(newViewAdapter()); //可多項選擇listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); //獲得Calendar實例finalCalendarc=Calendar.getInstance(); //獲得當前日期、時間 mYear=c.get(Calendar.YEAR); mMonth=c.get(Calendar.MONTH);mDay=c.get(Calendar.DAY_OF_MONTH);mHour=c.get(Calendar.HOUR_OF_DAY); mMinute=c.get(Calendar.MINUTE); //響應列表單擊事件listView.setOnItemClickListener(newOnItemClickListener(){publicvoidonItemClick(AdapterView<?>av,Viewv,intposition,longid){switch(position){ //設置是否開啟提醒case0:ctv1=(CheckedTe*tView)v;if(ctv1.isChecked()){on_off=0;}else{on_off=1;}break; //設置提醒日期case1:showDialog(DATE_DIALOG_ID);break; //設置提醒時間case2:showDialog(TIME_DIALOG_ID);break; //設置提醒內容case3: showDialog1("請輸入內容:");break; //設置是否開啟語音提醒case4:ctv2=(CheckedTe*tView)v;if(ctv2.isChecked()){alarm=0; setAlarm(false);}else{alarm=1;setAlarm(true);}break;default:break;}} }); } protectedvoidonResume(){ super.onResume(); //初始化列表 init(getIntent()); } //ListViewAdatper,該類實現(xiàn)了列表的每一項通過自定義視圖實現(xiàn)classViewAdaptere*tendsBaseAdapter{ //列表顯示內容 String[]strs={"是否開啟","日期","時間","內容","開啟鬧鐘"}; //獲得列表列數(shù) publicintgetCount(){ returnstrs.length; } //返回列表項 publicObjectgetItem(intposition){returnposition;} //返回列表ID publiclonggetItemId(intposition){ returnposition; } //獲得當前列表項視圖{Viewv=li.inflate(R.layout.item_row,null);switch(position){ //是否開啟該條備忘錄case0:ctv1=(CheckedTe*tView)li.inflate(android.R.layout.simple_list_item_multiple_choice,null); ctv1.setTe*t(strs[position]);if(on_off==0){ctv1.setChecked(false);}else{ctv1.setChecked(true);}returnctv1; //提醒日期case1:dateName=(Te*tView)v.findViewById(R.);dateDesc=(Te*tView)v.findViewById(R.id.desc); dateName.setTe*t(strs[position]);dateDesc.setTe*t(mYear+"/"+mMonth+"/"+mDay);returnv;//提醒時間case2:timeName=(Te*tView)v.findViewById(R.);timeDesc=(Te*tView)v.findViewById(R.id.desc);timeName.setTe*t(strs[position]);timeDesc.setTe*t(mHour+":"+mMinute); returnv; //提醒內容 case3:contentName=(Te*tView)v.findViewById(R.);contentDesc=(Te*tView)v.findViewById(R.id.desc);contentName.setTe*t(strs[position])contentDesc.setTe*t(content);returnv; //是否聲音提示case4:ctv2=(CheckedTe*tView)li.inflate(ctv2.setTe*t(strs[position]);if(alarm==0){ ctv2.setChecked(false);}else{ctv2.setChecked(true);}returnctv2;default:break;}returnnull; } //顯示對話框protectedDialogonCreateDialog(intid){ switch(id){ //顯示日期對話框 caseDATE_DIALOG_ID:returnnewDatePickerDialog(this,mDateSetListener,mYear,mMonth,mDay); //顯示時間對話框 caseTIME_DIALOG_ID:returnnewTimePickerDialog(this,mTimeSetListener,mHour,mMinute,false);}returnnull;} finalStringBC_ACTION=".amaker.ch17.TaskReceiver"; //設置通知提示privatevoidsetAlarm(booleanflag){//獲得AlarmManager實例finalAlarmManageram=(AlarmManager)getSystemService(ALARM_SERVICE); //實例化IntentIntentintent=newIntent(); //設置Intentaction屬性intent.setAction(BC_ACTION);intent.putE*tra("msg",content); //實例化PendingIntentfinalPendingIntentpi=PendingIntent.getBroadcast(getApplicationConte*t(),0,intent,0);//獲得系統(tǒng)時間finallongtime1=System.currentTimeMillis();Calendarc=Calendar.getInstance();c.set(mYear,mMonth,mDay,mHour,mMinute);longtime2=c.getTimeInMillis();if(flag&&(time2-time1)>0&&on_off==1){am.set(AlarmManager.RTC_WAKEUP,time2,pi);}else{ am.cancel(pi);}}//設置提示日期對話框 privatevoidshowDialog1(Stringmsg){Viewv=li.inflate(R.layout.item_content,null);contentET.setTe*t(content);newAlertDialog.Builder(this).setView(v).setMessage(msg).setCancelable(false).setPositiveButton("確定",newDialogInterface.OnClickListener(){publicvoidonClick(DialogInterfacedialog,intid){content=contentET.getTe*t().toString(); contentDesc.setTe*t(content); } }).show(); } //時間選擇對話框 privateTimePickerDialog.OnTimeSetListenermTimeSetListener= newTimePickerDialog.OnTimeSetListener(){ publicvoidonTimeSet(TimePickerview,inthourOfDay,intminute){ mHour=hourOfDay; mMinute=minute; timeDesc.setTe*t(mHour+":"+mMinute);} }; //日期選擇對話框privateDatePickerDialog.OnDateSetListenermDateSetListener=newDatePickerDialog.OnDateSetListener(){publicvoidonDateSet(DatePickerview,intyear,intmonthOfYear, intdayOfMonth){mYear=year;mMonth=monthOfYear;mDay=dayOfMonth; dateDesc.setTe*t(mYear+"/"+mMonth+"/"+mDay); } }; //保存或修改備忘錄信息 protectedvoidonPause(){ super.onPause(); saveOrUpdate(); }; //保存或修改備忘錄信息 privatevoidsaveOrUpdate(){ ContentValuesvalues=newContentValues(); values.clear(); values.put(Tasks.CONTENT,contentDesc.getTe*t().toString()); values.put(Tasks.DATE1,dateDesc.getTe*t().toString()); values.put(Tasks.TIME1,timeDesc.getTe*t().toString()); values.put(Tasks.ON_OFF,ctv1.isChecked()?1:0); values.put(Tasks.ALARM,ctv2.isChecked()?1:0); //修改 if(id1!=0){Uriuri=ContentUris.withAppendedId(Tasks.CONTENT_URI,id1);getContentResolver().update(uri,values,null,null); //保存 }else{Uriuri=TaskList.Tasks.CONTENT_URI; getContentResolver().insert(uri,values); } }-.zTaskList.java文件package.amaker.ch17.app;.Uri;vider.BaseColumns;publicfinalclassTaskList{ //授權常量publicstaticfinalStringAUTHORITY=".vider.TaskList";privateTaskList(){}//內部類publicstaticfinalclassTasksimplementsBaseColumns{privateTasks(){}//UripublicstaticfinalUriCONTENT_URI=Uri.parse("content://"+AUTHORITY+"/taskLists");publicstaticfinalStringCONTENT_TYPE="vnd.android.cursor.dir/vnd.amaker.tasklist";publicstaticfinalStringCONTENT_ITEM_TYPE="vnd.android.cursor.item/vnd.amaker.tasklist";//默認排序常量publicstaticfinalStringDEFAULT_SORT_ORDER="createdDESC";//表字段常量publicstaticfinalStringCONTENT="content";publicstaticfinalStringCREATED="created";publicstaticfinalStringDATE1="date1";publicstaticfinalStringTIME1="time1";publicstaticfinalStringON_OFF="on_off";publicstaticfinalStringALARM="alarm";}}TaskListActivity.java文件-.zpackage.amaker.ch17.app;tivity;importandroid.content.ContentUris;importandroid.content.Intent;importandroid.database.Cursor;.Uri;importandroid.os.Bundle;importandroid.view.Menu;importandroid.view.MenuItem;importandroid.view.View;importandroid.widget.*;import.amaker.ch17.app.TaskList.Tasks;publicclassTaskListActivitye*tendsListActivity{ //菜單項常量 privatestaticfinalintNEW=1; privatestaticfinalintDEL=2; //查詢列數(shù)組 privatestaticfinalString[]PROJECTION=newString[]{ Tasks._ID, //0 Tasks.CONTENT,//1 Tasks.CREATED,//2 Tasks.ALARM, //3 Tasks.DATE1,//4 Tasks.TIME1, //5 Tasks.ON_OFF //6 }; protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); //獲得Intent finalIntentintent=getIntent(); //設置Uri if(intent.getData()==null){ intent.setData(Tasks.CONTENT_URI); } //獲得ListView ListViewlistView=getListView(); //查詢所有備忘錄信息 Cursorcursor=managedQuery(getIntent().getData(),PROJECTION,null,null,Tasks.DEFAULT_SORT_ORDER); //創(chuàng)立Adapter SimpleCursorAdapteradapter=newSimpleCursorAdapter(this,android.R.layout.simple_list_item_2,cursor,newString[]{Tasks._ID,Tasks.CONTENT},newint[]{android.R.id.te*t1,android.R.id.te*t2}); //將備忘錄信息顯示到ListView setListAdapter(adapter); //為ListView添加單擊事件監(jiān)聽器listView.setOnItemClickListener(newOnItemClickListener(){publicvoidonItemClick(AdapterView<?>av,Viewv,intposition,longid){ //通過ID查詢備忘錄信息Uriuri=ContentUris.withAppendedId(Tasks.CONTENT_URI,id);Cursorcursor=managedQuery(uri,PROJECTION,null,null,Tasks.DEFAULT_SORT_ORDER);if(cursor.moveToNe*t()){intid1=cursor.getInt(0);Stringcontent=cursor.getString(1);Stringcreated=cursor.getString(2);intalarm=cursor.getInt(3);Stringdate1=cursor.getString(4);Stringtime1=cursor.getString(5);inton_off=cursor.getInt(6);Bundleb=newBundle();b.putInt("id",id1); b.putString("content",content);b.putString("created",created);b.putInt("alarm",alarm);b.putString("date1",date1);b.putString("time1",time1);b.putInt("on_off",on_off); //將備忘錄信息添加到Intentin//啟動備忘錄詳細信息Activity intent.setClass(TaskListActivity.this,TaskDetailActivity.class);startActivity(intent);}}});} //創(chuàng)立選項菜單 publicbooleanonCreateOptionsMenu(Menumenu){ menu.add(0,NEW,0,"新建"); menu.add(0,DEL,0,"刪除"); returntrue; } //選項菜單項單擊方法 publicbooleanonOptionsItemSelected(MenuItemitem){ switch(item.getItemId()){ caseNEW: //啟動備忘錄詳細信息ActivityIntentintent=newIntent();intent.setClass(this,TaskDetailActivity.class);startActivity(intent);returntrue;caseDEL:returntrue;}returnfalse;}}-.z〔5〕TaskListProvider.java文件package.amaker.ch17.app;importjava.util.HashMap;importandroid.content.*;importandroid.database.Cursor;importandroid.database.SQLE*ception;importandroid.database.sqlite.*;.Uri;importandroid.te*t.Te*tUtils;import.amaker.ch17.app.TaskList.Tasks;publicclassTaskListProvidere*tendsContentProvider{//數(shù)據(jù)庫名稱常量privatestaticfinalStringDATABASE_NAME="task_list.db";//數(shù)據(jù)庫版本常量privatestaticfinalintDATABASE_VERSION=1;//表名稱常量privatestaticfinalStringTASK_LIST_TABLE_NAME="taskLists";//查詢列集合privatestaticHashMap<String,String>sTaskListProjectionMap;//查詢、更新條件privatestaticfinalintTASKS=1;privatestaticfinalintTASK_ID=2;//Uri工具類privatestaticfinalUriMatchersUriMatcher;//數(shù)據(jù)庫工具類實例privateDatabaseHelpermOpenHelper;//內部工具類,創(chuàng)立或翻開數(shù)據(jù)庫,創(chuàng)立或刪除表privatestaticclassDatabaseHelpere*tendsSQLiteOpenHelper{DatabaseHelper(Conte*tconte*t){super(conte*t,DATABASE_NAME,null,DATABASE_VERSION);} //創(chuàng)立表publicvoidonCreate(SQLiteDatabasedb){db.e*ecSQL("CREATETABLE"+TASK_LIST_TABLE_NAME+"("+Tasks._ID+"INTEGERPRIMARYKEY,"+Tasks.DATE1+"TE*T,"+Tasks.TIME1+"TE*T,"+Tasks.CONTENT+"TE*T,"+Tasks.ON_OFF+"INTEGER,"+Tasks.ALARM+"INTEGER,"+Tasks.CREATED+"TE*T"+");");}//刪除表publicvoidonUpgrade(SQLiteDatabasedb,intoldVersion,intnewVersion){db.e*ecSQL("DROPTABLEIFE*ISTStaskLists");onCreate(db);}}//創(chuàng)立或翻開數(shù)據(jù)庫publicbooleanonCreate(){mOpenHelper=newDatabaseHelper(getConte*t());returntrue;}//查詢publicCursorquery(Uriuri,String[]projection,Stringselection,String[]selectionArgs,StringsortOrder){SQLiteQueryBuilderqb=newSQLiteQueryBuilder();switch(sUriMatcher.match(uri)){//查詢所有caseTASKS:qb.setTables(TASK_LIST_TABLE_NAME);qb.setProjectionMap(sTaskListProjectionMap)break;//根據(jù)ID查詢caseTASK_ID:qb.setTables(TASK_LIST_TABLE_NAME);qb.setProjectionMap(sTaskListProjectionMap)qb.appendWhere(Tasks._ID+"="+uri.getPathSegments().get(1));break;default: thrownewIllegalArgumentE*ception("Uri錯誤!"+uri);}//使用默認排序StringorderBy;if(Te*tUtils.isEmpty(sortOrder)){orderBy=TaskList.Tasks.DEFAULT_SORT_ORDER;}else{orderBy=sortOrder;}//獲得數(shù)據(jù)庫實例SQLiteDatabasedb=mOpenHelper.getReadableDatabase();//返回游標集合Cursorc=qb.query(db,projection,selection,selectionArgs,null,null,orderBy);c.setNotificationUri(getConte*t().getContentResolver(),uri);returnc;}//獲得類型publicStringgetType(Uriuri){switch(sUriMatcher.match(uri)){caseTASKS:returnTasks.CONTENT_TYPE;caseTASK_ID:returnTasks.CONTENT_ITEM_TYPE;default: thrownewIllegalArgumentE*ception("錯誤的URI:"+uri);}}//保存數(shù)據(jù)publicUriinsert(Uriuri,ContentValuesinitialValues){if(sUriMatcher.match(uri)!=TASKS){thrownewIllegalArgumentE*ception("錯誤的URI:"+uri);}ContentValuesvalues;if(initialValues!=null){values=newContentValues(initialValues);}else{values=newContentValues();}//獲得數(shù)據(jù)庫實例SQLiteDatabasedb=mOpenHelper.getWritableDatabase();//保存數(shù)據(jù)返回行IDlongrowId=db.insert(TASK_LIST_TABLE_NAME,Tasks.CONTENT,values);if(rowId>0){UritaskUri=ContentUris.withAppendedId(TaskList.Tasks.CONTENT_URI,rowId);getConte*t().getContentResolver().notifyChange(taskUri,null);returntaskUri;}thrownewSQLE*ception("插入數(shù)據(jù)失敗"+uri);}//刪除數(shù)據(jù)publicintdelete(Uriuri,Stringwhere,String[]whereArgs){ //獲得數(shù)據(jù)庫實例SQLiteDatabasedb=mOpenHelper.getWritableDatabase();intcount;switch(sUriMatcher.match(uri)){//根據(jù)指定條件刪除caseTASKS:count=db.delete(TASK_LIST_TABLE_NAME,where,whereArgs);break;//根據(jù)指定條件和ID刪除caseTASK_ID:StringnoteId=uri.getPathSegments().get(1);count=db.delete(TASK_LIST_TABLE_NAME,Tasks._ID+"="+noteId+(!Te*tUtils.isEmpty(where)?"AND("+where+')':"),whereArgs);break;default:thrownewIllegalArgumentE*ception("錯誤的URI"+uri);}getConte*t().getContentResolver().notifyChange(uri,null);returncount;}//更新數(shù)據(jù)publicintupdate(Uriuri,ContentValuesvalues,Stringwhere,String[]whereArgs){ //獲得數(shù)據(jù)庫實例SQLiteDatabasedb=mOpenHelper.getWritableDatabase();intcount;switch(sUriMatcher.match(uri)){//根據(jù)指定條件更新caseTASKS:count=db.update(TASK_LIST_TABLE_NAME,values,where,whereArgs);break;//根據(jù)指定條件和ID更新caseTASK_ID:StringnoteId=uri.getPathSegments().get(1);count=db.update(TASK_LIST_TABLE_NAME,values,Tasks._ID+"="+noteId+(!Te*tUtils.isEmpty(where)?"AND("+where+')':"),whereArgs);break;default:thrownewIllegalArgumentE*ception("錯誤的URI"+uri);}getConte*t().getContentResolver().notifyChange(uri,null);returncount;}static{ //Uri匹配工具類sUriMatcher=newUriMatcher(UriMatcher.NO_MATCH);sUriMatcher.addURI(TaskList.AUTHORITY,"taskLists",TASKS);sUriMatcher.addURI(TaskList.AUTHORITY,"taskLists/*",TASK_ID);//實例化查詢列集合sTaskListProjectionMap=newHashMap<String,String>();//添加查詢列sTaskListProjectionMap.put(Tasks._ID,Tasks._ID);sTaskListProjectionMap.put(Tasks.CONTENT,Tasks.CONTENT);sTaskListProjectionMap.put(Tasks.CREATED,Tasks.CREATED);sTaskListProjectionMap.put(Tasks.ALARM,Tasks.ALARM);sTaskListProjectionMap.put(Tasks.DATE1,Tasks.DATE1);sTaskListProjectionMap.put(Tasks.TIME1,Tasks.TIME1);sTaskListProjectionMap.put(Tasks.ON_OFF,Tasks.ON_OFF);}}TaskReceiver.java文件package.amaker.ch17.app;importandroid.content.*;publicclassTaskReceivere*tendsBroadcastReceiver{ publicvoidonReceive(Conte*tconte*t,Intentintent){ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setClass(conte*t,AlarmActivity.class); conte*t.startActivity(intent); }}main.*ml文件<?*mlversion="1.0"encoding="utf-8"?><LinearLayout*mlns:android="schemas.android./apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><ListViewandroid:layout_width="fill_parent"android:layout_height="fill_parent"android:id="+id/itemlist"/></LinearLayout>string.*ml文件<?*mlversion="1.0"encoding="utf-8"?><resources><stringname="hello">HelloWorld,MainActivity!</string><stringname="app_name">Memorandum</string></resources>item_content.*ml文件<?*mlversion="1.0"encoding="utf-8"?><LinearLayout*mlns:android="schemas.android./apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"><EditTe*t android:te*t=" android:id="+id/content"android:layout_width="fill_parent"android:layout_height="50p*"/></LinearLayout>item_row.*ml文件<?*mlversion="1.0"encoding="utf-8"?><LinearLayout*mlns:android="schemas.android./apk/res/android"android:id="+id/vw1"android:layout_width="fill_parent"android:layout_height="wrap_content"android:padding="4p*"android:orientation="horizontal"><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="vertical"><Te*tViewandroid:id="+id/name"android:te*tSize="18sp"android:te*tStyle="bold"android:layout_width="fill_parent"android:layout_height="wrap_content"/><Te*tViewandroid:id="+id/desc"android:te*tSize="14sp"
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年齊齊哈爾市泰來縣公益崗保潔人員招聘2人備考筆試題庫及答案解析
- 2026河北省定向北京交通大學選調生招錄備考考試題庫及答案解析
- 2025山東聊城市消防救援支隊食堂服務人員招錄6人參考筆試題庫附答案解析
- 《觀察物體》數(shù)學課件教案
- 2026廣西醫(yī)科大學附屬口腔醫(yī)院人才招聘35人備考考試試題及答案解析
- 2026清華大學面向應屆畢業(yè)生招聘參考筆試題庫附答案解析
- 2025泰安新泰市泰山電力學校教師招聘備考筆試試題及答案解析
- 2025遼寧鞍山市立山區(qū)事業(yè)單位招聘博士研究生3人備考考試試題及答案解析
- 網服務合同協(xié)議書
- 耕地被占用協(xié)議書
- 共創(chuàng)賬號合同協(xié)議
- 2026年贛州職業(yè)技術學院單招職業(yè)技能測試題庫帶答案詳解
- 2025年區(qū)域經濟一體化戰(zhàn)略可行性研究報告
- 港口安全規(guī)劃與應急預案
- 2025廣東廣州琶洲街道招聘雇員(協(xié)管員)5人筆試考試參考題庫及答案解析
- 2026年江西萍實鐵路發(fā)展股份有限公司校園招聘4人筆試考試參考試題及答案解析
- 短期臨時工合同范本
- 分布式光伏運維培訓課件
- 廣鐵局歷年機考題目及答案
- 2025年10月自考00160審計學試題及答案含評分參考
- 2026寧電投(石嘴山市)能源發(fā)展有限公司秋季校園招聘100人筆試考試備考題庫及答案解析
評論
0/150
提交評論