|
1 | 1 | package processing.mode.android;
|
2 | 2 |
|
3 | 3 | import processing.app.Base;
|
4 |
| -import processing.app.Editor; |
5 | 4 | import processing.app.Platform;
|
6 | 5 | import processing.app.Preferences;
|
7 | 6 | import processing.app.exec.ProcessHelper;
|
|
10 | 9 |
|
11 | 10 | import javax.swing.*;
|
12 | 11 | import java.awt.*;
|
| 12 | +import java.io.BufferedReader; |
13 | 13 | import java.io.File;
|
| 14 | +import java.io.FileReader; |
14 | 15 | import java.io.IOException;
|
15 | 16 | import java.text.DateFormat;
|
16 | 17 | import java.text.ParseException;
|
17 | 18 | import java.text.SimpleDateFormat;
|
| 19 | +import java.util.ArrayList; |
18 | 20 | import java.util.Date;
|
19 | 21 |
|
20 | 22 | class AndroidSDK {
|
21 | 23 | private final File folder;
|
22 | 24 | private final File tools;
|
| 25 | + private final File platforms; |
23 | 26 | private final File platformTools;
|
24 | 27 | private final File androidTool;
|
25 | 28 |
|
@@ -62,6 +65,11 @@ public AndroidSDK(File folder) throws BadSDKException, IOException {
|
62 | 65 | throw new BadSDKException("There is no platform-tools folder in " + folder);
|
63 | 66 | }
|
64 | 67 |
|
| 68 | + platforms = new File(folder, "platforms"); |
| 69 | + if (!platforms.exists()) { |
| 70 | + throw new BadSDKException("There is no platforms folder in " + folder); |
| 71 | + } |
| 72 | + |
65 | 73 | androidTool = findAndroidTool(tools);
|
66 | 74 |
|
67 | 75 | final Platform p = Base.getPlatform();
|
@@ -385,4 +393,39 @@ public static ProcessResult runADB(final String... cmd)
|
385 | 393 | // throw ioe;
|
386 | 394 | // }
|
387 | 395 | }
|
| 396 | + |
| 397 | + public static class SDKTarget { |
| 398 | + public int version = 0; |
| 399 | + public String name; |
| 400 | + } |
| 401 | + |
| 402 | + public ArrayList<SDKTarget> getAvailableSdkTargets() throws IOException { |
| 403 | + ArrayList<SDKTarget> targets = new ArrayList<SDKTarget>(); |
| 404 | + |
| 405 | + for(File platform : platforms.listFiles()) { |
| 406 | + File propFile = new File(platform, "build.prop"); |
| 407 | + if(!propFile.exists()) continue; |
| 408 | + |
| 409 | + SDKTarget target = new SDKTarget(); |
| 410 | + |
| 411 | + BufferedReader br = new BufferedReader(new FileReader(propFile)); |
| 412 | + String line; |
| 413 | + while ((line = br.readLine()) != null) { |
| 414 | + String[] lineData = line.split("="); |
| 415 | + if(lineData[0].equals("ro.build.version.sdk")) { |
| 416 | + target.version = Integer.valueOf(lineData[1]); |
| 417 | + } |
| 418 | + |
| 419 | + if(lineData[0].equals("ro.build.version.release")) { |
| 420 | + target.name = lineData[1]; |
| 421 | + break; |
| 422 | + } |
| 423 | + } |
| 424 | + br.close(); |
| 425 | + |
| 426 | + if(target.version != 0 && target.name != null) targets.add(target); |
| 427 | + } |
| 428 | + |
| 429 | + return targets; |
| 430 | + } |
388 | 431 | }
|
0 commit comments