-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownloadQueue.java
More file actions
190 lines (139 loc) · 4.51 KB
/
DownloadQueue.java
File metadata and controls
190 lines (139 loc) · 4.51 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package com.shank.SambaExplorer;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class DownloadQueue extends ListActivity {
public ArrayAdapter<String> mList;
public String[] mListStrings;
boolean active;
private Thread m_updateThread;
private int curListID=0;
public class UpdateQueueThread implements Runnable {
private DownloadQueue activity;
public UpdateQueueThread(DownloadQueue act) {
activity = act;
}
public void run() {
while (true) {
while (!activity.active) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
int qt = DownloadService.QueueTop-1;
for (int i=2047; i>qt; i--) {
mListStrings[i] = "";
}
int u=0;
for (int i=qt; i>=0; i--) {
mListStrings[i] = DownloadService.GetDownloadQueue(u++);
}
runOnUiThread(updateAdapter);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_PROGRESS, 1);
mListStrings = new String[2048];
for (int i=0;i<2048;i++) mListStrings[i] = "";
ListView view = getListView();
mList = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mListStrings);
view.setAdapter(mList);
view.setLongClickable(true);
m_updateThread = new Thread(new UpdateQueueThread(this));
m_updateThread.start();
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
menu.add(0, 0, 0, "Remove" + menuInfo.toString());
}
public boolean onContextItemSelected(android.view.MenuItem menuitem) {
switch (menuitem.getItemId()) {
case 0:
break;
}
return false;
}
@Override
public void onPause() {
super.onPause();
active = false;
}
@Override
public void onResume() {
super.onResume();
active = true;
}
private Runnable updateAdapter = new Runnable() {
@Override
public void run() {
mList.notifyDataSetChanged();
}
};
public void SetLastLine(String contents) {
mListStrings[curListID] = contents;
runOnUiThread(updateAdapter);
}
public void AddLine(String contents) {
mListStrings[curListID] = contents;
curListID++;
runOnUiThread(updateAdapter);
}
public void onLongClick(View view) {
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
if (DownloadService.servicePaused == false) {
menu.add(0, 0, 0, "Pause Downloads");
} else {
menu.add(0, 0, 0, "Resume Downloads");
}
menu.add(0, 1, 1, "Cancel All Downloads");
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 0:
DownloadService.servicePaused = !DownloadService.servicePaused;
if (DownloadService.servicePaused) {
DownloadService.showNotification("Download service paused.");
} else {
DownloadService.showNotification("Download service unpaused.");
}
break;
case 1:
DownloadService.QueueTop = 1;
DownloadService.serviceCancel = true;
DownloadService.showNotification("Download queue cleared.");
break;
}
return false;
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
String contents = l.getItemAtPosition(position).toString();
}
}