Skip to content

Commit 883785b

Browse files
committed
some comments about progress update
1 parent e0a1ede commit 883785b

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

src/processing/mode/android/SDKUpdater.java

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ public void propertyChange(PropertyChangeEvent evt) {
121121
}
122122

123123
class QueryTask extends SwingWorker<Object, Object> {
124+
ProgressIndicator progress;
125+
126+
QueryTask() {
127+
super();
128+
progress = new ConsoleProgressIndicator();
129+
}
130+
124131
@Override
125132
protected Object doInBackground() throws Exception {
126133
numUpdates = 0;
@@ -131,8 +138,6 @@ protected Object doInBackground() throws Exception {
131138
*/
132139
AndroidSdkHandler mHandler = AndroidSdkHandler.getInstance(AndroidSDK.load().getSdkFolder());
133140

134-
ProgressIndicator progress = new ConsoleProgressIndicator();
135-
136141
FileSystemFileOp fop = (FileSystemFileOp) FileOpUtils.create();
137142
RepoManager mRepoManager = mHandler.getSdkManager(progress);
138143
mRepoManager.loadSynchronously(0, progress, new LegacyDownloader(fop, new SettingsController() {
@@ -222,6 +227,20 @@ protected void done() {
222227
}
223228

224229
class DownloadTask extends SwingWorker<Object, Object> {
230+
ProgressIndicator progress;
231+
232+
DownloadTask() {
233+
super();
234+
// This code can help understanding more advanced users of the progress
235+
// indicator and the download functionality:
236+
// https://github.com/JetBrains/android/blob/master/android/src/com/android/tools/idea/welcome/wizard/InstallComponentsPath.java
237+
// From Android Plugin for IntelliJ IDEA:
238+
// https://github.com/JetBrains/android
239+
// My impression is that the current progress has to be set using progress.setFraction()
240+
//and then can be retrieved with progress.getFraction();
241+
progress = new ConsoleProgressIndicator();
242+
}
243+
225244
@Override
226245
protected Object doInBackground() throws Exception {
227246
downloadTaskRunning = true;
@@ -233,12 +252,11 @@ protected Object doInBackground() throws Exception {
233252

234253
FileSystemFileOp fop = (FileSystemFileOp) FileOpUtils.create();
235254
CustomSettings settings = new CustomSettings();
236-
LegacyDownloader downloader = new LegacyDownloader(fop, settings);
237-
ProgressIndicator progress = new ConsoleProgressIndicator();
255+
Downloader downloader = new LegacyDownloader(fop, settings);
238256

239257
RepoManager mRepoManager = mHandler.getSdkManager(progress);
240258
mRepoManager.loadSynchronously(0, progress, downloader, settings);
241-
259+
242260
List<RemotePackage> remotes = new ArrayList<>();
243261
for (String path : settings.getPaths(mRepoManager)) {
244262
RemotePackage p = mRepoManager.getPackages().getRemotePackages().get(path);
@@ -275,7 +293,6 @@ protected void done() {
275293
get();
276294
actionButton.setEnabled(false);
277295
status.setText("Refreshing packages...");
278-
279296
queryTask = new QueryTask();
280297
queryTask.addPropertyChangeListener(SDKUpdater.this);
281298
queryTask.execute();
@@ -394,6 +411,21 @@ public void actionPerformed(ActionEvent e) {
394411
downloadTask = new DownloadTask();
395412
progressBar.setIndeterminate(true);
396413
downloadTask.execute();
414+
415+
// getFraction() always returns 0.0, needs to be set somewhere (??)
416+
// Thread update = new Thread() {
417+
// @Override
418+
// public void run() {
419+
// while (downloadTaskRunning) {
420+
// try {
421+
// Thread.sleep(100);
422+
// } catch (InterruptedException e) { }
423+
// System.out.println("Updating: " + downloadTask.progress.getFraction());
424+
// }
425+
// }
426+
// };
427+
// update.start();
428+
397429
status.setText("Downloading available updates...");
398430
actionButton.setText("Cancel");
399431
}

0 commit comments

Comments
 (0)