Android Task List / Selector

Credit for finding out how to do this goes to dims, who has been doing lots of cool Android hacking lately:

http://davanum.wordpress.com/2007/12/18/android-task-manager-primitive-prototype/

If you’re interested in Android and what it can do, you should be following his online journal!

As a way to keep pushing and testing Hecl, I decided to see if I could copy what he’d done in Hecl. It has indeed produced a few improvements to the Java code. That done, making it work was short and sweet:

set layoutparams [linearlayoutparams -new {FILL_PARENT WRAP_CONTENT}
set layout [linearlayout -new $context]
$layout setorientation VERTICAL

# Create ourselves some commands to access Android internals.
java android.app.ActivityManagerNative activitymanagernative
java android.app.IActivityManager iactivitymanager
java {android.app.IActivityManager$TaskInfo} taskinfo
java android.content.ComponentName componentname

java java.util.List javalist
set am [activitymanagernative getdefault]
set tasks [$am gettasks 10 0 [null]]
set len [$tasks size]
set tasklist [list]
for {set i 0} {< $i $len} {incr $i} {
    set baseactivity [[$tasks get $i] -field baseactivity]
    lappend $tasklist "Task: [$baseactivity getpackagename]"
}

$layout addview [textview -new $context -layoutparams $layoutparams 
         -text "Currently running tasks"]

set lview [basiclist $context $tasklist -layoutparams $layoutparams]
$layout addview $lview
$lview requestfocus

set callback [callback -new [list [list SelectTask]]]
$lview setonitemclicklistener $callback

heclcmd setcontentview $layout

proc SelectTask {parent view position id} {
    [activitymanagernative getdefault] movetasktofront $position
}

It could have been squeezed further by avoiding some of the temporary variables, and perhaps also by implementing a mapping between java.util.List and Hecl lists.

I think one of the next things I want to do is work on some infrastructure so that people will be able to actually work on scripts on their phone. That’s sort of a departure from the past (most phone keyboards would be sheer torture for inputting long scripts), but it’s a cool demo in any case.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s