30.04.2013 Views

Android - CommonsWare

Android - CommonsWare

Android - CommonsWare

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

}<br />

});<br />

}<br />

}<br />

}<br />

Leveraging Java Libraries<br />

Compile and run it (including incorporating the Beanshell JAR as<br />

mentioned above), and install it on the emulator. Fire it up, and you get a<br />

trivial IDE, with a large text area for your script and a big "Go!" button to<br />

execute it:<br />

import android.widget.Toast;<br />

Figure 95. The AndShell Beanshell IDE<br />

Toast.makeText(context, "Hello, world!", 5000).show();<br />

Note the use of context to refer to the activity when making the Toast. That<br />

is the global set by the activity to reference back to itself. You could call this<br />

global variable anything you want, so long as the set() call and the script<br />

code use the same name.<br />

Then, click the Go! button, and you get:<br />

327<br />

Subscribe to updates at http://commonsware.com Special Creative Commons BY-SA 3.0 License Edition

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!