Android Project Combat-recite the word dev02-create a plan implementation

Source: Internet
Author: User

This article explains

In this article, we will explain how to create a plan feature implementation.

The Create Schedule feature is in the Create plan interface.

In the createplanactivity.

In the background module only describes the management layer, other database operations, etc. please see for yourself

Effect

Execution flowchart

Create a Plan UI interface feature description

1> Banner Display Create schedule character

Hftitletextview = (TextView) Findviewbyid (R.id.hftitletextview); Hftitletextview.settext ("Create plan");

2> Create a fill for a schedule item

a Steps > Word title input operation, only need to display components and get components to

private void Init () {    Studynameedittext = (EditText) Findviewbyid (r.id.studynameedittext);}

  

b Steps 1> Initialization of selected word book related attributes and values

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 Steps 2> Select Word Book layout click to listen

private void Logic () {        Selectwordbookrelativelayout.setonclicklistener (new Onclicklistener () {            @Override Public            void OnClick (view view) {                alertselectworkbook ();            }        });}

b Steps 3> pop-up Radio box select Word Book

private void Alertselectworkbook () {       new Alertdialog.builder (context)        . Settitle ("Please select a book")        . SetIcon ( Android. R.drawable.ic_dialog_info)                        . Setsinglechoiceitems (Wordbookconstant.wdbk_cate_array, WordBookSelectedIndex,           New Dialoginterface.onclicklistener () {public             void OnClick (dialoginterface dialog, int which) {                
Wordbookname = Wordbookconstant.wdbk_cate_array[which]; Wordbookselectedindex = which; Wordbooknametextview.settext (wordbookname); Toast.maketext (Context, "Word book is:" + Wordbookname, Toast.length_long). Show (); } } ) . Setnegativebutton ("Cancel", null) . Show ();

  

C Steps 1> Initial selection per day unit volume layout components and values

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 Steps 2> Select daily Word volume layout Click to listen

private void Logic () {    Selectdayunitrelativelayout.setonclicklistener (new Onclicklistener () {            @Override Public            void OnClick (view view) {                alertselectdayunit ();            }    });}

C Steps 3> pop-up radio box select the unit amount per day

private void Alertselectdayunit () {        new Alertdialog.builder (context)         . Settitle ("Select unit per day")         . 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, "unit amount per day:" + Dayunitstr, Toast.length_long). Show ();             }           }         )         . Setnegativebutton ("Cancel", null)         . Show ();

3> Create a Learning Plan OK button listener

private void Logic () {    Confirmbutton.setonclicklistener (new Onclicklistener () {            @Override public            Void OnClick (view view) {                if (validate ()) {                    Createstudyplan ();}}        });}

  

4> Validation Information

Before you create, you need to enter the validation information, that is, the input and selection information

This information will be used as some of the properties of the plan

Private Boolean validate () {        studyplaname = Studynameedittext.gettext (). toString (). Trim ();        if (Studyplaname = = NULL | | ". Equals (Studyplaname)) {            Toast.maketext (context," Learning name must be filled in ", Toast.length_long). Show ();            return false;        }        return true;}

5> Create a Learning Plan method

Because it is a time-consuming operation, it also needs to be done in multithreading

private void Createstudyplan () {        createstudyplanprogressdialog.setmessage ("Planning data is being created");        Createstudyplanprogressdialog.show ();        Thread createstudyplanthread =            new Thread (new Createstudyplanthread ());        Createstudyplanthread.start ();}

6> Create a Learning Plan thread

In addition to creating a plan, you need the initial Word table data, which is the copy of the sdcard corresponding word book data into the Learning Plan.

Class Createstudyplanthread implements Runnable {public       void run () {           //create plan           new Studyplanmanager (). Create (                studyplaname, Wordbookname, Integer.parseint (DAYUNITSTR));           Initial Word table Data           new Wordmanager (). InitData (Studyplaname, wordbookname);
SYSTEMUTIL.SLEEPVD (+); Myhandler.sendemptymessage (0); } }

  

Create a planning feature backstage module explained

The Create Schedule feature calls two management modules

One is the Plan management module Studyplanmanager

A Word management module Wordmanager

1> module creation features for plan management

Which is to create a scheduling feature

public void Create (string studyplaname, string wordbookname, int dayunit) {if (Studyplandao = = null) {s        Tudyplandao = new Studyplandao ();        }//---------//Create Learning Plan object Studyplan Studyplan = new Studyplan ();        Studyplan.name = Studyplaname;        Studyplan.wordbookname = Wordbookname;        Studyplan.allwordcount = Wordbookconstant.getwordcountfromwordbook (wordbookname);        Studyplan.dayunitcount = Dayunit; Total unit volume (except for +1, last unit less than) Studyplan.allunitcount = studyplan.allwordcount% RECITECONSTANT.DUNITG                    _word_count = = 0? Studyplan.allwordcount/reciteconstant.dunitg_word_count:studyplan.allwordcount/reciteconstant.dun        Itg_word_count + 1; All new units take days, not review (except +1, last day less than 70 words) Studyplan.needdaycount = studyplan.allwordcount% (dayunit                    * reciteconstant.dunitg_word_count) = = 0? Studyplan.allwordcount/(Dayunit* Reciteconstant.dunitg_word_count): Studyplan.allwordcount/(Dayunit * reciteconstant.dunitg_word_co        UNT) + 1;               studyplan.createdated = dateutil.getdatestring (Dateutil.formate_day);               Some of the properties recited in the plan studyplan.lasttodaytaskstate = Reciteconstant.todaytask_study;        Global.defaultrecitetimes = Integer.parseint (reciteconstant.rectimes_items_array[0]);        STUDYPLAN.LASTRECITEPROGRESSSTR = 0 + "/" + global.defaultrecitetimes;        Studyplan.lastunitgroupindex = 0;               ---------//---------//Add data String sppathstr = Pathconstant.stuplan_path + "sp_" + studyplaname;        Create Study plan file Createstudyplanfile (SPPATHSTR);        Add data to the Learning Plan database in Studyplandao.add (Studyplan, SPPATHSTR); //---------}

 

2> Initial Word table data for Word management

is to copy the sdcard corresponding word book data into the Learning Plan.

Call the Word Book database operation and the word database operation, here the database operation is local 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);
}

  

More please download the Source code interpretation

Application Download: please click

Source Download: please click

Android Project Combat-recite the word dev02-create a plan implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.