In the previous section, the embedded flash animation in the android program is roughly described. This time I made an extension based on the previous content and made a simple Flash Player.
The prerequisites are described in the previous section. You need to install the Android platform and the flash plug-in.
First look at the engineering drawing and:
Project source code:
Package COM. geolo. android. flash; <br/> Import COM. geolo. android. filebrowser; <br/> Import COM. geolo. android. r; <br/> Import android. app. activity; <br/> Import android. app. alertdialog; <br/> Import android. app. progressdialog; <br/> Import android. content. dialoginterface; <br/> Import android. content. intent; <br/> Import android. OS. bundle; <br/> Import android. OS. handler; <br/> Import android. OS. message; <br/> Import android. util. log; <br/> Import android. view. keyevent; <br/> Import android. view. view; <br/> Import android. webKit. webchromeclient; <br/> Import android. webKit. websettings. pluginstate; <br/> Import android. webKit. webview; <br/> Import android. widget. button; <br/> Import android. widget. framelayout; <br/> Import android. widget. progressbar; <br/> public class flashactivity extends activity {<br/> private Webview mwebview; <br/> private button playbutton, pausebutton, rewindbutton, exitbutton, filebutton; <br/> private progressbar mprogressbarhorizontal; <br/> private final static int progressbarsize = 0x0000; <br/> private final static int flash_start = 0x0001; <br/> private string flashname; <br/> private Boolean stopthread = false; <br/> private progressdialog mprogressdialog; <br/> @ override <br/> Public Void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); <br/> mprogressdialog = new progressdialog (this); <br/> mprogressdialog. setmessage ("The Flash animation is being loaded. Please wait ...... "); <br/> mprogressdialog. show (); <br/> intent = This. getintent (); <br/> string filename = intent. getstringextra ("FILENAME"); <br/> If (filename! = NULL &&! Filename. equals ("") {<br/> flashname = "file: //" + filename; <br/> // flashname = "javascript: setflashpath (flashname )"; <br/>} else {<br/> flashname = "file: // android_asset/sample/flash.swf"; <br/>}< br/> log. D (this. getclass (). getname (), flashname); <br/> mwebview = (webview) findviewbyid (R. id. webview01); <br/> mprogressbarhorizontal = (progressbar) findviewbyid (R. id. progress_horizontal); <br/> This. setprogre SS (mprogressbarhorizontal. getprogress () * 100); <br/> // This. setsecondaryprogress (mprogressbarhorizontal. getsecondaryprogress () * 100); <br/> playbutton = (button) findviewbyid (R. id. playbutton); <br/> pausebutton = (button) findviewbyid (R. id. pausebutton); <br/> rewindbutton = (button) findviewbyid (R. id. rewindbutton); <br/> exitbutton = (button) findviewbyid (R. id. exitbutton); <br/> filebutton = (button) findv Iewbyid (R. id. filebutton); <br/> playbutton. setonclicklistener (buttonlistener); <br/> pausebutton. setonclicklistener (buttonlistener); <br/> rewindbutton. setonclicklistener (buttonlistener); <br/> exitbutton. setonclicklistener (buttonlistener); <br/> filebutton. setonclicklistener (buttonlistener); <br/> mwebview. getsettings (). setjavascriptenabled (true); <br/> // mwebview. getsettings (). setpluginsenabled (true); <Br/> mwebview. getsettings (). setpluginstate (pluginstate. on); <br/> mwebview. setwebchromeclient (New webchromeclient (); <br/> mwebview. addjavascriptinterface (New calljava (), "calljava"); <br/> mwebview. loadurl ("file: // android_asset/sample/index.html"); <br/> // mwebview. loadurl ("javascript: setflashpath ('" + flashname + "')"); <br/> startthread (); <br/>}< br/> button. onclicklistener buttonlistener = new button. Onclicklistener () {<br/> @ override <br/> Public void onclick (view v) {<br/> int buttonid = v. GETID (); <br/> switch (buttonid) {<br/> case R. id. playbutton: <br/> mwebview. loadurl ("javascript: Play ()"); <br/> showflashprogress (5); <br/> break; <br/> case R. id. pausebutton: <br/> mwebview. loadurl ("javascript: Pause ()"); <br/> break; <br/> case R. id. rewindbutton: <br/> // mwebview. loadurl (flashname); <br/> try {<br /> Mwebview. loadurl ("about: blank"); <br/> mwebview. loadurl ("file: // android_asset/sample/index.html"); <br/> thread. sleep (1000); <br/> mwebview. loadurl ("javascript: setflashpath ('" + flashname + "')"); <br/>} catch (interruptedexception e) {<br/> log. E (this. getclass (). getname (), "Flash rewind error:", e); <br/>}< br/> break; <br/> case R. id. filebutton: <br/> intent = new intent (); <br/> intent. setclas S (flashactivity. this, filebrowser. class); <br/> startactivity (intent); <br/> stopthread = true; <br/> flashactivity. this. finish (); <br/> break; <br/> case R. id. exitbutton: <br/> quitdialog (); <br/> break; <br/> default: <br/> break; <br/>}< br/>}; <br/> Public void showflashprogress (float progresssize) {<br/> int size = (INT) progresssize; <br/> // toast. maketext (this, size + "", toast. length_short ). show (); <Br/> mprogressbarhorizontal. setprogress (size); <br/>}< br/> private void quitdialog () {<br/> New alertdialog. builder (this) <br/>. setmessage ("do not quit without fear") <br/>. setpositivebutton ("more daring than you", new alertdialog. onclicklistener () {<br/> @ override <br/> Public void onclick (dialoginterface dialog, int which) {<br/> stopthread = true; <br/> flashactivity. this. finish (); <br/>}< br/>}) <br/>. setnegativebutton ("afraid of you ", Null) <br/>. show (); <br/>}< br/> @ override <br/> Public Boolean onkeydown (INT keycode, keyevent event) {<br/> switch (keycode) {<br/> case keyevent. keycode_back: <br/> quitdialog (); <br/> break; <br/> default: <br/> break; <br/>}< br/> return false; <br/>}< br/> @ override <br/> protected void onpause () {<br/> super. onpause (); <br/> mwebview. pausetimers (); <br/> If (isfinishing () {<br/> mwebview. loadurl ("about: Blank "); <br/> setcontentview (New framelayout (this )); <br/>}< br/> @ override <br/> protected void onresume () {<br/> super. onresume (); <br/> mwebview. resumetimers (); <br/>}< br/> private final class calljava {<br/> Public void consoleflashprogress (float progresssize) {<br/> showflashprogress (progresssize ); <br/>}< br/> private void startthread () {<br/> // change the value of progressbar through a thread <br/> New thread (New Runnable () {<br/> @ override <br/> Public void run () {<br/> try {<br/> thread. sleep (2000); <br/> message = new message (); <br/> message. what = flashactivity. flash_start; <br/> flashactivity. this. mymessagehandler. sendmessage (Message); <br/>} catch (interruptedexception E1) {<br/> thread. currentthread (). interrupt (); <br/>}</P> <p> while (! Stopthread &&! Thread. currentthread (). isinterrupted () {<br/> try {<br/> thread. sleep (2000); <br/> message message2 = new message (); <br/> message2.what = flashactivity. progressbarsize; <br/> flashactivity. this. mymessagehandler. sendmessage (message2); <br/>} catch (exception e) {<br/> thread. currentthread (). interrupt (); <br/>}< br/> }). start (); <br/>}< br/> handler mymessagehandler = new handler () {<br/> @ override <br/> Public void handlemessage (Message MSG) {<br/> switch (MSG. what) {<br/> case flashactivity. progressbarsize: <br/> mwebview. loadurl ("javascript: showcount ()"); <br/> break; <br/> case flashactivity. flash_start: <br/> mwebview. loadurl ("javascript: setflashpath ('" + flashname + "')"); <br/> log. D (this. getclass (). getname (), "Start FLASH:" + flashname); <br/> mprogressdialog. dismiss (); <br/> break; <br/> default: <br/> break; <br/>}< br/> super. handlemessage (MSG); <br/>}< br/>}; <br/>}
Package COM. geolo. android; <br/> Import Java. io. file; <br/> Import Java. util. list; <br/> Import android. content. context; <br/> Import android. view. view; <br/> Import android. view. viewgroup; <br/> Import android. widget. arrayadapter; <br/> Import android. widget. textview; <br/> public class filelistadapter extends arrayadapter <file >{</P> <p> Public filelistadapter (context, int resource, list <File> Object S) {<br/> super (context, resource, objects); <br/>}< br/> @ override <br/> Public View getview (INT position, view convertview, viewgroup parent) {<br/> textview view = (textview) super. getview (Position, convertview, parent); <br/> file = getitem (position); <br/> If (position = 0) {<br/> View. settext ("Current Directory:/root" + file. getabsolutepath (); <br/>} else if (position = 1 &&! Isroot () {<br/> View. settext ("back to the previous directory"); <br/>} else {<br/> View. settext (file. getname (); <br/>}< br/> return view; <br/>}</P> <p> Public Boolean isroot () {<br/> return getitem (0 ). getparent () = NULL; <br/>}< br/>}
Package COM. geolo. android; <br/> Import Java. io. file; <br/> Import Java. io. filefilter; <br/> Import Java. util. arraylist; <br/> Import Java. util. list; <br/> Import COM. geolo. android. flash. flashactivity; <br/> Import android. app. listactivity; <br/> Import android. content. intent; <br/> Import android.net. uri; <br/> Import android. OS. bundle; <br/> Import android. view. keyevent; <br/> Import android. view. view; <br/> Import android. widget. listview; <br/> public class filebrowser extends listactivity {<br/> Private Static final filefilter filter = new filefilter () {<br/> Public Boolean accept (file F) {<br/> // return F. isdirectory () | f. getname (). matches ("^. *? //. (JPG | PNG | BMP | GIF) $ "); <br/> return true; <br/>}< br/>}; <br/> private filelistadapter filelist; <br/> Public void oncreate (bundle icicicle) {<br/> super. oncreate (icicle); <br/> file sdcard = android. OS. environment. getexternalstoragedirectory (); <br/> Fill (sdcard); <br/>}< br/> Public Boolean onkeydown (INT keycode, keyevent event) {<br/> If (keycode = keyevent. keycode_back &&! Filelist. isroot () {<br/> Fill (filelist. getitem (1); <br/> intent = new intent (); <br/> intent. setclass (filebrowser. this, flashactivity. class); <br/> startactivity (intent); <br/> // return true; <br/>}< br/> return Super. onkeydown (keycode, event); <br/>}</P> <p> private void fill (file folder) {<br/> List <File> files = new arraylist <File> (); <br/> files. add (folder); <br/> If (folder. getparentfile ()! = NULL) {<br/> files. add (folder. getparentfile (); <br/>}< br/> for (File file: folder. listfiles (filter) {<br/> files. add (File); <br/>}< br/> filelist = new filelistadapter (this, android. r. layout. simple_list_item_1, files); <br/> setlistadapter (filelist); <br/>}</P> <p> @ override <br/> protected void onlistitemclick (listview l, view V, int position, long ID) {<br/> file = filelist. getitem (position ); <Br/> intent = new intent (); <br/> intent. setaction (Android. content. intent. action_view); <br/> If (file. isdirectory () {<br/> Fill (File); <br/>} else if (file. getname (). matches ("^. *? //. (JPG | PNG | BMP | GIF) $ ") {<br/> intent. setdataandtype (URI. fromfile (file), "image/*"); <br/> startactivity (intent); <br/>} else if (file. getname (). matches ("^. *? //. (SWF) $ ") {<br/> intent. setclass (filebrowser. this, flashactivity. class); <br/> intent. putextra ("FILENAME", file. getabsolutepath (). replace ("/mnt", ""); <br/> startactivity (intent); <br/> filebrowser. this. finish (); <br/>}< br/>
<MCE: script src = "play. JS "mce_src =" play. JS "> </MCE: SCRIPT> <br/> <Table border = "0" cellpadding = "0" cellspacing = "1" bgcolor = "#000000"> <br/> <tr> <br/> <TD> <br/> <Object ID = "movie" classid = "CLSID: d27cdb6e-ae6d-11cf-96b8-444553540000 "<br/> codebase =" http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0 "<br/> align =" Middle "> <br/> <Param name =" movie "value =" about: blank" /> <Br/> <Param name = "quality" value = "high"/> <br/> </Object> <br/> </TD> <br/> </tr> <br/> </table> </P> <p> <! -- <A href = "javascript: calljava. consoleflashprogress (3) "mce_href =" javascript: calljava. consoleflashprogress (3) "> Add progress </a> <br/> <a href =" # "mce_href =" # "onclick =" loadswf('', 'testflash.swf ', '123 ', '200') "> testbutton </a> --> <br/> <p id =" geolo "> </P> <br/> <MCE: script Type = "text/JavaScript"> <! -- <Br/> // loadswf ("testflash.swf", "800", "480"); // loadswf ("flash Address", "width", "height ") <br/> function setflashpath (filepath) {<br/> var Path = filepath; <br/> loadswf (path, "800", "480 "); // loadswf ("flash Address", "width", "height") <br/> // geolo. innertext = "ABC:" + filepath. tostring (); <br/>}< br/> // --> </MCE: SCRIPT> <br/>
VaR total; // define the total number of snapshots of a flash video <br/> var frame_number; // define the current number of clips for a flash video <br/> // the scroll bar image dragging Program <br/> var dragapproved = false; <br/> var Z, X, Y <br/> // dynamically displays the current number of frames/total number of frames of the video to be played (progress bar) <br/> function showcount () {<br/> // calljava is available. leleflashprogress (5); <br/> total = movie. totalframes; <br/> frame_number = movie. currentframe (); <br/> frame_number ++; <br/> var progresssize = 100 * (frame_number/movie. totalframes (); <br/> calljava. consoleflashprogress (progresssize); <br/>}< br/> // play the video <br/> function play () {<br/> movie. play (); <br/>}< br/> // pause <br/> function pause () {<br/> movie. stopplay (); <br/>}< br/> // start loading the Flash video <br/> function loadswf (FSRC, fwidth, fheight) {<br/> movie. loadmovie (0, FSRC); <br/> movie. width = fwidth; <br/> movie. height = fheight; <br/> frame_number = movie. currentframe (); <br/>}
Main. xml
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <! -- Autor: geolo statement: copyright, subject to investigation --> <br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: Orientation = "vertical" Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent"> <br/> <webview Android: Id = "@ + ID/webview01" Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content"/> <br/> <progressbar Android: Id = "@ + ID/progress_horizontal" <Br/> style = "? Android: ATTR/progressbarstylehorizontal "Android: layout_width =" fill_parent "<br/> Android: layout_height =" wrap_content "Android: max =" 100 "<br/> Android: progress = "0" Android: secondaryprogress = "0"/> <br/> <linearlayout Android: Orientation = "horizontal" <br/> Android: layout_width = "fill_parent" Android: layout_height = "wrap_content"> <br/> <button Android: Id = "@ + ID/playbutton" Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" Android: text = ""/> <br/> <button Android: Id = "@ + ID/pausebutton" Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" Android: text = "Suspend"/> <br/> <button Android: id = "@ + ID/rewindbutton" Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" Android: TEXT = "replay"/> <br/> <button Android: Id = "@ + ID/filebutton" Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" Android: text = "Open File"/> <br/> <button Android: Id = "@ + ID/exitbutton" Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" Android: TEXT = "exit"/> <br/> </linearlayout>
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <manifest xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> package = "com. geolo. android "Android: versioncode =" 1 "<br/> Android: versionname =" 1.0 "> <br/> <application Android: icon =" @ drawable/icon "Android: label = "@ string/app_name"> <br/> <activity Android: Name = ". flash. flashactivity "Android: Label =" @ string/app_name "<br/> Android: screenorientation =" Landscape "<br/> Android: theme =" @ Android: style/theme. notitlebar. fullscreen "> <br/> <intent-filter> <br/> <action Android: Name =" android. intent. action. main "/> <br/> <category Android: Name =" android. intent. category. launcher "/> <br/> </intent-filter> <br/> </activity> <br/> <activity Android: Name = ". filebrowser "/> <br/> </Application> <br/> <supports-screens Android: resizeable =" true "<br/> Android: smallscreens =" true "Android: largescreens = "true" <br/> Android: normalscreens = "true" Android: anydensity = "true"> </supports-screens> <br/> </manifest>
Package project resources download: http://download.csdn.net/source/2926306