鬧鐘提醒備忘錄移動開發(fā)技術(shù)實驗報告_第1頁
鬧鐘提醒備忘錄移動開發(fā)技術(shù)實驗報告_第2頁
鬧鐘提醒備忘錄移動開發(fā)技術(shù)實驗報告_第3頁
鬧鐘提醒備忘錄移動開發(fā)技術(shù)實驗報告_第4頁
已閱讀5頁,還剩28頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、鬧鐘提醒備忘錄移動開發(fā)技術(shù)實驗報告 鬧鐘提醒備忘錄移動開發(fā)技術(shù)實驗報告 目錄 第一部分:app 簡介 . 2 (1) 需求分析 . 2 (2) 系統(tǒng)目標(biāo) . 2 (3) 開發(fā)及運(yùn)行環(huán)境 . 2 第二部分:開發(fā)技術(shù) . 3 (1)sharedprefenrences 技術(shù) . 3 (2)數(shù)據(jù)庫 . 11 (3)crud 操作 . 12 (4)時鐘提醒 . 13 第三部分:功能介紹 . 15 (1)登錄模塊 . 15 (2)注冊模塊 . 16 (3)主界面模塊 . 16 (4)新建備忘錄模塊 . 17 (5)刪除備忘錄模塊 . 18 第四部分:遇到的問題和解決辦法 . 20 (1)無法刷新 ui

2、. 20 (1)無法使用某些 api . 20 第五部分:總結(jié) . 21 第一部分:app 簡介 (1 1 ) 需求分析 隨著時代的發(fā)展,我們每天需要處理的事務(wù)也呈現(xiàn)了爆炸式的增長。記住親朋好友的生日并及時送上生日的祝福;記住上司布置的任務(wù);記住幾天后的出行車票時間等,這些紛繁的信息記憶是不是正在讓您深陷其中?目前,手機(jī)上已經(jīng)有了備忘錄功能和鬧鐘功能,但二者之間并沒有實現(xiàn)消息的互通(蘋果手機(jī)用戶可以設(shè)置事件的鬧鐘提醒,但是安卓用戶卻還沒有使用這樣的功能)。用戶在備忘錄中記錄下需要設(shè)置時間提醒事件后,還需要再打開鬧鐘app,并設(shè)置鬧鐘提醒,這在無形中增加了用戶的負(fù)擔(dān),并且產(chǎn)生了糟糕的用戶體驗。

3、現(xiàn)在,這些都不再是問題,在本次的課程設(shè)計中,使用我的軟件,用戶可以十分方便的新建備忘錄,根據(jù)標(biāo)題查找備忘錄事件,刪除已過期的備忘錄并可以隨意修改備忘錄內(nèi)容。除此之外,用戶還可以為每條事件添加重要程度,并在主界面按重要程度展示所有的已建備忘錄列表本軟件致力于幫助用戶時刻記錄下生活中的重要信息并在設(shè)置的時間給用戶發(fā)送提醒,讓您不缺席生活中的重要時刻。 (2 2 ) 系統(tǒng)目標(biāo) 1,友好的操作界面和良好的人機(jī)互動。 2,軟件的登錄界面保證了信息的保密性。 3,隨時對重要信息的記錄并設(shè)置到時間提醒。 4,備忘錄內(nèi)容的修改,刪除和查詢。 5,也可將其用作記錄本使用,代替原有的單一備忘錄 app。 6,系統(tǒng)

4、可靠運(yùn)行,安全有效。 (3 3 ) 開發(fā)及運(yùn)行環(huán)境 (1) 開發(fā)工具:android studio (2) 系統(tǒng)環(huán)境:windows 10 家庭中文版 (3) 開發(fā)語言:java,xml 第二部分:開發(fā)技術(shù) (1 1 ) sharedprefenrences s 技術(shù) 在用戶第一次進(jìn)入軟件時,可以注冊個人賬號,包括賬號和密碼;密碼須二次輸入同樣的字符,否則無法注冊成功;賬號和密碼使用 sharedprefenrence 技術(shù)保存。保存用戶的賬號密碼,屬于用戶的偏好參數(shù),若使用數(shù)據(jù)庫來存儲這些數(shù)據(jù),未免有些大材小用,此時 sharedpreferences 技術(shù)就派上用場。sharedprefe

5、rences 使用鍵-值的形式來存儲數(shù)據(jù)。在我們的實例中,賬號為鍵,密碼為值,具有唯一匹配性,我們只需要調(diào)用 sharedpreferences 的getxxx(name), 就可以根據(jù)鍵獲得對應(yīng)的值。使用起來很方便! 登錄界面源碼: package com.example.uilayouttest.activity; import android.content.intent; import android.content.sharedpreferences; import android.content.pm.activityinfo; import android.support.v7.

6、app.actionbar; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.text.textutils; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.textview; import android.widget.toast; import com.example.uilayouttes

7、t.adapter.md5utils; import com.example.uilayouttest.r; public class loginactivity extends appcompatactivity private textview tv_main_title;/標(biāo)題 private textview tv_back,tv_register,tv_find_psw;/返回鍵,顯示的注冊,找回密碼 private button btn_login;/登錄按鈕 private string username,psw,sppsw;/獲取的用戶名,密碼,加密密碼 private edi

8、ttext et_user_name,et_psw;/編輯框 override protected void oncreate(bundle savedinstancestate) super.oncreate(savedinstancestate); setcontentview(r.layout.activity_login); /設(shè)置此界面為豎屏 setrequestedorientation(activityinfo.screen_orientation_portrait); init(); actionbar actionbar=getsupportactionbar(); if(a

9、ctionbar!=null) actionbar.hide(); /獲取界面控件 private void init() /從 main_title_bar 中獲取的 id tv_main_title=findviewbyid(r.id.tv_main_title); tv_main_title.settext(登錄); tv_back=findviewbyid(r.id.tv_back); /從 activity_login.xml 中獲取的 tv_register=findviewbyid(r.id.tv_register); tv_find_psw=findviewbyid(r.id.

10、tv_find_psw); btn_login=findviewbyid(r.id.btn_login); et_user_name=findviewbyid(r.id.et_user_name); et_psw=findviewbyid(r.id.et_psw); /返回鍵的點擊事件 tv_back.setonclicklistener(new view.onclicklistener() override public void onclick(view v) /登錄界面銷毀 loginactivity.this.finish(); ); /立即注冊控件的點擊事件 tv_register.

11、setonclicklistener(new view.onclicklistener() override public void onclick(view v) /為了跳轉(zhuǎn)到注冊界面,并實現(xiàn)注冊功能 intent intent=new intent(loginactivity.this,registeractivity.class); startactivityforresult(intent, 1); ); /找回密碼控件的點擊事件 tv_find_psw.setonclicklistener(new view.onclicklistener() override public void

12、 onclick(view v) /跳轉(zhuǎn)到找回密碼界面(此頁面暫未創(chuàng)建) ); /登錄按鈕的點擊事件 btn_login.setonclicklistener(new view.onclicklistener() override public void onclick(view v) /開始登錄,獲取用戶名和密碼 gettext().tostring().trim(); username=et_user_name.gettext().tostring().trim(); psw=et_psw.gettext().tostring().trim(); /對當(dāng)前用戶輸入的密碼進(jìn)行 md5 加密再

13、進(jìn)行比對判斷, md5utils.md5( ); psw 進(jìn)行加密判斷是否一致 string md5psw= md5utils.md5(psw); / md5psw ; sppsw 為 根據(jù)從 sharedpreferences 中用戶名讀取密碼 / 定義方法 readpsw 為了讀取用戶名,得到密碼 sppsw=readpsw(username); / textutils.isempty if(textutils.isempty(username) toast.maketext(loginactivity.this, 請輸入用戶名, toast.length_short).show(); r

14、eturn; else if(textutils.isempty(psw) toast.maketext(loginactivity.this, 請輸入密碼, toast.length_short).show(); return; / md5psw.equals(); 判斷,輸入的密碼加密后,是否與保存在 sharedpreferences 中一致 else if(md5psw.equals(sppsw) /一致登錄成功 toast.maketext(loginactivity.this, 登錄成功, toast.length_short).show(); /保存登錄狀態(tài),在界面保存登錄的用戶

15、名 定義個方法 saveloginstatus boolean 狀態(tài) , username 用戶名; saveloginstatus(true, username); /登錄成功后關(guān)閉此頁面進(jìn)入主頁 intent data=new intent(); /datad.putextra( ); name , value ; data.putextra(islogin,true); /result_ok 為 activity 系統(tǒng)常量,狀態(tài)碼為-1 / 表示此頁面下的內(nèi)容操作成功將 data 返回到上一頁面,如果是用 back 返回過去的則不存在用 setresult 傳遞 data 值 setre

16、sult(result_ok,data); /銷毀登錄界面 loginactivity.this.finish(); /跳轉(zhuǎn)到主界面,登錄成功的狀態(tài)傳遞到 mainactivity 中 startactivity(new intent(loginactivity.this, mainactivity.class); return; else if(sppsw!=null!textutils.isempty(sppsw)!md5psw.equals(sppsw) toast.maketext(loginactivity.this, 輸入的用戶名和密碼不一致, toast.length_short

17、).show(); return; else toast.maketext(loginactivity.this, 此用戶名不存在, toast.length_short).show(); ); /* *從 sharedpreferences 中根據(jù)用戶名讀取密碼 */ private string readpsw(string username) /getsharedpreferences(logininfo,mode_private); /logininfo,mode_private; mode_private 表示可以繼續(xù)寫入 sharedpreferences sp=getshared

18、preferences(logininfo, mode_private); /sp.getstring() username, ; return sp.getstring(username , ); /* *保存登錄狀態(tài)和登錄用戶名到 sharedpreferences 中 */ private void saveloginstatus(boolean status,string username) /saveloginstatus(true, username); /logininfo 表示文件名 sharedpreferences sp=getsharedpreferences(login

19、info, mode_private); sharedpreferences sp=getsharedpreferences(logininfo, mode_private); /獲取編輯器 sharedpreferences.editor editor=sp.edit(); /存入 boolean 類型的登錄狀態(tài) editor.putboolean(islogin, status); /存入登錄狀態(tài)時的用戶名 editor.putstring(loginusername, username); /提交修改 mit(); /* * 注冊成功的數(shù)據(jù)返回至此 * param requestcode

20、 請求碼 * param resultcode 結(jié)果碼 * param data 數(shù)據(jù) */ override /顯示數(shù)據(jù), onactivityresult /startactivityforresult(intent, 1); 從注冊界面中獲取數(shù)據(jù) /int requestcode , int resultcode , intent data / loginactivity - startactivityforresult - onactivityresult(); protected void onactivityresult(int requestcode, int resultcod

21、e, intent data) /super.onactivityresult(requestcode, resultcode, data); super.onactivityresult(requestcode, resultcode, data); if(data!=null) /是獲取注冊界面回傳過來的用戶名 / getextra().getstring(*); string username=data.getstringextra(username); if(!textutils.isempty(username) /設(shè)置用戶名到 et_user_name 控件 et_user_nam

22、e.settext(username); /et_user_name 控件的 setselection()方法來設(shè)置光標(biāo)位置 et_user_name.setselection(username.length(); 注冊界面源碼如下: package com.example.uilayouttest.activity; import android.content.intent; import android.content.sharedpreferences; import android.content.pm.activityinfo; import android.graphics.co

23、lor; import android.support.v7.app.actionbar; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.text.textutils; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.relativelayout; import android.widget.

24、textview; import android.widget.toast; import com.example.uilayouttest.adapter.md5utils; import com.example.uilayouttest.r; public class registeractivity extends appcompatactivity private textview tv_main_title;/標(biāo)題 private textview tv_back;/返回按鈕 private button btn_register;/注冊按鈕 /用戶名,密碼,再次輸入的密碼的控件 p

25、rivate edittext et_user_name,et_psw,et_psw_again; /用戶名,密碼,再次輸入的密碼的控件的獲取值 private string username,psw,pswagain; /標(biāo)題布局 private relativelayout rl_title_bar; override protected void oncreate(bundle savedinstancestate) super.oncreate(savedinstancestate); /設(shè)置頁面布局 ,注冊界面 setcontentview(r.layout.activity_reg

26、ister); /設(shè)置此界面為豎屏 / actionbar actionbar = getsupportactionbar(); / if (actionbar != null) / actionbar.hide(); setrequestedorientation(activityinfo.screen_orientation_portrait); init(); private void init() /從 main_title_bar.xml 頁面布局中獲取對應(yīng)的 ui 控件 tv_main_title=findviewbyid(r.id.tv_main_title); / tv_mai

27、n_title.settext(注冊); tv_back=findviewbyid(r.id.tv_back); /布局根元素 rl_title_bar=findviewbyid(r.id.title_bar); / rl_title_bar.setbackgroundcolor(color.transparent); /從 activity_register.xml 頁面中獲取對應(yīng)的 ui 控件 btn_register=findviewbyid(r.id.btn_register); et_user_name=findviewbyid(r.id.et_user_name); et_psw=

28、findviewbyid(r.id.et_psw); et_psw_again=findviewbyid(r.id.et_psw_again); button btnback=findviewbyid(r.id.btn_backtologin); btnback.setonclicklistener(new view.onclicklistener() override public void onclick(view v) startactivity(new intent(registeractivity.this,loginactivity.class); ); / tv_back.set

29、onclicklistener(new view.onclicklistener() / override / public void onclick(view v) / /返回鍵 / registeractivity.this.finish(); / / ); /注冊按鈕 btn_register.setonclicklistener(new view.onclicklistener() override public void onclick(view v) /獲取輸入在相應(yīng)控件中的字符串 geteditstring(); /判斷輸入框內(nèi)容 if(textutils.isempty(use

30、rname) toast.maketext(registeractivity.this, 請輸入用戶名, toast.length_short).show(); return; else if(textutils.isempty(psw) toast.maketext(registeractivity.this, 請輸入密碼, toast.length_short).show(); return; else if(textutils.isempty(pswagain) toast.maketext(registeractivity.this, 請再次輸入密碼, toast.length_sho

31、rt).show(); return; else if(!psw.equals(pswagain) toast.maketext(registeractivity.this, 輸入兩次的密碼不一樣, toast.length_short).show(); return; /* *從 sharedpreferences 中讀取輸入的用戶名,判斷sharedpreferences 中是否有此用戶名 */ else if(isexistusername(username) toast.maketext(registeractivity.this, 此賬戶名已經(jīng)存在, toast.length_sho

32、rt).show(); return; else toast.maketext(registeractivity.this, 注冊成功, toast.length_short).show(); /把賬號、密碼和賬號標(biāo)識保存到 sp 里面 /* * 保存賬號和密碼到 sharedpreferences 中 */ saveregisterinfo(username, psw); /注冊成功后把賬號傳遞到 loginactivity.java 中 / 返回值到 loginactivity 顯示 intent data = new intent(); data.putextra(username, u

33、sername); setresult(result_ok, data); /result_ok 為 activity 系統(tǒng)常量,狀態(tài)碼為-1, / 表示此頁面下的內(nèi)容操作成功將 data 返回到上一頁面,如果是用 back 返回過去的則不存在用 setresult 傳遞 data 值 registeractivity.this.finish(); ); /* * 獲取控件中的字符串 */ private void geteditstring() username=et_user_name.gettext().tostring().trim(); psw=et_psw.gettext().to

34、string().trim(); pswagain=et_psw_again.gettext().tostring().trim(); /* * 從 sharedpreferences 中讀取輸入的用戶名,判斷 sharedpreferences 中是否有此用戶名 */ private boolean isexistusername(string username) boolean has_username=false; /mode_private sharedpreferences sp = getsharedpreferences( ); / logininfo, mode_private

35、 sharedpreferences sp=getsharedpreferences(logininfo, mode_private); /獲取密碼 string sppsw=sp.getstring(username, );/傳入用戶名獲取密碼 /如果密碼不為空則確實保存過這個用戶名 if(!textutils.isempty(sppsw) has_username=true; return has_username; /* * 保存賬號和密碼到 sharedpreferences 中 sharedpreferences */ private void saveregisterinfo(st

36、ring username,string psw) string md5psw = md5utils.md5(psw);/把密碼用 md5 加密 /logininfo 表示文件名, mode_private sharedpreferences sp = getsharedpreferences( ); sharedpreferences sp=getsharedpreferences(logininfo, mode_private); /獲取編輯器, sharedpreferences.editor editor - sp.edit(); sharedpreferences.editor ed

37、itor=sp.edit(); /以用戶名為 key,密碼為 value 保存在 sharedpreferences 中 /key,value,如鍵值對,editor.putstring(用戶名,密碼); editor.putstring(username, md5psw); /提交修改 mit(); mit(); (2 2 )數(shù)據(jù)庫 本軟件使用 sqlite 輕量級數(shù)據(jù)庫,在創(chuàng)建數(shù)據(jù)庫時,是通過使用sqliteopenhelper 類的構(gòu)造函數(shù)實現(xiàn) 代碼如下: public class dbopenhelper extends sqliteopenhelper private static

38、final string tag = dbopenhelper.class.getsimplename(); private static final int version = 1; private static final string db_name = memo.db; public dbopenhelper() super(memoapplication.getcontext(), db_name, null, version); override public void oncreate(sqlitedatabase db) /*第一次初始化 app,創(chuàng)建表結(jié)構(gòu) */ db.exe

39、csql(create table if not exists + columncontacts.event_table_name + ( + basecolumns._id + integer primary key autoincrement, + columncontacts.event_title_column + text, + columncontacts.event_content_column + text, + columncontacts.event_created_time_column + datetime, + columncontacts.event_updated

40、_time_column + datetime, + columncontacts.event_remind_time_column + datetime, + columncontacts.event_is_important_column + integer, + columncontacts.event_is_clocked + integer + ); (3 3 )c c rud 操作 使用 eventdao 類實現(xiàn)添加,查詢,刪除等操作 代碼如下: 1,查詢操作: public listevent findall() /降序排列,按重要性和創(chuàng)建時間 string sql = sele

41、ct * from + columncontacts.event_table_name + order by + columncontacts.event_is_important_column + desc, + columncontacts.event_created_time_column + desc; return mtemplate.query(sql, mcallback); public listevent findallwithnoclocked() string sql = select * from + columncontacts.event_table_name +

42、where + columncontacts.event_is_clocked + = + constants.eventclockflag.none; return mtemplate.query(sql, mcallback); 2,添加操作: public int create(event event) return (int) mtemplate.create(columncontacts.event_table_name, generatecontentvalues(event, false); 3,更新操作: public int update(event event) retur

43、n mtemplate.update(columncontacts.event_table_name, generatecontentvalues(event, true), basecolumns._id + = ?, integer.tostring(event.getmid(); 4,刪除操作 public int remove(listinteger ids) stringbuilder whereconditions = new stringbuilder(basecolumns._id + in(); for (integer id : ids) whereconditions.a

44、ppend(id).append(,); whereconditions.deletecharat(whereconditions.length() - 1).append(); return mtemplate.remove(columncontacts.event_table_name, whereconditions.tostring(); (4 4 )時鐘提醒 在退出軟件后,為了讓我們的提醒服務(wù)在后臺?;睿帉?clockservice 類在后臺運(yùn)行。 代碼如下: public class clockservice extends service private static fina

45、l string tag = clockservice; public static final string extra_event_id = extra.event.id; public static final string extra_event_remind_time = extra.event.remind.time; public static final string extra_event = extra.event; private eventdao meventdao = eventdao.getinstance(); public clockservice() log.

46、d(tag, clockservice: constructor); override public ibinder onbind(intent intent) throw new unsupportedoperationexception(not yet implemented); override public int onstartcommand(intent intent, int flags, int startid) log.d(tag, onstartcommand: onstartcommand); wakelockutil.wakeupandunlock(); posttoc

47、lockactivity(getapplicationcontext(), intent); return super.onstartcommand(intent, flags, startid); private void posttoclockactivity(context context, intent intent) intent i = new intent(); i.setclass(context, clockactivity.class); i.putextra(extra_event_id, intent.getintextra(extra_event_id, -1); event event = meventdao.findbyid(intent.getintextra(extra_event_id, -1); if (event = null) return; i.pu

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論