@@ -121,6 +121,13 @@ public void propertyChange(PropertyChangeEvent evt) {
121
121
}
122
122
123
123
class QueryTask extends SwingWorker <Object , Object > {
124
+ ProgressIndicator progress ;
125
+
126
+ QueryTask () {
127
+ super ();
128
+ progress = new ConsoleProgressIndicator ();
129
+ }
130
+
124
131
@ Override
125
132
protected Object doInBackground () throws Exception {
126
133
numUpdates = 0 ;
@@ -131,8 +138,6 @@ protected Object doInBackground() throws Exception {
131
138
*/
132
139
AndroidSdkHandler mHandler = AndroidSdkHandler .getInstance (AndroidSDK .load ().getSdkFolder ());
133
140
134
- ProgressIndicator progress = new ConsoleProgressIndicator ();
135
-
136
141
FileSystemFileOp fop = (FileSystemFileOp ) FileOpUtils .create ();
137
142
RepoManager mRepoManager = mHandler .getSdkManager (progress );
138
143
mRepoManager .loadSynchronously (0 , progress , new LegacyDownloader (fop , new SettingsController () {
@@ -222,6 +227,20 @@ protected void done() {
222
227
}
223
228
224
229
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
+
225
244
@ Override
226
245
protected Object doInBackground () throws Exception {
227
246
downloadTaskRunning = true ;
@@ -233,12 +252,11 @@ protected Object doInBackground() throws Exception {
233
252
234
253
FileSystemFileOp fop = (FileSystemFileOp ) FileOpUtils .create ();
235
254
CustomSettings settings = new CustomSettings ();
236
- LegacyDownloader downloader = new LegacyDownloader (fop , settings );
237
- ProgressIndicator progress = new ConsoleProgressIndicator ();
255
+ Downloader downloader = new LegacyDownloader (fop , settings );
238
256
239
257
RepoManager mRepoManager = mHandler .getSdkManager (progress );
240
258
mRepoManager .loadSynchronously (0 , progress , downloader , settings );
241
-
259
+
242
260
List <RemotePackage > remotes = new ArrayList <>();
243
261
for (String path : settings .getPaths (mRepoManager )) {
244
262
RemotePackage p = mRepoManager .getPackages ().getRemotePackages ().get (path );
@@ -275,7 +293,6 @@ protected void done() {
275
293
get ();
276
294
actionButton .setEnabled (false );
277
295
status .setText ("Refreshing packages..." );
278
-
279
296
queryTask = new QueryTask ();
280
297
queryTask .addPropertyChangeListener (SDKUpdater .this );
281
298
queryTask .execute ();
@@ -394,6 +411,21 @@ public void actionPerformed(ActionEvent e) {
394
411
downloadTask = new DownloadTask ();
395
412
progressBar .setIndeterminate (true );
396
413
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
+
397
429
status .setText ("Downloading available updates..." );
398
430
actionButton .setText ("Cancel" );
399
431
}
0 commit comments