Skip to content

Commit bb3b82c

Browse files
authored
Merge pull request #543 from DeerajTheepshi/GSoC19-p1.1
GSOC19 p1.1 - SDK download updates
2 parents de881bd + 50d213b commit bb3b82c

File tree

5 files changed

+433
-166
lines changed

5 files changed

+433
-166
lines changed

mode/languages/mode.properties

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ android_mode.dialog.cannot_export_package_body = The sketch still has the defaul
8888
android_mode.dialog.cannot_use_default_icons_title = Cannot export package...
8989
android_mode.dialog.cannot_use_default_icons_body = The sketch does not include all required app icons. Processing could use its default set of Android icons, which are okay to test the app on your device, but a bad idea to distribute it on the Play store. Create a full set of unique icons for your app, and copy them into the sketch folder. Once you have done that, try exporting the sketch again.<br><br>For more info on distributing apps from Processing,<br>check <a href=\"%s\">this online tutorial</a>.
9090
android_mode.warn.cannot_load_sdk_title = Bad news...
91-
android_mode.warn.cannot_load_sdk_body = The Android SDK could not be loaded.\nThe Android Mode will be disabled.
91+
android_mode.warn.cannot_load_sdk_body = The Android SDK could not be loaded, because:\n%s.\nThe Android Mode will be disabled.
9292
android_mode.info.cannot_open_sdk_path = "Android SDK path couldn't be opened.";
9393
android_mode.error.cannot_create_avd = "Could not create a virtual device for the emulator.";
9494
android_mode.dialog.no_devices_found_title = No devices found!
@@ -139,9 +139,9 @@ android_sdk.dialog.found_installed_sdk_body = Processing found a valid Android S
139139
android_sdk.option.use_existing_sdk = Use existing SDK
140140
android_sdk.option.download_new_sdk = Download new SDK
141141
android_sdk.dialog.cannot_find_sdk_title = Cannot find an Android SDK...
142-
android_sdk.dialog.cannot_find_sdk_body = Processing did not find an Android SDK on this computer. If there is one, and you know where it is, click \"Locate SDK path\" to select it, or \"Download SDK\" to let Processing download the SDK automatically.<br><br>If you want to download the SDK manually, you can get the command line tools from <a href=\"%s\">here</a>. Make sure to install the SDK platform for API %s.
142+
android_sdk.dialog.cannot_find_sdk_body = Processing did not find an Android SDK on this computer. If there is one, and you know where it is, click \"Locate SDK path\" to select it, or \"Download SDK\" to let Processing download the SDK automatically.<br><br>If you want to download the SDK manually, you can get the command line tools from <a href=\"%s\">here</a>. Make sure to install the SDK platform for API 26 or higher.
143143
android_sdk.dialog.invalid_sdk_title = Android SDK is not valid...
144-
android_sdk.dialog.invalid_sdk_body = Processing found an Android SDK, but is not valid. It could be missing some files, or might not be including the required platform for API %s.<br><br>If a valid SDK is available in a different location, click \"Locate SDK path\" to select it, or \"Download SDK\" to let Processing download the SDK automatically.<br><br>If you want to download the SDK manually, you can get the command line tools from <a href=\"%s\">here</a>. Make sure to install the SDK platform for API %s.
144+
android_sdk.dialog.invalid_sdk_body = Processing found an Android SDK, but is not valid. It could be missing some files, or might not be including the required platform for API 26 or higher.<br><br>If a valid SDK is available in a different location, click \"Locate SDK path\" to select it, or \"Download SDK\" to let Processing download the SDK automatically.<br><br>If you want to download the SDK manually, you can get the command line tools from <a href=\"%s\">here</a>. Make sure to install the SDK platform for API 26 or higher.
145145
android_sdk.option.download_sdk = Download SDK automatically
146146
android_sdk.option.locate_sdk = Locate SDK path manually
147147
android_sdk.dialog.download_phone_image_title = Download phone system image?
@@ -172,7 +172,7 @@ android_sdk.error.missing_tools_folder = There is no tools folder in %s
172172
android_sdk.error.missing_platform_tools_folder = There is no platform-tools folder in %s
173173
android_sdk.error.missing_build_tools_folder = There is no build-tools folder in %s
174174
android_sdk.error.missing_platforms_folder = There is no platforms folder in %s
175-
android_sdk.error.missing_target_platform = There is no Android %s in %s
175+
android_sdk.error.missing_target_platform = There is no Android %s (or greater) in %s
176176
android_sdk.error.missing_android_jar = android.jar for plaform %s is missing from %s
177177
android_debugger.info.removing_expired_keystore = Removing expired debug.keystore file.
178178
android_debugger.error.cannot_remove_expired_keystore = Could not remove the expired debug.keystore file.
@@ -259,6 +259,8 @@ sdk_downloader.error_cannot_find_emulator = Cannot find the emulator
259259
sdk_downloader.error.cannot_unpack_platform = Error unpacking platform to "%s"
260260
sdk_downloader.download_title = SDK download
261261
sdk_downloader.download_sdk_label = Downloading Android SDK...
262+
sdk_downloader.download_error_title = Incomplete download
263+
sdk_downloader.download_error_message = SDK Installation is incomplete due to: \n%s
262264

263265
# ---------------------------------------
264266
# System image downloader

mode/src/processing/mode/android/AndroidEditor.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,22 @@ public void actionPerformed(ActionEvent e) {
183183
});
184184
androidMenu.add(item);
185185

186+
//For testing SDK Downloader - Remove Later. --------------------------------------
187+
item = new JMenuItem("SDK Downloader");
188+
item.addActionListener(new ActionListener() {
189+
public void actionPerformed(ActionEvent e) {
190+
try {
191+
AndroidSDK.download(null,androidMode);
192+
} catch (AndroidSDK.BadSDKException ex) {
193+
ex.printStackTrace();
194+
} catch (AndroidSDK.CancelException ex) {
195+
ex.printStackTrace();
196+
}
197+
}
198+
});
199+
androidMenu.add(item);
200+
//--------------------------------------------------------------------
201+
186202
androidMenu.addSeparator();
187203

188204
fragmentItem = new JCheckBoxMenuItem(AndroidMode.getTextString("menu.android.app"));

mode/src/processing/mode/android/AndroidMode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ public void checkSDK(Editor editor) {
171171
}
172172
}
173173
if (sdk == null) {
174-
Messages.showWarning(AndroidMode.getTextString("android_mode.warn.cannot_load_sdk_title"),
175-
AndroidMode.getTextString("android_mode.warn.cannot_load_sdk_body"), tr);
174+
Messages.showWarning(AndroidMode.getTextString("android_mode.warn.cannot_load_sdk_title"),
175+
AndroidMode.getTextString("android_mode.warn.cannot_load_sdk_body"), tr);
176176
} else {
177177
Devices devices = Devices.getInstance();
178178
devices.setSDK(sdk);

mode/src/processing/mode/android/AndroidSDK.java

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class AndroidSDK {
9292
private static final int INVALID_SDK = 3;
9393
private static int loadError = NO_ERROR;
9494

95+
private static boolean backOptionSelected;
96+
9597
public AndroidSDK(File folder) throws BadSDKException, IOException {
9698
this.folder = folder;
9799
if (!folder.exists()) {
@@ -117,11 +119,17 @@ public AndroidSDK(File folder) throws BadSDKException, IOException {
117119
if (!platforms.exists()) {
118120
throw new BadSDKException(AndroidMode.getTextString("android_sdk.error.missing_platforms_folder", folder));
119121
}
120-
121-
targetPlatform = new File(platforms, AndroidBuild.TARGET_PLATFORM);
122+
123+
String[] availPlatforms = platforms.list();
124+
int maxVersion = 26;
125+
for (String availPlatform:availPlatforms){
126+
int platformVersion = Integer.parseInt(availPlatform.substring(availPlatform.length()-2));
127+
if (platformVersion >= maxVersion) maxVersion = platformVersion;
128+
}
129+
targetPlatform = new File(platforms, "android-"+maxVersion);
122130
if (!targetPlatform.exists()) {
123131
throw new BadSDKException(AndroidMode.getTextString("android_sdk.error.missing_target_platform",
124-
AndroidBuild.TARGET_SDK, platforms.getAbsolutePath()));
132+
maxVersion, platforms.getAbsolutePath()));
125133
}
126134

127135
androidJar = new File(targetPlatform, "android.jar");
@@ -133,6 +141,8 @@ public AndroidSDK(File folder) throws BadSDKException, IOException {
133141
avdManager = findCliTool(new File(tools, "bin"), "avdmanager");
134142
sdkManager = findCliTool(new File(tools, "bin"), "sdkmanager");
135143

144+
Preferences.set("android.sdk.target",maxVersion+"");
145+
136146
String path = Platform.getenv("PATH");
137147

138148
Platform.setenv("ANDROID_SDK", folder.getCanonicalPath());
@@ -403,11 +413,17 @@ public static AndroidSDK load(boolean checkEnvSDK, Frame editor) throws IOExcept
403413

404414
static public AndroidSDK locate(final Frame window, final AndroidMode androidMode)
405415
throws BadSDKException, CancelException, IOException {
406-
416+
backOptionSelected = false;
417+
407418
if (loadError == SKIP_ENV_SDK) {
408419
// The user does not want to use the environment SDK, so let's simply
409420
// download a new one to the sketchbook folder.
410-
return download(window, androidMode);
421+
AndroidSDK sdk = download(window, androidMode);
422+
if(sdk==null && backOptionSelected){
423+
return locate(window,androidMode);
424+
} else {
425+
return sdk;
426+
}
411427
}
412428

413429
// At this point, there is no ANDROID_SDK env variable, no SDK in the preferences,
@@ -416,7 +432,11 @@ static public AndroidSDK locate(final Frame window, final AndroidMode androidMod
416432
int result = showLocateDialog(window);
417433

418434
if (result == JOptionPane.YES_OPTION) {
419-
return download(window, androidMode);
435+
AndroidSDK sdk = download(window, androidMode);
436+
if(sdk==null && backOptionSelected){
437+
return locate(window,androidMode);
438+
}
439+
return sdk;
420440
} else if (result == JOptionPane.NO_OPTION) {
421441
// User will manually select folder containing SDK folder
422442
File folder = selectFolder(AndroidMode.getTextString("android_sdk.dialog.select_sdk_folder"), null, window);
@@ -448,9 +468,13 @@ static public boolean locateSysImage(final Frame window,
448468
static public AndroidSDK download(final Frame editor, final AndroidMode androidMode)
449469
throws BadSDKException, CancelException {
450470
final SDKDownloader downloader = new SDKDownloader(editor);
451-
downloader.run(); // This call blocks until the SDK download complete, or user cancels.
452-
453-
if (downloader.cancelled()) {
471+
//downloader.run(); // This call blocks until the SDK download complete, or user cancels.
472+
473+
if (downloader.isGoBack()){
474+
backOptionSelected = true;
475+
return null;
476+
}
477+
else if (downloader.cancelled()) {
454478
throw new CancelException(AndroidMode.getTextString("android_sdk.error.sdk_download_canceled"));
455479
}
456480
AndroidSDK sdk = downloader.getSDK();

0 commit comments

Comments
 (0)