Skip to content

Commit 164b036

Browse files
committed
add showMessage() function to AndroidMode to allow for info text with
embedded links, fix #289
1 parent 1dd4cc2 commit 164b036

File tree

3 files changed

+105
-27
lines changed

3 files changed

+105
-27
lines changed

src/processing/mode/android/AndroidEditor.java

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343

4444
import java.awt.event.ActionEvent;
4545
import java.awt.event.ActionListener;
46+
import java.awt.event.MouseAdapter;
47+
import java.awt.event.MouseEvent;
4648
import java.io.File;
4749
import java.io.IOException;
4850
import java.util.TimerTask;
@@ -641,22 +643,55 @@ public void run() {
641643
public void handleRunDevice() {
642644
if (Platform.isWindows() && !Preferences.getBoolean("usbDriverWarningShown")) {
643645
Preferences.setBoolean("usbDriverWarningShown", true);
644-
645-
String message = "";
646-
File usbDriverFile = new File(((AndroidMode) sketch.getMode()).getSDK().getSdkFolder(), "extras/google/usb_driver");
646+
647+
File sdkFolder = androidMode.getSDK().getSdkFolder();
648+
File usbDriverFile = new File(sdkFolder, "extras/google/usb_driver");
649+
JComponent[] text = null;
647650
if (usbDriverFile.exists()) {
648-
message = "<html><body>" +
649-
"You might need to install Google USB Driver to run the sketch on your device.<br>" +
650-
"Please follow the guide at <a href='http://developer.android.com/tools/extras/oem-usb.html#InstallingDriver'>http://developer.android.com/tools/extras/oem-usb.html#InstallingDriver</a> to install the driver.<br>" +
651-
"For your reference, the driver is located in: " + usbDriverFile.getAbsolutePath();
651+
JLabel text1 = new JLabel("<html>You might need to install Google USB Driver to run<br>" +
652+
"the sketch on your device.</html>");
653+
JLabel text2 = new JLabel("<html>Please follow</html>");
654+
final String url1 = "http://developer.android.com/sdk/win-usb.html";
655+
String urlText1 = "<html><a href=\"" + url1 + "\">this guide</a></html>";
656+
JLabel link1 = new JLabel(urlText1);
657+
link1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
658+
link1.addMouseListener(new MouseAdapter() {
659+
public void mouseClicked(MouseEvent e) {
660+
Platform.openURL(url1);
661+
}
662+
});
663+
JLabel text3 = new JLabel("<html>to install the driver.</html>");
664+
JLabel text4 = new JLabel("<html>For your reference, the driver is located in:<br>" +
665+
"C:/blah/blah/blah/lala</body></html>");
666+
text = new JComponent[] { text1, text2, link1, text3, text4 };
652667
} else {
653-
message = "<html><body>" +
654-
"You might need to install Google USB Driver to run the sketch on your device.<br>" +
655-
"Please follow the guide at <a href='http://developer.android.com/tools/extras/oem-usb.html#InstallingDriver'>http://developer.android.com/tools/extras/oem-usb.html#InstallingDriver</a> to install the driver.<br>" +
656-
"You will also need to download the driver from <a href='http://developer.android.com/sdk/win-usb.html'>http://developer.android.com/sdk/win-usb.html</a>";
668+
JLabel text1 = new JLabel("<html>You might need to install Google USB Driver to run the sketch<br>" +
669+
"on your device.</html>");
670+
JLabel text2 = new JLabel("<html>Please follow</html>");
671+
final String url1 = "http://developer.android.com/sdk/win-usb.html";
672+
String urlText1 = "<html><a href=\"" + url1 + "\">this guide</a></html>";
673+
JLabel link1 = new JLabel(urlText1);
674+
link1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
675+
link1.addMouseListener(new MouseAdapter() {
676+
public void mouseClicked(MouseEvent e) {
677+
Platform.openURL(url1);
678+
}
679+
});
680+
JLabel text3 = new JLabel("<html>to install the driver.</html>");
681+
JLabel text4 = new JLabel("<html>You will also need to download the driver from</html>");
682+
final String url2 = "https://dl-ssl.google.com/android/repository/latest_usb_driver_windows.zip";
683+
String urlText2 = "<html><a href=\"" + url2 + "\">here</a>.</html>";
684+
JLabel link2 = new JLabel(urlText2);
685+
link2.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
686+
link2.addMouseListener(new MouseAdapter() {
687+
public void mouseClicked(MouseEvent e) {
688+
Platform.openURL(url2);
689+
}
690+
});
691+
text = new JComponent[] { text1, text2, link1, text3, text4, link2 };
657692
}
658-
Messages.showWarning("USB Driver warning", message);
659-
693+
String title = "USB Driver warning";
694+
AndroidMode.showMessage(title, text, 400, 100);
660695
} else {
661696
new Thread() {
662697
public void run() {

src/processing/mode/android/AndroidMode.java

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
import processing.mode.android.AndroidSDK.CancelException;
3737
import processing.mode.java.JavaMode;
3838

39+
import java.awt.Container;
40+
import java.awt.Dimension;
41+
import java.awt.FlowLayout;
42+
import java.awt.event.MouseAdapter;
43+
import java.awt.event.MouseEvent;
3944
import java.io.BufferedInputStream;
4045
import java.io.BufferedOutputStream;
4146
import java.io.File;
@@ -49,6 +54,12 @@
4954
import java.util.zip.ZipEntry;
5055
import java.util.zip.ZipFile;
5156

57+
import javax.swing.JComponent;
58+
import javax.swing.JFrame;
59+
import javax.swing.JLabel;
60+
import javax.swing.JOptionPane;
61+
import javax.swing.SwingConstants;
62+
5263

5364
public class AndroidMode extends JavaMode {
5465
private AndroidSDK sdk;
@@ -318,22 +329,36 @@ public void handleRunDevice(Sketch sketch, AndroidEditor editor,
318329

319330
public void showSelectComponentMessage(int appComp) {
320331
if (showBluetoothDebugMessage && appComp == AndroidBuild.WATCHFACE) {
321-
Messages.showMessage("Is Debugging over Bluetooth enabled?",
322-
"Processing will access the wearable through the handheld paired to it.\n" +
323-
"Your watch won't show up in the device list, select the paired handheld.\n" +
324-
"Make sure to enable \"Debugging over Bluetooth\" for this to work:\n" +
325-
"http://developer.android.com/training/wearables/apps/bt-debugging.html");
332+
JLabel text1 = new JLabel("<html>Processing will access the watch through the phone<br>" +
333+
"paired to it. Your watch won't show up in the device list,<br>"+
334+
"select the paired phone.</html>");
335+
JLabel text2 = new JLabel("<html>Make sure to enable</html>");
336+
final String url = "http://developer.android.com/training/wearables/apps/bt-debugging.html";
337+
String urlText = "<html><a href=\"" + url + "\">debugging over bluetooth</a></html>";
338+
JLabel link = new JLabel(urlText);
339+
link.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
340+
link.addMouseListener(new MouseAdapter() {
341+
public void mouseClicked(MouseEvent e) {
342+
Platform.openURL(url);
343+
}
344+
});
345+
JLabel text3 = new JLabel("<html>for this to work.</html>");
346+
JComponent[] text = new JComponent[] { text1, text2, link, text3 };
347+
String title = "Is Debugging over Bluetooth enabled?";
348+
showMessage(title, text, 400, 100);
326349
showBluetoothDebugMessage = false;
327-
}
350+
}
328351
}
329352

330353
public void showPostBuildMessage(int appComp) {
331354
if (showWallpaperSelectMessage && appComp == AndroidBuild.WALLPAPER) {
332-
Messages.showMessage("Now select the wallpaper...",
333-
"Processing built and installed your sketch\n" +
334-
"as a live wallpaper on the selected device.\n" +
335-
"You need to open the wallpaper selector\n" +
336-
"in order to set it as the new background.");
355+
JLabel text1 = new JLabel("<html>Processing just built and installed your sketch as a<br>" +
356+
"live wallpaper on the selected device.<br><br>" +
357+
"You need to open the wallpaper selector in the device in order to<br>"+
358+
"set it as the new background.</html>");
359+
JComponent[] text = new JComponent[] { text1 };
360+
String title = "Wallpaper installed!";
361+
showMessage(title, text, 400, 100);
337362
showWallpaperSelectMessage = false;
338363
}
339364
}
@@ -429,4 +454,22 @@ public static void extractFolder(File file, File newPath, boolean setExec) throw
429454
}
430455
zip.close();
431456
}
457+
458+
static public void showMessage(String title, JComponent[] text,
459+
int w, int h) {
460+
if (title == null) title = "Message";
461+
if (Base.isCommandLine()) {
462+
String concat = "";
463+
for (JComponent txt: text) concat += txt.toString();
464+
System.out.println(title + ": " + concat);
465+
} else {
466+
JFrame frame = new JFrame();
467+
Container outer = frame.getContentPane();
468+
outer.setLayout(new FlowLayout(FlowLayout.LEFT));
469+
for (JComponent txt: text) outer.add(txt);
470+
outer.setPreferredSize(new Dimension(w, h));
471+
JOptionPane.showMessageDialog(frame, outer, title,
472+
JOptionPane.INFORMATION_MESSAGE);
473+
}
474+
}
432475
}

src/processing/mode/android/KeyStoreManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ public void actionPerformed(ActionEvent e) {
126126
public void actionPerformed(ActionEvent e) {
127127
setVisible(false);
128128
int result = Messages.showYesNoQuestion(editor, "Android keystore",
129-
"Are you sure you want to reset the password?", "<html><body>We will have to reset the keystore to do this, " +
130-
"which means you won't be able to upload an update for your app signed with the new keystore to Google Play.<br/><br/>" +
131-
"We will make a backup for the old keystore.</body></html>");
129+
"Are you sure you want to reset the password?", "We will have to reset the keystore to do this, " +
130+
"which means you won't be able to upload an update for your app signed with the new keystore to Google Play.\n\n" +
131+
"We will make a backup for the old keystore.");
132132

133133
if (result == JOptionPane.NO_OPTION) {
134134
setVisible(true);

0 commit comments

Comments
 (0)