1
1
package processing .mode .android ;
2
2
3
- import java .awt .FileDialog ;
4
- import java .awt .Frame ;
5
- import java .io .File ;
6
- import java .io .IOException ;
7
- import java .text .DateFormat ;
8
- import java .text .ParseException ;
9
- import java .text .SimpleDateFormat ;
10
- import java .util .Date ;
11
-
12
- import javax .swing .JFileChooser ;
13
- import javax .swing .JOptionPane ;
14
-
15
3
import processing .app .Base ;
4
+ import processing .app .Editor ;
16
5
import processing .app .Platform ;
17
6
import processing .app .Preferences ;
18
7
import processing .app .exec .ProcessHelper ;
19
8
import processing .app .exec .ProcessResult ;
20
9
import processing .core .PApplet ;
21
10
11
+ import javax .swing .*;
12
+ import java .awt .*;
13
+ import java .io .File ;
14
+ import java .io .IOException ;
15
+ import java .text .DateFormat ;
16
+ import java .text .ParseException ;
17
+ import java .text .SimpleDateFormat ;
18
+ import java .util .Date ;
19
+
22
20
class AndroidSDK {
23
21
private final File folder ;
24
22
private final File tools ;
@@ -31,8 +29,10 @@ class AndroidSDK {
31
29
private static final String ANDROID_SDK_SECONDARY =
32
30
"The Android SDK does not appear to be installed, <br>" +
33
31
"because the ANDROID_SDK variable is not set. <br>" +
34
- "If it is installed, click “Yes” to select the <br>" +
35
- "location of the SDK, or “No” to visit the SDK<br>" +
32
+ "If it is installed, click “Locate SDK path” to select the <br>" +
33
+ "location of the SDK, or “Download SDK” to let <br>" +
34
+ "Processing download SDK automatically.<br><br>" +
35
+ "If you want to download SDK manually, you can visit <br>" +
36
36
"download site at http://developer.android.com/sdk." ;
37
37
38
38
private static final String SELECT_ANDROID_SDK_FOLDER =
@@ -234,17 +234,18 @@ public static AndroidSDK load() throws BadSDKException, IOException {
234
234
}
235
235
236
236
237
- static public AndroidSDK locate (final Frame window )
238
- throws BadSDKException , IOException {
239
- final int result = Base .showYesNoQuestion (window , "Android SDK" ,
240
- ANDROID_SDK_PRIMARY , ANDROID_SDK_SECONDARY );
237
+ static public AndroidSDK locate (final Frame window , final AndroidMode androidMode )
238
+ throws BadSDKException , IOException {
239
+ final int result = showLocateDialog (window );
241
240
if (result == JOptionPane .CANCEL_OPTION ) {
242
241
throw new BadSDKException ("User canceled attempt to find SDK." );
243
242
}
244
- if (result == JOptionPane .NO_OPTION ) {
245
- // user admitted they don't have the SDK installed, and need help.
246
- Base .openURL (ANDROID_SDK_URL );
247
- throw new BadSDKException ("No SDK installed." );
243
+ if (result == JOptionPane .YES_OPTION ) {
244
+ // here we are going to download sdk automatically
245
+ //Base.openURL(ANDROID_SDK_URL);
246
+ //throw new BadSDKException("No SDK installed.");
247
+
248
+ return download (androidMode );
248
249
}
249
250
while (true ) {
250
251
// TODO this is really a yucky way to do this stuff. fix it.
@@ -263,6 +264,52 @@ static public AndroidSDK locate(final Frame window)
263
264
}
264
265
}
265
266
267
+ static public AndroidSDK download (final AndroidMode androidMode ) throws BadSDKException {
268
+ AndroidMode .sdkDownloadInProgress = true ;
269
+
270
+ SwingUtilities .invokeLater (new Runnable () {
271
+ @ Override
272
+ public void run () {
273
+ SDKDownloader downloader = new SDKDownloader (androidMode );
274
+ downloader .startDownload ();
275
+ }
276
+ });
277
+ return null ;
278
+ }
279
+
280
+ static public int showLocateDialog (Frame editor ) {
281
+ // Pane formatting adapted from the Quaqua guide
282
+ // http://www.randelshofer.ch/quaqua/guide/joptionpane.html
283
+ JOptionPane pane =
284
+ new JOptionPane ("<html> " +
285
+ "<head> <style type=\" text/css\" >" +
286
+ "b { font: 13pt \" Lucida Grande\" }" +
287
+ "p { font: 11pt \" Lucida Grande\" ; margin-top: 8px; width: 300px }" +
288
+ "</style> </head>" +
289
+ "<b>" + ANDROID_SDK_PRIMARY + "</b>" +
290
+ "<p>" + ANDROID_SDK_SECONDARY + "</p>" ,
291
+ JOptionPane .QUESTION_MESSAGE );
292
+
293
+ String [] options = new String [] {
294
+ "Download SDK automatically" , "Locate SDK path manually"
295
+ };
296
+ pane .setOptions (options );
297
+
298
+ // highlight the safest option ala apple hig
299
+ pane .setInitialValue (options [0 ]);
300
+
301
+ JDialog dialog = pane .createDialog (editor , null );
302
+ dialog .setVisible (true );
303
+
304
+ Object result = pane .getValue ();
305
+ if (result == options [0 ]) {
306
+ return JOptionPane .YES_OPTION ;
307
+ } else if (result == options [1 ]) {
308
+ return JOptionPane .NO_OPTION ;
309
+ } else {
310
+ return JOptionPane .CLOSED_OPTION ;
311
+ }
312
+ }
266
313
267
314
// this was banished from Base because it encourages bad practice.
268
315
// TODO figure out a better way to handle the above.
0 commit comments