Professional Documents
Culture Documents
LI CM N
Trong thi gian thc hin lun vn, di s hng dn ca Khoa Cng Ngh Thng Tin Trng i Hc S Phm Tp.HCM v c bit l s hng dn ca thy Trn Ngc Bo, chng em hon thnh lun vn vi thi gian nh d kin. C c kt qu y chng em xin chn thnh gi li cm n n : Thy Trn Ngc Bo Trng phng Cng Ngh Thng Tin Trng i hc S Phm Tp.HCM tn tnh hng dn, gip chng em nh hng v pht trin lun vn tt nghip. S gip v hng dn nhit tnh ca thy gip chng em cng c kin thc v hon thnh tt lun vn tt nghip. Chng em xin chn thnh cm n thy. Qu thy c Khoa Cng Ngh Thng Tin Trng i hc S Phm Tp.HCM ni ring v cc thy c Trng i Hc S Phm ni chung tn tnh hng dn dy bo, gip chng em trang b nhng kin thc qu bu trong sut thi gian hc tp v nghin cu. D rt c gng v lin tc nng cao kin thc, nhng ti vn khng th trnh nhng sai st v hn ch. Do chng em rt mong nhn c s thng cm v kin ch bo chng em c th hon thin nhng sai st m chng em mc phi. Mt ln na, chng em xin chn thnh cm n.
Nhm sinh vin thc hin L Anh Ton Trn Cng Minh
MC LC
Bng cc thut ng v cc t vit tt ........................................................................ 8 Danh mc cc bng biu........................................................................................... 9 Danh mc cc hnh nh .......................................................................................... 11 Li noi u ............................................................................................................. 14 PHN 1: TM HIU V K THUT LP TRNH TRN ANDROID ................ 16 1 Cc bc tin hnh lp trnh trong Android ............................................... 16 1.1. 1.2. 1.3. 1.4. 2 Java Runtime Environment (JRE) ............................................................ 16 Eclipse IDE.............................................................................................. 16 Android SDK ........................................................................................... 16 Android ADT........................................................................................... 17
K thut lp trnh vi cc iu khin .............................................................. 17 2.1. ListView .................................................................................................. 17 2.1.1. Yu cu t ra ..................................................................................... 17 2.1.2. Gii quyt ........................................................................................... 18 2.2. GridView ................................................................................................. 18 2.2.1. Yu cu t ra ..................................................................................... 18 2.2.2. Gii quyt ........................................................................................... 18 2.3. Spinner View, DatePicker ........................................................................ 19 2.3.1. Yu cu t ra ..................................................................................... 19 2.3.2. Gii quyt ........................................................................................... 19 2.4. TabHost View .......................................................................................... 20 2.4.1. Yu cu t ra ..................................................................................... 20 2.4.2. Gii quyt ........................................................................................... 21 2.5. Gallery v ImageView ............................................................................. 21 2.5.1. Yu cu t ra ..................................................................................... 21 2.5.2. Gii quyt ........................................................................................... 22 3
K thut lp trnh vi SQLite ......................................................................... 22 3.1. 3.2. Gii thiu................................................................................................. 22 V d minh ha ........................................................................................ 24
3.2.1. t vn ........................................................................................... 24 3.2.2. Gii quyt ........................................................................................... 25 4 K thut lp trnh vi Web Service ................................................................. 25 4.1. 4.2. Dng SOAP (Simple Object Access Protocol) ......................................... 25 Vi d minh ha ........................................................................................ 26
4.2.1. t vn ........................................................................................... 26 4.2.2. Gii quyt ........................................................................................... 28 5 Pht audio, video trong Android ..................................................................... 28 5.1. Gii thiu................................................................................................. 28
5.1.1. Pht audio ........................................................................................... 28 5.1.2 Pht video ............................................................................................ 30 5.2. Minh ha ................................................................................................. 31 5.2.1. Vn t ra ....................................................................................... 31 5.2.2. Gii quyt ........................................................................................... 31 PHN 2: XY DNG NG DNG TRA CU THNG TIN TU, XE ............. 32 6 Ki n truc ng du ng va c ta yu c u ............................................................. 32 6.1. 6.2 7 Ki n truc ng du ng .................................................................................. 32 Cc s c t yu cu .......................................................................... 33
7.1.1. Thc th Hang..................................................................................... 47 7.1.2. Thc th PhuongTien .......................................................................... 47 7.1.3. Thc th LoaiPhuongTien ................................................................... 47 7.1.4. Thc th Phim ..................................................................................... 48 7.1.5. Thc th HinhAnh............................................................................... 48 4
7.1.6. Thc th DiaDiem ............................................................................... 48 7.1.7. Thc th Tuyen ................................................................................... 48 7.1.8. Thc th TrungGian ............................................................................ 49 7.1.9. Thc th LoaiGhe ............................................................................... 49 7.1.10. Thc th Gia ..................................................................................... 49 7.1.11. Thc th DoiTuong ........................................................................... 50 7.1.12. Thc th KhuyenMai ........................................................................ 50 7.1.13. Mi kt hp ChiTietTuyen ................................................................ 50 7.1.14. Mi kt hp ChiTietViTri ................................................................. 51 7.2. M hnh vt l (PDM).............................................................................. 51
7.2.1. Bng Hang .......................................................................................... 53 7.2.2. Bng Phim .......................................................................................... 53 7.2.3. Bng LoaiPhuongTien......................................................................... 54 7.2.4. Bng ChiTietHang .............................................................................. 54 7.2.5. Bng PhuongTien ................................................................................ 54 7.2.6. Bng HinhAnh .................................................................................... 55 7.2.7. Bng KhuyenMai ................................................................................ 56 7.2.8. Bng Gia ............................................................................................. 56 7.2.9. Bng ChiTietViTri .............................................................................. 57 7.2.10. Bng LoaiGhe ................................................................................... 58 7.2.11. Bng Tuyn ....................................................................................... 58 7.2.12. Bng TrungGian ................................................................................ 59 7.2.13. Bng ChiTietTuyen ........................................................................... 60 7.2.14. Bng Nhom ....................................................................................... 60 7.2.15. Bng NguoiDung .............................................................................. 60 7.2.16. Bng ChucNang ................................................................................ 61 7.2.17. Bng ChiTietChucNang .................................................................... 61 7.3. Thit k giao din .................................................................................... 62 5
7.3.1. Giao din phn h tra cu trn nn web ............................................... 62 7.3.2. Giao din qun tr phn h web ........................................................... 67 7.3.3. Giao din phn h tra cu trn thit b di ng .................................... 99 8 Ci t .......................................................................................................... 109 8.1. 8.2. 8.3. 9 Ci t phn h qun tr web .................................................................. 109 Ci t phn h tra cu trn nn web ..................................................... 109 Ci t phn h tra cu trn mobile ........................................................ 110
Tng kt ....................................................................................................... 110 9.1. Kt lun ................................................................................................. 110 9.1.1. Nhng kt qu t c v mt l thuyt .......................................... 110 9.1.2. Nhng kt qu t c v mt ng dng ......................................... 110 9.2. Hng pht trin .................................................................................... 111
TI LIU THAM KHO .................................................................................... 112 PH LC: M NGUN PHN MINH HA K THUT ................................ 113 1 K thut lp trnh vi cc iu khin ............................................................ 113 1.1 ListView ................................................................................................ 113
1.1.1 Xy dng giao din ............................................................................ 113 1.1.2 Xy dng x l .................................................................................. 115 1.2 GridView ............................................................................................... 117
1.2.1 Xy dng giao din ............................................................................ 117 1.2.2 Xy dng x l .................................................................................. 118 1.3 Spinner View, DatePicker ...................................................................... 121
1.3.1 Xy dng giao din ............................................................................ 121 5.3.2. Xy dng x l ................................................................................. 123 1.4 TabHost View ........................................................................................ 126
1.4.1 Xy dng giao din ............................................................................ 126 1.4.2 Xy dng x l .................................................................................. 128 1.5 Gallery v ImageView .......................................................................... 128 6
1.5.1 Xy dng giao din ............................................................................ 128 1.5.2 Xy dng x l .................................................................................. 129 2 K thut lp trnh vi SQLite ....................................................................... 131 2.1 2.2 3. Xy dng giao din ................................................................................ 131 Xy dng x l ...................................................................................... 136
K thut lp trnh vi Web Service ............................................................... 144 3.1 3.2 Xy dng giao din ................................................................................ 144 Xy dng x l ...................................................................................... 148
4.
Demo lp trnh pht audio, video .................................................................. 153 4.1 4.2 Xy dng giao din ................................................................................ 153 Xy dng x l ...................................................................................... 155
Bng 7.18 - M t bng ChiTietHang ..................................................................... 54 Bng 7.19 - M t bng PhuongTien ..................................................................... 54 Bng 7.20 - M t bng HinhAnh ........................................................................... 55 Bng 7.21 - M t bng KhuyenMai ....................................................................... 56 Bng 7.22 - M t bng Gia.................................................................................... 56 Bng 7.23 - M t bng ChiTietViTri ..................................................................... 57 Bng 7.24 - M t bng LoaiGhe ............................................................................ 58 Bng 7.25 - M t bng Tuyen ............................................................................... 58 Bng 7.26 - M t bng TrungGian ........................................................................ 59 Bng 7.27 - M t bng ChiTietTuyen ................................................................... 60 Bng 7.28 - M t bng Nhom ............................................................................... 60 Bng 7.29 - M t bng NguoiDung ....................................................................... 60 Bng 7.30 - M t bng ChucNang......................................................................... 61 Bng 7.31 - M t bng ChiTietChucNang ............................................................. 61
10
Danh mc cc hnh nh
Hnh 2.1 - Giao din iu khin ListView .............................................................. 17 Hnh 2.2 - Giao din iu khin GridView ............................................................. 18 Hnh 2.3 - Giao din minh ha Spinner View va Datepicker ................................... 19 Hnh 2.4 - Giao din iu khin TabHost ............................................................... 20 Hnh 2.5 - Giao din iu khin Gallery v ImageView.......................................... 21 Hnh 3.1 - Giao din ng dng minh ha SQLite .................................................... 24 Hnh 4.1 - Minh ha kt qu sau khi gi web service .............................................. 27 Hnh 4.2 - M hnh kt ni gi Web Service va giao di n minh ho a........................ 27 Hnh 4.3 - Hnh minh ha vic chn th vin KSOAP2 vo ng dng .................... 28 Hnh 5.1 - Minh ha pht t p tin video v audio ..................................................... 31 Hnh 6.1 - Kin trc ng dng tra cu thng tin tu xe ........................................... 32 Hnh 6.2 - S use case ca ngi dng cui....................................................... 34 Hnh 6.3 - S use case ca ngi qun tr h thng tu, xe ................................ 38 Hnh 6.4 - Quy trnh x l nghip v tra cu gi tu, xe trn thit b di ng ........ 41 Hnh 6.5 - Quy trnh x l nghip v tra cu l trnh tu, xe trn thit b di ng .. 41 Hnh 6.6 - Quy trnh x l nghip v tra cu gi v tu, xe trn thit b di ng .... 42 Hnh 6.7 - Quy trnh x l nghip v tra cu trn nn web ..................................... 43 Hnh 6.8 - Quy trnh x l nghip v nhp liu trn web server ............................. 44 Hnh 6.9 - Quy trnh x l nghip v phn quyn .................................................. 45 Hnh 7.1 - S CDM ........................................................................................... 46 Hnh 7.2 - S vt l PDM .................................................................................. 52 Hnh 7.3 - Giao din trang tra cu .......................................................................... 62 Hnh 7.4 - Giao din kt qu khi khng cung cp loi phng tin v hng ........... 63 Hnh 7.5 - Giao din kt qu tra cu khi cung cp thng tin hng vn chuyn ........ 63 Hnh 7.6 - Giao din kt qu tra cu khi cung cp thng tin loi phng tin ......... 64 Hnh 7.7 - Giao din kt qu khi cung cp loi phng tin v hng ...................... 64 11
Hnh 7.8 - Giao din thng tin l trnh ca tuyn .................................................... 65 Hnh 7.9 - Giao din thng tin gi v trn cc trm ca tuyn ................................. 66 Hnh 7.10 - Giao din thng tin gi v gia cc trm ca tuyn .............................. 66 Hnh 7.11 - Giao din th hin hnh nh ca phng tin ....................................... 67 Hnh 7.12 - Giao din mn hnh ng nhp............................................................. 67 Hnh 7.13 - Activity biu din Use case ng nhp................................................. 68 Hnh 7.14 Giao din mn hnh chnh ca trang qun tr ....................................... 69 Hnh 7.15 - Giao din mn hnh qun l phng tin dnh cho nhn vin h thng 69 Hnh 7.16 - Activity biu din use case nhp liu ................................................... 70 Hnh 7.17 - Giao din mn hnh qun l phng tin cho cc i tng khc......... 71 Hnh 7.18 - Activity biu din use case nhp liu ................................................... 72 Hnh 7.19 - Giao din qun l tuyn i vi nhn vin nhp liu h thng ............. 73 Hnh 7.20 - Activity biu din use case nhp liu ................................................... 74 Hnh 7.21 - Giao din qun l tuyn i vi cc i tng khc ............................. 75 Hnh 7.22 - Activity biu din use case nhp liu ................................................... 76 Hnh 7.23 - Giao din qun l hng i vi nhn vin nhp liu h thng .............. 77 Hnh 7.24 - Activity biu din use case nhp liu ................................................... 78 Hnh 7.25 - Giao din qun l hng i vi cc i tng khc .............................. 79 Hnh 7.26 - Activity biu din use case nhp liu ................................................... 80 Hnh 7.27 - Giao din qun l ti khon i vi nhn vin nhp liu h thng........ 81 Hnh 7.28 - Activity biu din use case nhp liu ................................................... 82 Hnh 7.29 - Giao din qun l ti khon i vi cc nhm i tng khc ............. 83 Hnh 7.30 - Activity biu din use case nhp liu ................................................... 84 Hnh 7.31 - Giao din qun l nhm ngi dng .................................................... 85 Hnh 7.32 - Activity biu din use case nhp liu ................................................... 86 Hnh 7.33 - Giao din danh mc a im .............................................................. 87 Hnh 7.34 - Activity biu din use case nhp li ..................................................... 88 Hnh 7.35 - Giao din danh mc hnh nh i vi nhn vin h thng .................... 89 12
Hnh 7.36 - Activity biu din use case nhp liu ................................................... 90 Hnh 7.37 - Giao din danh mc hnh nh i vi cc i tng khc .................... 91 Hnh 7.38 - Activity biu din use case nhp liu ................................................... 92 Hnh 7.39 - Giao din danh mc phim i vi nhn vin h thng ......................... 93 Hnh 7.40 - Activity biu din use case nhp liu ................................................... 94 Hnh 7.41 - Giao din danh mc phim i vi cc i tng khc .......................... 95 Hnh 7.42 - Activity biu din use case nhp liu ................................................... 96 Hnh 7.43 - Giao din danh mc loi gh................................................................ 96 Hnh 7.44 - Giao din danh mc i tng ............................................................. 97 Hnh 7.45 - Giao din danh mc loi phng tin .................................................. 97 Hnh 7.46 - Giao din danh mc khuyn mi .......................................................... 98 Hnh 7.47 - Giao din danh mc nhm chc nng .................................................. 98 Hnh 7.48 - Giao din mn hnh chnh ng dng .................................................... 99 Hnh 7.49 - Giao din mn hnh lc s tra cu ..................................................... 99 Hnh 7.50 - Activity biu din use case lc s tra cu ........................................ 100 Hnh 7.51 - Giao din mn hnh Gii thiu ........................................................... 101 Hnh 7.52 Giao din mn hnh hng dn s dng ............................................ 101 Hnh 7.53 Giao din mn hnh tra cu ............................................................... 102 Hnh 7.54 - Activity biu din Use case tra cu tu, xe......................................... 103 Hnh 7.55 - Giao din mn hnh danh sch phng tin........................................ 104 Hnh 7.56 - Giao din mn hnh th hin gi chy tu, xe..................................... 104 Hnh 7.57 - Activity biu din Use case xem gi chy tu, xe .............................. 105 Hnh 7.58 - Giao din mn hnh th hin l trnh .................................................. 106 Hnh 7.59 - Activity biu din Use case xem l trnh tu, xe ................................ 106 Hnh 7.60 - Giao din mn hnh th hin gi v .................................................... 107 Hnh 7.61 - Activity biu din Use case xem gi v tu, xe .................................. 108 Hnh 7.62 - Giao din mn hnh th hin l trnh trn bn ................................ 109 13
Li noi u
Ngy nay khi cc thit b cm tay tr nn ph bin, cng nh s pht trin ln mnh ca cc h thng vin thng lm cho cc dch v phc v nhu cu con ngi trn thit b cm tay ngy cng ph bin. c bit l cc dch v tra cu trc tuyn trn thit b cm tay, n c d on l rt pht trin khi m cng ngh mng 3G ang c pht trin mt cch rng ri, em li cho ngi dng tc truyn ti d liu rt nhanh. Cng vi l s ra i ca h iu hnh m ngun m Android c kh nng ty bin cao, c th coi y l mt bc tin trong lnh vc cng ngh. Theo comScore, th trng in thoi thng minh M thi gian gn y c nhiu du hiu cho thy h iu hnh Android ca Google ch ng hon ton h iu hnh iOS ca Apple v BlackBerry ca RIM. Ch trong qu u tin ca nm 2011, c n 69,5 triu ngi M s dng loi in thoi ny, tng 13% so vi cuc kho st tng t kt thc vo thng 11/2010. 33% s ngi dng in thoi tui t 13 tr ln tham gia cuc kho st cho bit h thch h iu hnh Android, 28,9% thich cc dng in thoi BlackBerry ca RIM, trong khi ch c 25,2% ngi s dng chn cc sn phm ca Apple. Vi nhng con s ni ln s pht trin vt bc, tinh u vit v tim nng pht trin ca h iu hnh Android ln n mc no. Khi nhu cu thng tin ngy cng pht trin, ngi dng s mun truy cp hoc tm kim thng tin mi lc, mi ni. Khng phi lc no ngi dng cng c th s dng laptop hay desktop tm kim thng tin. Hn na, ngy nay in thoi thng minh y chc nng, cu hnh cao, c gi thnh r v ngy cng c ph bin. Do vic xy dng cc ng dng trn thit b di ng s tr thnh mt ngnh cng nghip ha hn s c tc pht trin nhanh trong nhng nm ti. Dn s trung bnh c nc nm 2011 c tnh 87,84 triu ngi (Tng cc Thng k), nhu cu i li vo cc dp l, tt thng rt ln. Do nhu cu thng tin v gi v 14
tu, xe thng rt ln nhng ngun thng tin cung cp li thng rt t. Hin nay trong nc cng c mt s ng dng tra cu nh thng tin cc tuyn xe but (ng dng VietBus) c xy dng ln p ng nhu cu i li vi xe but. Tuy nhin, cc ng dng tra cu thng tin v xe khch, tu la Vit Nam trn cc thit b di ng thng minh dng h iu hnh Android vn cha c quan tm v pht trin ng mc. V nhng l do trn m chng em quyt nh i su nghin cu, tm hiu k thut lp trnh trn Android xy dng mt ng dng tra cu thng tin v tu, xe trn thit b di ng s dng h iu hnh m ngun m Android. ti ca nhm ch yu hng n hai vn chinh sau y: Mt l, xy dng ng dng tra cu thng tin cc hng tu, xe trn Android c cc chc nng chinh sau: Cho php tra cu thng tin gi chy, l trnh, gi v vi im i v Cho php chia s thng tin tra cu thng qua cc ng dng nh Cho php xem li lc s cc tra cu gn y nht ca ngi dng im n do ngi dng cung cp. -
SMS, Facebook, Gmail. Hai l, xy dng mt web server h tr cho vic nhp liu cc thng tin v cc hng tu, xe. Bn cnh l vic h tr ly tin tnh t trang web dng HTML ca hng tu, xe. Lu n vn c trinh bay g m 2 ph n chinh: Ph n 1: gii thi u v m t s ky thu t l p trinh c ban trn Android Ph n 2: xy dng ng du ng tra cu thng tin tau , xe
M c du chung em a u t kha nhi u cng sc va thi gi vao lu n vn nay nhng ch c ch n cung khng trnh khoi nhng sai st. Chng em rt mong nhn c nhng ki n ong gop va s thng cam cua quy th y c . Xin chn thanh cam n. Anh Toan & Cng Minh 15
N i Dung Lu n Vn
PHN 1: TM HIU V K THUT LP TRNH TRN ANDROID
1 Cc bc tin hnh lp trnh trong Android
Khng ging nh iOS, SDK chy h iu hnh Android c th hot ng c trn hu ht cc nn tng t Windows, Linux v Mac. Do vy, hu ht cc h iu hnh v cu hnh my tnh hin nay u c th ti v v s dng c b cng c lp trnh lp trnh ny. Thm na, cc nn tng v cc b cng c lp trnh ca Android u min ph. Do cc nh pht trin c th ti v trc tip cc b cng c lp trnh ny trn trang ch ca ngi pht hnh. c th bt u lp trnh trn h iu hnh Android, mt s phn mm sau s cn phi c ci t :
L gi h tr lp trnh trn h iu hnh Android. Chng ta c th vo trang web : http://developer.android.com/sdk/index.html v ti v bn SDK ph hp cho mnh. Cng vic cn lm tip theo l gii nn tp tin va ti v vo trong mt th mc c nh (lu ng dn ca n) v tin hnh ci t..
2.2. GridView
2.2.1. Yu cu t ra
S dng iu khin GridView xy dng giao din mn hnh ca ng dng nh sau:
18
Bc 1: xy dng lp tha k t lp BaseAdapter v np chng cc hm getCount(), getItem(), getItemId(), getView() thc hin vic gn kt d liu n iu khin GridView. Bc 2: xy dng mt lp tha k t lp Activity hin th GridView. Thng qua hm setAdapter() d liu v hin th ln GridView. Ngoi ra, thit lp x l khi chn mt mc tin, ta thit lp setOnItemClickListener() cho GridView v hin thc hm onItemClick(). Chi tit xin xem thm trong phn Ph lc mc 1.2.
thc hin c yu cu trn, chng ta s thc hin theo cc bc chinh sau : Bc 1: nh ngha giao din cho mn hnh trong tp XML Bc 2: to lp k tha t lp Activity thit lp hin th v x l cho Spinner, DatePicker. Gn kt d liu ln iu khin Spinner bng cch to mt th hin ca lp ArrayAdapter, sau gi hm setAdapter() thc thi. hin th hp thoi DatePicker ta cn np chng hm onCreateDialog(). Thng tin ngy thng khi cp nht trong hp thoi c x l thng qua hm onDateSet(), tai y ta c th ly thng tin ngy thng c chn. Chi tit xin xem thm trong phn Ph lc mc 1.3
20
onUpgrade() c 3 tham s truyn vo ln lt l i tng thuc lp SQLiteDatabase, s ch phin bn c, s ch phin bn mi ca c s d liu, c dng cp nht c s d liu. getReadableDatabase() tr v mt i tng SQLiteDatabase, dng m mt c s d liu (ch cho php c, khng ghi). getWriteableDatabase() tr v mt i tng SQLiteDatabase, dng m mt c s d liu (cho php ghi). thc hin vic truy vn, thm, xa, sa d liu ta dng lp SQLiteDatabase. Mt s hm thng dng ca lp ny : Hm query() c 7 tham s ln lt v kt qu tr v l i tng Cursor. Ta cn dng mt s hm lt trn dng d liu nh moveToFirst() dch chuyn n dng u tin, cn moveToLast() n dng cui cng , moveToNext() n dng tip theo dng hin ti, moveToPrevious() n dng trc dng hin ti, getCount() ly s lng dng. Danh sach 7 tham s nh sau: cc ct. - String selection : iu kin lc. Nu null s ly tt c. - String[] selectionArgs : danh sch cc gi tr dng thay th ? trong tham s selection. - String groupBy: iu kin gom nhm, nh dng tng t nh GROUP BY trong SQL. - String having: iu kin lc cho cc dng khi gom nhm, nh dng tng t nh mnh HAVING trong SQL. - String orderBy: sp xp, nh dng tng t nh mnh ORDER BY trong SQL. Hm insert() c 3 tham s v gi tr tr v l m ca dng mi nht c chn, nu tht bi tr v -1. String table: bng cn chn d liu. String nullColumnHack : dng ti u, c th null . SQL khng String table: tn ca bng s c thc hin truy vn. String[] columns: danh sch cc ct cn ly. Nu null s ly tt c
cho php thm mt hng trng vo m khng bit t nht tn ca mt ct. Nu tham s 23
values l rng s khng c dng no c thm vo. Trng hp ny, ta c th gii quyt bng cch truyn tn mt ct c php null vo nullColumnHack. ContentValue values: gi tr dng cp {kha,gi tr}.
Hm update() c 4 tham s v gi tr tr v l s dng c cp nht c cc dng. String[] whereArgs: cc tham s trong whereClause. Hm delete() c 3 tham s v gi tr tr v l s dng c xa. String table: bng cn xa. String whereClause: null nu xa tt c cc dng. String[] whereArgs: cc tham s cho whereClause. String table: bng cn cp nht. ContentValues values: (column_name, value). String whereClause: iu kin where cp nht, null s cp nht tt
3.2. V d minh ha
3.2.1. t vn
Ta s xy dng mt v d minh ha cc thao tc truy vn, thm, xa, sa vi SQLite. Giao din n gin nh sau :
gian tn, tn phng thc dng, a ch URL ca Web Service. Ngoi ra, c mt tham s m rng khc cng quan trng khng km l SOAP_ACTION, n l s kt hp gia khng gian tn v tn phng thc bng cng thc sau: SOAP_ACTION = NAMESPACE + METHOD_NAME Cc bc sau s gip thc hin mt li gi Web Service vi KSOAP2 : Bc 1: to mt i tng SoapObject vi 2 tham s truyn vo l khng gian tn v tn phng thc (hm) ca dch v. Bc 2: truyn cc tham s cho phng thc ca Web Services (nu c) dng hm addProperty(). Hm ny c 2 tham i ln lt l tn bin cn truyn tham tr v gi tr ca n. Bc 3: to i tng SoapSerializationEnvelope ch nh cc thng tin khc nh: phin bn SOAP, Web Service c da trn .NET hay khng, thit lp u ra cho thng ip kt qu. Bc 4: to i tng AndroidHttpTransport, truyn vo a ch URL ca Web Service cn gi. Bc 5: thc hin li gi call() t i tng HttpTransportSE, vi 2 tham s truyn vo l SOAP_ACTION v i tng SoapSerializationEnvelope to. Bc 6:Nhn kt qu tr v thng qua i tng SoapSerializationEnvelope bng hm getResponse() khi kt qu tr v l mt kiu chui hay bng thuc tnh bodyIn khi kt qu tr v l mt kiu danh sch.
4.2. V d minh ha
4.2.1. t vn
Chng ta s to mt ng dng minh ha hin th chi tit l trnh tu la bng vic gi Web Service xy dng bng .NET (dng SOAP). Web Service ny c tham s u vo l m tuyn, im i, im n. Kt qu u ra vi thng tin gm thng tin chinh nh tn trm trn l trnh, thi gian i, thi gian n , c ly chng. V d kt qu gi Web Service vi m tuyn l 154, im i l Si Gn, im kt thc l Nha Trang dng nh sau:
26
Hnh 4.1 - Minh ha kt qu sau khi gi web service M hnh kt ni Web Service v giao din chng trnh n gin nh sau:
SQL Server
Hnh 4.3 - Hnh minh ha vic chn th vin KSOAP2 vo ng dng Bc 2: xy dng lp tha k t ListActivity hin th giao din mn hnh. Lp ny cng s hin thc giao din OnClickListener, np chng hm onClick() x l s kin khi ngi dng n vo nt thc hin gi Web Service ly thng tin chi tit v l trnh. Xin xem thm chi tit trong phn Ph lc mc 3.
pht tp tin audio, ta s dng lp MediaPlayer. Lp ny c th dng iu khin vic pht cc tp tin audio, video. Mt s phng thc thng dng ca lp MediaPlayer : video pht. MediaPlayer. prepare() v prepareAsync(): thao tc chun b cho vic pht audio, video dng ln lt cho trng hp ng b v bt ng b. setOnCompletionListener(): ng k x l mt s kin khi tp tin audio , video c pht hon thnh. setOnPreparedListener(): ng k x l mt s kin mt tp tin audi o , video c np vo v sn sng pht. setOnErrorListener(): ng k x l mt s kin khi c mt li xut hin trong qu trnh pht audio, video. pht mt t p tin audio, ta c th lm nh sau : To mt th hin ca lp MediaPlayer. Dng hm setDataSource() thit lp ng dn n tp tin audio cn pht. Gi ln lt hm prepare(), start() t i tng MediaPlayer bt u pht audio. 29 seekTo(): dng dch chuyn v tri pht ca audio, video. setMediaController(): thit lp i tng MediaController. setVideoPath(): thit lp ngun d liu phat video. setVideoURL(): thit lp ng dn URI phat video. start(): bt u pht audio, video. stop(): ngng pht audio, video. reset(): thit lp li i tng MediaPlayer trng thi cha khi to. release(): gii phng cc ti nguyn lin quan n i tng getDuration(): ly thi lng pht ca audio, video getCurrentPosition(): ly v tr (thi lng) ang pht ca audio, video pause(): tm dng pht audio, video resume(): pht li audio, video, sau khi tm dng. getVideoHeight(), getVideoWidth(): ly chiu cao v chiu rng ca
Ch : khi gi hm stop() dng vic pht, nhng sau mun pht li th phi gi ln lt cc hm reset(), prepare(), start().
5.2. Minh ha
5.2.1. Vn t ra
minh ha, chng ta s xy dng mt chng trnh cho php pht cc tp tin audio, video t th nh SD Card ca thit b di ng. Danh sch cc nh dng audio, video c Android h tr s c ti ln t th nh. Khi ngi dng chn bng cch n vo th bi ht s c pht. Giao din chng trnh n gin nh sau:
Kt qu tra cu
Ly d liu
Ngi qun tr
Kin trc h thng tra cu tu, xe gm : Phn h tra cu trn nn web : ngi dng thc hin vic tra cu thng tin tu, xe trn nn web ASP.NET. Phn h tra cu trn nn thit b di ng chy h iu hnh Android : ngi dng thc hin vic tra cu thng tin tu, xe trn thit b di ng chy h iu hnh Android. ng dng ny hot ng bng vic gi cc Web Service tng ng vi thng tin ngi dng cung cp thng qua mng Internet, sau thng tin chi tit v tu (xe) s c tr v cho ngi dng. Phn h qun tr trn web server ASP.NET : trong phn h ny, ngi qun tr h thng s qun l thng tin v tu, xe thng qua ng dng qun l trn nn web (ASP.NET). ng dng qun l ny truy xut c s d liu t h qun tr Microsoft SQL Server, thc hin cc thao tc ca ngi qun tr h thng. Ngoi vic nhp liu t web server th d liu cng s c ly t cc trang HTML ca mt s hng vn ti thng qua Window Service c lp lch thc hin theo nh k.
6.2 Cc s c t yu cu
6.2.1. S Use-case S use case ca ngi dng cui
33
<<include>>
Hnh 6.2 - S use case ca ngi dng cui Ngi dng s c cung cp cc thng tin v l trnh, gi i, n v tt c cc gi v trn tuyn tra cu. Ngoi ra, ngi dng cng c th chia s thng tin tra cu ca mnh ln trn qua cac ng du ng nh SMS , Gmail, Facebook bn b c bit. V ngi dng cng c th lu li lc s tra cu xem li bt c lc no khi cn thit m khng cn phi thc hin li vic tra cu. Mt tin ich khc l ngi dng c cung cp s in thoi v chc nng gi in thoi ngay trn ng dng thc hin cuc gi ti cc hng vn chuyn. c t cc use case ca ngi dng cui Bng 6.1 - c t use case tra cu gi tu, xe Use Case ID Use Case Name Actor UC 1 Tra cu gi tu, xe Ngi dng cui 34
Description
Cho php ngi dng xem chi tit gi tu, xe chy 1. Ngi dng cung cp cc thng tin tra cu: ni i, ni n, ngy tra cu, loi phng tin, hng 2. Danh sch cc phng tin thoa mn yu cu c lit k 3. Ngi dng chn phng tin mun i, thng tin chi tit v gi chy c hin th. Ngi dng khng cung cp thng tin hng, loi phng tin, danh sch phng tin ca tt c cc hng thoa yu cu c hin th. 1. H thng khng hin thdo xy ra li kt ni c s d liu 2. H thng hin th d liu sai do nhp liu khng ng 3. H thng khng hin th c do li ng truyn mng, h thng yu cu ngi dng thc hin li chc nng ny. Ngi dng cung cp cc thng tin u vo tra cu Chi tit gi chy ca phng tin c hin th Bng 6.2 - c t use case tra cu hnh trnh tu, xe
Action Steps
Extension Points
Exceptions
Pre-Conditions Post-Conditions
Use Case ID Use Case Name Actor Description Action Steps Extension Points
UC 2 Tra cu hnh trnh tu, xe Ngi dng cui Cho php ngi dng xem chi tit hnh trnh tu, xe 1. Ngi dng chn xem hnh trnh 2. H thng hin th thng tin chi tit v hnh trnh tu, xe 1. H thng khng hin th c do xy ra li kt ni c s d liu. 2. H thng khng hin th c do li ng truyn mng, h thng yu cu ngi dng kim tra li ng truyn mng. 35
Exceptions
Pre-Conditions Post-Conditions
Ngi dng thc hin xong tra cu gi tu, xe Thng tin chi tit hnh trnh c hin th. Bng 6.3 - c t use case tra cu gi v tu, xe
Use Case ID Use Case Name Actor Description Action Steps Extension Points
UC 3 Tra cu gi v tu, xe Ngi dng cui Cho php ngi dng xem chi tit gi v tu, xe 1. Ngi dng chn xem gi v tu, xe 2. Thng tin chi tit v gi v tu, xe c hin th
Exceptions
Pre-Conditions Post-Conditions
1. H thng khng hin th c do xy ra li kt ni c s d liu. 2. H thng khng hin th c do li ng truyn mng, h thng yu cu ngi dng kim tra li ng truyn mng 3. H thng hin th thng tin kt qu khng hp l do d liu b sai. Ngi dng thc hin xong tra cu gi tu, xe Thng tin chi tit gi v ca phng tin c hin th Bng 6.4 - c t use case gi t v tu, xe
UC 4 Gi t v tu, xe Ngi dng cui Cho php ngi dng gi in t v tu, xe 1. Ngi dng chn xem s in thoi t vv thc hin gi in thc hin t v tu, xe 2. Cuc gi i (t v tu, xe) c thc hin.
Action Steps
36
Ngi dng ch mun xem s in thoi t v m khng gi Khng th gi t v xe do: s in thoi khng hp l hay khng tn ti trong thc t Ngi dng thc hin xong tra cu gi v tu, xe Ngi dng thy s in thoi t v hoc cuc gi t v c thc hin Bng 6.5 - c t use case chia s thng tin kt qu tra cu
UC 5 Chia s thng tin kt qu tra cu (l trnh, gi v, gi chy) Ngi dng cui Cho php ngi dng chia s kt qu tra cu c 1. Ngi dng chn chc nng xem gi tu, xe 2. Chn chc nng chia s thng tin tra cu. 1. Khng th chia s thng tin do li ng truyn mng hoc thit b di ng khng c ng dng h tr
Exceptions
chia s 2. Thng tin chia s b thiu: do cha thi gian ly ht thng tin kt qu tra cu t Web Service. Ngi dng thc hin xong tra cu gi v tu, xe Thng tin c chia s Bng 6.6 - c t use case xem lc s tra cu
Pre-Conditions Post-Conditions
UC 6 Xem lc s tra cu 37
Ngi dng cui Cho php ngi dng xem li nhng tra cu thc hin
1. Ngi dng chn xem lc s tra cu. 2. Danh sch tra cu thc hin c hin th 3. Ngi dng chn xem chi tit thng tin kt qu tra cu c. Extension Points Ngi dng chia s thng tin tra cu Exceptions 1. Khng th chia s thng tin do li ng truyn mng hoc thit b di ng khng c ng dng h tr chia s 2. Chi tit thng tin tra cu b thiu: do cha thi gian ly ht thng tin kt qu tra cu t Web Service. Pre-Conditions Post-Conditions Ngi dng thc hin t nht mt ln tra cu Thng tin chi tit kt qu tra cu trc c hin th
Nhp liu
Xa
Sa
Ngi qun tr h thng v ngi qun tr ca hng vn chuyn s thc hin vic nhp d liu cho cc thng tin v tu, xe. Ngoi ra, qun tr vin cng c th thc hin vic phn quyn cho tng user trong h thng. Nhng trc khi lm cc vic th cc qun tr vin phi thc hin vic ng nhp vo h thng h thng xc nh v kim tra cc quyn i vi qun tr vin. c t cc use-case ca ngi qun tr h thng Bng 6.7 - c t use case ng nhp Use Case ID Use Case Name Actor Description UC 1 ng nhp Ngi qun tr Cho php ngi qun tr ng nhp qun tr h thng tu, xe Action Steps Extension Points Exceptions ng nhp khng thnh cng 1. Ti khon b kha 2. Nhp sai thng tin ti khon 3. Ti khon khng tn ti Ngi dng phi c ti khon 1. Ngi dng chn qun tr bt k chc nng no
Pre-Conditions Post-Conditions
Bng 6.8 - c t use case nhp liu Use Case ID Use Case Name Actor Description UC 2 Nhp liu Ngi qun tr Cho php ngi qun tr nhp liu thng tin cho h thng tu xe Action Steps 1. Ngi dng chn cc qun l cn nhp liu 39
2. Cung cp thng tin nhp liu 3. H thng kim tra quyn nhp liu 4. Bo nhp liu thnh cng Extension Points Exceptions Nhp liu khng thnh cng 1. Ngi dng khng cung cp y cc thng tin bt buc 2. Ngi dng khng c quyn nhp liu trn qun l Ngi dng phi c cp quyn thc hin chc nng . Ngi dng phi ng nhp Post-Conditions
Pre-Conditions
Bng 6.9 - c t use case phn quyn Use Case ID Use Case Name Actor Description UC 3 Phn quyn Ngi qun tr Cho php ngi qun tr phn quyn cho cc ngi dng khc thc hin 1 s chc nng nht nh Action Steps 1. Qun tr chn ngi dng cn cp quyn 2. Chn chc nng cn phn quyn 3. Chn thao tc cn phn quyn Ngi phn quyn cp quyn qu vi quyn ca mnh Ngi dng phi tn ti. Ngi qun tr phi c quyn cp quyn. Ngi dng phi thc hin ng nhp. Post-Conditions Cp quyn thnh cng
40
6.2.2. S x l nghip v BPM H thng tra cu thng tin tu, xe gm cc quy trnh x l nghip v sau: Quy trnh x l nghip v tra cu gi tu, xe trn thit b di ng :
Ngi dng cui H thng (Trn thit b di ng) Web Services Database
Tra cu gi tu xe
Chn tra cu tu xe
Chi tit gi tu xe
Chi tit gi tu xe
Chi tit gi tu xe
Hnh 6.4 - Quy trnh x l nghip v tra cu gi tu, xe trn thit b di ng Thng tin tra cu gm : im i, im n, loi phng tin, hng. Chi tit gi tu xe: gi i, gi n, thi gian tuyn (nu c) Quy trnh x l nghip v tra cu l trnh tu, xe trn thit b di ng
Ngi dng cui H thng (Trn thit b di ng) Web Services Truy xut d liu hnh trnh tu xe Database
Tra cu gi tu xe
Chi tit gi tu xe
Chi tit gi tu xe
D liu tu xe
Hnh 6.5 - Quy trnh x l nghip v tra cu l trnh tu, xe trn thit b di ng
41
Chi tit gi tu xe: gi i, gi n, thi gian tuyn (nu c) Chi tit hnh trnh tu xe: chi tit cc thng tin cc trm trn hnh trnh gm thi gian n (thi gian i), c ly. Quy trnh x l nghip v tra cu gi v tu, xe trn thit b di ng
Ngi dng cui H thng (Trn thit b di ng) Web Services Database
Chi tit gi tu xe
Tra cu gi v tu xe
Chi tit gi tu xe
Tra cu gi tu xe
Gi web services ly gi v tu xe
Chi tit gi tu xe
Chi tit gi v tu xe
Gi t v tu xe
Chi tit gi v tu xe
Hnh 6.6 - Quy trnh x l nghip v tra cu gi v tu, xe trn thit b di ng Chi tit gi tu gm: gi i, gi n, thi gian hnh trnh. Chi tit gi v tu gm: cc loi gh v gi bn tng ng.
42
Chn li im i v im n
Kim tra im i v n
L trnh
Gi v
Hnh 6.7 - Quy trnh x l nghip v tra cu trn nn web Thng tin tra cu gm : im i, im n, loi phng tin, hng. Khi xem chi tit th s hin ra : chi tit gi tu xe: gi i, gi n, thi gian tuyn (nu c), gi v trm, gi v trung gian, hnh nh ca phng tin.
43
Vo Trang ch
Tip nhn yu cu
Thao tc
Tip nhn yu cu 2
Hin th thng bo
[Business Error]
X l cc thao tc va chn
CSDL_QLTauXe
Hnh 6.8 - Quy trnh x l nghip v nhp liu trn web server 44
Ngi qun tr cung cp cc thng tin nhp d liu vo c s d liu. i vi nhn vin nhp liu ca cc hng vn chuyn th ch c quyn qun l cc thng tin ca hng mnh. i vi nhn vin nhp liu h thng s c qun l cc thng tin ca tt c cc hng. Quy trnh x l nghip v phn quyn
Nhn vin nhp liu h thng H thng (trn phn h web server) Database
Kim tra chc nng tn ti trong CTTK Thm mi chi tit ti khon
CSDL QLTauXe
Hnh 6.9 - Quy trnh x l nghip v phn quyn Ngi qun tr h thng thc hin chc nng phn quyn cho tng ngi dng trong h thng. Ngoi ra mt s ngi dng c bit ca hng cng c quyn phn quyn cho cc ti khon thuc hng ca mnh.
45
Hang MaHang <pi> Variable characters (5) <M> TenHang Variable characters (100) SDT Variable characters (12) DiaChi Variable characters (100) GioiThieu Text MienGiam Text Identifier_1 <pi> 0,n 1,n PhuongTien MaPhuongTien <pi> Variable characters (5) TenPhuongTien Variable characters (50) Identifier_1 <pi>
KhuyenMai MaKM <pi> Short integer ThongTinKM Text NgayBD Date & Time NgayKT Date & Time TieuDe Variable characters (100) Identifier_1 <pi> ChiTietTuyen ThoiGianDi Variable characters (80) ThoiGianDen Variable characters (80) ThoiGianTuyen Variable characters (50) ChiTietViTri Tang Byte ViTri Variable characters (10) SoLuong Integer ... 1,1 DoiTuong MaDoiTuong <pi> Variable characters (2) TenDoiTuong Variable characters (15) Identifier_1 <pi> Gia MaGia <pi> Long integer <M> NgayHL Date & Time GiaVe Float Identifier_1 <pi> 0,n Tuyen MaTuyen <pi> Integer <M> SDTDatVe Variable characters (12) TramDungChan Variable characters (200) Identifier_1 <pi>
1,n TrungGian DiaDiem MaDiaDiem <pi> Variable characters (5) TenDiaDiem Variable characters (100) Identifier_1 <pi> MaTrungGian <pi> Long integer <M> ThoiGianDi Variable characters (80) ThoiGianDen Variable characters (80) CuLy Variable characters (20) ThuTu Byte Identifier_1 <pi> LoaiGhe MaLoaiGhe <pi> Variable characters (5) TenLoaiGhe Variable characters (30) Identifier_1 <pi>
Kiu variable character variable character variable character variable character text
Key x
Not Din gii null x M hng x Tn hng S in thoi ca hng a ch ca hng Gii thiu m t v hng
Kch thc 5 50
Key x
Kch thc 20
Key x
Not Din gii null x M loi phng tin x Tn loi phng tin
47
Key x
Key x
Key x
Key x
Kiu long integer variable character variable character variable character byte
Kch thc 5 30 30 20
Key x
Not Din gii null x M trung gian x Thi gian i Thi gian n C ly x S th t trm
Kch thc 5 30
Key x
Kch thc
Key x
Kch thc 2 15
Key x
Kch thc
Key x
100
Not Din gii null x M khuyn mi x Thng tin khuyn mi x Ngy bt u khuyn mi x Ngy kt thc khuyn mi Tiu ca tin khuyn mi
7.1.13. Mi kt hp ChiTietTuyen
Bng 7.13 - M t thc th ChiTietTuyen 50
Kch thc 80 80 50
Key
Not Din gii null x Thi gian i Thi gian n Thi gian tuyn
7.1.14. Mi kt hp ChiTietViTri
Bng 7.14 - M t thc th ChiTietViTri
M t : cha thng tin chi tit v tuyn
Kch thc 10
Key
51
HinhAnh MaHinhAnh MaPhuongTien DuongDan MoTa integer <pk> varchar(5) <fk> varchar(100) ntext
ChiTietHang MaLoaiPhuongTien tinyint <pk,fk> MaHang varchar(5) <pk> PhuongTien MaPhuongTien MaHang MaLoaiPhuongTien TenPhuongTien Nhom MaNhom smallint <pk> TenNhom varchar(20) varchar(5) <pk> varchar(5) <fk1> tinyint <fk2> nvarchar(50)
Hang MaHang MaLoaiPhuongTien TenHang SDT DiaChi GioiThieu MienGiam varchar(5) <pk,fk> tinyint <fk> nvarchar(100) varchar(12) nvarchar(100) ntext ntext NguoiDung MaND MaHang MaNhom TenDangNhap MatKhau GioiTinh TinhTrang int <pk> varchar(5) <fk1> smallint <fk2> varchar(30) varchar(50) bit bit
KhuyenMai MaKM MaHang ThongTinKM NgayBD NgayKT TieuDe ... smallint <pk> varchar(5) <fk> ntext datetime datetime varchar(100)
ThaoTac MaThaoTac tinyint <pk> TenThaoTac nvarchar(50) DiaDiem MaDiaDiem varchar(5) <pk> TenDiaDiem nvarchar(100)
ChucNang MaChucNang tinyint <pk> TenChucNang nvarchar(50) ChiTietTuyen MaPhuongTien MaTuyen ThoiGianDi ThoiGianDen ThoiGianTuyen varchar(5) <pk,fk1> integer <pk,fk2> nvarchar(100) nvarchar(100) nvarchar(50)
TrungGian MaTrungGian MaTuyen MaDiaDiem ThoiGianDi ThoiGianDen CuLy ThuTu integer <pk> integer <fk1> varchar(5) <fk2> varchar(30) varchar(30) varchar(20) tinyint
Gia MaGia TrungGianKH TrungGianKT MaDoiTuong MaTG NgayHL GiaVe bigint integer integer varchar(2) integer datetime float <pk> <fk2> <fk1> <fk3> <fk4>
Tuyen MaTuyen DiemKhoiHanh DiemKetThuc SDTDatVe TrungGian TramDungChan integer <pk> varchar(5) <fk1> varchar(5) <fk2> varchar(12) varchar(10) nvarchar(200) ChiTietViTri
53
54
M t : Bng PhuongTien cha cc thng tin c th v phng tin Thuc tnh Kiu DL di MaPhuongTien MaHang MaLoaiPhuongTien TenPhuongTien varchar varchar tinyint nvarchar 50 5 5 x x x x x x x M phng tin M hng M loi phng tin Tn phng tin P F Not null Din gii
55
56
M t : Bng Gia cha thng tin c th v gi v Thuc tnh Kiu DL di MaGia TrungGianKH bigint integer x x P F Not null x M gi M im khi hnh trm trung gian TrungGianKT integer x M im kt thc trm trung gian MaDoiTuong MaTG varchar integer 2 x x x M i tng M im trung gian c p dng gi v NgayHL datetime x Ngy gi v c hiu lc p dng GiaVe float x Gi v Din gii
57
M t : Bng ChiTietViTri cha cc thng tin c th v v tr gh ca phng tin Thuc tnh Kiu DL di MaPhuongTien MaLoaiGhe MaGia Tang ViTri SoLuong varchar varchar bigint tinyint nvarchar integer 10 5 5 x x x x x x P F Not null x x x x M phng tin M loi gh M gi Tng V tr S lng Din gii
58
M t : Bng Tuyen cha thng tin c th v tuyn Thuc tnh Kiu DL di MaTuyen DiemKhoiHanh DiemKetThuc SDTDatVe TramDungChan integer varchar varchar varchar nvarchar 5 5 12 200 x x x P F Not null x x x M tuyn im khi hnh im kt thc S in thoi t v Trm dng chn ca tuyn Din gii
59
60
M t : Bng NguoiDung cha thng tin v ngi dng Thuc tnh Kiu DL di MaND MaHang MaNhom TenDangNhap MatKhau GioiTinh TinhTrang integer varchar smallint varchar varchar bit bit x 30 50 20 x x x P F Not null x x x x x M ngi dng M hng M nhm Tn ng nhp Mt khu Gii tnh Tnh trng Din gii
61
M t : Bng ChiTietChucNang cha thng tin c th v cc chc nng Thuc tnh Kiu DL di MaND MaChucNang integer tinyint x x x x P F Not null x x M ngi dng M chc nng Din gii
Hnh 7.3 - Giao din trang tra cu Ngi dng s cung cp cc tiu ch tra cu nh loi phng tin, hng vn chuyn, im khi hnh, im n m mnh mong mun. Ngi dng cn cung cp thng tin y kt qu tr v c th c tt nht vi nhu cu ngi dng. Ty theo nhu cu m ngi dng c th khng cung cp mt trong cc tiu chi . Vi tng trng hp khng cung cp cc tiu ch th kt qu khi hin th cng s c trnh by khc nhau cho ngi dng d theo di nht v chn c tuyn nh mong mun. 62
7.3.1.2.
Khi ngi dng khng cung cp thng tin loi phng tin v hng vn chuyn.
Hnh 7.4 - Giao din kt qu khi khng cung cp loi phng tin v hng Khi ngi dng khng cung cp thng tin v loi phng tin v hng vn chuyn th mc nh thng tin v loi phng tin v hng vn chuyn s c trnh by gip cho ngi dng d theo di v tm c tuyn mnh mong mun. Ngi dng cung cp thng tin hng vn chuyn nhng khng cung cp thng tin loi phng tin.
Hnh 7.5 - Giao din kt qu tra cu khi cung cp thng tin hng vn chuyn 63
Khi ngi dng cung cp thng tin v hng vn chuyn nhng khng cung cp thng tin v loi phng tin th mc nh thng tin v loi phng tin s c trnh by gip cho ngi dng d theo di v tm c tuyn mnh mong mun. Ngi dng cung cp thng tin loi phng tin nhng khng cung cp thng tin hng vn chuyn
Hnh 7.6 - Giao din kt qu tra cu khi cung cp thng tin loi phng tin Khi ngi dng cung cp thng tin v loi phng tin vn chuyn nhng khng cung cp thng tin v hng vn chuyn th mc nh thng tin v hng vn chuyn s c trnh by gip cho ngi dng d theo di v tm c tuyn mnh mong mun. Ngi dng cung cp thng tin loi phng tin v thng tin hng vn chuyn
Hnh 7.7 - Giao din kt qu khi cung cp loi phng tin v hng 64
Khi ngi dng cung cp thng tin v loi phng tin v hng vn chuyn th mc nh thng tin v loi phng tin v hng vn chuyn s khng c trnh by gip cho ngi dng d theo di v tm c tuyn mnh mong mun. 7.3.1.3. Giao din kt qu chi tit Thng tin v l trnh ca tuyn
Hnh 7.8 - Giao din thng tin l trnh ca tuyn y s hin th cc thng tin tng qut ca tuyn v l trnh cc trm m tuyn s i qua. Gi v n cc trm
65
Hnh 7.9 - Giao din thng tin gi v trn cc trm ca tuyn y s hin th gi v n tng trm trong l trnh tuyn s i qua. Gi v i gia cc trm
Hnh 7.10 - Giao din thng tin gi v gia cc trm ca tuyn y s hin th gi v i gia hai trm trung gian.
66
Hnh 7.11 - Giao din th hin hnh nh ca phng tin y s hin th hnh nh ca phng tin m ngi dng chn khi tra cu.
Mun vo c phn h qun tr thng tin tu, xe ngi dng phi ng nhp. Nu ngi dng cha ng nhp vo h thng m vn mun truy cp vo cc trang web h thng th h thng s t ng chuyn v trang ng nhp ny. Ni cch khc ngha l nu khng c ti khon th ngi dng khng th truy cp vo h thng. V vi mi nhm quyn khc nhau khi ng nhp vo h thng s c s dng cc chc nng khc nhau. Ring ngi dng Super Admin th c ton quyn s dng cc chc nng trong h thng.
ng nhp
Thng bo li ng nhp
[ NO ] Kim tra hp l
68
Hnh 7.14 Giao din mn hnh chnh ca trang qun tr Sau khi ng nhp thnh cng th h thng s t ng chuyn sang trang ch. Trang ch ca h thng s qun l cc thnh phn nh sau: phng tin, tuyn vn chuyn, hng vn chuyn, ti khon, nhm ngi dng 7.3.2.2. Qun l phng tin Qun l phng tin dnh cho nhn vin nhp liu h thng :
Hnh 7.15 - Giao din mn hnh qun l phng tin dnh cho nhn vin h thng 69
trang qun l phng tin dnh cho nhm ny, ngi dng s c chn mt hng mun xem t danh sch cc hng hin c. Ngi dng thuc nhm ny c ton quyn thm mi, xa hoc cp nht phng tin ca bt k 1 hng vn chuyn hin c no.
Ly DS Hng
[Success]
Chuyn qua trang cp nht Phng Tin Trang thm mi Phng Tin
Hnh 7.17 - Giao din mn hnh qun l phng tin cho cc i tng khc trang qun l phng tin dnh cho cc nhm khc, thng tin phng tin s c trnh by theo danh sch cc phng tin thuc hng vn chuyn m ngi dng i din. Vi nhm ny th ngi dng ch c th thm mi, xo, hoc sa thng tin cho cc phng tin thuc hng mnh i din.
71
Chuyn qua trang cp nht Phng Tin Trang thm mi Phng Tin
Hnh 7.18 - Activity biu din use case nhp liu 7.3.2.3. Qun l tuyn vn chuyn Qun l tuyn vn chuyn i vi nhn vin nhp liu h thng
72
Hnh 7.19 - Giao din qun l tuyn i vi nhn vin nhp liu h thng trang qun l tuyn dnh cho nhm ny, ngi dng s c chn mt hng mun xem t danh sch cc hng hin c. Ngi dng thuc nhm ny c ton quyn thm mi, xa hoc cp nht tuyn ca bt k m t hng vn chuyn hin c no.
73
Ly DS Hng
[Success]
Chn Xa Tuyn
Thm Trm
Thm Gi v trm
74
Hnh 7.21 - Giao din qun l tuyn i vi cc i tng khc trang qun l tuyn dnh cho cc nhm khc, thng tin tuyn s c trnh by theo danh sch cc tuyn thuc hng vn chuyn m ngi dng i din. Vi nhm ny th ngi dng ch c th thm mi, xo, hoc sa thng tin cho cc tuyn thuc hng mnh i din.
75
Mn hnh Qun l Tuyn (sn sng) [Exception] C Tuyn Thng bo cha c Tuyn
[Success] Hin th Danh sch Tuyn thuc hng ln mn hnh Hin th Nt Thm mi Tuyn
Chn Xa Tuyn
Thm Trm
Thm Gi v trm
7.3.2.4.
Hnh 7.23 - Giao din qun l hng i vi nhn vin nhp liu h thng chc nng qun l ny, i vi nhn vin nhp liu h thng s c thc hin cc thao tc thm, xa, sa i vi tt c cc hng hin c.
77
Chn Xa Hng
78
i vi cc ti khon khc
Hnh 7.25 - Giao din qun l hng i vi cc i tng khc Mi hng s c chnh sa thng tin ca hng mnh.
79
Chn Xa Hng
80
7.3.2.5.
Qun l Ti khon
Hnh 7.27 - Giao din qun l ti khon i vi nhn vin nhp liu h thng Vi nhm ti khon ny th s c thao tc ton b thm mi, xa, sa v cp quyn cho ti khon.
81
Ly DS Nhm
C Ti khon
[Success] Hin th Danh sch Ti khon thuc nhm ln mn hnh Hin th Nt Thm mi Ti khon
Chn Xa Ti khon
82
Hnh 7.29 - Giao din qun l ti khon i vi cc nhm i tng khc i vi cc nhm ti khon khc th s ch hin th nhng ti khon ca hng m thi.
83
Chn Xa Ti khon
84
7.3.2.6.
Hnh 7.31 - Giao din qun l nhm ngi dng i vi qun l ny th ch c nhm nhn vin nhp liu h thng mi c th thc hin cc thao tc thm mi, xa, sa c.
85
Chn Xa Nhm
Thm Thao tc
86
7.3.2.7.
Danh mc a im
Hnh 7.33 - Giao din danh mc a im i vi danh mc ny vic thao tc s c phn chia nh sau : Nhn vin nhp liu s c ton quyn thm mi, xa, sa. Cc nhm khc s ch c quyn thm mi m thi.
87
C a im
Hin th Nt Thm mi a im
Chn Xa a im
Chn cp nht a im
Chn thm mi a im
7.3.2.8.
Danh mc hnh nh
Hnh 7.35 - Giao din danh mc hnh nh i vi nhn vin h thng i vi nhm ti khon ny th khi chn danh mc hnh nh th danh sch phng tin s bao gm tt c cc phng tin ca tt c cc hng.
89
Ly DS Phng Tin
Mn hnh Danh mc Hnh nh (sn sng) [Exception] C Hnh nh Thng bo cha c Hnh nh
[Success]
Chn Xa Hnh nh
Hnh 7.36 - Activity biu din use case nhp liu Danh mc hnh nh i vi cc nhm ti khon khc
90
Hnh 7.37 - Giao din danh mc hnh nh i vi cc i tng khc i vi nhm ti khon ny th khi chn danh mc hnh nh th danh sch phng tin s bao gm tt c cc phng tin ca hng .
91
[Success]
Chn Xa Hnh nh
92
7.3.2.9.
Danh mc phim
Hnh 7.39 - Giao din danh mc phim i vi nhn vin h thng i vi nhm ti khon ny th khi chn danh mc phim s phi chn hng xem c cc phim ca hng .
93
Ly DS Hng
C Phim
[Success]
Chn Xa Phim
94
Hnh 7.41 - Giao din danh mc phim i vi cc i tng khc i vi nhm ti khon ny th khi chn danh mc phim hin ra tt c cc phim hng m ti khon thuc.
95
[Success]
Chn Xa Phim
Hnh 7.42 - Activity biu din use case nhp liu 7.3.2.10. Danh mc loi gh
i vi danh mc ny vic thao tc s c phn chia nh sau : Nhn vin nhp liu s c ton quyn thm mi, xa, sa. Cc nhm khc s ch c quyn thm mi m thi. X l tng t nh danh mc a im. 7.3.2.11. Danh mc i tng
Hnh 7.44 - Giao din danh mc i tng i vi danh mc ny vic thao tc s c phn chia nh sau : Nhn vin nhp liu s c ton quyn thm mi, xa, sa. Cc nhm khc s ch c quyn thm mi m thi. X l tng t nh danh mc a im. 7.3.2.12. Danh mc loi phng tin
i vi danh mc ny vic thao tc s c phn chia nh sau : Nhn vin nhp liu s c ton quyn thm mi, xa, sa. Cc nhm khc s ch c quyn thm mi m thi. X l tng t nh danh mc a im. 7.3.2.13. Danh mc khuyn mi
Hnh 7.46 - Giao din danh mc khuyn mi i vi danh mc ny vic thao tc s c phn chia nh sau : Nhn vin nhp liu s c ton quyn thm mi, xa, sa. Cc nhm khc s ch c quyn thm mi m thi. X l tng t nh danh mc a im. 7.3.2.14. Danh mc nhm chc nng
i vi danh mc ny th ch c nhm nhn vin nhp liu h thng mi c quyn thao tc. X l tng t nh danh mc a im .
Hnh 7.48 - Giao din mn hnh chnh ng dng Mn hnh chnh ng dng gm mt cc chc nng nh tra cu, lc s tra cu, hng dn s dng, gii thiu v ng dng. 7.3.3.2. Mn hnh lc s tra cu
Mn hnh lc s tra cu hin th 10 danh sch tra cu gn y nht ca ngi dng. Cc tra cu mi nht s c hin th phia trn cng. Trong mn hnh ny, ngi dng cng c th chia s thng tin tra cu thng qua cc ng dng nh SMS, Facebook, Gmail m thit b h tr, cng nh xem thng tin chi tit kt qu tra cu, gi in t v.
Chn l c s tra cu
Chi a s thng ti n
Hnh 7.50 - Activity biu din use case lc s tra cu 7.3.3.3. Mn hnh gii thiu
100
Hnh 7.51 - Giao din mn hnh Gii thiu Mn hnh trn gii thiu thng tin v ng dng cng nh cc chc nng chinh m ng dng h tr. 7.3.3.4. Mn hnh hng dn s dng
Hnh 7.52 Giao din mn hnh hng dn s dng Mn hnh trn cung cp mt s thng tin hng dn s dng cho ng dng.
101
7.3.3.5.
Mn hnh tra cu
Hnh 7.53 Giao din mn hnh tra cu Ngi dng cung cp thng tin u vo nh im i, im n, loi phng tin (khng bt buc), hng (khng bt buc), ngy tra cu sau thc hin tra cu, mn hnh danh sch cc phng tin thoa mn s c hin th.
102
Tra cu
Xem khuyn mi
103
Hnh 7.55 - Giao din mn hnh danh sch phng tin Tip theo ngi dng chn mt phng tin mun i, thng tin v gi chy (thi gian i, thi gian n) cng nh thng tin hng s c hin th.
Tra cu
Xem khuyn mi
Hnh 7.57 - Activity biu din Use case xem gi chy tu, xe 7.3.3.6. Mn hnh th hin l trnh
105
Hnh 7.58 - Giao din mn hnh th hin l trnh xem thng tin v l trnh, ngi dng chn chc nng l trnh. Thng tin chi tit v l trnh s c hin th.
T ra cu gi chy tu/xe
Chn phng ti n
Hnh 7.59 - Activity biu din Use case xem l trnh tu, xe 106
7.3.3.7.
Mn hnh th hin gi v
Hnh 7.60 - Giao din mn hnh th hin gi v xem thng tin v gi v, ngi dng chn chc nng xem gi v. Thng tin chi tit v gi v s c hin th. mn hnh ny, ngi dng c th chn s lng tng loi v mun i, ng dng cho php tnh tng s tin tng ng. Bn cnh ngi dng cng c th xem s in thoi t v hoc gi in t v, hnh nh ca phng tin.
107
Chn phng ti n
Ly thng ti n gi v
Gi t v
T nh ti n vi s l ng v chn
C s t v
[Excepti on]
T hng bo
[Success]
Gi i n
108
7.3.3.8.
Hnh 7.62 - Giao din mn hnh th hin l trnh trn bn Mn hnh ny th hin l trnh t im khi hnh n im kt thc chuyn i trn bn Google Map km khong cch tng ng.
8 Ci t
8.1. Ci t phn h qun tr web
Nn tng pht trin : .NET Framework 4.0. Cng c pht trin : Microsoft Visual Studio 2010 phin bn Ultimate. Th vin b sung : Ajax Control Toolkit, FCK editor, FFMpeg C s d liu : SQL Server 2008. Host : Window.
Cng c pht trin : Microsoft Visual Studio 2010 phin bn Ultimate Th vin b sung : Ajax Control Toolkit C s d liu : SQL Server 2008 Host : Window.
9 Tng kt
9.1. Kt lun
9.1.1. Nhng kt qu t c v mt l thuyt
Cng c l thuyt v cng ngh phn mm, kin thc v lp trnh web ASP.NET. Nm vng kin thc v kin trc v cch pht trin ng dng trn Android. Hiu thm v cch s dng HTML, CSS, JAVASCRIPT trong vic xy dng ng dng web.
Cho phep xem thng tin hng tu, xe va hinh anh phng ti n Tich hp bn Google Map vo ng dng H tr tinh toan t ng s ti n ng cac loa i gia ve ngi dung cho n va
gi in t v tu, xe. Xy dng mt server h tr nhp liu cc thng tin v cc hng tu, xe h tr phn quyn theo nhm v chc nng. H tr ly tin tnh t trang web dng HTML ca hng Thu n Thao . Bn cnh , ngi dng c th tra cu thng tin tu, xe trn nn web (ASP.NET).
111
112
113
android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dip" > <ImageView android:id="@+id/imgLogo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerInParent="true" android:scaleType="center" > </ImageView> <TextView android:id="@+id/txtTenDiaDiem" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="2dip" android:layout_toRightOf="@+id/imgLogo" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="#298AB7" android:textSize="14dp" > </TextView> <TextView android:id="@+id/txtThoiGianDen" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/txtTenDiaDiem" android:layout_marginLeft="2dip" android:layout_toRightOf="@+id/imgLogo" android:textColor="#1A1C18" android:textSize="12dp" > </TextView> <TextView android:id="@+id/txtThoiGianDi" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/txtThoiGianDen" android:layout_marginLeft="2dip" android:layout_toRightOf="@+id/imgLogo" android:textColor="#1A1C18" android:textSize="12dp" > </TextView> <ImageView android:id="@+id/imgKm" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerInParent="true" android:scaleType="center"
114
android:src="@drawable/km" > </ImageView> <TextView android:id="@+id/txtCuly" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_marginRight="2dip" android:layout_toLeftOf="@+id/imgKm" android:textColor="#1A1C18" android:textSize="12dp" > </TextView> </RelativeLayout>
1.1.2 Xy dng x l
Tp tin Adapter_ShowPath.java thc hin vic gn kt d liu n iu khin ListView.
public class Adapter_ShowPath extends BaseAdapter { ArrayList<ItemPath> itemList; public Activity context; public LayoutInflater inflater; public Adapter_ShowPath(Activity context, ArrayList<ItemPath> itemList) { super(); this.context = context; this.itemList = itemList; this.inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); } public int getCount() { // TODO Auto-generated method stub return itemList.size(); } public ItemPath getItem(int position) { // TODO Auto-generated method stub return itemList.get(position); } public long getItemId(int position) {
115
// TODO Auto-generated method stub return 0; } public static class ViewHolder { TextView txtThoiGianDi; TextView txtThoiGianDen; TextView txtTendiadiem; TextView txtCulychang; } public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = inflater.inflate(R.layout.row_path, null); holder.txtThoiGianDi = (TextView) convertView .findViewById(R.id.txtThoiGianDi); holder.txtThoiGianDen = (TextView) convertView .findViewById(R.id.txtThoiGianDen); holder.txtTendiadiem = (TextView) convertView .findViewById(R.id.txtTenDiaDiem); holder.txtCulychang = (TextView) convertView .findViewById(R.id.txtCuly); convertView.setTag(holder); } else holder = (ViewHolder) convertView.getTag(); ItemPath bean = (ItemPath) itemList.get(position); holder.txtTendiadiem.setText(bean.getDiadiem()); holder.txtCulychang.setText(bean.getCulychang()); holder.txtThoiGianDen .setText("Thi gian n: " + bean.getThoigianden()); holder.txtThoiGianDi.setText("Thi gian i: " + bean.getThoigiandi()); return convertView; } }
116
1.2
GridView
Tp tin main.xml nh ngha giao din cho mn hnh nh sau :
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/tile_background" android:orientation="vertical" > <GridView android:id="@+id/gridView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:horizontalSpacing="10dp" android:numColumns="auto_fit"
117
1.2.2 Xy dng x l
Tp tin Adapter_GridView.java hc hin vic gn kt d liu n iu khin GridView.
import java.util.ArrayList; import android.app.Activity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup;
118
import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; public class Adapter_GridView extends BaseAdapter { private ArrayList<String> listText; private ArrayList<Integer> listImage; private Activity activity; public Adapter_GridView(Activity activity, ArrayList<String> listText, ArrayList<Integer> listImage) { super(); this.listImage = listImage; this.listText = listText; this.activity = activity; } @Override public int getCount() { // TODO Auto-generated method stub return listText.size(); } @Override public String getItem(int position) { // TODO Auto-generated method stub return listText.get(position); } @Override public long getItemId(int position) { // TODO Auto-generated method stub return 0; } public static class ViewHolder { public ImageView imgView; public TextView txtViewTitle; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub ViewHolder view; LayoutInflater inflator = activity.getLayoutInflater(); if (convertView == null) { view = new ViewHolder(); convertView = inflator.inflate(R.layout.grid_item, null); view.txtViewTitle = (TextView) convertView .findViewById(R.id.textView1);
119
view.imgView = (ImageView) convertView .findViewById(R.id.imageView1); convertView.setTag(view); } else { view = (ViewHolder) convertView.getTag(); } view.txtViewTitle.setText(listText.get(position)); view.imgView.setImageResource(listImage.get(position)); return convertView; } }
120
1.3
121
android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/myspinner_background" /> </LinearLayout> <TextView android:id="@+id/selection_mactau" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:text="@string/loaiphuongtien" android:textColor="@color/cswhite" /> <Spinner android:id="@+id/spinner_loaipt" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/myspinner_background" /> <TextView android:id="@+id/selection_mactau" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:text="@string/phuongtien" android:textColor="@color/cswhite" /> <Spinner android:id="@+id/spinner_hang" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/myspinner_background" /> <TextView android:id="@+id/selection_ngay" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:paddingBottom="5dp" android:text="@string/ngay" android:textColor="@color/cswhite" /> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:layout_marginRight="8dp" android:orientation="horizontal" > <EditText android:id="@+id/edt_ngay" android:layout_width="fill_parent"
122
android:layout_height="wrap_content" android:layout_marginRight="5dp" android:layout_weight="1" android:drawSelectorOnTop="true" android:editable="false" /> <Button android:id="@+id/btn_xemgiotau" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:layout_weight="1" android:text="Tra cu" /> </LinearLayout> </LinearLayout>
5.3.2. Xy dng x l
Sau khi xy dng xong giao din, chng ta s i vo phn vit x l chi tit cho cc s kin. Tp tin MinhHoaTraCuuActivity.java gn kt d liu ln iu khin Spinner, hin th hp thoi DatePicker nh sau:
import java.util.ArrayList; import java.util.Calendar; import android.app.Activity; import android.app.DatePickerDialog; import android.app.Dialog; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.ArrayAdapter; import android.widget.DatePicker; import android.widget.EditText; import android.widget.Spinner; public class MinhHoaTraCuuActivity extends Activity { /** Called when the activity is first created. */ private Spinner spDiemDi, spDiemDen, spLoaiPhuongTien, spHang; private ArrayList<String> arrayDiemDi, arrayDiemDen, arrayLoaiPhuongTien, arrayHang; private ArrayAdapter<String> adapterDiemDi, adapterDiemDen, adapterLoaiPhuongTien, adapterHang; private EditText edtDatePicker; private int mYear, mMonth, mDay; @Override protected void onCreate(Bundle savedInstanceState) {
123
// TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); edtDatePicker = (EditText) findViewById(R.id.edt_ngay); final Calendar c = Calendar.getInstance(); mYear = c.get(Calendar.YEAR); mMonth = c.get(Calendar.MONTH); mDay = c.get(Calendar.DAY_OF_MONTH); int month = Integer.valueOf(mMonth) + 1; edtDatePicker.setText(month + "/" + mDay + "/" + mYear); edtDatePicker.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub showDialog(0); return true; } }); spDiemDi = (Spinner) findViewById(R.id.spinner_diemkh); spDiemDen = (Spinner) findViewById(R.id.spinner_diemkt); spLoaiPhuongTien = (Spinner) findViewById(R.id.spinner_loaipt); spHang = (Spinner) findViewById(R.id.spinner_hang); prepareList(); adapterDiemDi = new ArrayAdapter<String>(MinhHoaTraCuuActivity.this, android.R.layout.simple_spinner_item, arrayDiemDi); adapterDiemDen = new ArrayAdapter<String>(MinhHoaTraCuuActivity.this, android.R.layout.simple_spinner_item, arrayDiemDen); adapterLoaiPhuongTien = new ArrayAdapter<String>( MinhHoaTraCuuActivity.this, android.R.layout.simple_spinner_item, arrayLoaiPhuongTien); adapterHang = new ArrayAdapter<String>(MinhHoaTraCuuActivity.this, android.R.layout.simple_spinner_item, arrayHang);
124
adapterHang.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) ; spDiemDi.setAdapter(adapterDiemDi); spDiemDen.setAdapter(adapterDiemDen); spLoaiPhuongTien.setAdapter(adapterLoaiPhuongTien); spHang.setAdapter(adapterHang); } @Override protected Dialog onCreateDialog(int id) { // TODO Auto-generated method stub switch (id) { case 0: return new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay); } return null; } private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { mYear = year; mMonth = monthOfYear; mDay = dayOfMonth; int month = Integer.valueOf(mMonth) + 1; edtDatePicker.setText(month + "/" + mDay + "/" + mYear); } }; public void prepareList() { arrayDiemDi = new ArrayList<String>(); arrayDiemDen = new ArrayList<String>(); arrayLoaiPhuongTien = new ArrayList<String>(); arrayHang = new ArrayList<String>(); arrayDiemDi.add("Si Gn"); arrayDiemDi.add("H Ni"); arrayDiemDi.add(" Nng"); arrayDiemDen.add("Si Gn"); arrayDiemDen.add("H Ni"); arrayDiemDen.add(" Nng"); arrayLoaiPhuongTien.add("Xe khch");
125
arrayLoaiPhuongTien.add("Tu Hoa"); arrayHang.add("Tng cng ty ng st Vit Nam"); arrayHang.add("Xe khch CLC Mai Linh"); } }
1.4
TabHost View
Tp tin main.xml nh ngha giao din tab cho mn hnh nh sau:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" /> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0" /> </LinearLayout> </TabHost> </LinearLayout>
126
android:layout_width="0dip" android:layout_height="55dip" android:layout_weight="1" android:background="@drawable/tab_indicator" android:orientation="vertical" android:paddingLeft="4dp" android:paddingRight="4dp" > <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:paddingBottom="2dp" android:src="@drawable/ic_launcher" /> <TextView android:id="@+id/title" style="?android:attr/tabWidgetStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" /> </RelativeLayout>
127
1.4.2 Xy dng x l
Tp tin MinhHoaTabHostActivity.java hin th mn hnh dng tab nh sau:
import android.app.TabActivity; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.TabHost; import android.widget.TextView; public class MinhHoaTabHostActivity extends TabActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); addTab("Tra cu", R.drawable.icsearch, MinhHoaTraCuuActivity.class); addTab("Gi chy", R.drawable.timetable, MinhHoaTraCuuActivity.class); addTab("L trnh", R.drawable.timeline, MinhHoaTraCuuActivity.class); addTab("Bn ", R.drawable.map, MinhHoaTraCuuActivity.class); addTab("Gi v", R.drawable.dollars, MinhHoaTraCuuActivity.class); } private void addTab(String labelId, int drawableId, Class<?> c) { TabHost tabHost = getTabHost(); Intent intent = new Intent(this, c); TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); View tabIndicator = LayoutInflater.from(this).inflate( R.layout.tab_indicator, getTabWidget(), false); TextView title = (TextView) tabIndicator.findViewById(R.id.title); title.setText(labelId); ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon); icon.setImageResource(drawableId); spec.setIndicator(tabIndicator); spec.setContent(intent); tabHost.addTab(spec); } }
1.5
Gallery v ImageView
1.5.2 Xy dng x l
Tp tin GalleryView.java nh ngha lp ImageAdapter tha k t BaseAdapter thc hin vic gn kt hnh nh ln iu khin Gallery v lp GalleryViewActivity k tha t lp Activity hin th iu khin Gallery v ImageView nh sau: 129
import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.AdapterView.OnItemClickListener; public class GalleryView extends Activity { Integer[] pics = { R.drawable.pic1, R.drawable.pic2, R.drawable.pic3, R.drawable.pic4, R.drawable.pic5, R.drawable.pic6, R.drawable.pic7, R.drawable.pic8, }; ImageView imageView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Gallery ga = (Gallery) findViewById(R.id.Gallery01); ga.setAdapter(new ImageAdapter(this)); imageView = (ImageView) findViewById(R.id.ImageView01); ga.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { imageView.setImageResource(pics[arg2]); } }); } public class ImageAdapter extends BaseAdapter { private Context ctx; int imageBackground; public ImageAdapter(Context c) { ctx = c; TypedArray ta = obtainStyledAttributes(R.styleable.Gallery1); imageBackground = ta.getResourceId(
130
R.styleable.Gallery1_android_galleryItemBackground, 1); ta.recycle(); } @Override public int getCount() { return pics.length; } @Override public Object getItem(int arg0) { return arg0; } @Override public long getItemId(int arg0) { return arg0; } @Override public View getView(int arg0, View arg1, ViewGroup arg2) { ImageView iv = new ImageView(ctx); iv.setImageResource(pics[arg0]); iv.setScaleType(ImageView.ScaleType.FIT_XY); iv.setLayoutParams(new Gallery.LayoutParams(150, 120)); iv.setBackgroundResource(imageBackground); return iv; } } }
131
android:id="@+id/txtTenKhoa" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="H" android:textColor="#FFFFFF" android:textSize="15dp" android:textStyle="bold" /> <EditText android:id="@+id/edtFirstName" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="Nhp vo h" /> <TextView android:id="@+id/txtLastName" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Tn" android:textColor="#FFFFFF" android:textSize="15dp" android:textStyle="bold" /> <EditText android:id="@+id/edtLastName" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="Nhp tn" /> <TextView android:id="@+id/txtPhone" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="S in thoi" android:textColor="#FFFFFF" android:textSize="15dp" android:textStyle="bold" /> <EditText android:id="@+id/edtPhone" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="Nhp sdt" android:phoneNumber="true" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:id="@+id/btnThem" android:layout_width="fill_parent"
132
android:layout_height="wrap_content" android:layout_weight="1" android:text="Thm" /> <Button android:id="@+id/btnXoaTatCa" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="Xa tt c" /> </LinearLayout> <TextView android:id="@+id/txt1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#28282C" android:gravity="left" android:paddingTop="15dp" android:text="Danh sch danh b" android:textColor="#FFFFFF" android:textSize="15dp" android:textStyle="bold" /> <ListView android:id="@+id/android:list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#170F12" android:drawSelectorOnTop="false" /> <TextView android:id="@+id/android:empty" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#505050" android:text="Cha c d liu" /> </LinearLayout>
133
android:textColor="#FFFFFF" android:textSize="15dp" android:textStyle="bold" /> <EditText android:id="@+id/edtFirstName" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="Nhp vo h" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Tn" android:textColor="#FFFFFF" android:textSize="15dp" android:textStyle="bold" /> <EditText android:id="@+id/edtLastName" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="Nhp tn" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="S in thoi" android:textColor="#FFFFFF" android:textSize="15dp" android:textStyle="bold" /> <EditText android:id="@+id/edtPhone" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="Nhp sdt" android:phoneNumber="true" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:id="@+id/btnCapnhat" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="Cp nht" /> <Button android:id="@+id/btnthoat"
134
android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="Thot" /> <Button android:id="@+id/btnxoa" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="Xa" /> </LinearLayout> </LinearLayout>
135
2.2 Xy dng x l
Tp tin DefaultDataHelper.java thc hin vic to, cp nht c s d liu cng nh nh ngha cc thao tc truy vn, thm, xa, sa nh sau :
import java.util.ArrayList; import java.util.List; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.content.ContentValues; import android.content.Context; public class DefaultDataHelper { private static final String DATABASE = "Contacts.db"; private static final int VERSION = 1; private static final String TABLE = "Contact"; private static final String COLUMN_ID = "ContactID"; private static final String COLUMN_FIRSTNAME = "FirstName"; private static final String COLUMN_LASTNAME = "LastName"; private static final String COLUMN_PHONE = "Phone"; private static final String sqlCREATE = "CREATE TABLE " + TABLE + "(ContactID INTEGER PRIMARY KEY AUTOINCREMENT, FirstName TEXT NOT NULL,LastName TEXT NOT NULL, Phone TEXT NOT NULL)"; private static final String sqlDROP = "DROP TABLE IF EXISTS " + TABLE; private SQLiteDatabase sqlDB; private Context contentContext; private static class DefaultOpenHelper extends SQLiteOpenHelper { DefaultOpenHelper(Context context) { super(context, DATABASE, null, VERSION); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(sqlCREATE); } @Override public void onUpgrade(SQLiteDatabase db, int OldVersion, int NewVersion) { db.execSQL(sqlDROP); onCreate(db); } }
136
public DefaultDataHelper(Context context) { contentContext = context; DefaultOpenHelper DefaultOpenHelper = new DefaultOpenHelper( contentContext); sqlDB = DefaultOpenHelper.getWritableDatabase(); } public long DeleteAll() { return sqlDB.delete(TABLE, null, null); } public long Update(Integer ContactID, String FirstName, String LastName, String phone) { ContentValues value = new ContentValues(); value.put(COLUMN_LASTNAME, LastName); value.put(COLUMN_FIRSTNAME, FirstName); value.put(COLUMN_PHONE, phone); return sqlDB.update(TABLE, value, "ContactID=" + ContactID, null); } public long Insert(String FirstName, String LastName, String phone) { ContentValues value = new ContentValues(); value.put(COLUMN_LASTNAME, LastName); value.put(COLUMN_FIRSTNAME, FirstName); value.put(COLUMN_PHONE, phone); return sqlDB.insert(TABLE, null, value); } public List<String[]> SelectAll() { List<String[]> list = new ArrayList<String[]>(); Cursor cursor = sqlDB.query(TABLE, new String[] { COLUMN_ID, COLUMN_FIRSTNAME, COLUMN_LASTNAME, COLUMN_PHONE }, null, null, null, null, COLUMN_FIRSTNAME); if (cursor.moveToFirst()) { do { list.add(new String[] { cursor.getString(0), cursor.getString(1), cursor.getString(2),cursor.getString(3) }); } while (cursor.moveToNext()); if (cursor != null && !cursor.isClosed()) { cursor.close(); } } return list;
137
} public int Delete(Integer DeparmentID) { return sqlDB.delete(TABLE, "DepartmentID =" + DeparmentID, null); } }
138
edtLast = (EditText) findViewById(R.id.edtLastName); edtPhone = (EditText) findViewById(R.id.edtPhone); btnThem.setOnClickListener(this); btnXoaTatCa.setOnClickListener(this); RefreshData(); } @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.btnThem: String ho = edtFirst.getText().toString(); String ten = edtLast.getText().toString(); String phone = edtPhone.getText().toString(); if (ho.length() == 0 || ten.length() == 0 || phone.length() == 0) { Toast.makeText(SQLiteAPIActivity.this, "Bn cn nhp y thng tin", Toast.LENGTH_SHORT) .show(); } else { InsertDepartment(ho, ten, phone); } break; case R.id.btnXoaTatCa: deleteAllContacts(); break; case R.id.btnthoat: dismissDialog(DIALOG_FUNCTION); break; case R.id.btnCapnhat: ContactInfo item = (ContactInfo) adapter.getItem(position); updateContact(item.getMadanhba(), edtFirst_function.getText() .toString().toUpperCase(), edtLast_function.getText() .toString().toUpperCase(), edtPhone_Function.getText().toString()); dismissDialog(DIALOG_FUNCTION); break; case R.id.btnxoa: ContactInfo item2 = (ContactInfo) adapter.getItem(position); deleteDepartment(item2.getMadanhba()); dismissDialog(DIALOG_FUNCTION); break; } }
139
private void InsertDepartment(String firstName, String lastName, String phone) { if (DefaultDataHelper.Insert(firstName, lastName, phone) != -1) { RefreshData(); edtFirst.setText(""); edtLast.setText(""); edtPhone.setText(""); } else { Toast.makeText(SQLiteAPIActivity.this, "Thm khng thnh cng", Toast.LENGTH_SHORT).show(); } } @Override protected Dialog onCreateDialog(int id) { // TODO Auto-generated method stub switch (id) { case DIALOG_FUNCTION: item = (ContactInfo) adapter.getItem(position); this.dialog = new Dialog(SQLiteAPIActivity.this); this.dialog.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); dialog.setTitle("Cp nht, xa danh b"); dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON); dialog.setContentView(R.layout.dialog_function); dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.update); dialog.setCancelable(true); btnCapNhat = (Button) dialog.findViewById(R.id.btnCapnhat); btnThoat = (Button) dialog.findViewById(R.id.btnthoat); btnXoa = (Button) dialog.findViewById(R.id.btnxoa); edtFirst_function = (EditText) dialog.findViewById(R.id.edtFirstName); edtLast_function = (EditText) dialog.findViewById(R.id.edtLastName); edtPhone_Function = (EditText) dialog.findViewById(R.id.edtPhone); edtFirst_function.setText(item.getHo()); edtLast_function.setText(item.getTen()); edtPhone_Function.setText(item.getSdt()); btnCapNhat.setOnClickListener(this); btnXoa.setOnClickListener(this);
140
btnThoat.setOnClickListener(this); } return dialog; } @Override protected void onPrepareDialog(int id, Dialog dialog) { // TODO Auto-generated method stub switch (id) { case DIALOG_FUNCTION: item = (ContactInfo) adapter.getItem(position); this.dialog = dialog; this.dialog.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); btnCapNhat = (Button) dialog.findViewById(R.id.btnCapnhat); btnThoat = (Button) dialog.findViewById(R.id.btnthoat); btnXoa = (Button) dialog.findViewById(R.id.btnxoa); edtFirst_function = (EditText) dialog .findViewById(R.id.edtFirstName); edtLast_function = (EditText) dialog.findViewById(R.id.edtLastName); edtPhone_Function = (EditText) dialog.findViewById(R.id.edtPhone); edtFirst_function.setText(item.getHo()); edtLast_function.setText(item.getTen()); edtPhone_Function.setText(item.getSdt()); btnCapNhat.setOnClickListener(this); btnXoa.setOnClickListener(this); btnThoat.setOnClickListener(this); } } @Override protected void onListItemClick(ListView l, View v, int position, long id) { // TODO Auto-generated method stub this.position = position; showDialog(DIALOG_FUNCTION); } private void deleteDepartment(Integer contactID) { if (DefaultDataHelper.Delete(contactID) != -1) { Toast.makeText(SQLiteAPIActivity.this, "Xa thnh cng", Toast.LENGTH_SHORT).show(); RefreshData();
141
} else { Toast.makeText(SQLiteAPIActivity.this, "Xa tht bi", Toast.LENGTH_SHORT).show(); } } private void RefreshData() { Contacts.clear(); itemlist.clear(); Contacts = DefaultDataHelper.SelectAll(); for (String[] u : Contacts) { ContactInfo item = new ContactInfo(Integer.parseInt(u[0]), u[1], u[2], u[3]); itemlist.add(item); } adapter = new AdapterListView(SQLiteAPIActivity.this, itemlist); setListAdapter(adapter); } private void updateContact(Integer contactID, String firstName, String lastName, String phone) { if (firstName.length() == 0 || lastName.length() == 0 || phone.length() == 0) { Toast.makeText(SQLiteAPIActivity.this, "H tn v s in thoi khng c rng", Toast.LENGTH_SHORT).show(); } else { if (DefaultDataHelper.Update(contactID, firstName, lastName, phone) != -1) { Toast.makeText(SQLiteAPIActivity.this, "Cp nht thnh cng", Toast.LENGTH_SHORT).show(); RefreshData(); } else { Toast.makeText(SQLiteAPIActivity.this, "Cp nht tht bi", Toast.LENGTH_SHORT).show(); } } } private void deleteAllContacts() { if (DefaultDataHelper.DeleteAll() != -1) { Toast.makeText(SQLiteAPIActivity.this, "Xa tt c thnh cng", Toast.LENGTH_SHORT).show(); RefreshData(); } else
142
Tp tin AdapterListView.java thc hin gn kt d liu t c s d liu ln iu khin ListView trong mn hnh chnh. Np chng cc hm l getCount(), getItem(), getItemId(), getView() ln lt dng nh ngha hm ly s lng, thng tin, nh danh (v tr), giao din hin th ca mc tin :
import java.util.ArrayList; import android.app.Activity; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; public class AdapterListView extends BaseAdapter { Activity context; public LayoutInflater inflater; ArrayList<ContactInfo> itemlist; public AdapterListView(Activity context, ArrayList<ContactInfo> itemlist) { super(); this.context = context; this.itemlist = itemlist; inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public int getCount() { // TODO Auto-generated method stub return itemlist.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return itemlist.get(position); } @Override
143
public long getItemId(int position) { // TODO Auto-generated method stub return position; } public static class ViewHolder { TextView txtName; TextView txtPhone; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub ViewHolder viewHolder; if (convertView == null) { viewHolder = new ViewHolder(); convertView = inflater.inflate(R.layout.custom_row_listview, null); viewHolder.txtName = (TextView) convertView .findViewById(R.id.txtName); viewHolder.txtPhone = (TextView) convertView .findViewById(R.id.txtPhone); convertView.setTag(viewHolder); } else viewHolder = (ViewHolder) convertView.getTag(); ContactInfo item = (ContactInfo) itemlist.get(position); viewHolder.txtName.setText(item.getHo() + " " + item.getTen()); viewHolder.txtPhone.setText(item.getSdt()); return convertView; } }
144
android:orientation="vertical" > <TextView android:id="@+id/txtDiemDi" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="im i" android:textSize="13dp" /> <EditText android:id="@+id/edtDiemDi" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="left" android:hint="Nhp im i" android:textSize="13dp" /> <TextView android:id="@+id/txtDiemDen" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="im n" android:textColor="#FFFFFF" android:textSize="13dp" /> <EditText android:id="@+id/edtDiemDen" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="left" android:hint="Nhp im n" android:textSize="13dp" /> <TextView android:id="@+id/txtMaTuyen" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="M tuyn" android:textColor="#FFFFFF" android:textSize="13dp" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <EditText android:id="@+id/edtMaTuyen" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:hint="Nhp tuyn"
145
android:textSize="13dp" /> <Button android:id="@+id/btnOk" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Xem l trnh" /> </LinearLayout> <TextView android:id="@+id/txt1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#390606" android:gravity="left" android:text="Chi tit l trnh" android:textColor="#FFFFFF" android:textSize="15dp" android:textStyle="bold" /> <ListView android:id="@+id/android:list" style="@style/ListView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="2" android:background="#ECF7F7" android:divider="#A90000" android:dividerHeight="1sp" android:drawSelectorOnTop="false" > </ListView> <TextView android:id="@+id/android:empty" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#505050" android:text="Cha c d liu" /> </LinearLayout>
146
android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerInParent="true" android:scaleType="center" > </ImageView> <TextView android:id="@+id/txtTenDiaDiem" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="2dip" android:layout_toRightOf="@+id/imgLogo" android:text="TextView" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="#A90000" android:textSize="14dp" > </TextView> <TextView android:id="@+id/txtThoiGianDen" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/txtTenDiaDiem" android:layout_marginLeft="2dip" android:layout_toRightOf="@+id/imgLogo" android:text="TextView" android:textColor="#0F0C0B" android:textSize="12dp" > </TextView> <TextView android:id="@+id/txtThoiGianDi" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/txtThoiGianDen" android:layout_marginLeft="2dip" android:layout_toRightOf="@+id/imgLogo" android:text="TextView" android:textColor="#0F0C0B" android:textSize="12dp" > </TextView> <ImageView android:id="@+id/imgKm" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerInParent="true" android:scaleType="center" android:src="@drawable/km" > </ImageView> <TextView
147
android:id="@+id/txtCuly" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_marginRight="2dip" android:layout_toLeftOf="@+id/imgKm" android:text="TextView" android:textColor="#0F0C0B" android:textSize="12dp" > </TextView> </RelativeLayout>
3.2 Xy dng x l
Tp tin Adapter_ListView.java thc hin gn kt d liu ln ListView nh sau:
package at.demo; import java.util.ArrayList; import android.app.Activity; import android.content.Context; import at.demo.R; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; public class Adapter_ListView extends BaseAdapter { ArrayList<ItemPath> itemList; public Activity context; public LayoutInflater inflater; private int max, count; public Adapter_ListView(Activity context, ArrayList<ItemPath> itemList) { super(); this.context = context; this.itemList = itemList; this.inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); count = itemList.size(); if (count > 0) { max = itemList.get(count - 1).getThutu(); }
148
} public int getMax() { return max; } public int getCount() { // TODO Auto-generated method stub return itemList.size(); } public ItemPath getItem(int position) { // TODO Auto-generated method stub return itemList.get(position); } public long getItemId(int position) { // TODO Auto-generated method stub return 0; } public static class ViewHolder { ImageView imgViewLogo; TextView txtThoiGianDi; TextView txtThoiGianDen; TextView txtTendiadiem; TextView txtCulychang; ImageView imgKm; } public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = inflater.inflate(R.layout.row_listitem, null); holder.imgViewLogo = (ImageView) convertView .findViewById(R.id.imgLogo); holder.txtThoiGianDi = (TextView) convertView .findViewById(R.id.txtThoiGianDi); holder.txtThoiGianDen = (TextView) convertView .findViewById(R.id.txtThoiGianDen); holder.txtTendiadiem = (TextView) convertView .findViewById(R.id.txtTenDiaDiem); holder.txtCulychang = (TextView) convertView .findViewById(R.id.txtCuly); holder.imgKm = (ImageView) convertView.findViewById(R.id.imgKm); convertView.setTag(holder);
149
} else holder = (ViewHolder) convertView.getTag(); ItemPath bean = (ItemPath) itemList.get(position); byte thutu = bean.getThutu(); holder.txtTendiadiem.setText(bean.getDiadiem()); if (bean.getCulychang().equals("anyType{}")) { holder.imgKm.setVisibility(View.GONE); holder.txtCulychang.setText(""); } else { holder.imgKm.setVisibility(View.VISIBLE); holder.txtCulychang.setText(bean.getCulychang()); } if (count == 1) { holder.txtThoiGianDi.setText(""); holder.txtThoiGianDen.setText(""); } else { if (thutu == max) { holder.txtThoiGianDi.setText(""); } else holder.txtThoiGianDi.setText("Thi gian i: " + bean.getThoigiandi()); holder.txtThoiGianDen.setText("Thi gian n: " + bean.getThoigianden()); } return convertView; } }
Tp tin MainActivity.java thc hin xy dng giao din mn hnh, gi Web Service :
import java.util.ArrayList; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.AndroidHttpTransport; import android.app.ListActivity; import android.app.ProgressDialog; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button;
150
import android.widget.EditText; public class MainActivity extends ListActivity implements OnClickListener { private final static String URL_WS = "http://10.0.2.2:21644/WebSite2/WebService.asmx"; ArrayList<ItemPath> arraylist_path; EditText edtDiemDi, edtDiemDen, edtMaTuyen; Adapter_ListView adapter; Button btnXemLoTrinh; int max, matuyen; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); btnXemLoTrinh = (Button) findViewById(R.id.btnOk); edtMaTuyen = (EditText) findViewById(R.id.edtMaTuyen); edtDiemDi = (EditText) findViewById(R.id.edtDiemDi); edtDiemDen = (EditText) findViewById(R.id.edtDiemDen); btnXemLoTrinh.setOnClickListener(this); } @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.btnOk: matuyen = Integer.parseInt(edtMaTuyen.getText().toString()); new PreparedTask().execute(edtDiemDi.getText().toString(), edtDiemDen.getText().toString()); break; } } public class PreparedTask extends AsyncTask<String, Void, ArrayList<ItemPath>> { private final ProgressDialog dialog = new ProgressDialog( MainActivity.this); @Override protected void onPreExecute() { // TODO Auto-generated method stub this.dialog.setMessage("ang ti d liu..."); this.dialog.show(); } @Override
151
protected ArrayList<ItemPath> doInBackground(String... params) { // TODO Auto-generated method stub return prepareArrayLits(params[0], params[1]); } @Override protected void onPostExecute(ArrayList<ItemPath> result) { // TODO Auto-generated method stub // super.onPostExecute(result); if (this.dialog.isShowing()) this.dialog.dismiss(); adapter = new Adapter_ListView(MainActivity.this, result); setListAdapter(adapter); max = adapter.getMax(); } } public ArrayList<ItemPath> prepareArrayLits(String madiemdi, String madiemden) { arraylist_path = new ArrayList<ItemPath>(); try { arraylist_path = getPath(matuyen, madiemdi, madiemden); } catch (Exception e) { } return arraylist_path; } public ArrayList<ItemPath> getPath(int matuyen, String diemdi, String diemden) throws Exception { String SOAP_ACTION = "http://tempuri.org/GetPath"; String METHOD_NAME = "GetPath"; String NAMESPACE = "http://tempuri.org/"; String URL = URL_WS + "?op=GetPath"; SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); request.addProperty("matuyen", matuyen); request.addProperty("diemdi", diemdi);
152
request.addProperty("diemden", diemden); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport( URL); androidHttpTransport.call(SOAP_ACTION, envelope); SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn; SoapObject a = (SoapObject) resultsRequestSOAP.getProperty(0); int count = a.getPropertyCount(); ArrayList<ItemPath> bki = new ArrayList<ItemPath>(); for (int i = 0; i < count; i++) { SoapObject so = (SoapObject) a.getProperty(i); String tendiadiem = so.getProperty("Tendiadiem").toString(); String thoigian_den = so.getProperty("Thoigianden").toString(); String thoigian_di = so.getProperty("Thoigiandi").toString(); String culychang = so.getProperty("Culychang").toString(); Byte thutu = Byte.valueOf(so.getProperty("Thutu").toString()); String tg_tuyen = so.getProperty("Tg_tuyen").toString(); bki.add(new ItemPath(tendiadiem, thoigian_di, thoigian_den, tg_tuyen, culychang, thutu, R.drawable.ic_launcher)); } return bki; } }
153
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout> </TabHost>
154
<TextView android:id="@+id/txtTitle" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Bi ht: " /> <ImageView android:id="@+id/iv1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:paddingTop="100dp" android:src="@drawable/audio" /> </LinearLayout>
4.2 Xy dng x l
Tp tin PlaylistActivity.java thc hin ti cc tp tin c nh dng audio, video c h tr :
import java.io.File; import java.io.FilenameFilter; import java.util.ArrayList; import java.util.List; import android.app.ListActivity; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.os.Bundle;
155
import android.os.Environment; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TabHost; public class PlaylistActivity extends ListActivity { private static final String URL_SDCARD = Environment .getExternalStorageDirectory().getAbsolutePath(); private SharedPreferences shared; private List<String> songs = new ArrayList<String>();
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.playlist); shared = getSharedPreferences("song_file", MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE); getSongFromSDCard(); } public void getSongFromSDCard() {
if (home.listFiles(new FilterSong()).length > 0) { for (File file : home.listFiles(new FilterSong())) { songs.add(file.getName()); } ArrayAdapter<String> songList = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, songs); setListAdapter(songList); } } @Override protected void onListItemClick(ListView l, View v, int position, long id) { Editor edit = shared.edit(); String filename = songs.get(position); edit.putString("url_song", filename); edit.putBoolean("isPlay", true); edit.putInt("position", position); edit.commit(); TabHost tabHost = (TabHost) getParent().findViewById(
156
android.R.id.tabhost); if (filename.endsWith(".mp3") || filename.endsWith(".mid") || filename.endsWith(".wav")) { tabHost.setCurrentTab(1); } else tabHost.setCurrentTab(2); } public class FilterSong implements FilenameFilter { @Override public boolean accept(File dir, String filename) { // TODO Auto-generated method stub return (filename.endsWith(".mp3") || filename.endsWith(".3gp") || filename.endsWith(".mid") || filename.endsWith(".wav") || filename .endsWith("mp4")); } } }
Tp tin PlayAudioActivity.java dng pht bi ht loi audio khi ngi dng chn bi ht audio :
import java.io.File; import java.io.FilenameFilter; import java.io.IOException; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.content.SharedPreferences; import android.media.MediaPlayer; import android.media.MediaPlayer.OnPreparedListener; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.util.Log; import android.view.MotionEvent; import android.widget.MediaController; import android.widget.TextView; import android.widget.Toast; import android.widget.MediaController.MediaPlayerControl; public class PlayAudioActivity extends Activity implements MediaPlayerControl, OnPreparedListener { private static final String URL_SDCARD = Environment .getExternalStorageDirectory().getAbsolutePath(); private MediaPlayer mediaPlayer; private SharedPreferences shared;
157
private List<String> songs; private MediaController mediaController; private Handler handler = new Handler(); private String url_song; private boolean isPlay, isFirst; private Integer position; private TextView txtTitleAudio; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.playaudio); txtTitleAudio = (TextView) findViewById(R.id.txtTitle); songs = new ArrayList<String>(); getSongFromSDCard(); shared = getSharedPreferences("song_file", MODE_WORLD_READABLE); isFirst = true; mediaPlayer = new MediaPlayer(); mediaPlayer.setOnPreparedListener(this); mediaController = new MediaController(this); } public void getSongFromSDCard() { File home = new File(URL_SDCARD); if (home.listFiles(new FilterSong()).length > 0) { for (File file : home.listFiles(new FilterSong())) { songs.add(file.getName()); } } } public class FilterSong implements FilenameFilter { @Override public boolean accept(File dir, String filename) { // TODO Auto-generated method stub return (filename.endsWith(".mp3") || filename.endsWith(".3gp") || filename.endsWith(".mid") || filename.endsWith(".wav") || filename .endsWith("mp4")); } } @Override protected void onResume() { // TODO Auto-generated method stub
158
super.onResume(); url_song = shared.getString("url_song", ""); if (url_song.length() != 0) { txtTitleAudio.setText("Bi ht: " + url_song); } isPlay = shared.getBoolean("isPlay", false); position = shared.getInt("position", 0); if (isFirst) { try { mediaPlayer.setDataSource(URL_SDCARD + "/" + url_song); mediaPlayer.prepare(); mediaPlayer.start(); isFirst = false; isPlay = false; } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (isPlay) { mediaPlayer.stop(); mediaPlayer.reset(); } try { Log.i("heelo","restart ne"); mediaPlayer.setDataSource(URL_SDCARD + "/" + url_song); mediaPlayer.prepare(); mediaPlayer.start(); isPlay = false; } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace();
159
} } } public void onPrepared(MediaPlayer mediaPlayer) { mediaController.setMediaPlayer(this); mediaController.setAnchorView(findViewById(R.id.main_audio_view)); handler.post(new Runnable() { public void run() { mediaController.setEnabled(true); mediaController.show(); } }); } @Override public int getBufferPercentage() { // TODO Auto-generated method stub return 0; } @Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub mediaController.show(); return false; } @Override public void start() { // TODO Auto-generated method stub mediaPlayer.start(); } @Override public void pause() { // TODO Auto-generated method stub mediaPlayer.pause(); } @Override public int getDuration() { // TODO Auto-generated method stub return mediaPlayer.getDuration(); } @Override public boolean isPlaying() { // TODO Auto-generated method stub return mediaPlayer.isPlaying();
160
} @Override public int getCurrentPosition() { // TODO Auto-generated method stub return mediaPlayer.getCurrentPosition(); } @Override public void seekTo(int pos) { // TODO Auto-generated method stub; mediaPlayer.seekTo(pos); } @Override public boolean canPause() { // TODO Auto-generated method stub return true; } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); if (mediaPlayer.isPlaying()) { mediaPlayer.stop(); mediaPlayer.reset(); } } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); mediaPlayer.release(); } @Override public boolean canSeekBackward() { // TODO Auto-generated method stub return true; } @Override public boolean canSeekForward() { // TODO Auto-generated method stub return true; } }
161
Tp tin PlayVideoActivity.java dng pht bi ht loi video khi ngi dng chn bi ht video :
import android.app.Activity; import android.content.SharedPreferences; import android.os.Bundle; import android.os.Environment; import android.widget.MediaController; import android.widget.TextView; import android.widget.VideoView; public class PlayVideoActivity extends Activity{ private VideoView videoView; private MediaController mediaController; private String url_song; private SharedPreferences shared; private boolean isPlay, isFirst; private TextView txtTitleVideo; private static final String URL_SDCARD= Environment.getExternalStorageDirectory().getAbsolutePath(); @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.playvideo); txtTitleVideo = (TextView)findViewById(R.id.txtTitleVideo); videoView = (VideoView)findViewById(R.id.vv1); shared = getSharedPreferences("song_file", MODE_WORLD_READABLE); mediaController = new MediaController(PlayVideoActivity.this); mediaController.setMediaPlayer(videoView); videoView.setMediaController(mediaController); isFirst=true; } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); if(videoView.isPlaying()) { videoView.stopPlayback(); videoView.clearFocus(); } } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume();
162
url_song =shared.getString("url_song", ""); if(url_song.length()!=0) { txtTitleVideo.setText("Bi ht: "+ url_song); } isPlay = shared.getBoolean("isPlay", false); if(isFirst) { try { videoView.setVideoPath(URL_SDCARD + "/"+ url_song); videoView.requestFocus(); videoView.start(); mediaController.show(); isFirst=false; isPlay=false; } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if(isPlay) { videoView.stopPlayback(); } try { videoView.setVideoPath(URL_SDCARD + "/"+ url_song); videoView.start(); mediaController.show(); isPlay=false; } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); }
} }
163
164