Skip to content

Commit c51b18a

Browse files
committed
Add SDK downloading progress window
1 parent 9bc0b80 commit c51b18a

File tree

3 files changed

+150
-45
lines changed

3 files changed

+150
-45
lines changed

src/processing/mode/android/AndroidMode.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class AndroidMode extends JavaMode {
3535
private File coreZipLocation;
3636
private AndroidRunner runner;
3737

38+
public static boolean sdkDownloadInProgress = false;
3839

3940
public AndroidMode(Base base, File folder) {
4041
super(base, folder);
@@ -131,10 +132,12 @@ public void checkSDK(Editor parent) {
131132
}
132133
}
133134
if (sdk == null) {
134-
Base.showWarning("It's gonna be a bad day",
135-
"The Android SDK could not be loaded.\n" +
136-
"Use of Android mode will be all but disabled.",
137-
null);
135+
if(!sdkDownloadInProgress) {
136+
Base.showWarning("It's gonna be a bad day",
137+
"The Android SDK could not be loaded.\n" +
138+
"Use of Android mode will be all but disabled.",
139+
null);
140+
}
138141
}
139142
}
140143

src/processing/mode/android/AndroidSDK.java

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,17 @@ public static AndroidSDK load() throws BadSDKException, IOException {
234234

235235

236236
static public AndroidSDK locate(final Frame window)
237-
throws BadSDKException, IOException {
237+
throws BadSDKException, IOException {
238238
final int result = showLocateDialog(window);
239239
if (result == JOptionPane.CANCEL_OPTION) {
240240
throw new BadSDKException("User canceled attempt to find SDK.");
241241
}
242242
if (result == JOptionPane.YES_OPTION) {
243243
// here we are going to download sdk automatically
244-
Base.openURL(ANDROID_SDK_URL);
245-
throw new BadSDKException("No SDK installed.");
244+
//Base.openURL(ANDROID_SDK_URL);
245+
//throw new BadSDKException("No SDK installed.");
246+
247+
return download();
246248
}
247249
while (true) {
248250
// TODO this is really a yucky way to do this stuff. fix it.
@@ -261,46 +263,50 @@ static public AndroidSDK locate(final Frame window)
261263
}
262264
}
263265

266+
static public AndroidSDK download() throws BadSDKException {
267+
AndroidMode.sdkDownloadInProgress = true;
268+
269+
SwingUtilities.invokeLater(new Runnable() {
270+
@Override
271+
public void run() {
272+
SDKDownloader downloader = new SDKDownloader();
273+
downloader.startDownload();
274+
}
275+
});
276+
return null;
277+
}
278+
264279
static public int showLocateDialog(Frame editor) {
265-
if (!Base.isMacOS()) {
266-
return JOptionPane.showConfirmDialog(editor,
267-
"<html><body>" +
268-
"<b>" + ANDROID_SDK_PRIMARY + "</b>" +
269-
"<br>" + ANDROID_SDK_SECONDARY, "Android SDK",
270-
JOptionPane.YES_NO_OPTION,
271-
JOptionPane.QUESTION_MESSAGE);
280+
// Pane formatting adapted from the Quaqua guide
281+
// http://www.randelshofer.ch/quaqua/guide/joptionpane.html
282+
JOptionPane pane =
283+
new JOptionPane("<html> " +
284+
"<head> <style type=\"text/css\">"+
285+
"b { font: 13pt \"Lucida Grande\" }"+
286+
"p { font: 11pt \"Lucida Grande\"; margin-top: 8px; width: 300px }"+
287+
"</style> </head>" +
288+
"<b>" + ANDROID_SDK_PRIMARY + "</b>" +
289+
"<p>" + ANDROID_SDK_SECONDARY + "</p>",
290+
JOptionPane.QUESTION_MESSAGE);
291+
292+
String[] options = new String[] {
293+
"Download SDK automatically", "Locate SDK path manually"
294+
};
295+
pane.setOptions(options);
296+
297+
// highlight the safest option ala apple hig
298+
pane.setInitialValue(options[0]);
299+
300+
JDialog dialog = pane.createDialog(editor, null);
301+
dialog.setVisible(true);
302+
303+
Object result = pane.getValue();
304+
if (result == options[0]) {
305+
return JOptionPane.YES_OPTION;
306+
} else if (result == options[1]) {
307+
return JOptionPane.NO_OPTION;
272308
} else {
273-
// Pane formatting adapted from the Quaqua guide
274-
// http://www.randelshofer.ch/quaqua/guide/joptionpane.html
275-
JOptionPane pane =
276-
new JOptionPane("<html> " +
277-
"<head> <style type=\"text/css\">"+
278-
"b { font: 13pt \"Lucida Grande\" }"+
279-
"p { font: 11pt \"Lucida Grande\"; margin-top: 8px; width: 300px }"+
280-
"</style> </head>" +
281-
"<b>" + ANDROID_SDK_PRIMARY + "</b>" +
282-
"<p>" + ANDROID_SDK_SECONDARY + "</p>",
283-
JOptionPane.QUESTION_MESSAGE);
284-
285-
String[] options = new String[] {
286-
"Download SDK automatically", "Locate SDK path manually"
287-
};
288-
pane.setOptions(options);
289-
290-
// highlight the safest option ala apple hig
291-
pane.setInitialValue(options[0]);
292-
293-
JDialog dialog = pane.createDialog(editor, null);
294-
dialog.setVisible(true);
295-
296-
Object result = pane.getValue();
297-
if (result == options[0]) {
298-
return JOptionPane.YES_OPTION;
299-
} else if (result == options[1]) {
300-
return JOptionPane.NO_OPTION;
301-
} else {
302-
return JOptionPane.CLOSED_OPTION;
303-
}
309+
return JOptionPane.CLOSED_OPTION;
304310
}
305311
}
306312

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package processing.mode.android;
2+
3+
import processing.app.Preferences;
4+
5+
import javax.swing.*;
6+
import javax.swing.border.EmptyBorder;
7+
import java.awt.*;
8+
import java.awt.event.ActionEvent;
9+
import java.awt.event.ActionListener;
10+
11+
public class SDKDownloader extends JFrame {
12+
13+
public SDKDownloader() {
14+
super("Android SDK downloading...");
15+
16+
createLayout();
17+
}
18+
19+
public void startDownload() {
20+
}
21+
22+
private void createLayout() {
23+
Container outer = getContentPane();
24+
outer.removeAll();
25+
26+
Box pain = Box.createVerticalBox();
27+
pain.setBorder(new EmptyBorder(13, 13, 13, 13));
28+
outer.add(pain);
29+
30+
String labelText =
31+
"Downloading Android SDK...";
32+
JLabel textarea = new JLabel(labelText);
33+
textarea.setAlignmentX(LEFT_ALIGNMENT);
34+
pain.add(textarea);
35+
36+
JProgressBar progressBar = new JProgressBar(0, 100);
37+
progressBar.setValue(0);
38+
progressBar.setStringPainted(true);
39+
progressBar.setIndeterminate(true);
40+
pain.add(progressBar);
41+
42+
// buttons
43+
JPanel buttons = new JPanel();
44+
// buttons.setPreferredSize(new Dimension(400, 35));
45+
// JPanel buttons = new JPanel() {
46+
// public Dimension getPreferredSize() {
47+
// return new Dimension(400, 35);
48+
// }
49+
// public Dimension getMinimumSize() {
50+
// return new Dimension(400, 35);
51+
// }
52+
// public Dimension getMaximumSize() {
53+
// return new Dimension(400, 35);
54+
// }
55+
// };
56+
57+
// Box buttons = Box.createHorizontalBox();
58+
buttons.setAlignmentX(LEFT_ALIGNMENT);
59+
JButton cancelButton = new JButton("Cancel download");
60+
Dimension dim = new Dimension(Preferences.BUTTON_WIDTH,
61+
cancelButton.getPreferredSize().height);
62+
63+
cancelButton.setPreferredSize(dim);
64+
cancelButton.addActionListener(new ActionListener() {
65+
public void actionPerformed(ActionEvent e) {
66+
setVisible(false);
67+
}
68+
});
69+
cancelButton.setEnabled(true);
70+
71+
buttons.add(cancelButton);
72+
// buttons.setMaximumSize(new Dimension(300, buttons.getPreferredSize().height));
73+
pain.add(buttons);
74+
75+
JRootPane root = getRootPane();
76+
root.setDefaultButton(cancelButton);
77+
ActionListener disposer = new ActionListener() {
78+
public void actionPerformed(ActionEvent actionEvent) {
79+
setVisible(false);
80+
}
81+
};
82+
processing.app.Toolkit.registerWindowCloseKeys(root, disposer);
83+
processing.app.Toolkit.setIcon(this);
84+
85+
pack();
86+
87+
Dimension screen = processing.app.Toolkit.getScreenSize();
88+
Dimension windowSize = getSize();
89+
90+
setLocation((screen.width - windowSize.width) / 2,
91+
(screen.height - windowSize.height) / 2);
92+
93+
setVisible(true);
94+
setAlwaysOnTop(true);
95+
}
96+
}

0 commit comments

Comments
 (0)