<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>David's Computer Stuff Journal: Android Task List / Selector</title>
    <link>http://journal.dedasys.com/articles/2007/12/19/android-task-list-selector</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Android Task List / Selector</title>
      <description>&lt;p&gt;Credit for finding out how to do this goes to &lt;a href="http://davanum.wordpress.com/"&gt;dims&lt;/a&gt;, who has been doing lots of cool Android hacking lately:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://davanum.wordpress.com/2007/12/18/android-task-manager-primitive-prototype/"&gt;http://davanum.wordpress.com/2007/12/18/android-task-manager-primitive-prototype/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're interested in Android and what it can do, you should be following his online journal!&lt;/p&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;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} {&amp;lt; $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
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It could have been squeezed further by avoiding some of the temporary variables, and perhaps also by implementing a mapping between &lt;code&gt;java.util.List&lt;/code&gt; and Hecl lists.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;</description>
      <pubDate>Wed, 19 Dec 2007 04:20:00 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:8824f225-ed06-430d-adfe-af66e529ade7</guid>
      <author>David N. Welton</author>
      <link>http://journal.dedasys.com/articles/2007/12/19/android-task-list-selector</link>
      <category>hecl</category>
      <category>android</category>
      <trackback:ping>http://journal.dedasys.com/articles/trackback/1835</trackback:ping>
    </item>
  </channel>
</rss>
