1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
var println = function(s) { java.lang.System.out.println(s); }
var sql = Packages.SQLite;
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({
first: st.column_string(0),
last: st.column_string(1),
cell: null
});
} 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$(inner);
window.orderFront$(application);
window.makeKey$(application);
window._setHidden$(NO);
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);
navbar.setDelegate$({
navigationBar$buttonClicked$: function(navbar, button) {
Packages.java.lang.Runtime.getRuntime().gc();
}
});
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]);
var now = name[0].toUpperCase();
if (letter != now) {
letter = now;
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 col = new obc.UITableColumn().initWithTitle$identifier$width$("Name", "name", 320);
var table = seclist.table();
table.setSeparatorStyle$(1);
table.addTableColumn$(col);
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");
var controller = new obc.AVController().init();
var wavfile = obc.NSBundle().mainBundle().pathForResource$ofType$("start", "wav")
var wavitem = new obc.AVItem().initWithPath$error$(wavfile, null);
wavitem.setVolume$(100);
controller.setCurrentItem$(wavitem);
controller.setCurrentTime$(0);
controller.play$(null);
|