diff options
author | Jay Freeman <saurik@saurik.com> | 2008-03-11 03:37:55 +0000 |
---|---|---|
committer | Jay Freeman <saurik@saurik.com> | 2008-03-11 03:37:55 +0000 |
commit | 090e74f70d3bc182719fd1d28ea45312bcdbc9f4 (patch) | |
tree | a3124e30ca575514519dbe568dfd84ec52d3fddd /data/iphone-java/HelloScript.app | |
parent | 2048c0f0d9fba74a699399e19b1ed99147d6cea4 (diff) |
Various mergings from the JocStrap project.
git-svn-id: http://svn.telesphoreo.org/trunk@185 514c082c-b64e-11dc-b46d-3d985efe055d
Diffstat (limited to 'data/iphone-java/HelloScript.app')
-rwxr-xr-x | data/iphone-java/HelloScript.app/HelloScript | 3 | ||||
-rw-r--r-- | data/iphone-java/HelloScript.app/HelloScript.js | 130 |
2 files changed, 65 insertions, 68 deletions
diff --git a/data/iphone-java/HelloScript.app/HelloScript b/data/iphone-java/HelloScript.app/HelloScript index 2b4460d41..6b6f58340 100755 --- a/data/iphone-java/HelloScript.app/HelloScript +++ b/data/iphone-java/HelloScript.app/HelloScript @@ -1,5 +1,4 @@ #!/bin/bash -# XXX: -Xbootclasspath is used as JamVM runs 3x faster # XXX: Java is symlink'd to here so the home button works cd "$(dirname "$0")" -exec "$(dirname "$0")"/Java -Xmx8M -Xss256K -Xbootclasspath/p:/usr/share/java/jocstrap.jar:/usr/share/java/js.jar -cp /usr/share/java/sqlite.jar:/usr/share/java/uicaboodle.jar com.saurik.uicaboodle.Main com.saurik.uicaboodle.ScriptApplication HelloScript.js "$@" +exec "$(dirname "$0")"/Java -Xmx8M -Xss256K -cp /usr/share/java/jocstrap.jar:/usr/share/java/js.jar:/usr/share/java/sqlite.jar:/usr/share/java/uicaboodle.jar com.saurik.uicaboodle.Main com.saurik.uicaboodle.ScriptApplication "$@" -- HelloScript.js diff --git a/data/iphone-java/HelloScript.app/HelloScript.js b/data/iphone-java/HelloScript.app/HelloScript.js index 18d45240a..a8c14a445 100644 --- a/data/iphone-java/HelloScript.app/HelloScript.js +++ b/data/iphone-java/HelloScript.app/HelloScript.js @@ -1,110 +1,108 @@ var println = function(s) { java.lang.System.out.println(s); } var sql = Packages.SQLite; -var contacts = []; -var sections = []; +function getName(contact) { + var name = contact.first; + if (contact.last != null) + name += " " + contact.last; + return name; +} + +function numberOfSectionsInSectionList$(list) { + return sections_.length; +} + +function sectionList$titleForSection$(list, section) { + return sections_[section].title; +} + +function sectionList$rowForSection$(list, section) { + return sections_[section].row; +} + +function numberOfRowsInTable$(table) { + return contacts_.length; +} + +function table$cellForRow$column$reusing$(table, row, col, reusing) { + var contact = contacts_[row]; + + var cell; + if (reusing != null) + cell = reusing; + else + cell = new obc.UIImageAndTextTableCell().init(); + + cell.setTitle$(getName(contact)); + return cell; +} + +function table$canSelectRow$(table, row) { + return NO; +} + +var contacts_ = []; +var sections_ = []; var ab = new sql.Database(); ab.open(application.userHomeDirectory().toString() + "/Library/AddressBook/AddressBook.sqlitedb", 0666); try { var st = ab.prepare("select first, last from ABPerson where first is not null order by first"); try { while (st.step()) - contacts.push({ + contacts_.push({ first: st.column_string(0), - last: st.column_string(1), - cell: null + last: st.column_string(1) }); } finally { st.close(); } } finally { ab.close(); } -function getName(contact) { - var name = contact.first; - if (contact.last != null) - name += " " + contact.last; - return name; -} - var outer = obc.UIHardware.fullScreenApplicationContentRect(); -var inner = outer.clone(); -inner.origin.x = inner.origin.y = 0; +var window = new obc.UIWindow().initWithContentRect$(outer); -var window = new obc.UIWindow().initWithContentRect$(inner); window.orderFront$(application); window.makeKey$(application); window._setHidden$(NO); +var inner = window.bounds(); var navsize = obc.UINavigationBar().defaultSize(); -var navbar = new obc.UINavigationBar().initWithFrame$(new obc.CGRect(0, 0, inner.size.width, navsize.height)); -navbar.setBarStyle$(1); -navbar.showButtonsWithLeftTitle$rightTitle$leftBack$("Run GC", null, YES); +var navrect = new obc.CGRect(0, 0, inner.size.width, navsize.height); -navbar.setDelegate$({ - navigationBar$buttonClicked$: function(navbar, button) { - Packages.java.lang.Runtime.getRuntime().gc(); - } -}); +var view = new obc.UIView().initWithFrame$(inner); +window.setContentView$(view); + +var navbar = new obc.UINavigationBar().initWithFrame$(navrect); +view.addSubview$(navbar); + +navbar.setBarStyle$(1); var navitem = new obc.UINavigationItem().initWithTitle$("Contact List"); navbar.pushNavigationItem$(navitem); var letter = null; -for (var i = 0; i != contacts.length; ++i) { - var name = getName(contacts[i]); +for (var i = 0; i != contacts_.length; ++i) { + var name = getName(contacts_[i]); var now = name[0].toUpperCase(); if (letter != now) { letter = now; - sections.push({ + sections_.push({ row: i, title: now }); } } -var seclist = new obc.UISectionList().initWithFrame$(new obc.CGRect(0, navsize.height, inner.size.width, inner.size.height - navsize.height)); - -seclist.setDataSource$({ - numberOfSectionsInSectionList$: function(list) { - return sections.length; - }, - - sectionList$titleForSection$: function(list, section) { - return sections[section].title; - }, - - sectionList$rowForSection$: function(list, section) { - return sections[section].row; - }, - - numberOfRowsInTable$: function(table) { - return contacts.length; - }, - - table$cellForRow$column$: function(table, row, col) { - var contact = contacts[row]; - if (contact.cell != null) - return contact.cell; - var cell = new obc.UIImageAndTextTableCell().init(); - cell.setTitle$(getName(contact)); - contact.cell = cell; - return cell; - } -}); - -seclist.reloadData(); +var lower = new obc.CGRect(0, navsize.height, inner.size.width, inner.size.height - navsize.height); +var list = new obc.UISectionList().initWithFrame$(lower); +view.addSubview$(list); var col = new obc.UITableColumn().initWithTitle$identifier$width$("Name", "name", 320); -var table = seclist.table(); +var table = list.table(); table.setSeparatorStyle$(1); table.addTableColumn$(col); +table.setReusesTableCells$(YES); -var view = new obc.UIView().initWithFrame$(inner); -view.addSubview$(navbar); -view.addSubview$(seclist); - -window.setContentView$(view); - -/* XXX: this works around a VM bug and will be removed */ -java.lang.Class.forName("osx.Celestial"); +list.setDataSource$(this); +list.reloadData(); var controller = new obc.AVController().init(); var wavfile = obc.NSBundle().mainBundle().pathForResource$ofType$("start", "wav") |