remi-andrake 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README.markdown +3 -0
- data/Rakefile +57 -0
- data/examples/andrake/HelloAndroid/HelloAndroid.java +22 -0
- data/examples/andrake/HelloAndroid/init.rb +44 -0
- data/examples/andrake/HelloAndroid/layout/main.xml +13 -0
- data/examples/android/BasicUI/AndroidManifest.xml +20 -0
- data/examples/android/BasicUI/build.xml +269 -0
- data/examples/android/BasicUI/reinstall-and-debug-on-default-device +6 -0
- data/examples/android/BasicUI/reinstall-and-run-on-default-device +6 -0
- data/examples/android/BasicUI/res/drawable/icon.png +0 -0
- data/examples/android/BasicUI/res/layout/main.xml +23 -0
- data/examples/android/BasicUI/res/layout/result.xml +12 -0
- data/examples/android/BasicUI/res/values/colors.xml +10 -0
- data/examples/android/BasicUI/res/values/strings.xml +6 -0
- data/examples/android/BasicUI/src/com/android/basicui/AnotherView.java +39 -0
- data/examples/android/BasicUI/src/com/android/basicui/BasicUI.java +102 -0
- data/examples/android/BasicUI/src/com/android/basicui/R.java +36 -0
- data/examples/android/BasicUI/src/com/android/basicui/UiResult.java +20 -0
- data/examples/android/COPYING +1 -0
- data/examples/android/HelloAndroid/AndroidManifest.xml +15 -0
- data/examples/android/HelloAndroid/build.xml +269 -0
- data/examples/android/HelloAndroid/res/drawable/icon.png +0 -0
- data/examples/android/HelloAndroid/res/layout/main.xml +12 -0
- data/examples/android/HelloAndroid/res/values/strings.xml +5 -0
- data/examples/android/HelloAndroid/src/com/android/hello/HelloAndroid.java +16 -0
- data/examples/android/HelloAndroid/src/com/android/hello/R.java +23 -0
- data/examples/android/LICENSE +1 -0
- data/examples/android/LolcatBuilder/AndroidManifest.xml +32 -0
- data/examples/android/LolcatBuilder/README.txt +90 -0
- data/examples/android/LolcatBuilder/build.xml +269 -0
- data/examples/android/LolcatBuilder/res/drawable/app_icon.png +0 -0
- data/examples/android/LolcatBuilder/res/drawable/photo_border.9.png +0 -0
- data/examples/android/LolcatBuilder/res/layout-land/lolcat_activity.xml +91 -0
- data/examples/android/LolcatBuilder/res/layout/lolcat_activity.xml +90 -0
- data/examples/android/LolcatBuilder/res/layout/lolcat_caption_dialog.xml +68 -0
- data/examples/android/LolcatBuilder/res/values/strings.xml +45 -0
- data/examples/android/LolcatBuilder/src/com/android/lolcat/LolcatActivity.java +808 -0
- data/examples/android/LolcatBuilder/src/com/android/lolcat/LolcatView.java +638 -0
- data/examples/android/LolcatBuilder/src/com/android/lolcat/R.java +60 -0
- data/examples/android/README.markdown +9 -0
- data/examples/android/Translate/AndroidManifest.xml +35 -0
- data/examples/android/Translate/CHANGELOG +9 -0
- data/examples/android/Translate/README +13 -0
- data/examples/android/Translate/TODO +1 -0
- data/examples/android/Translate/build.xml +269 -0
- data/examples/android/Translate/res/drawable/ad.png +0 -0
- data/examples/android/Translate/res/drawable/ae.png +0 -0
- data/examples/android/Translate/res/drawable/af.png +0 -0
- data/examples/android/Translate/res/drawable/ag.png +0 -0
- data/examples/android/Translate/res/drawable/ai.png +0 -0
- data/examples/android/Translate/res/drawable/al.png +0 -0
- data/examples/android/Translate/res/drawable/am.png +0 -0
- data/examples/android/Translate/res/drawable/an.png +0 -0
- data/examples/android/Translate/res/drawable/ao.png +0 -0
- data/examples/android/Translate/res/drawable/ar.png +0 -0
- data/examples/android/Translate/res/drawable/as.png +0 -0
- data/examples/android/Translate/res/drawable/at.png +0 -0
- data/examples/android/Translate/res/drawable/au.png +0 -0
- data/examples/android/Translate/res/drawable/aw.png +0 -0
- data/examples/android/Translate/res/drawable/ax.png +0 -0
- data/examples/android/Translate/res/drawable/az.png +0 -0
- data/examples/android/Translate/res/drawable/ba.png +0 -0
- data/examples/android/Translate/res/drawable/babelfish.png +0 -0
- data/examples/android/Translate/res/drawable/bb.png +0 -0
- data/examples/android/Translate/res/drawable/bd.png +0 -0
- data/examples/android/Translate/res/drawable/be.png +0 -0
- data/examples/android/Translate/res/drawable/bf.png +0 -0
- data/examples/android/Translate/res/drawable/bg.png +0 -0
- data/examples/android/Translate/res/drawable/bh.png +0 -0
- data/examples/android/Translate/res/drawable/bi.png +0 -0
- data/examples/android/Translate/res/drawable/bj.png +0 -0
- data/examples/android/Translate/res/drawable/bm.png +0 -0
- data/examples/android/Translate/res/drawable/bn.png +0 -0
- data/examples/android/Translate/res/drawable/bo.png +0 -0
- data/examples/android/Translate/res/drawable/br.png +0 -0
- data/examples/android/Translate/res/drawable/bs.png +0 -0
- data/examples/android/Translate/res/drawable/bt.png +0 -0
- data/examples/android/Translate/res/drawable/bv.png +0 -0
- data/examples/android/Translate/res/drawable/bw.png +0 -0
- data/examples/android/Translate/res/drawable/by.png +0 -0
- data/examples/android/Translate/res/drawable/bz.png +0 -0
- data/examples/android/Translate/res/drawable/ca.png +0 -0
- data/examples/android/Translate/res/drawable/catalonia.png +0 -0
- data/examples/android/Translate/res/drawable/cc.png +0 -0
- data/examples/android/Translate/res/drawable/cd.png +0 -0
- data/examples/android/Translate/res/drawable/cf.png +0 -0
- data/examples/android/Translate/res/drawable/cg.png +0 -0
- data/examples/android/Translate/res/drawable/ch.png +0 -0
- data/examples/android/Translate/res/drawable/ci.png +0 -0
- data/examples/android/Translate/res/drawable/ck.png +0 -0
- data/examples/android/Translate/res/drawable/cl.png +0 -0
- data/examples/android/Translate/res/drawable/cm.png +0 -0
- data/examples/android/Translate/res/drawable/cn.png +0 -0
- data/examples/android/Translate/res/drawable/co.png +0 -0
- data/examples/android/Translate/res/drawable/cr.png +0 -0
- data/examples/android/Translate/res/drawable/cs.png +0 -0
- data/examples/android/Translate/res/drawable/cu.png +0 -0
- data/examples/android/Translate/res/drawable/cv.png +0 -0
- data/examples/android/Translate/res/drawable/cx.png +0 -0
- data/examples/android/Translate/res/drawable/cy.png +0 -0
- data/examples/android/Translate/res/drawable/cz.png +0 -0
- data/examples/android/Translate/res/drawable/de.png +0 -0
- data/examples/android/Translate/res/drawable/dj.png +0 -0
- data/examples/android/Translate/res/drawable/dk.png +0 -0
- data/examples/android/Translate/res/drawable/dm.png +0 -0
- data/examples/android/Translate/res/drawable/dz.png +0 -0
- data/examples/android/Translate/res/drawable/ec.png +0 -0
- data/examples/android/Translate/res/drawable/ee.png +0 -0
- data/examples/android/Translate/res/drawable/eg.png +0 -0
- data/examples/android/Translate/res/drawable/eh.png +0 -0
- data/examples/android/Translate/res/drawable/england.png +0 -0
- data/examples/android/Translate/res/drawable/er.png +0 -0
- data/examples/android/Translate/res/drawable/es.png +0 -0
- data/examples/android/Translate/res/drawable/et.png +0 -0
- data/examples/android/Translate/res/drawable/europeanunion.png +0 -0
- data/examples/android/Translate/res/drawable/fam.png +0 -0
- data/examples/android/Translate/res/drawable/fi.png +0 -0
- data/examples/android/Translate/res/drawable/fj.png +0 -0
- data/examples/android/Translate/res/drawable/fk.png +0 -0
- data/examples/android/Translate/res/drawable/fm.png +0 -0
- data/examples/android/Translate/res/drawable/fo.png +0 -0
- data/examples/android/Translate/res/drawable/fr.png +0 -0
- data/examples/android/Translate/res/drawable/ga.png +0 -0
- data/examples/android/Translate/res/drawable/gb.png +0 -0
- data/examples/android/Translate/res/drawable/gd.png +0 -0
- data/examples/android/Translate/res/drawable/ge.png +0 -0
- data/examples/android/Translate/res/drawable/gf.png +0 -0
- data/examples/android/Translate/res/drawable/gh.png +0 -0
- data/examples/android/Translate/res/drawable/gi.png +0 -0
- data/examples/android/Translate/res/drawable/gl.png +0 -0
- data/examples/android/Translate/res/drawable/gm.png +0 -0
- data/examples/android/Translate/res/drawable/gn.png +0 -0
- data/examples/android/Translate/res/drawable/gp.png +0 -0
- data/examples/android/Translate/res/drawable/gq.png +0 -0
- data/examples/android/Translate/res/drawable/gr.png +0 -0
- data/examples/android/Translate/res/drawable/gs.png +0 -0
- data/examples/android/Translate/res/drawable/gt.png +0 -0
- data/examples/android/Translate/res/drawable/gu.png +0 -0
- data/examples/android/Translate/res/drawable/gw.png +0 -0
- data/examples/android/Translate/res/drawable/gy.png +0 -0
- data/examples/android/Translate/res/drawable/hk.png +0 -0
- data/examples/android/Translate/res/drawable/hm.png +0 -0
- data/examples/android/Translate/res/drawable/hn.png +0 -0
- data/examples/android/Translate/res/drawable/hr.png +0 -0
- data/examples/android/Translate/res/drawable/ht.png +0 -0
- data/examples/android/Translate/res/drawable/hu.png +0 -0
- data/examples/android/Translate/res/drawable/id.png +0 -0
- data/examples/android/Translate/res/drawable/ie.png +0 -0
- data/examples/android/Translate/res/drawable/il.png +0 -0
- data/examples/android/Translate/res/drawable/in.png +0 -0
- data/examples/android/Translate/res/drawable/io.png +0 -0
- data/examples/android/Translate/res/drawable/iq.png +0 -0
- data/examples/android/Translate/res/drawable/ir.png +0 -0
- data/examples/android/Translate/res/drawable/is.png +0 -0
- data/examples/android/Translate/res/drawable/it.png +0 -0
- data/examples/android/Translate/res/drawable/jm.png +0 -0
- data/examples/android/Translate/res/drawable/jo.png +0 -0
- data/examples/android/Translate/res/drawable/jp.png +0 -0
- data/examples/android/Translate/res/drawable/ke.png +0 -0
- data/examples/android/Translate/res/drawable/kg.png +0 -0
- data/examples/android/Translate/res/drawable/kh.png +0 -0
- data/examples/android/Translate/res/drawable/ki.png +0 -0
- data/examples/android/Translate/res/drawable/km.png +0 -0
- data/examples/android/Translate/res/drawable/kn.png +0 -0
- data/examples/android/Translate/res/drawable/kp.png +0 -0
- data/examples/android/Translate/res/drawable/kr.png +0 -0
- data/examples/android/Translate/res/drawable/kw.png +0 -0
- data/examples/android/Translate/res/drawable/ky.png +0 -0
- data/examples/android/Translate/res/drawable/kz.png +0 -0
- data/examples/android/Translate/res/drawable/la.png +0 -0
- data/examples/android/Translate/res/drawable/lb.png +0 -0
- data/examples/android/Translate/res/drawable/lc.png +0 -0
- data/examples/android/Translate/res/drawable/li.png +0 -0
- data/examples/android/Translate/res/drawable/lk.png +0 -0
- data/examples/android/Translate/res/drawable/lr.png +0 -0
- data/examples/android/Translate/res/drawable/ls.png +0 -0
- data/examples/android/Translate/res/drawable/lt.png +0 -0
- data/examples/android/Translate/res/drawable/lu.png +0 -0
- data/examples/android/Translate/res/drawable/lv.png +0 -0
- data/examples/android/Translate/res/drawable/ly.png +0 -0
- data/examples/android/Translate/res/drawable/ma.png +0 -0
- data/examples/android/Translate/res/drawable/mc.png +0 -0
- data/examples/android/Translate/res/drawable/md.png +0 -0
- data/examples/android/Translate/res/drawable/me.png +0 -0
- data/examples/android/Translate/res/drawable/mg.png +0 -0
- data/examples/android/Translate/res/drawable/mh.png +0 -0
- data/examples/android/Translate/res/drawable/mk.png +0 -0
- data/examples/android/Translate/res/drawable/ml.png +0 -0
- data/examples/android/Translate/res/drawable/mm.png +0 -0
- data/examples/android/Translate/res/drawable/mn.png +0 -0
- data/examples/android/Translate/res/drawable/mo.png +0 -0
- data/examples/android/Translate/res/drawable/mp.png +0 -0
- data/examples/android/Translate/res/drawable/mq.png +0 -0
- data/examples/android/Translate/res/drawable/mr.png +0 -0
- data/examples/android/Translate/res/drawable/ms.png +0 -0
- data/examples/android/Translate/res/drawable/mt.png +0 -0
- data/examples/android/Translate/res/drawable/mu.png +0 -0
- data/examples/android/Translate/res/drawable/mv.png +0 -0
- data/examples/android/Translate/res/drawable/mw.png +0 -0
- data/examples/android/Translate/res/drawable/mx.png +0 -0
- data/examples/android/Translate/res/drawable/my.png +0 -0
- data/examples/android/Translate/res/drawable/mz.png +0 -0
- data/examples/android/Translate/res/drawable/na.png +0 -0
- data/examples/android/Translate/res/drawable/nc.png +0 -0
- data/examples/android/Translate/res/drawable/ne.png +0 -0
- data/examples/android/Translate/res/drawable/nf.png +0 -0
- data/examples/android/Translate/res/drawable/ng.png +0 -0
- data/examples/android/Translate/res/drawable/ni.png +0 -0
- data/examples/android/Translate/res/drawable/nl.png +0 -0
- data/examples/android/Translate/res/drawable/no.png +0 -0
- data/examples/android/Translate/res/drawable/np.png +0 -0
- data/examples/android/Translate/res/drawable/nr.png +0 -0
- data/examples/android/Translate/res/drawable/nu.png +0 -0
- data/examples/android/Translate/res/drawable/nz.png +0 -0
- data/examples/android/Translate/res/drawable/om.png +0 -0
- data/examples/android/Translate/res/drawable/pa.png +0 -0
- data/examples/android/Translate/res/drawable/pe.png +0 -0
- data/examples/android/Translate/res/drawable/pf.png +0 -0
- data/examples/android/Translate/res/drawable/pg.png +0 -0
- data/examples/android/Translate/res/drawable/ph.png +0 -0
- data/examples/android/Translate/res/drawable/pk.png +0 -0
- data/examples/android/Translate/res/drawable/pl.png +0 -0
- data/examples/android/Translate/res/drawable/pm.png +0 -0
- data/examples/android/Translate/res/drawable/pn.png +0 -0
- data/examples/android/Translate/res/drawable/pr.png +0 -0
- data/examples/android/Translate/res/drawable/ps.png +0 -0
- data/examples/android/Translate/res/drawable/pt.png +0 -0
- data/examples/android/Translate/res/drawable/pw.png +0 -0
- data/examples/android/Translate/res/drawable/py.png +0 -0
- data/examples/android/Translate/res/drawable/qa.png +0 -0
- data/examples/android/Translate/res/drawable/re.png +0 -0
- data/examples/android/Translate/res/drawable/readme.txt +9 -0
- data/examples/android/Translate/res/drawable/ro.png +0 -0
- data/examples/android/Translate/res/drawable/rs.png +0 -0
- data/examples/android/Translate/res/drawable/ru.png +0 -0
- data/examples/android/Translate/res/drawable/rw.png +0 -0
- data/examples/android/Translate/res/drawable/sa.png +0 -0
- data/examples/android/Translate/res/drawable/sb.png +0 -0
- data/examples/android/Translate/res/drawable/sc.png +0 -0
- data/examples/android/Translate/res/drawable/scotland.png +0 -0
- data/examples/android/Translate/res/drawable/sd.png +0 -0
- data/examples/android/Translate/res/drawable/se.png +0 -0
- data/examples/android/Translate/res/drawable/sg.png +0 -0
- data/examples/android/Translate/res/drawable/sh.png +0 -0
- data/examples/android/Translate/res/drawable/si.png +0 -0
- data/examples/android/Translate/res/drawable/sj.png +0 -0
- data/examples/android/Translate/res/drawable/sk.png +0 -0
- data/examples/android/Translate/res/drawable/sl.png +0 -0
- data/examples/android/Translate/res/drawable/sm.png +0 -0
- data/examples/android/Translate/res/drawable/sn.png +0 -0
- data/examples/android/Translate/res/drawable/so.png +0 -0
- data/examples/android/Translate/res/drawable/sr.png +0 -0
- data/examples/android/Translate/res/drawable/st.png +0 -0
- data/examples/android/Translate/res/drawable/sv.png +0 -0
- data/examples/android/Translate/res/drawable/sy.png +0 -0
- data/examples/android/Translate/res/drawable/sz.png +0 -0
- data/examples/android/Translate/res/drawable/tc.png +0 -0
- data/examples/android/Translate/res/drawable/td.png +0 -0
- data/examples/android/Translate/res/drawable/tf.png +0 -0
- data/examples/android/Translate/res/drawable/tg.png +0 -0
- data/examples/android/Translate/res/drawable/th.png +0 -0
- data/examples/android/Translate/res/drawable/tj.png +0 -0
- data/examples/android/Translate/res/drawable/tk.png +0 -0
- data/examples/android/Translate/res/drawable/tl.png +0 -0
- data/examples/android/Translate/res/drawable/tm.png +0 -0
- data/examples/android/Translate/res/drawable/tn.png +0 -0
- data/examples/android/Translate/res/drawable/to.png +0 -0
- data/examples/android/Translate/res/drawable/tr.png +0 -0
- data/examples/android/Translate/res/drawable/tt.png +0 -0
- data/examples/android/Translate/res/drawable/tv.png +0 -0
- data/examples/android/Translate/res/drawable/tw.png +0 -0
- data/examples/android/Translate/res/drawable/tz.png +0 -0
- data/examples/android/Translate/res/drawable/ua.png +0 -0
- data/examples/android/Translate/res/drawable/ug.png +0 -0
- data/examples/android/Translate/res/drawable/um.png +0 -0
- data/examples/android/Translate/res/drawable/us.png +0 -0
- data/examples/android/Translate/res/drawable/uy.png +0 -0
- data/examples/android/Translate/res/drawable/uz.png +0 -0
- data/examples/android/Translate/res/drawable/va.png +0 -0
- data/examples/android/Translate/res/drawable/vc.png +0 -0
- data/examples/android/Translate/res/drawable/ve.png +0 -0
- data/examples/android/Translate/res/drawable/vg.png +0 -0
- data/examples/android/Translate/res/drawable/vi.png +0 -0
- data/examples/android/Translate/res/drawable/vn.png +0 -0
- data/examples/android/Translate/res/drawable/vu.png +0 -0
- data/examples/android/Translate/res/drawable/wales.png +0 -0
- data/examples/android/Translate/res/drawable/wf.png +0 -0
- data/examples/android/Translate/res/drawable/ws.png +0 -0
- data/examples/android/Translate/res/drawable/ye.png +0 -0
- data/examples/android/Translate/res/drawable/yt.png +0 -0
- data/examples/android/Translate/res/drawable/za.png +0 -0
- data/examples/android/Translate/res/drawable/zm.png +0 -0
- data/examples/android/Translate/res/drawable/zw.png +0 -0
- data/examples/android/Translate/res/layout/about_dialog.xml +15 -0
- data/examples/android/Translate/res/layout/history_activity.xml +21 -0
- data/examples/android/Translate/res/layout/history_record.xml +77 -0
- data/examples/android/Translate/res/layout/language_dialog.xml +30 -0
- data/examples/android/Translate/res/layout/language_entry.xml +25 -0
- data/examples/android/Translate/res/layout/main.xml +13 -0
- data/examples/android/Translate/res/layout/translate_activity.xml +114 -0
- data/examples/android/Translate/res/menu/history_activity_menu.xml +35 -0
- data/examples/android/Translate/res/menu/translate_activity_menu.xml +35 -0
- data/examples/android/Translate/res/raw/dictionary.txtgz +0 -0
- data/examples/android/Translate/res/values/strings.xml +50 -0
- data/examples/android/Translate/sign +11 -0
- data/examples/android/Translate/src/com/beust/android/translate/AboutDialog.java +39 -0
- data/examples/android/Translate/src/com/beust/android/translate/Entities.java +990 -0
- data/examples/android/Translate/src/com/beust/android/translate/History.java +164 -0
- data/examples/android/Translate/src/com/beust/android/translate/HistoryActivity.java +124 -0
- data/examples/android/Translate/src/com/beust/android/translate/HistoryRecord.java +83 -0
- data/examples/android/Translate/src/com/beust/android/translate/ITranslate.aidl +27 -0
- data/examples/android/Translate/src/com/beust/android/translate/ITranslate.java +139 -0
- data/examples/android/Translate/src/com/beust/android/translate/LanguageDialog.java +90 -0
- data/examples/android/Translate/src/com/beust/android/translate/Languages.java +220 -0
- data/examples/android/Translate/src/com/beust/android/translate/Lists.java +64 -0
- data/examples/android/Translate/src/com/beust/android/translate/Maps.java +33 -0
- data/examples/android/Translate/src/com/beust/android/translate/R.java +333 -0
- data/examples/android/Translate/src/com/beust/android/translate/Translate.java +117 -0
- data/examples/android/Translate/src/com/beust/android/translate/TranslateActivity.java +443 -0
- data/examples/android/Translate/src/com/beust/android/translate/TranslateService.java +63 -0
- data/examples/android/WikiNotes/AndroidManifest.xml +64 -0
- data/examples/android/WikiNotes/README.TXT +67 -0
- data/examples/android/WikiNotes/bin/WikiNotes.ap_ +0 -0
- data/examples/android/WikiNotes/build.xml +269 -0
- data/examples/android/WikiNotes/res/drawable/icon.png +0 -0
- data/examples/android/WikiNotes/res/drawable/icon_delete.png +0 -0
- data/examples/android/WikiNotes/res/drawable/icon_recent.png +0 -0
- data/examples/android/WikiNotes/res/drawable/icon_start.png +0 -0
- data/examples/android/WikiNotes/res/drawable/parchmentbase.png +0 -0
- data/examples/android/WikiNotes/res/layout/main.xml +33 -0
- data/examples/android/WikiNotes/res/layout/wiki_note_edit.xml +49 -0
- data/examples/android/WikiNotes/res/layout/wiki_search.xml +45 -0
- data/examples/android/WikiNotes/res/menu/notelist.xml +24 -0
- data/examples/android/WikiNotes/res/values/strings.xml +70 -0
- data/examples/android/WikiNotes/res/xml/searchable.xml +30 -0
- data/examples/android/WikiNotes/src/com/google/android/wikinotes/Eula.java +60 -0
- data/examples/android/WikiNotes/src/com/google/android/wikinotes/R.java +90 -0
- data/examples/android/WikiNotes/src/com/google/android/wikinotes/WikiActivityHelper.java +448 -0
- data/examples/android/WikiNotes/src/com/google/android/wikinotes/WikiNoteEditor.java +121 -0
- data/examples/android/WikiNotes/src/com/google/android/wikinotes/WikiNotes.java +282 -0
- data/examples/android/WikiNotes/src/com/google/android/wikinotes/WikiNotesList.java +159 -0
- data/examples/android/WikiNotes/src/com/google/android/wikinotes/db/WikiNote.java +100 -0
- data/examples/android/WikiNotes/src/com/google/android/wikinotes/db/WikiNotesProvider.java +331 -0
- data/examples/different_states_of_andrakeness/BasicUI_1/AndroidManifest.xml +20 -0
- data/examples/different_states_of_andrakeness/BasicUI_1/AnotherView.java +39 -0
- data/examples/different_states_of_andrakeness/BasicUI_1/BasicUI.java +102 -0
- data/examples/different_states_of_andrakeness/BasicUI_1/UiResult.java +20 -0
- data/examples/different_states_of_andrakeness/BasicUI_1/build.xml +269 -0
- data/examples/different_states_of_andrakeness/BasicUI_1/res/drawable/icon.png +0 -0
- data/examples/different_states_of_andrakeness/BasicUI_1/res/layout/main.xml +23 -0
- data/examples/different_states_of_andrakeness/BasicUI_1/res/layout/result.xml +12 -0
- data/examples/different_states_of_andrakeness/BasicUI_1/res/values/colors.xml +10 -0
- data/examples/different_states_of_andrakeness/BasicUI_1/res/values/strings.xml +6 -0
- data/examples/different_states_of_andrakeness/BasicUI_1/src/com/android/basicui/AnotherView.java +39 -0
- data/examples/different_states_of_andrakeness/BasicUI_1/src/com/android/basicui/BasicUI.java +102 -0
- data/examples/different_states_of_andrakeness/BasicUI_1/src/com/android/basicui/R.java +36 -0
- data/examples/different_states_of_andrakeness/BasicUI_1/src/com/android/basicui/UiResult.java +20 -0
- data/examples/different_states_of_andrakeness/BasicUI_2/AndroidManifest.xml +20 -0
- data/examples/different_states_of_andrakeness/BasicUI_2/build.xml +269 -0
- data/examples/different_states_of_andrakeness/BasicUI_2/reinstall-and-debug-on-default-device +6 -0
- data/examples/different_states_of_andrakeness/BasicUI_2/reinstall-and-run-on-default-device +6 -0
- data/examples/different_states_of_andrakeness/BasicUI_2/res/drawable/icon.png +0 -0
- data/examples/different_states_of_andrakeness/BasicUI_2/res/layout/main.xml +23 -0
- data/examples/different_states_of_andrakeness/BasicUI_2/res/layout/result.xml +12 -0
- data/examples/different_states_of_andrakeness/BasicUI_2/res/values/colors.xml +10 -0
- data/examples/different_states_of_andrakeness/BasicUI_2/res/values/strings.xml +6 -0
- data/examples/different_states_of_andrakeness/BasicUI_2/src/com/android/basicui/AnotherView.java +39 -0
- data/examples/different_states_of_andrakeness/BasicUI_2/src/com/android/basicui/BasicUI.java +102 -0
- data/examples/different_states_of_andrakeness/BasicUI_2/src/com/android/basicui/R.java +36 -0
- data/examples/different_states_of_andrakeness/BasicUI_2/src/com/android/basicui/UiResult.java +20 -0
- data/examples/different_states_of_andrakeness/BasicUI_3/AndroidManifest.xml +20 -0
- data/examples/different_states_of_andrakeness/BasicUI_3/app.css +4 -0
- data/examples/different_states_of_andrakeness/BasicUI_3/build.xml +269 -0
- data/examples/different_states_of_andrakeness/BasicUI_3/res/drawable/icon.png +0 -0
- data/examples/different_states_of_andrakeness/BasicUI_3/res/layout/main.xml +22 -0
- data/examples/different_states_of_andrakeness/BasicUI_3/res/layout/result.xml +12 -0
- data/examples/different_states_of_andrakeness/BasicUI_3/res/values/colors.xml +10 -0
- data/examples/different_states_of_andrakeness/BasicUI_3/res/values/strings.xml +6 -0
- data/examples/different_states_of_andrakeness/BasicUI_3/src/com/android/basicui/AnotherView.java +39 -0
- data/examples/different_states_of_andrakeness/BasicUI_3/src/com/android/basicui/BasicUI.java +102 -0
- data/examples/different_states_of_andrakeness/BasicUI_3/src/com/android/basicui/R.java +36 -0
- data/examples/different_states_of_andrakeness/BasicUI_3/src/com/android/basicui/UiResult.java +20 -0
- data/examples/different_states_of_andrakeness/BasicUI_4/AndroidManifest.xml +20 -0
- data/examples/different_states_of_andrakeness/BasicUI_4/app.sass +3 -0
- data/examples/different_states_of_andrakeness/BasicUI_4/build.xml +269 -0
- data/examples/different_states_of_andrakeness/BasicUI_4/res/drawable/icon.png +0 -0
- data/examples/different_states_of_andrakeness/BasicUI_4/res/layout/main.xml +22 -0
- data/examples/different_states_of_andrakeness/BasicUI_4/res/layout/result.xml +12 -0
- data/examples/different_states_of_andrakeness/BasicUI_4/res/values/colors.xml +10 -0
- data/examples/different_states_of_andrakeness/BasicUI_4/res/values/strings.xml +6 -0
- data/examples/different_states_of_andrakeness/BasicUI_4/src/com/android/basicui/AnotherView.java +39 -0
- data/examples/different_states_of_andrakeness/BasicUI_4/src/com/android/basicui/BasicUI.java +102 -0
- data/examples/different_states_of_andrakeness/BasicUI_4/src/com/android/basicui/R.java +36 -0
- data/examples/different_states_of_andrakeness/BasicUI_4/src/com/android/basicui/UiResult.java +20 -0
- data/examples/different_states_of_andrakeness/BasicUI_5/AndroidManifest.xml +20 -0
- data/examples/different_states_of_andrakeness/BasicUI_5/app.sass +3 -0
- data/examples/different_states_of_andrakeness/BasicUI_5/build.xml +269 -0
- data/examples/different_states_of_andrakeness/BasicUI_5/res/drawable/icon.png +0 -0
- data/examples/different_states_of_andrakeness/BasicUI_5/res/layout/main.xml +21 -0
- data/examples/different_states_of_andrakeness/BasicUI_5/res/layout/result.xml +12 -0
- data/examples/different_states_of_andrakeness/BasicUI_5/res/values/colors.xml +10 -0
- data/examples/different_states_of_andrakeness/BasicUI_5/res/values/strings.xml +6 -0
- data/examples/different_states_of_andrakeness/BasicUI_5/src/com/android/basicui/AnotherView.java +39 -0
- data/examples/different_states_of_andrakeness/BasicUI_5/src/com/android/basicui/BasicUI.java +102 -0
- data/examples/different_states_of_andrakeness/BasicUI_5/src/com/android/basicui/R.java +36 -0
- data/examples/different_states_of_andrakeness/BasicUI_5/src/com/android/basicui/UiResult.java +20 -0
- data/examples/different_states_of_andrakeness/BasicUI_6/AndroidManifest.xml +20 -0
- data/examples/different_states_of_andrakeness/BasicUI_6/app.sass +17 -0
- data/examples/different_states_of_andrakeness/BasicUI_6/build.xml +269 -0
- data/examples/different_states_of_andrakeness/BasicUI_6/res/drawable/icon.png +0 -0
- data/examples/different_states_of_andrakeness/BasicUI_6/res/layout/main.haml +4 -0
- data/examples/different_states_of_andrakeness/BasicUI_6/res/layout/result.xml +12 -0
- data/examples/different_states_of_andrakeness/BasicUI_6/res/values/colors.xml +10 -0
- data/examples/different_states_of_andrakeness/BasicUI_6/res/values/strings.xml +6 -0
- data/examples/different_states_of_andrakeness/BasicUI_6/src/com/android/basicui/AnotherView.java +39 -0
- data/examples/different_states_of_andrakeness/BasicUI_6/src/com/android/basicui/BasicUI.java +102 -0
- data/examples/different_states_of_andrakeness/BasicUI_6/src/com/android/basicui/R.java +36 -0
- data/examples/different_states_of_andrakeness/BasicUI_6/src/com/android/basicui/UiResult.java +20 -0
- data/examples/different_states_of_andrakeness/BasicUI_7/app.sass +17 -0
- data/examples/different_states_of_andrakeness/BasicUI_7/build.xml +269 -0
- data/examples/different_states_of_andrakeness/BasicUI_7/res/drawable/icon.png +0 -0
- data/examples/different_states_of_andrakeness/BasicUI_7/res/layout/main.haml +4 -0
- data/examples/different_states_of_andrakeness/BasicUI_7/res/layout/result.xml +12 -0
- data/examples/different_states_of_andrakeness/BasicUI_7/res/values/colors.xml +10 -0
- data/examples/different_states_of_andrakeness/BasicUI_7/res/values/strings.xml +6 -0
- data/examples/different_states_of_andrakeness/BasicUI_7/src/com/android/basicui/AnotherView.java +39 -0
- data/examples/different_states_of_andrakeness/BasicUI_7/src/com/android/basicui/BasicUI.java +102 -0
- data/examples/different_states_of_andrakeness/BasicUI_7/src/com/android/basicui/R.java +36 -0
- data/examples/different_states_of_andrakeness/BasicUI_7/src/com/android/basicui/UiResult.java +20 -0
- data/examples/different_states_of_andrakeness/BasicUI_8/app/activities/AnotherView.java +39 -0
- data/examples/different_states_of_andrakeness/BasicUI_8/app/activities/BasicUI.java +102 -0
- data/examples/different_states_of_andrakeness/BasicUI_8/app/activities/UiResult.java +20 -0
- data/examples/different_states_of_andrakeness/BasicUI_8/app/layouts/main.haml +4 -0
- data/examples/different_states_of_andrakeness/BasicUI_8/app/layouts/result.xml +12 -0
- data/examples/different_states_of_andrakeness/BasicUI_8/app/styles/app.sass +17 -0
- data/examples/different_states_of_andrakeness/BasicUI_8/init.rb +13 -0
- data/examples/different_states_of_andrakeness/BasicUI_8/res/drawable/icon.png +0 -0
- data/examples/more-apps/AnyCut/AndroidManifest.xml +58 -0
- data/examples/more-apps/AnyCut/NOTICE +190 -0
- data/examples/more-apps/AnyCut/res/drawable/app_icon.png +0 -0
- data/examples/more-apps/AnyCut/res/drawable/sym_action_call.png +0 -0
- data/examples/more-apps/AnyCut/res/drawable/sym_action_sms.png +0 -0
- data/examples/more-apps/AnyCut/res/layout/custom_shortcut_creator.xml +33 -0
- data/examples/more-apps/AnyCut/res/layout/front_door.xml +44 -0
- data/examples/more-apps/AnyCut/res/layout/list.xml +22 -0
- data/examples/more-apps/AnyCut/res/layout/shortcut_editor.xml +38 -0
- data/examples/more-apps/AnyCut/res/values/colors.xml +22 -0
- data/examples/more-apps/AnyCut/res/values/strings.xml +48 -0
- data/examples/more-apps/AnyCut/src/com/example/anycut/ActivityPickerActivity.java +171 -0
- data/examples/more-apps/AnyCut/src/com/example/anycut/CreateShortcutActivity.java +324 -0
- data/examples/more-apps/AnyCut/src/com/example/anycut/CustomShortcutCreatorActivity.java +83 -0
- data/examples/more-apps/AnyCut/src/com/example/anycut/FrontDoorActivity.java +75 -0
- data/examples/more-apps/AnyCut/src/com/example/anycut/ShortcutEditorDialog.java +171 -0
- data/examples/more-apps/AnyCut/src/com/google/android/photostream/UserTask.java +457 -0
- data/examples/more-apps/LolcatBuilder/AndroidManifest.xml +32 -0
- data/examples/more-apps/LolcatBuilder/README.txt +90 -0
- data/examples/more-apps/LolcatBuilder/build.xml +269 -0
- data/examples/more-apps/LolcatBuilder/res/drawable/app_icon.png +0 -0
- data/examples/more-apps/LolcatBuilder/res/drawable/photo_border.9.png +0 -0
- data/examples/more-apps/LolcatBuilder/res/layout-land/lolcat_activity.xml +91 -0
- data/examples/more-apps/LolcatBuilder/res/layout/lolcat_activity.xml +90 -0
- data/examples/more-apps/LolcatBuilder/res/layout/lolcat_caption_dialog.xml +68 -0
- data/examples/more-apps/LolcatBuilder/res/values/strings.xml +45 -0
- data/examples/more-apps/LolcatBuilder/src/com/android/lolcat/LolcatActivity.java +808 -0
- data/examples/more-apps/LolcatBuilder/src/com/android/lolcat/LolcatView.java +638 -0
- data/examples/more-apps/LolcatBuilder/src/com/android/lolcat/R.java +60 -0
- data/examples/simplegen/template-dir1/app/foo.xml._erb +1 -0
- data/examples/simplegen/template-dir1/dynamic_dirname/_%dynamic%_/foo +0 -0
- data/examples/simplegen/template-dir1/dynamic_filename/%dynamic%_file.rb.erb +1 -0
- data/examples/simplegen/template-dir1/many_dirs/many/dirs/hello.txt.erb +2 -0
- data/lib/andrake.rb +17 -0
- data/lib/andrake/activity.rb +32 -0
- data/lib/andrake/application.rb +202 -0
- data/lib/andrake/bin.rb +66 -0
- data/lib/andrake/hybrid.rb +87 -0
- data/lib/andrake/resource_manager.rb +42 -0
- data/lib/android.rb +21 -0
- data/lib/android/activity.rb +2 -0
- data/lib/android/application.rb +194 -0
- data/lib/android/bin.rb +75 -0
- data/lib/android/extensions.rb +9 -0
- data/lib/android/gen.rb +86 -0
- data/lib/android/javaclass.rb +26 -0
- data/lib/android/layout.rb +142 -0
- data/lib/javaclass.rb +50 -0
- data/lib/simplegen.rb +236 -0
- data/spec/andrake/basic_ui_spec.rb +12 -0
- data/spec/andrake/hello_android_spec.rb +36 -0
- data/spec/android/basic_ui_spec.rb +33 -0
- data/spec/android/hello_android_spec.rb +55 -0
- data/spec/custom_matcher.rb +51 -0
- data/spec/javaclass/examples/Eula.java +60 -0
- data/spec/javaclass/examples/WikiActivityHelper.java +448 -0
- data/spec/javaclass/examples/WikiNoteEditor.java +121 -0
- data/spec/javaclass/examples/WikiNotes.java +282 -0
- data/spec/javaclass/examples/WikiNotesList.java +159 -0
- data/spec/javaclass/javaclass_spec.rb +36 -0
- data/spec/rcov.opts +2 -0
- data/spec/simplegen/simplegen_spec.rb +139 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +51 -0
- metadata +727 -0
@@ -0,0 +1,83 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2008 Google Inc.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
package com.example.anycut;
|
18
|
+
|
19
|
+
import android.app.Activity;
|
20
|
+
import android.content.Intent;
|
21
|
+
import android.net.Uri;
|
22
|
+
import android.os.Bundle;
|
23
|
+
import android.text.TextUtils;
|
24
|
+
import android.view.View;
|
25
|
+
import android.widget.EditText;
|
26
|
+
|
27
|
+
/**
|
28
|
+
* A simple activity to allow the user to manually type in an Intent.
|
29
|
+
*/
|
30
|
+
public class CustomShortcutCreatorActivity extends Activity implements View.OnClickListener {
|
31
|
+
|
32
|
+
@Override
|
33
|
+
protected void onCreate(Bundle savedState) {
|
34
|
+
super.onCreate(savedState);
|
35
|
+
|
36
|
+
setContentView(R.layout.custom_shortcut_creator);
|
37
|
+
|
38
|
+
findViewById(R.id.ok).setOnClickListener(this);
|
39
|
+
findViewById(R.id.cancel).setOnClickListener(this);
|
40
|
+
}
|
41
|
+
|
42
|
+
public void onClick(View view) {
|
43
|
+
switch (view.getId()) {
|
44
|
+
case R.id.ok: {
|
45
|
+
Intent intent = createShortcutIntent();
|
46
|
+
setResult(RESULT_OK, intent);
|
47
|
+
finish();
|
48
|
+
break;
|
49
|
+
}
|
50
|
+
|
51
|
+
case R.id.cancel: {
|
52
|
+
setResult(RESULT_CANCELED);
|
53
|
+
finish();
|
54
|
+
break;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
private Intent createShortcutIntent() {
|
60
|
+
Intent intent = new Intent();
|
61
|
+
|
62
|
+
EditText view;
|
63
|
+
view = (EditText) findViewById(R.id.action);
|
64
|
+
intent.setAction(view.getText().toString());
|
65
|
+
|
66
|
+
view = (EditText) findViewById(R.id.data);
|
67
|
+
String data = view.getText().toString();
|
68
|
+
view = (EditText) findViewById(R.id.type);
|
69
|
+
String type = view.getText().toString();
|
70
|
+
|
71
|
+
boolean dataEmpty = TextUtils.isEmpty(data);
|
72
|
+
boolean typeEmpty = TextUtils.isEmpty(type);
|
73
|
+
if (!dataEmpty && typeEmpty) {
|
74
|
+
intent.setData(Uri.parse(data));
|
75
|
+
} else if (!typeEmpty && dataEmpty) {
|
76
|
+
intent.setType(type);
|
77
|
+
} else if (!typeEmpty && !dataEmpty) {
|
78
|
+
intent.setDataAndType(Uri.parse(data), type);
|
79
|
+
}
|
80
|
+
|
81
|
+
return new Intent().putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
|
82
|
+
}
|
83
|
+
}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2008 Google Inc.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
package com.example.anycut;
|
18
|
+
|
19
|
+
import android.app.Activity;
|
20
|
+
import android.content.Intent;
|
21
|
+
import android.os.Bundle;
|
22
|
+
import android.view.View;
|
23
|
+
import android.view.View.OnClickListener;
|
24
|
+
import android.widget.Toast;
|
25
|
+
|
26
|
+
/**
|
27
|
+
* The activity that shows up in the list of all applications. It has a button
|
28
|
+
* allowing the user to create a new shortcut, and guides them to using Any Cut
|
29
|
+
* through long pressing on the location of the desired shortcut.
|
30
|
+
*/
|
31
|
+
public class FrontDoorActivity extends Activity implements OnClickListener {
|
32
|
+
private static final int REQUEST_SHORTCUT = 1;
|
33
|
+
|
34
|
+
@Override
|
35
|
+
protected void onCreate(Bundle savedState) {
|
36
|
+
super.onCreate(savedState);
|
37
|
+
|
38
|
+
setContentView(R.layout.front_door);
|
39
|
+
|
40
|
+
// Setup the new shortcut button
|
41
|
+
View view = findViewById(R.id.newShortcut);
|
42
|
+
if (view != null) {
|
43
|
+
view.setOnClickListener(this);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
public void onClick(View view) {
|
48
|
+
switch (view.getId()) {
|
49
|
+
case R.id.newShortcut: {
|
50
|
+
// Start the activity to create a shortcut intent
|
51
|
+
Intent intent = new Intent(this, CreateShortcutActivity.class);
|
52
|
+
startActivityForResult(intent, REQUEST_SHORTCUT);
|
53
|
+
break;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
@Override
|
59
|
+
protected void onActivityResult(int requestCode, int resultCode, Intent result) {
|
60
|
+
if (resultCode != RESULT_OK) {
|
61
|
+
return;
|
62
|
+
}
|
63
|
+
|
64
|
+
switch (requestCode) {
|
65
|
+
case REQUEST_SHORTCUT: {
|
66
|
+
// Boradcast an intent that tells the home screen to create a new shortcut
|
67
|
+
result.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
|
68
|
+
sendBroadcast(result);
|
69
|
+
|
70
|
+
// Inform the user that the shortcut has been created
|
71
|
+
Toast.makeText(this, R.string.shortcutCreated, Toast.LENGTH_SHORT).show();
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
@@ -0,0 +1,171 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2008 Google Inc.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
package com.example.anycut;
|
18
|
+
|
19
|
+
import android.app.AlertDialog;
|
20
|
+
import android.content.Context;
|
21
|
+
import android.content.DialogInterface;
|
22
|
+
import android.content.Intent;
|
23
|
+
import android.content.DialogInterface.OnClickListener;
|
24
|
+
import android.content.Intent.ShortcutIconResource;
|
25
|
+
import android.graphics.Bitmap;
|
26
|
+
import android.os.Bundle;
|
27
|
+
import android.text.Editable;
|
28
|
+
import android.text.TextUtils;
|
29
|
+
import android.text.TextWatcher;
|
30
|
+
import android.view.View;
|
31
|
+
import android.widget.EditText;
|
32
|
+
import android.widget.ImageView;
|
33
|
+
|
34
|
+
/**
|
35
|
+
* A dialog that can edit a shortcut intent. For now the icon is displayed, and only
|
36
|
+
* the name may be edited.
|
37
|
+
*/
|
38
|
+
public class ShortcutEditorDialog extends AlertDialog implements OnClickListener, TextWatcher {
|
39
|
+
static final String STATE_INTENT = "intent";
|
40
|
+
|
41
|
+
private boolean mCreated = false;
|
42
|
+
|
43
|
+
private Intent mIntent;
|
44
|
+
private ImageView mIconView;
|
45
|
+
private EditText mNameView;
|
46
|
+
private OnClickListener mOnClick;
|
47
|
+
private OnCancelListener mOnCancel;
|
48
|
+
|
49
|
+
public ShortcutEditorDialog(Context context, OnClickListener onClick,
|
50
|
+
OnCancelListener onCancel) {
|
51
|
+
super(context);
|
52
|
+
|
53
|
+
mOnClick = onClick;
|
54
|
+
mOnCancel = onCancel;
|
55
|
+
|
56
|
+
// Setup the dialog
|
57
|
+
View view = getLayoutInflater().inflate(R.layout.shortcut_editor, null, false);
|
58
|
+
setTitle(R.string.shortcutEditorTitle);
|
59
|
+
setButton(context.getText(android.R.string.ok), this);
|
60
|
+
setButton2(context.getText(android.R.string.cancel), mOnClick);
|
61
|
+
setOnCancelListener(mOnCancel);
|
62
|
+
setCancelable(true);
|
63
|
+
setView(view);
|
64
|
+
|
65
|
+
mIconView = (ImageView) view.findViewById(R.id.shortcutIcon);
|
66
|
+
mNameView = (EditText) view.findViewById(R.id.shortcutName);
|
67
|
+
}
|
68
|
+
|
69
|
+
public void onClick(DialogInterface dialog, int which) {
|
70
|
+
if (which == BUTTON1) {
|
71
|
+
String name = mNameView.getText().toString();
|
72
|
+
if (TextUtils.isEmpty(name)) {
|
73
|
+
// Don't allow an empty name
|
74
|
+
mNameView.setError(getContext().getText(R.string.errorEmptyName));
|
75
|
+
return;
|
76
|
+
}
|
77
|
+
mIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
|
78
|
+
}
|
79
|
+
mOnClick.onClick(dialog, which);
|
80
|
+
}
|
81
|
+
|
82
|
+
@Override
|
83
|
+
protected void onCreate(Bundle state) {
|
84
|
+
super.onCreate(state);
|
85
|
+
if (state != null) {
|
86
|
+
mIntent = state.getParcelable(STATE_INTENT);
|
87
|
+
}
|
88
|
+
|
89
|
+
mCreated = true;
|
90
|
+
|
91
|
+
// If an intent is set make sure to load it now that it's safe
|
92
|
+
if (mIntent != null) {
|
93
|
+
loadIntent(mIntent);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
@Override
|
98
|
+
public Bundle onSaveInstanceState() {
|
99
|
+
Bundle state = super.onSaveInstanceState();
|
100
|
+
state.putParcelable(STATE_INTENT, getIntent());
|
101
|
+
return state;
|
102
|
+
}
|
103
|
+
|
104
|
+
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
105
|
+
// Do nothing
|
106
|
+
}
|
107
|
+
|
108
|
+
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
109
|
+
// Do nothing
|
110
|
+
}
|
111
|
+
|
112
|
+
public void afterTextChanged(Editable text) {
|
113
|
+
if (text.length() == 0) {
|
114
|
+
mNameView.setError(getContext().getText(R.string.errorEmptyName));
|
115
|
+
} else {
|
116
|
+
mNameView.setError(null);
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
/**
|
121
|
+
* Saves the current state of the editor into the intent and returns it.
|
122
|
+
*
|
123
|
+
* @return the intent for the shortcut being edited
|
124
|
+
*/
|
125
|
+
public Intent getIntent() {
|
126
|
+
mIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, mNameView.getText().toString());
|
127
|
+
return mIntent;
|
128
|
+
}
|
129
|
+
|
130
|
+
/**
|
131
|
+
* Reads the state of the shortcut from the intent and sets up the editor
|
132
|
+
*
|
133
|
+
* @param intent A shortcut intent to edit
|
134
|
+
*/
|
135
|
+
public void setIntent(Intent intent) {
|
136
|
+
mIntent = intent;
|
137
|
+
if (mCreated) {
|
138
|
+
loadIntent(intent);
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
/**
|
143
|
+
* Loads the editor state from a shortcut intent.
|
144
|
+
*
|
145
|
+
* @param intent The shortcut intent to load the editor from
|
146
|
+
*/
|
147
|
+
private void loadIntent(Intent intent) {
|
148
|
+
// Show the icon
|
149
|
+
Bitmap iconBitmap = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
|
150
|
+
if (iconBitmap != null) {
|
151
|
+
mIconView.setImageBitmap(iconBitmap);
|
152
|
+
} else {
|
153
|
+
ShortcutIconResource iconRes = intent.getParcelableExtra(
|
154
|
+
Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
|
155
|
+
if (iconRes != null) {
|
156
|
+
int res = getContext().getResources().getIdentifier(iconRes.resourceName, null,
|
157
|
+
iconRes.packageName);
|
158
|
+
mIconView.setImageResource(res);
|
159
|
+
} else {
|
160
|
+
mIconView.setVisibility(View.INVISIBLE);
|
161
|
+
}
|
162
|
+
}
|
163
|
+
|
164
|
+
// Fill in the name field for editing
|
165
|
+
mNameView.addTextChangedListener(this);
|
166
|
+
mNameView.setText(intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME));
|
167
|
+
|
168
|
+
// Ensure the intent has the proper flags
|
169
|
+
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
170
|
+
}
|
171
|
+
}
|
@@ -0,0 +1,457 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2008 Google Inc.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
package com.google.android.photostream;
|
18
|
+
|
19
|
+
import android.os.*;
|
20
|
+
import android.os.Process;
|
21
|
+
|
22
|
+
import java.util.concurrent.ThreadPoolExecutor;
|
23
|
+
import java.util.concurrent.TimeUnit;
|
24
|
+
import java.util.concurrent.BlockingQueue;
|
25
|
+
import java.util.concurrent.LinkedBlockingQueue;
|
26
|
+
import java.util.concurrent.ThreadFactory;
|
27
|
+
import java.util.concurrent.Callable;
|
28
|
+
import java.util.concurrent.FutureTask;
|
29
|
+
import java.util.concurrent.ExecutionException;
|
30
|
+
import java.util.concurrent.TimeoutException;
|
31
|
+
import java.util.concurrent.CancellationException;
|
32
|
+
import java.util.concurrent.atomic.AtomicInteger;
|
33
|
+
|
34
|
+
/**
|
35
|
+
* <p>UserTask enables proper and easy use of the UI thread. This class allows to
|
36
|
+
* perform background operations and publish results on the UI thread without
|
37
|
+
* having to manipulate threads and/or handlers.</p>
|
38
|
+
*
|
39
|
+
* <p>A user task is defined by a computation that runs on a background thread and
|
40
|
+
* whose result is published on the UI thread. A user task is defined by 3 generic
|
41
|
+
* types, called <code>Params</code>, <code>Progress</code> and <code>Result</code>,
|
42
|
+
* and 4 steps, called <code>begin</code>, <code>doInBackground</code>,
|
43
|
+
* <code>processProgress<code> and <code>end</code>.</p>
|
44
|
+
*
|
45
|
+
* <h2>Usage</h2>
|
46
|
+
* <p>UserTask must be subclassed to be used. The subclass will override at least
|
47
|
+
* one method ({@link #doInBackground(Object[])}), and most often will override a
|
48
|
+
* second one ({@link #onPostExecute(Object)}.)</p>
|
49
|
+
*
|
50
|
+
* <p>Here is an example of subclassing:</p>
|
51
|
+
* <pre>
|
52
|
+
* private class DownloadFilesTask extends UserTask<URL, Integer, Long> {
|
53
|
+
* public File doInBackground(URL... urls) {
|
54
|
+
* int count = urls.length;
|
55
|
+
* long totalSize = 0;
|
56
|
+
* for (int i = 0; i < count; i++) {
|
57
|
+
* totalSize += Downloader.downloadFile(urls[i]);
|
58
|
+
* publishProgress((int) ((i / (float) count) * 100));
|
59
|
+
* }
|
60
|
+
* }
|
61
|
+
*
|
62
|
+
* public void processProgress(Integer... progress) {
|
63
|
+
* setProgressPercent(progress[0]);
|
64
|
+
* }
|
65
|
+
*
|
66
|
+
* public void end(Long result) {
|
67
|
+
* showDialog("Downloaded " + result + " bytes");
|
68
|
+
* }
|
69
|
+
* }
|
70
|
+
* </pre>
|
71
|
+
*
|
72
|
+
* <p>Once created, a task is executed very simply:</p>
|
73
|
+
* <pre>
|
74
|
+
* new DownloadFilesTask().execute(new URL[] { ... });
|
75
|
+
* </pre>
|
76
|
+
*
|
77
|
+
* <h2>User task's generic types</h2>
|
78
|
+
* <p>The three types used by a user task are the following:</p>
|
79
|
+
* <ol>
|
80
|
+
* <li><code>Params</code>, the type of the parameters sent to the task upon
|
81
|
+
* execution.</li>
|
82
|
+
* <li><code>Progress</code>, the type of the progress units published during
|
83
|
+
* the background computation.</li>
|
84
|
+
* <li><code>Result</code>, the type of the result of the background
|
85
|
+
* computation.</li>
|
86
|
+
* </ol>
|
87
|
+
* <p>Not all types are always used by a user task. To mark a type as unused,
|
88
|
+
* simply use the type {@link Void}:</p>
|
89
|
+
* <pre>
|
90
|
+
* private class MyTask extends UserTask<Void, Void, Void) { ... }
|
91
|
+
* </pre>
|
92
|
+
*
|
93
|
+
* <h2>The 4 steps</h2>
|
94
|
+
* <p>When a user task is executed, the task goes through 4 steps:</p>
|
95
|
+
* <ol>
|
96
|
+
* <li>{@link #onPreExecute()}, invoked on the UI thread immediately after the task
|
97
|
+
* is executed. This step is normally used to setup the task, for instance by
|
98
|
+
* showing a progress bar in the user interface.</li>
|
99
|
+
* <li>{@link #doInBackground(Object[])}, invoked on the background thread
|
100
|
+
* immediately after {@link # onPreExecute ()} finishes executing. This step is used
|
101
|
+
* to perform background computation that can take a long time. The parameters
|
102
|
+
* of the user task are passed to this step. The result of the computation must
|
103
|
+
* be returned by this step and will be passed back to the last step. This step
|
104
|
+
* can also use {@link #publishProgress(Object[])} to publish one or more units
|
105
|
+
* of progress. These values are published on the UI thread, in the
|
106
|
+
* {@link #onProgressUpdate(Object[])} step.</li>
|
107
|
+
* <li>{@link # onProgressUpdate (Object[])}, invoked on the UI thread after a
|
108
|
+
* call to {@link #publishProgress(Object[])}. The timing of the execution is
|
109
|
+
* undefined. This method is used to display any form of progress in the user
|
110
|
+
* interface while the background computation is still executing. For instance,
|
111
|
+
* it can be used to animate a progress bar or show logs in a text field.</li>
|
112
|
+
* <li>{@link # onPostExecute (Object)}, invoked on the UI thread after the background
|
113
|
+
* computation finishes. The result of the background computation is passed to
|
114
|
+
* this step as a parameter.</li>
|
115
|
+
* </ol>
|
116
|
+
*
|
117
|
+
* <h2>Threading rules</h2>
|
118
|
+
* <p>There are a few threading rules that must be followed for this class to
|
119
|
+
* work properly:</p>
|
120
|
+
* <ul>
|
121
|
+
* <li>The task instance must be created on the UI thread.</li>
|
122
|
+
* <li>{@link #execute(Object[])} must be invoked on the UI thread.</li>
|
123
|
+
* <li>Do not call {@link # onPreExecute ()}, {@link # onPostExecute (Object)},
|
124
|
+
* {@link #doInBackground(Object[])}, {@link # onProgressUpdate (Object[])}
|
125
|
+
* manually.</li>
|
126
|
+
* <li>The task can be executed only once (an exception will be thrown if
|
127
|
+
* a second execution is attempted.)</li>
|
128
|
+
* </ul>
|
129
|
+
*/
|
130
|
+
public abstract class UserTask<Params, Progress, Result> {
|
131
|
+
private static final String LOG_TAG = "UserTask";
|
132
|
+
|
133
|
+
private static final int CORE_POOL_SIZE = 1;
|
134
|
+
private static final int MAXIMUM_POOL_SIZE = 10;
|
135
|
+
private static final int KEEP_ALIVE = 10;
|
136
|
+
|
137
|
+
private static final BlockingQueue<Runnable> sWorkQueue =
|
138
|
+
new LinkedBlockingQueue<Runnable>(MAXIMUM_POOL_SIZE);
|
139
|
+
|
140
|
+
private static final ThreadFactory sThreadFactory = new ThreadFactory() {
|
141
|
+
private final AtomicInteger mCount = new AtomicInteger(1);
|
142
|
+
|
143
|
+
public Thread newThread(Runnable r) {
|
144
|
+
return new Thread(r, "UserTask #" + mCount.getAndIncrement());
|
145
|
+
}
|
146
|
+
};
|
147
|
+
|
148
|
+
private static final ThreadPoolExecutor sExecutor = new ThreadPoolExecutor(CORE_POOL_SIZE,
|
149
|
+
MAXIMUM_POOL_SIZE, KEEP_ALIVE, TimeUnit.SECONDS, sWorkQueue, sThreadFactory);
|
150
|
+
|
151
|
+
private static final int MESSAGE_POST_RESULT = 0x1;
|
152
|
+
private static final int MESSAGE_POST_PROGRESS = 0x2;
|
153
|
+
private static final int MESSAGE_POST_CANCEL = 0x3;
|
154
|
+
|
155
|
+
private static final InternalHandler sHandler = new InternalHandler();
|
156
|
+
|
157
|
+
private final WorkerRunnable<Params, Result> mWorker;
|
158
|
+
private final FutureTask<Result> mFuture;
|
159
|
+
|
160
|
+
private volatile Status mStatus = Status.PENDING;
|
161
|
+
|
162
|
+
/**
|
163
|
+
* Indicates the current status of the task. Each status will be set only once
|
164
|
+
* during the lifetime of a task.
|
165
|
+
*/
|
166
|
+
public enum Status {
|
167
|
+
/**
|
168
|
+
* Indicates that the task has not been executed yet.
|
169
|
+
*/
|
170
|
+
PENDING,
|
171
|
+
/**
|
172
|
+
* Indicates that the task is running.
|
173
|
+
*/
|
174
|
+
RUNNING,
|
175
|
+
/**
|
176
|
+
* Indicates that {@link UserTask#onPostExecute(Object)} has finished.
|
177
|
+
*/
|
178
|
+
FINISHED,
|
179
|
+
}
|
180
|
+
|
181
|
+
/**
|
182
|
+
* Creates a new user task. This constructor must be invoked on the UI thread.
|
183
|
+
*/
|
184
|
+
public UserTask() {
|
185
|
+
mWorker = new WorkerRunnable<Params, Result>() {
|
186
|
+
public Result call() throws Exception {
|
187
|
+
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
188
|
+
return doInBackground(mParams);
|
189
|
+
}
|
190
|
+
};
|
191
|
+
|
192
|
+
mFuture = new FutureTask<Result>(mWorker) {
|
193
|
+
@Override
|
194
|
+
protected void done() {
|
195
|
+
Message message;
|
196
|
+
Result result = null;
|
197
|
+
|
198
|
+
try {
|
199
|
+
result = get();
|
200
|
+
} catch (InterruptedException e) {
|
201
|
+
android.util.Log.w(LOG_TAG, e);
|
202
|
+
} catch (ExecutionException e) {
|
203
|
+
throw new RuntimeException("An error occured while executing doInBackground()",
|
204
|
+
e.getCause());
|
205
|
+
} catch (CancellationException e) {
|
206
|
+
message = sHandler.obtainMessage(MESSAGE_POST_CANCEL,
|
207
|
+
new UserTaskResult<Result>(UserTask.this, (Result[]) null));
|
208
|
+
message.sendToTarget();
|
209
|
+
return;
|
210
|
+
} catch (Throwable t) {
|
211
|
+
throw new RuntimeException("An error occured while executing "
|
212
|
+
+ "doInBackground()", t);
|
213
|
+
}
|
214
|
+
|
215
|
+
message = sHandler.obtainMessage(MESSAGE_POST_RESULT,
|
216
|
+
new UserTaskResult<Result>(UserTask.this, result));
|
217
|
+
message.sendToTarget();
|
218
|
+
}
|
219
|
+
};
|
220
|
+
}
|
221
|
+
|
222
|
+
/**
|
223
|
+
* Returns the current status of this task.
|
224
|
+
*
|
225
|
+
* @return The current status.
|
226
|
+
*/
|
227
|
+
public final Status getStatus() {
|
228
|
+
return mStatus;
|
229
|
+
}
|
230
|
+
|
231
|
+
/**
|
232
|
+
* Override this method to perform a computation on a background thread. The
|
233
|
+
* specified parameters are the parameters passed to {@link #execute(Object[])}
|
234
|
+
* by the caller of this task.
|
235
|
+
*
|
236
|
+
* This method can call {@link #publishProgress(Object[])} to publish updates
|
237
|
+
* on the UI thread.
|
238
|
+
*
|
239
|
+
* @param params The parameters of the task.
|
240
|
+
*
|
241
|
+
* @return A result, defined by the subclass of this task.
|
242
|
+
*
|
243
|
+
* @see #onPreExecute()
|
244
|
+
* @see #onPostExecute(Object)
|
245
|
+
* @see #publishProgress(Object[])
|
246
|
+
*/
|
247
|
+
public abstract Result doInBackground(Params... params);
|
248
|
+
|
249
|
+
/**
|
250
|
+
* Runs on the UI thread before {@link #doInBackground(Object[])}.
|
251
|
+
*
|
252
|
+
* @see #onPostExecute(Object)
|
253
|
+
* @see #doInBackground(Object[])
|
254
|
+
*/
|
255
|
+
public void onPreExecute() {
|
256
|
+
}
|
257
|
+
|
258
|
+
/**
|
259
|
+
* Runs on the UI thread after {@link #doInBackground(Object[])}. The
|
260
|
+
* specified result is the value returned by {@link #doInBackground(Object[])}
|
261
|
+
* or null if the task was cancelled or an exception occured.
|
262
|
+
*
|
263
|
+
* @param result The result of the operation computed by {@link #doInBackground(Object[])}.
|
264
|
+
*
|
265
|
+
* @see #onPreExecute()
|
266
|
+
* @see #doInBackground(Object[])
|
267
|
+
*/
|
268
|
+
@SuppressWarnings({"UnusedDeclaration"})
|
269
|
+
public void onPostExecute(Result result) {
|
270
|
+
}
|
271
|
+
|
272
|
+
/**
|
273
|
+
* Runs on the UI thread after {@link #publishProgress(Object[])} is invoked.
|
274
|
+
* The specified values are the values passed to {@link #publishProgress(Object[])}.
|
275
|
+
*
|
276
|
+
* @param values The values indicating progress.
|
277
|
+
*
|
278
|
+
* @see #publishProgress(Object[])
|
279
|
+
* @see #doInBackground(Object[])
|
280
|
+
*/
|
281
|
+
@SuppressWarnings({"UnusedDeclaration"})
|
282
|
+
public void onProgressUpdate(Progress... values) {
|
283
|
+
}
|
284
|
+
|
285
|
+
/**
|
286
|
+
* Runs on the UI thread after {@link #cancel(boolean)} is invoked.
|
287
|
+
*
|
288
|
+
* @see #cancel(boolean)
|
289
|
+
* @see #isCancelled()
|
290
|
+
*/
|
291
|
+
public void onCancelled() {
|
292
|
+
}
|
293
|
+
|
294
|
+
/**
|
295
|
+
* Returns <tt>true</tt> if this task was cancelled before it completed
|
296
|
+
* normally.
|
297
|
+
*
|
298
|
+
* @return <tt>true</tt> if task was cancelled before it completed
|
299
|
+
*
|
300
|
+
* @see #cancel(boolean)
|
301
|
+
*/
|
302
|
+
public final boolean isCancelled() {
|
303
|
+
return mFuture.isCancelled();
|
304
|
+
}
|
305
|
+
|
306
|
+
/**
|
307
|
+
* Attempts to cancel execution of this task. This attempt will
|
308
|
+
* fail if the task has already completed, already been cancelled,
|
309
|
+
* or could not be cancelled for some other reason. If successful,
|
310
|
+
* and this task has not started when <tt>cancel</tt> is called,
|
311
|
+
* this task should never run. If the task has already started,
|
312
|
+
* then the <tt>mayInterruptIfRunning</tt> parameter determines
|
313
|
+
* whether the thread executing this task should be interrupted in
|
314
|
+
* an attempt to stop the task.
|
315
|
+
*
|
316
|
+
* @param mayInterruptIfRunning <tt>true</tt> if the thread executing this
|
317
|
+
* task should be interrupted; otherwise, in-progress tasks are allowed
|
318
|
+
* to complete.
|
319
|
+
*
|
320
|
+
* @return <tt>false</tt> if the task could not be cancelled,
|
321
|
+
* typically because it has already completed normally;
|
322
|
+
* <tt>true</tt> otherwise
|
323
|
+
*
|
324
|
+
* @see #isCancelled()
|
325
|
+
* @see #onCancelled()
|
326
|
+
*/
|
327
|
+
public final boolean cancel(boolean mayInterruptIfRunning) {
|
328
|
+
return mFuture.cancel(mayInterruptIfRunning);
|
329
|
+
}
|
330
|
+
|
331
|
+
/**
|
332
|
+
* Waits if necessary for the computation to complete, and then
|
333
|
+
* retrieves its result.
|
334
|
+
*
|
335
|
+
* @return The computed result.
|
336
|
+
*
|
337
|
+
* @throws CancellationException If the computation was cancelled.
|
338
|
+
* @throws ExecutionException If the computation threw an exception.
|
339
|
+
* @throws InterruptedException If the current thread was interrupted
|
340
|
+
* while waiting.
|
341
|
+
*/
|
342
|
+
public final Result get() throws InterruptedException, ExecutionException {
|
343
|
+
return mFuture.get();
|
344
|
+
}
|
345
|
+
|
346
|
+
/**
|
347
|
+
* Waits if necessary for at most the given time for the computation
|
348
|
+
* to complete, and then retrieves its result.
|
349
|
+
*
|
350
|
+
* @param timeout Time to wait before cancelling the operation.
|
351
|
+
* @param unit The time unit for the timeout.
|
352
|
+
*
|
353
|
+
* @return The computed result.
|
354
|
+
*
|
355
|
+
* @throws CancellationException If the computation was cancelled.
|
356
|
+
* @throws ExecutionException If the computation threw an exception.
|
357
|
+
* @throws InterruptedException If the current thread was interrupted
|
358
|
+
* while waiting.
|
359
|
+
* @throws TimeoutException If the wait timed out.
|
360
|
+
*/
|
361
|
+
public final Result get(long timeout, TimeUnit unit) throws InterruptedException,
|
362
|
+
ExecutionException, TimeoutException {
|
363
|
+
return mFuture.get(timeout, unit);
|
364
|
+
}
|
365
|
+
|
366
|
+
/**
|
367
|
+
* Executes the task with the specified parameters. The task returns
|
368
|
+
* itself (this) so that the caller can keep a reference to it.
|
369
|
+
*
|
370
|
+
* This method must be invoked on the UI thread.
|
371
|
+
*
|
372
|
+
* @param params The parameters of the task.
|
373
|
+
*
|
374
|
+
* @return This instance of UserTask.
|
375
|
+
*
|
376
|
+
* @throws IllegalStateException If {@link #getStatus()} returns either
|
377
|
+
* {@link UserTask.Status#RUNNING} or {@link UserTask.Status#FINISHED}.
|
378
|
+
*/
|
379
|
+
public final UserTask<Params, Progress, Result> execute(Params... params) {
|
380
|
+
if (mStatus != Status.PENDING) {
|
381
|
+
switch (mStatus) {
|
382
|
+
case RUNNING:
|
383
|
+
throw new IllegalStateException("Cannot execute task:"
|
384
|
+
+ " the task is already running.");
|
385
|
+
case FINISHED:
|
386
|
+
throw new IllegalStateException("Cannot execute task:"
|
387
|
+
+ " the task has already been executed "
|
388
|
+
+ "(a task can be executed only once)");
|
389
|
+
}
|
390
|
+
}
|
391
|
+
|
392
|
+
mStatus = Status.RUNNING;
|
393
|
+
|
394
|
+
onPreExecute();
|
395
|
+
|
396
|
+
mWorker.mParams = params;
|
397
|
+
sExecutor.execute(mFuture);
|
398
|
+
|
399
|
+
return this;
|
400
|
+
}
|
401
|
+
|
402
|
+
/**
|
403
|
+
* This method can be invoked from {@link #doInBackground(Object[])} to
|
404
|
+
* publish updates on the UI thread while the background computation is
|
405
|
+
* still running. Each call to this method will trigger the execution of
|
406
|
+
* {@link #onProgressUpdate(Object[])} on the UI thread.
|
407
|
+
*
|
408
|
+
* @param values The progress values to update the UI with.
|
409
|
+
*
|
410
|
+
* @see # onProgressUpdate (Object[])
|
411
|
+
* @see #doInBackground(Object[])
|
412
|
+
*/
|
413
|
+
protected final void publishProgress(Progress... values) {
|
414
|
+
sHandler.obtainMessage(MESSAGE_POST_PROGRESS,
|
415
|
+
new UserTaskResult<Progress>(this, values)).sendToTarget();
|
416
|
+
}
|
417
|
+
|
418
|
+
private void finish(Result result) {
|
419
|
+
onPostExecute(result);
|
420
|
+
mStatus = Status.FINISHED;
|
421
|
+
}
|
422
|
+
|
423
|
+
private static class InternalHandler extends Handler {
|
424
|
+
@SuppressWarnings({"unchecked", "RawUseOfParameterizedType"})
|
425
|
+
@Override
|
426
|
+
public void handleMessage(Message msg) {
|
427
|
+
UserTaskResult result = (UserTaskResult) msg.obj;
|
428
|
+
switch (msg.what) {
|
429
|
+
case MESSAGE_POST_RESULT:
|
430
|
+
// There is only one result
|
431
|
+
result.mTask.finish(result.mData[0]);
|
432
|
+
break;
|
433
|
+
case MESSAGE_POST_PROGRESS:
|
434
|
+
result.mTask.onProgressUpdate(result.mData);
|
435
|
+
break;
|
436
|
+
case MESSAGE_POST_CANCEL:
|
437
|
+
result.mTask.onCancelled();
|
438
|
+
break;
|
439
|
+
}
|
440
|
+
}
|
441
|
+
}
|
442
|
+
|
443
|
+
private static abstract class WorkerRunnable<Params, Result> implements Callable<Result> {
|
444
|
+
Params[] mParams;
|
445
|
+
}
|
446
|
+
|
447
|
+
@SuppressWarnings({"RawUseOfParameterizedType"})
|
448
|
+
private static class UserTaskResult<Data> {
|
449
|
+
final UserTask mTask;
|
450
|
+
final Data[] mData;
|
451
|
+
|
452
|
+
UserTaskResult(UserTask task, Data... data) {
|
453
|
+
mTask = task;
|
454
|
+
mData = data;
|
455
|
+
}
|
456
|
+
}
|
457
|
+
}
|