该篇说明

该篇我们进行单词测试实现讲解

也就是单词测试界面WordExamActivity中功能

布局也需要在xml中实现

但是也需要有单词测试视图类来设置一些值具体查看对照源码

在该界面中,测试完后会更新数据

效果如图

android产品功能测试 安卓功能测试代码_List

流程图

android产品功能测试 安卓功能测试代码_List_02

单词测试界面功能流程详解

1>显示单词测试信息

a> 首先要加载单词测试数据

需要调用单词测试管理模块加载数据功能

private voidloadWordExamData() {
loadingExamDataProgressBar=(ProgressBar)
findViewById(R.id.loadingExamDataProgressBar);
loadingExamDataProgressBar.setVisibility(View.VISIBLE);newThread() {public voidrun() {newWordExamManager().loadData();
SystemUtil.sleepvd(2000);
myHandler.sendEmptyMessage(0);
}
}.start();
}

b> handler处理0的消息并初始及处理逻辑

@SuppressLint("HandlerLeak")private voidinitHandler() {
myHandler= newHandler() {public voidhandleMessage(android.os.Message msg) {switch(msg.what) {case 0:
wordExamLinearLayout.setVisibility(View.VISIBLE);
loadingExamDataProgressBar.setVisibility(View.GONE);
init();
logic();break;
}
}
};
}

c> 接着在初始中加载显示单词测试界面

private voidloadView() {//正确选项随机数Global.rightOptionRandom= Math.floor(Math.random() * 4 + 1);
WordDet wordDet= Global.wordDetList.get(Global.studyedWordId - 1);//单词测试标题wordExamTitelTextView.setText(wordDet.wordStr+ String.format(" /%s/", wordDet.pron));
WordExamView.initOptions(this);
WordExamView.setOptionsData(wordDet);
}

2>四个选项添加监听

来实现点击判断选择的正确还是错误。进一步确定执行

监听类请自行查看源码

private voidlogic() {for(int i=1; i<=4; i++) {
LinearLayout wordExamOptionll= WordExamView.weOptionLLayoutList.get(i-1);
wordExamOptionll.setOnClickListener(newWordExamOptionClickListener(wordExamOptionll, i));
}
}

3>测试正确后下一个

a> 跳转下一个

单选正确后自动跳转到下一个

如果是已是最后一个,那么更新数据

public voidexamNext() {
Global.studyedWordId+= 1;if(Global.studyedWordId <=Global.wordList.size()) {
timer.schedule(newTimerTask() {
@Overridepublic voidrun() {
myHandler.sendEmptyMessage(1);
}
},1000);
}else if((Global.studyedWordId >Global.wordList.size())) {
updateData();
}
}

b> 使用计时器控制1秒后跳转

Handler异步任务处理1的消息测试下个单词

@SuppressLint("HandlerLeak")private voidinitHandler() {
myHandler= newHandler() {public voidhandleMessage(android.os.Message msg) {switch(msg.what) {case 1:if(timer != null) {
timer.cancel();
}
timer= newTimer();
showNextView();break;
}
}
};
}

c> 更新数据

如果测试完最后一个,就进行更新数据。

如果从单词背诵界面跳转的,才更新记录次数

private voidupdateData() {
clear();if(parentStr != null && parentStr.equals("wordDet")) {
updateDataProgressDialog.setMessage("正在更新数据");
updateDataProgressDialog.show();newThread(){
@Overridepublic voidrun() {
updateRecordTimes();
}
}.start();
}else if(parentStr.equals("wordList")) {
Toast.makeText(context,
Global.selectUnitGroupFlagStr+ "单元测组试完,回到单词列表界面!!!",
Toast.LENGTH_LONG).show();
toNextView(WordListActivity.class);
}
}

d> 更新次数

> 没有完成次数进度才可设置需要更新数据

> 如果结果记录次数等于需要背诵的次数,则返回到今天任务

进度归0(会存储到数据库),同时需要清空单词记录表及单词表

> 否则返回到单词列表,递增进度(不保存到数据库)

private voidupdateRecordTimes() {int recitedtimes =Integer.parseInt(Global.studyPlanObj.lastReciteProgressStr.split("/")[0]);int resultRtimes = 0;if(recitedtimes !=Global.defaultReciteTimes) {
resultRtimes= recitedtimes + 1;
Global.studyPlanObj.lastReciteProgressStr= resultRtimes + "/" + Global.defaultReciteTimes;if(resultRtimes ==Global.defaultReciteTimes) {newReciteManager().updateData();
SystemUtil.sleepvd(2000);
myHandler.sendEmptyMessage(2);
}else{newReciteManager().updateReciteProgress(Global.studyPlanObj.lastReciteProgressStr);
SystemUtil.sleepvd(2000);
myHandler.sendEmptyMessage(3);
}
}
}

4>测试错误后的操作

测试错误后显示按钮操作

> 返回学习按钮,返回单词列表界面进行学习

> 继续测试按钮,重新开始测试

public voidshowButtonAfterNotRight() {
returnToStudyButton.setVisibility(View.VISIBLE);
continueExamButton.setVisibility(View.VISIBLE);
returnToStudyButton.setOnClickListener(newOnClickListener() {
@Overridepublic voidonClick(View v) {
clear();
toNextView(WordListActivity.class);
}
});
continueExamButton.setOnClickListener(newOnClickListener() {
@Overridepublic voidonClick(View v) {
Global.studyedWordId= 1;
Global.examedWordId= 1;
returnToStudyButton.setVisibility(View.GONE);
continueExamButton.setVisibility(View.GONE);
showNextView();
}
});
}

单词测试后台功能详解

在加载数据以及更新次数方法使用到了后台模块

使用到了如下模块功能

> 单词测试管理WordExamManager的加载数据loadData()方法

> 背诵管理ReciteManager的更新背诵次数updateReciteProgress()方法

1>单词测试管理加载数据详解

a> 首先是加载数据方法

public voidloadData() {if(Global.examWordDetList == null) {if(wordDetManager == null) {
wordDetManager= newWordDetManager();
}
List tmexamWordList =getExamWordList();
Global.examWordDetList=wordDetManager.findMoreWordDet(tmexamWordList);
}
}

b> 获得测试单词范围

private ListgetExamWordList() {//确定单元及组String unitGroupIntro=Global.todayStudyUnitGroupIntroList.get(Global.studyPlanObj.lastUnitGroupIndex);int cunit = Integer.parseInt(unitGroupIntro.split("-")[0]);int cgroup = Integer.parseInt(unitGroupIntro.split("-")[1]);int scopeBegin = -1;int scopeEnd = -1;//确定范围
if(cunit == 1 && cgroup <= 3) {
scopeBegin= (cunit - 1) * ReciteConstant.DUNIT_WORD_COUNT + (cgroup+1) *ReciteConstant.DUNITG_WORD_COUNT;
scopeEnd= scopeBegin + 3 *ReciteConstant.DUNITG_WORD_COUNT;
}else{
scopeEnd= (cunit - 1) * ReciteConstant.DUNIT_WORD_COUNT + cgroup *ReciteConstant.DUNITG_WORD_COUNT;if(scopeEnd >Global.studyPlanObj.allWordCount) {
scopeEnd= Global.studyPlanObj.allWordCount -ReciteConstant.DUNITG_WORD_COUNT;
}
scopeBegin= scopeEnd - 3 *ReciteConstant.DUNITG_WORD_COUNT;
}if(wordDao == null) {
wordDao= newWordDao();
}
String pathStr= PathConstant.STUPLAN_PATH + "sp_" +Global.studyPlanObj.name;returnwordDao.findScope(scopeBegin, scopeEnd, pathStr);
}

c> 根据单词列表得到单词详解列表

这里引用单词详解模块WordDetManager的查找更多单词详解方法

请查看源码点到该类

public List findMoreWordDet(ListwordList) {
List wordDetList = new ArrayList();for(Word word : wordList) {
WordDet wordDet=findDetWord(word.wordStr);if(wordDet != null) {
wordDetList.add(wordDet);
}
}returnwordDetList;
}

查找某个单词的单词详解方法

publicWordDet findDetWord(String wordStr) {if(dictDao == null) {
dictDao= newDictDao();
}
String wordDefinition=dictDao.findWordDefinition(wordStr);
WordDet wordDet=jsonDefiToDefWord(wordStr, wordDefinition);returnwordDet;
}

2>背诵管理更新次数详解

更新背诵次数,直接调用相应的dao即可

public voidupdateReciteProgress(String reciteProgressStr) {if(reciteDao == null) {
reciteDao= newReciteDao ();
}
String pathStr= PathConstant.STUPLAN_PATH + "sp_" +Global.studyPlanObj.name;
reciteDao.updateReciteProgress(reciteProgressStr, Global.studyPlanObj.name, pathStr);
}

到此《android项目实战-背呗单词》重点功能及技术介绍完结