@@ -69,28 +69,35 @@ class AndroidSDK {
69
69
private static final String SDK_DOWNLOAD_URL =
70
70
"https://developer.android.com/studio/index.html#downloads" ;
71
71
72
+ private static final String USE_ENV_SDK_TITLE = "Found an Android SDK!" ;
73
+ private static final String USE_ENV_SDK_MESSAGE =
74
+ "Processing found a valid Android SDK that seems to be in use already. " +
75
+ "Processing could use this SDK too, or download a new one.<br><br>" +
76
+ "Sharing the same SDK across different development tools, like Processing " +
77
+ "and Android Studio, will save space (the SDK may use up to several GBs), " +
78
+ "but when one tool updates the SDK, it can create problems in the other. " +
79
+ "If Processing downloads a new SDK, it will keep it separate from the one " +
80
+ "it just found.<br><br>" +
81
+ "What do you want to do?" ;
82
+
72
83
private static final String MISSING_SDK_TITLE =
73
- "Cannot find the Android SDK..." ;
74
-
84
+ "Cannot find an Android SDK..." ;
75
85
private static final String MISSING_SDK_MESSAGE =
76
- "The Android SDK does not appear to be installed, " +
77
- "because the ANDROID_SDK variable is not set. " +
78
- "If it is installed, click \" Locate SDK path\" to select the " +
79
- "location of the SDK, or \" Download SDK\" to let " +
80
- "Processing download the SDK automatically.<br><br>" +
86
+ "Processing did not find an Android SDK on this computer. " +
87
+ "If there is one, and you know where it is, click \" Locate SDK path\" " +
88
+ "to select it, or \" Download SDK\" to let Processing download the SDK automatically.<br><br>" +
81
89
"If you want to download the SDK manually, you can get " +
82
90
"the command line tools from <a href=\" " + SDK_DOWNLOAD_URL + "\" >here</a>. " +
83
91
"Make sure to install the SDK platform for API " + AndroidBuild .TARGET_SDK + "." ;
84
92
85
93
private static final String INVALID_SDK_TITLE =
86
- "The Android SDK is not valid..." ;
87
-
94
+ "Android SDK is not valid..." ;
88
95
private static final String INVALID_SDK_MESSAGE =
89
- "The found Android SDK cannot be used by Processing. " +
90
- "It could be missing files, or does not include the required platform for " +
91
- "API " + AndroidBuild .TARGET_SDK + ". If a valid SDK is available in a different location, " +
92
- "click \" Locate SDK path \" to select the " +
93
- "location of the valid SDK , or \" Download SDK\" to let " +
96
+ "Processing found an Android SDK, but is not valid. It could be missing " +
97
+ "some files, or might not be including the required platform for " +
98
+ "API " + AndroidBuild .TARGET_SDK + "<br><br> " +
99
+ "If a valid SDK is available in a different location, " +
100
+ "click \" Locate SDK path \" to select it , or \" Download SDK\" to let " +
94
101
"Processing download the SDK automatically.<br><br>" +
95
102
"If you want to download the SDK manually, you can get " +
96
103
"the command line tools from <a href=\" " + SDK_DOWNLOAD_URL + "\" >here</a>. " +
@@ -106,7 +113,8 @@ class AndroidSDK {
106
113
"The system image needed by the emulator does not appear to be installed. " +
107
114
"Do you want Processing to download and install it now? <br><br>" +
108
115
"Otherwise, you will need to do it through the sdkmanager<br>" +
109
- "command line tool, check <a href=\" " + COMMAND_LINE_TUT_URL + "\" >this online tutorial</a> for more info." ;
116
+ "command line tool, check <a href=\" " + COMMAND_LINE_TUT_URL +
117
+ "\" >this online tutorial</a> for more info." ;
110
118
111
119
private static final String ANDROID_SYS_IMAGE_WEAR_PRIMARY =
112
120
"Download watch system image?" ;
@@ -115,7 +123,8 @@ class AndroidSDK {
115
123
"The system image needed by the emulator does not appear to be installed. " +
116
124
"Do you want Processing to download and install it now? <br><br>" +
117
125
"Otherwise, you will need to do it through the sdkmanager<br>" +
118
- "command line tool, check <a href=\" " + COMMAND_LINE_TUT_URL + "\" >this online tutorial</a> for more info." ;
126
+ "command line tool, check <a href=\" " + COMMAND_LINE_TUT_URL +
127
+ "\" >this online tutorial</a> for more info." ;
119
128
120
129
private static final String SELECT_ANDROID_SDK_FOLDER =
121
130
"Choose the location of the Android SDK" ;
@@ -129,9 +138,10 @@ class AndroidSDK {
129
138
"https://developer.android.com/studio/run/oem-usb.html#InstallingDriver" ;
130
139
131
140
private static final String SDK_INSTALL_MESSAGE =
132
- "Processing just downloaded and installed the Android SDK succesfully! " +
133
- "The Android mode is now ready to use, for more information visit " +
134
- "the <a href=\" " + PROCESSING_FOR_ANDROID_URL + "\" >Processing for Android website</a>" ;
141
+ "Processing just downloaded and installed the Android SDK succesfully. " +
142
+ "The Android mode is now ready to use!<br><br>" +
143
+ "For more information (reference, examples, and tutorials) " +
144
+ "visit the <a href=\" " + PROCESSING_FOR_ANDROID_URL + "\" >Processing for Android website</a>" ;
135
145
136
146
private static final String DRIVER_INSTALL_MESSAGE = "<br><br>" +
137
147
"If you are planning to use Google Nexus devices, then you need the " +
@@ -140,9 +150,10 @@ class AndroidSDK {
140
150
"\" >these instructions</a>.<br><br>" +
141
151
"The installation files are available in this folder:</br>" ;
142
152
143
- private static final int NO_ERROR = 0 ;
144
- private static final int MISSING_SDK = 1 ;
145
- private static final int INVALID_SDK = 2 ;
153
+ private static final int NO_ERROR = 0 ;
154
+ private static final int SKIP_ENV_SDK = 1 ;
155
+ private static final int MISSING_SDK = 2 ;
156
+ private static final int INVALID_SDK = 3 ;
146
157
private static int loadError = NO_ERROR ;
147
158
148
159
public AndroidSDK (File folder ) throws BadSDKException , IOException {
@@ -355,19 +366,13 @@ private static File findAvdManager(final File tools) throws BadSDKException {
355
366
* @throws BadSDKException
356
367
* @throws IOException
357
368
*/
358
- public static AndroidSDK load () throws IOException {
369
+ public static AndroidSDK load (boolean checkEnvSDK , Frame editor ) throws IOException {
359
370
loadError = NO_ERROR ;
360
371
361
- // Give priority to preferences. Rationale: when user runs the mode for the first time
362
- // and there is a valid SDK in the environment, it will be stored in the
363
- // preferences. So in this case, priority is given to an existing (and valid) SDK.
364
- // From that point on, if the preference value is changed then it means that the user
365
- // wants to use a custom SDK, so the mode should not revert back to the global SDK.
366
- // Also, using the global SDK risks breaking the mode as that SDK is most likely
367
- // going to be used by Android Studio, and we don't know what updates it may apply
368
- // that could be incompatible with the mode. So better keep using the local SDK in
369
- // the preferences.
372
+ // Give priority to preferences:
373
+ // https://github.com/processing/processing-android/issues/372
370
374
final String sdkPrefsPath = Preferences .get ("android.sdk.path" );
375
+ System .out .println ("Processing preferences: " + sdkPrefsPath );
371
376
if (sdkPrefsPath != null ) {
372
377
try {
373
378
final AndroidSDK androidSDK = new AndroidSDK (new File (sdkPrefsPath ));
@@ -380,9 +385,24 @@ public static AndroidSDK load() throws IOException {
380
385
}
381
386
382
387
final String sdkEnvPath = Platform .getenv ("ANDROID_SDK" );
388
+ System .out .println ("ANDROID_SDK: " + sdkEnvPath );
383
389
if (sdkEnvPath != null ) {
384
390
try {
385
391
final AndroidSDK androidSDK = new AndroidSDK (new File (sdkEnvPath ));
392
+
393
+ System .out .println ("ENVIRONMENT SDK CAN BE USED BY PROCESSING!!" );
394
+
395
+ if (checkEnvSDK && editor != null ) {
396
+ // There is a valid SDK in the environment, but let's give the user
397
+ // the option to not to use it. After this, we should go straight to
398
+ // download a new SDK.
399
+ int result = showEnvSDKDialog (editor );
400
+ if (result == JOptionPane .NO_OPTION ) {
401
+ loadError = SKIP_ENV_SDK ;
402
+ return null ;
403
+ }
404
+ }
405
+
386
406
// Set this value in preferences.txt, in case ANDROID_SDK
387
407
// gets knocked out later. For instance, by that pesky Eclipse,
388
408
// which nukes all env variables when launching from the IDE.
@@ -402,11 +422,22 @@ public static AndroidSDK load() throws IOException {
402
422
403
423
static public AndroidSDK locate (final Frame window , final AndroidMode androidMode )
404
424
throws BadSDKException , CancelException , IOException {
405
- final int result = showLocateDialog (window );
425
+
426
+ if (loadError == SKIP_ENV_SDK ) {
427
+ // The user does not want to use the environment SDK, so let's simply
428
+ // download a new one to the sketchbook folder.
429
+ return download (window , androidMode );
430
+ }
431
+
432
+ // At this point, there is no ANDROID_SDK env variable, no SDK in the preferences,
433
+ // or either one was invalid, so we will continue by asking the user to either locate
434
+ // a valid SDK manually, or download a new one.
435
+ int result = showLocateDialog (window );
436
+
406
437
if (result == JOptionPane .YES_OPTION ) {
407
438
return download (window , androidMode );
408
439
} else if (result == JOptionPane .NO_OPTION ) {
409
- // user will manually select folder containing SDK folder
440
+ // User will manually select folder containing SDK folder
410
441
File folder = selectFolder (SELECT_ANDROID_SDK_FOLDER , null , window );
411
442
if (folder == null ) {
412
443
throw new CancelException ("User canceled attempt to find SDK" );
@@ -471,7 +502,43 @@ static public boolean downloadSysImage(final Frame editor,
471
502
}
472
503
return res ;
473
504
}
505
+
474
506
507
+ static public int showEnvSDKDialog (Frame editor ) {
508
+ String title = USE_ENV_SDK_TITLE ;
509
+ String htmlString = "<html> " +
510
+ "<head> <style type=\" text/css\" >" +
511
+ "p { font: " + FONT_SIZE + "pt \" Lucida Grande\" ; " +
512
+ "margin: " + TEXT_MARGIN + "px; " +
513
+ "width: " + TEXT_WIDTH + "px }" +
514
+ "</style> </head>" +
515
+ "<body> <p>" + USE_ENV_SDK_MESSAGE + "</p> </body> </html>" ;
516
+ JEditorPane pane = new JEditorPane ("text/html" , htmlString );
517
+ pane .addHyperlinkListener (new HyperlinkListener () {
518
+ @ Override
519
+ public void hyperlinkUpdate (HyperlinkEvent e ) {
520
+ if (e .getEventType ().equals (HyperlinkEvent .EventType .ACTIVATED )) {
521
+ Platform .openURL (e .getURL ().toString ());
522
+ }
523
+ }
524
+ });
525
+ pane .setEditable (false );
526
+ JLabel label = new JLabel ();
527
+ pane .setBackground (label .getBackground ());
528
+
529
+ String [] options = new String [] { "Use existing SDK" , "Download new SDK" };
530
+ int result = JOptionPane .showOptionDialog (null , pane , title ,
531
+ JOptionPane .DEFAULT_OPTION , JOptionPane .QUESTION_MESSAGE ,
532
+ null , options , options [0 ]);
533
+ if (result == JOptionPane .YES_OPTION ) {
534
+ return JOptionPane .YES_OPTION ;
535
+ } else if (result == JOptionPane .NO_OPTION ) {
536
+ return JOptionPane .NO_OPTION ;
537
+ } else {
538
+ return JOptionPane .CLOSED_OPTION ;
539
+ }
540
+ }
541
+
475
542
476
543
static public int showLocateDialog (Frame editor ) {
477
544
// How to show a option dialog containing clickable links:
0 commit comments