Sunday, February 21, 2010

More code examples

There is a new update of DroidScript available at http://droidscript.se

I have also included the following code examples in the editor:
// Toast example program. Select this code and click Run.
var Toast = Packages.android.widget.Toast;
Toast.makeText(
    Activity,
    "Hello World!",
    Toast.LENGTH_SHORT).show();
   
// Select this code and click Run. It will create a button in
// the server activity.
var Widget = Packages.android.widget;
var button = new Widget.Button(Activity);
button.setText("Hello World!");
button.setOnClickListener(function () {
    button.setText("You Clicked Me!"); })
Activity.setContentView(button);

// You can also run code as a new Activity. Select this code
// and click "Run as Activity". A new DroidScript activity will
// be created, and the onCreate function is called.
function onCreate(icicle)
{
    var Widget = Packages.android.widget;
    var Graphics = Packages.android.graphics;
    var font = Graphics.Typeface.create(
        Graphics.Typeface.SANS_SERIF,
        Graphics.Typeface.BOLD);
    var button = new Widget.Button(Activity);
    button.setText("Hello World!");
    button.setTypeface(font);
    button.setTextSize(26);
    button.setBackgroundColor(Graphics.Color.rgb(0, 0, 64));
    button.setTextColor(Graphics.Color.rgb(255, 255, 255));
    button.setOnClickListener(function () {
        button.setText("You Clicked Me!"); })
    Activity.setContentView(button);
}

0 comments:

Post a Comment