-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
62 lines (57 loc) · 1.46 KB
/
app.js
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
var win = Ti.UI.createWindow({
exitOnClose: true,
title: 'Android Progress Notification',
layout: 'vertical'
});
var startBtn = Ti.UI.createButton({
title: 'Start progress'
});
var counter = 0;
var interval;
function runNotify() {
counter += 10;
notify(counter);
}
startBtn.addEventListener('click', function() {
counter = 0;
runNotify();
interval = setInterval(runNotify, 1000);
});
win.add(startBtn);
var cancelBtn = Ti.UI.createButton({
title: 'Cancel progress'
});
cancelBtn.addEventListener('click', function() {
if (notif) {
clearInterval(interval);
notif.cancel();
notif = null;
}
});
win.add(cancelBtn);
var ProgressNotif = require('nc.progressnotification');
var notif;
function notify(progress) {
if (!notif) {
var intent = Ti.Android.currentActivity.intent;
intent.setFlags(Ti.Android.FLAG_ACTIVITY_SINGLE_TOP);
var pending = Ti.Android.createPendingIntent({
intent: intent,
updateCurrentIntent: true
});
notif = ProgressNotif.createNotification({
id: 1234,
number: 1,
icon: Ti.App.Android.R.drawable.appicon,
pendingIntent: pending,
title: 'Filename.pdf'
});
}
notif.text = 'Downloading...('+ progress +'%)';
if (progress >= 100) {
notif.text = 'Download complete';
clearInterval(interval);
}
notif.notify(progress);
}
win.open();