标签:
该篇说明
该篇我们来详解创建计划功能实现。
创建计划功能是在创建计划界面中的。
也就是在CreatePlanActivity中
在后台模块中只描述管理层,其它的数据库操作等请自行查看
效果如图
执行流程图
创建计划UI界面功能说明
1> 横幅显示创建计划字符
hfTitleTextView = (TextView) findViewById(R.id.hfTitleTextView); hfTitleTextView.setText("创建计划");
2> 创建计划项的填写
a步骤> 单词书名输入操作,只需要显示组件和获取组件即可
private void init() { studyNameEditText = (EditText) findViewById(R.id.studyNameEditText); }
b步骤1> 初始化选择单词书相关属性及值
private void init() {
selectWordBookRelativeLayout = (RelativeLayout) findViewById(R.id.selectWordBookRelativeLayout); wordBooknameTextView = (TextView) findViewById(R.id.wordBooknameTextView); wordBookname = WordBookConstant.WDBK_CATE_ARRAY[0]; wordBooknameTextView.setText(wordBookname);
}
b步骤2> 选择单词书布局点击监听
private void logic() { selectWordBookRelativeLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { alertSelectWorkBook(); } }); }
b步骤3> 弹出的单选框选择单词书
private void alertSelectWorkBook () { new AlertDialog.Builder(context) .setTitle("请选择书籍") .setIcon(android.R.drawable.ic_dialog_info) .setSingleChoiceItems(WordBookConstant.WDBK_CATE_ARRAY, wordBookSelectedIndex, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss();
wordBookname = WordBookConstant.WDBK_CATE_ARRAY[which]; wordBookSelectedIndex = which; wordBooknameTextView.setText(wordBookname); Toast.makeText(context, "单词书是:" + wordBookname, Toast.LENGTH_LONG).show(); } } ) .setNegativeButton("取消", null) .show(); }
c步骤1> 初始选择每天单元量布局组件及值
private void init() { selectDayUnitRelativeLayout = (RelativeLayout) findViewById(R.id.selectDayUnitRelativeLayout); dayUnitTextView = (TextView) findViewById(R.id.dayUnitTextView); dayUnitStr = ReciteConstant.DUNITCT_ITEMS_ARRAY[0]; dayUnitTextView.setText(dayUnitStr); }
c步骤2> 选择每天单词量布局点击监听
private void logic() { selectDayUnitRelativeLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { alertSelectDayUnit(); } }); }
c步骤3> 弹出的单选框选择每天单元量
private void alertSelectDayUnit() { new AlertDialog.Builder(context) .setTitle("请选择每天单元量") .setIcon(android.R.drawable.ic_dialog_info) .setSingleChoiceItems(ReciteConstant.DUNITCT_ITEMS_ARRAY, dayUnitSelectedIndex, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); dayUnitStr = ReciteConstant.DUNITCT_ITEMS_ARRAY[which]; dayUnitSelectedIndex = which; dayUnitTextView.setText(dayUnitStr); Toast.makeText(context, "每天单元量:" + dayUnitStr, Toast.LENGTH_LONG).show(); } } ) .setNegativeButton("取消", null) .show(); }
3> 创建学习计划确定按钮监听
private void logic() { confirmButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { if(validate()) { createStudyPlan(); } } }); }
4> 效验信息
在创建前需要进效验信息,也就是输入和选择项的信息的
这些信息将作为计划的一些属性
private boolean validate() { studyPlaname = studyNameEditText.getText().toString().trim(); if(studyPlaname == null || "".equals(studyPlaname)) { Toast.makeText(context, "学习名必须填写", Toast.LENGTH_LONG).show(); return false; } return true; }
5> 创建学习计划方法
因为是耗时操作,所以也需要在多线程完成
private void createStudyPlan() { createStudyPlanProgressDialog.setMessage("正在创建计划数据"); createStudyPlanProgressDialog.show(); Thread createStudyPlanThread = new Thread(new CreateStudyPlanThread()); createStudyPlanThread.start(); }
6> 创建学习计划线程
除了创建计划以外,还需要初始单词表数据,也就是将sdcard对应的单词书数据复制到了学习计划中
class CreateStudyPlanThread implements Runnable { public void run() { //创建计划 new StudyPlanManager().create( studyPlaname, wordBookname, Integer.parseInt(dayUnitStr)); //初始单词表数据 new WordManager().initData(studyPlaname, wordBookname);
SystemUtil.sleepvd(2000); myHandler.sendEmptyMessage(0); } }
创建计划功能后台模块讲解
创建计划功能调用了两个管理模块
一个是计划管理模块StudyPlanManager
一个单词管理模块WordManager
1> 计划管理的模块创建功能
也就是创建计划功能
public void create(String studyPlaname, String wordBookname, int dayUnit) { if(studyPlanDao == null) { studyPlanDao = new StudyPlanDao(); } //--------- // 创建学习计划对象 StudyPlan studyPlan = new StudyPlan(); studyPlan.name = studyPlaname; studyPlan.wordBookname = wordBookname; studyPlan.allWordCount = WordBookConstant.getWordCountFromWordBook(wordBookname); studyPlan.dayUnitCount = dayUnit; //总单元量(除不尽+1,最后一个单元少于70) studyPlan.allUnitCount = studyPlan.allWordCount % ReciteConstant.DUNITG_WORD_COUNT == 0 ? studyPlan.allWordCount / ReciteConstant.DUNITG_WORD_COUNT : studyPlan.allWordCount / ReciteConstant.DUNITG_WORD_COUNT + 1; //所有新单元耗时天数,不算复习(除不尽+1, 最后一天少于70个单词) studyPlan.needDayCount = studyPlan.allWordCount % (dayUnit * ReciteConstant.DUNITG_WORD_COUNT) == 0 ? studyPlan.allWordCount / (dayUnit * ReciteConstant.DUNITG_WORD_COUNT) : studyPlan.allWordCount / (dayUnit * ReciteConstant.DUNITG_WORD_COUNT) + 1; studyPlan.createDated = DateUtil.getDateString(DateUtil.FORMATE_DAY); //一些计划中背诵的属性 studyPlan.lastTodayTaskState = ReciteConstant.TODAYTASK_STUDY; Global.defaultReciteTimes = Integer.parseInt(ReciteConstant.RECTIMES_ITEMS_ARRAY[0]); studyPlan.lastReciteProgressStr = 0 + "/" + Global.defaultReciteTimes; studyPlan.lastUnitGroupIndex = 0; //--------- //--------- //添加数据 String spPathStr = PathConstant.STUPLAN_PATH + "sp_" + studyPlaname; // 创建学习计划文件 createStudyPlanFile(spPathStr); //添加数据到学习计划数据库中 studyPlanDao.add(studyPlan, spPathStr); //--------- }
2> 单词管理的的初始单词表数据
就是将sdcard对应的单词书数据复制到了学习计划中
调用了单词书的数据库操作以及单词的数据库操作,这里数据库操作都是本地的sqlite3
public void initData(String studyPlaname, String wordBookname) { if(wordDao == null) { wordDao = new WordDao(); } if(wordBookDao == null) { wordBookDao = new WordBookDao(); } List<String> wordStrList = wordBookDao.findWordBook(wordBookname); String pathStr = PathConstant.STUPLAN_PATH + "sp_" + studyPlaname; wordDao.initAddMoreUseTransaction(wordStrList, pathStr);
}
更多请自行下载源码解读
应用下载:请点击
源码下载:请点击
标签:
原文地址:http://www.cnblogs.com/vomzoo/p/5445758.html