mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
change how folders are handled on android sdk
This commit is contained in:
@@ -1928,7 +1928,8 @@ public class Base {
|
||||
} catch (Exception e) { }
|
||||
|
||||
if (sketchbookFolder == null) {
|
||||
sketchbookFolder = promptSketchbookLocation();
|
||||
showError("No sketchbook",
|
||||
"Problem while trying to get the sketchbook", null);
|
||||
}
|
||||
|
||||
// create the folder if it doesn't exist already
|
||||
@@ -1947,33 +1948,33 @@ public class Base {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check for a new sketchbook location.
|
||||
*/
|
||||
static protected File promptSketchbookLocation() {
|
||||
// Most often this will happen on Linux, so default to their home dir.
|
||||
File folder = new File(System.getProperty("user.home"), "sketchbook");
|
||||
String prompt = "Select a folder to place sketches...";
|
||||
|
||||
// FolderSelector fs = new FolderSelector(prompt, folder, new Frame());
|
||||
// folder = fs.getFolder();
|
||||
folder = Base.selectFolder(prompt, folder, new Frame());
|
||||
|
||||
// folder = Base.selectFolder(prompt, folder, null);
|
||||
// PApplet.selectFolder(prompt,
|
||||
// "promptSketchbookCallback", dflt,
|
||||
// Preferences.this, dialog);
|
||||
|
||||
if (folder == null) {
|
||||
System.exit(0);
|
||||
}
|
||||
// Create the folder if it doesn't exist already
|
||||
if (!folder.exists()) {
|
||||
folder.mkdirs();
|
||||
return folder;
|
||||
}
|
||||
return folder;
|
||||
}
|
||||
// /**
|
||||
// * Check for a new sketchbook location.
|
||||
// */
|
||||
// static protected File promptSketchbookLocation() {
|
||||
// // Most often this will happen on Linux, so default to their home dir.
|
||||
// File folder = new File(System.getProperty("user.home"), "sketchbook");
|
||||
// String prompt = "Select a folder to place sketches...";
|
||||
//
|
||||
//// FolderSelector fs = new FolderSelector(prompt, folder, new Frame());
|
||||
//// folder = fs.getFolder();
|
||||
// folder = Base.selectFolder(prompt, folder, new Frame());
|
||||
//
|
||||
//// folder = Base.selectFolder(prompt, folder, null);
|
||||
//// PApplet.selectFolder(prompt,
|
||||
//// "promptSketchbookCallback", dflt,
|
||||
//// Preferences.this, dialog);
|
||||
//
|
||||
// if (folder == null) {
|
||||
// System.exit(0);
|
||||
// }
|
||||
// // Create the folder if it doesn't exist already
|
||||
// if (!folder.exists()) {
|
||||
// folder.mkdirs();
|
||||
// return folder;
|
||||
// }
|
||||
// return folder;
|
||||
// }
|
||||
|
||||
|
||||
// .................................................................
|
||||
@@ -2066,43 +2067,43 @@ public class Base {
|
||||
// }
|
||||
|
||||
|
||||
static class FolderSelector {
|
||||
File folder;
|
||||
boolean ready;
|
||||
|
||||
FolderSelector(String prompt, File defaultFile, Frame parentFrame) {
|
||||
PApplet.selectFolder(prompt, "callback", defaultFile, this, parentFrame);
|
||||
}
|
||||
|
||||
public void callback(File folder) {
|
||||
this.folder = folder;
|
||||
ready = true;
|
||||
}
|
||||
|
||||
boolean isReady() {
|
||||
return ready;
|
||||
}
|
||||
|
||||
/** block until the folder is available */
|
||||
File getFolder() {
|
||||
while (!ready) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) { }
|
||||
}
|
||||
return folder;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Blocking version of folder selection. Runs and sleeps until an answer
|
||||
* comes back. Avoid using: try to make things work with the async
|
||||
* selectFolder inside PApplet instead.
|
||||
*/
|
||||
static public File selectFolder(String prompt, File folder, Frame frame) {
|
||||
return new FolderSelector(prompt, folder, frame).getFolder();
|
||||
}
|
||||
// static class FolderSelector {
|
||||
// File folder;
|
||||
// boolean ready;
|
||||
//
|
||||
// FolderSelector(String prompt, File defaultFile, Frame parentFrame) {
|
||||
// PApplet.selectFolder(prompt, "callback", defaultFile, this, parentFrame);
|
||||
// }
|
||||
//
|
||||
// public void callback(File folder) {
|
||||
// this.folder = folder;
|
||||
// ready = true;
|
||||
// }
|
||||
//
|
||||
// boolean isReady() {
|
||||
// return ready;
|
||||
// }
|
||||
//
|
||||
// /** block until the folder is available */
|
||||
// File getFolder() {
|
||||
// while (!ready) {
|
||||
// try {
|
||||
// Thread.sleep(100);
|
||||
// } catch (InterruptedException e) { }
|
||||
// }
|
||||
// return folder;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Blocking version of folder selection. Runs and sleeps until an answer
|
||||
// * comes back. Avoid using: try to make things work with the async
|
||||
// * selectFolder inside PApplet instead.
|
||||
// */
|
||||
// static public File selectFolder(String prompt, File folder, Frame frame) {
|
||||
// return new FolderSelector(prompt, folder, frame).getFolder();
|
||||
// }
|
||||
|
||||
|
||||
// .................................................................
|
||||
|
||||
@@ -33,44 +33,44 @@ import com.sun.jna.Native;
|
||||
/**
|
||||
* Used by Base for platform-specific tweaking, for instance finding the
|
||||
* sketchbook location using the Windows registry, or OS X event handling.
|
||||
*
|
||||
* The methods in this implementation are used by default, and can be
|
||||
* overridden by a subclass, if loaded by Base.main().
|
||||
*
|
||||
*
|
||||
* The methods in this implementation are used by default, and can be
|
||||
* overridden by a subclass, if loaded by Base.main().
|
||||
*
|
||||
* These methods throw vanilla-flavored Exceptions, so that error handling
|
||||
* occurs inside Base.
|
||||
*
|
||||
* There is currently no mechanism for adding new platforms, as the setup is
|
||||
* not automated. We could use getProperty("os.arch") perhaps, but that's
|
||||
* debatable (could be upper/lowercase, have spaces, etc.. basically we don't
|
||||
* occurs inside Base.
|
||||
*
|
||||
* There is currently no mechanism for adding new platforms, as the setup is
|
||||
* not automated. We could use getProperty("os.arch") perhaps, but that's
|
||||
* debatable (could be upper/lowercase, have spaces, etc.. basically we don't
|
||||
* know if name is proper Java package syntax.)
|
||||
*/
|
||||
public class Platform {
|
||||
Base base;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set the default L & F. While I enjoy the bounty of the sixteen possible
|
||||
* exception types that this UIManager method might throw, I feel that in
|
||||
* exception types that this UIManager method might throw, I feel that in
|
||||
* just this one particular case, I'm being spoiled by those engineers
|
||||
* at Sun, those Masters of the Abstractionverse. It leaves me feeling sad
|
||||
* and overweight. So instead, I'll pretend that I'm not offered eleven dozen
|
||||
* ways to report to the user exactly what went wrong, and I'll bundle them
|
||||
* all into a single catch-all "Exception". Because in the end, all I really
|
||||
* all into a single catch-all "Exception". Because in the end, all I really
|
||||
* care about is whether things worked or not. And even then, I don't care.
|
||||
*
|
||||
*
|
||||
* @throws Exception Just like I said.
|
||||
*/
|
||||
public void setLookAndFeel() throws Exception {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void init(Base base) {
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public File getSettingsFolder() throws Exception {
|
||||
// otherwise make a .processing directory int the user's home dir
|
||||
File home = new File(System.getProperty("user.home"));
|
||||
@@ -92,32 +92,32 @@ public class Platform {
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return null if not overridden, which will cause a prompt to show instead.
|
||||
* @return null if not overridden, which will cause a prompt to show instead.
|
||||
* @throws Exception
|
||||
*/
|
||||
public File getDefaultSketchbookFolder() throws Exception {
|
||||
return null;
|
||||
return new File(System.getProperty("user.dir"), "sketchbook");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void openURL(String url) throws Exception {
|
||||
String launcher = Preferences.get("launcher");
|
||||
if (launcher != null) {
|
||||
Runtime.getRuntime().exec(new String[] { launcher, url });
|
||||
} else {
|
||||
showLauncherWarning();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean openFolderAvailable() {
|
||||
return Preferences.get("launcher") != null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void openFolder(File file) throws Exception {
|
||||
String launcher = Preferences.get("launcher");
|
||||
if (launcher != null) {
|
||||
@@ -127,11 +127,11 @@ public class Platform {
|
||||
showLauncherWarning();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
public interface CLibrary extends Library {
|
||||
CLibrary INSTANCE = (CLibrary)Native.loadLibrary("c", CLibrary.class);
|
||||
int setenv(String name, String value, int overwrite);
|
||||
@@ -140,13 +140,13 @@ public class Platform {
|
||||
int putenv(String string);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setenv(String variable, String value) {
|
||||
CLibrary clib = CLibrary.INSTANCE;
|
||||
clib.setenv(variable, value, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getenv(String variable) {
|
||||
CLibrary clib = CLibrary.INSTANCE;
|
||||
return clib.getenv(variable);
|
||||
@@ -158,15 +158,15 @@ public class Platform {
|
||||
return clib.unsetenv(variable);
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
protected void showLauncherWarning() {
|
||||
Base.showWarning("No launcher available",
|
||||
"Unspecified platform, no launcher available.\n" +
|
||||
Base.showWarning("No launcher available",
|
||||
"Unspecified platform, no launcher available.\n" +
|
||||
"To enable opening URLs or folders, add a \n" +
|
||||
"\"launcher=/path/to/app\" line to preferences.txt",
|
||||
"\"launcher=/path/to/app\" line to preferences.txt",
|
||||
null);
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ import processing.core.PApplet;
|
||||
|
||||
public class AndroidEditor extends JavaEditor {
|
||||
// private AndroidBuild build;
|
||||
private AndroidMode amode;
|
||||
private AndroidMode androidMode;
|
||||
|
||||
// private static final String ANDROID_CORE_FILENAME =
|
||||
// "processing-android-core-" + Base.VERSION_NAME + ".zip";
|
||||
@@ -59,19 +59,20 @@ public class AndroidEditor extends JavaEditor {
|
||||
|
||||
protected AndroidEditor(Base base, String path, EditorState state, Mode mode) throws Exception {
|
||||
super(base, path, state, mode);
|
||||
amode = (AndroidMode) mode;
|
||||
androidMode = (AndroidMode) mode;
|
||||
androidMode.checkSDK(this);
|
||||
|
||||
// try {
|
||||
AndroidSDK sdk = amode.loadSDK();
|
||||
if (sdk == null) {
|
||||
sdk = AndroidSDK.locate(this);
|
||||
}
|
||||
// } catch (BadSDKException bse) {
|
||||
// statusError(bse);
|
||||
//
|
||||
// } catch (IOException e) {
|
||||
// statusError(e);
|
||||
//// try {
|
||||
// AndroidSDK sdk = amode.loadSDK();
|
||||
// if (sdk == null) {
|
||||
// sdk = AndroidSDK.locate(this);
|
||||
// }
|
||||
//// } catch (BadSDKException bse) {
|
||||
//// statusError(bse);
|
||||
////
|
||||
//// } catch (IOException e) {
|
||||
//// statusError(e);
|
||||
//// }
|
||||
|
||||
/*
|
||||
if (sdk == null) {
|
||||
@@ -182,7 +183,7 @@ public class AndroidEditor extends JavaEditor {
|
||||
item = new JMenuItem("Android SDK Manager");
|
||||
item.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
File file = amode.getSDK().getAndroidTool();
|
||||
File file = androidMode.getSDK().getAndroidTool();
|
||||
PApplet.exec(new String[] { file.getAbsolutePath(), "sdk" });
|
||||
}
|
||||
});
|
||||
@@ -191,7 +192,7 @@ public class AndroidEditor extends JavaEditor {
|
||||
item = new JMenuItem("Android AVD Manager");
|
||||
item.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
File file = amode.getSDK().getAndroidTool();
|
||||
File file = androidMode.getSDK().getAndroidTool();
|
||||
PApplet.exec(new String[] { file.getAbsolutePath(), "avd" });
|
||||
}
|
||||
});
|
||||
@@ -341,7 +342,7 @@ public class AndroidEditor extends JavaEditor {
|
||||
startIndeterminate();
|
||||
prepareRun();
|
||||
try {
|
||||
amode.handleRunEmulator(sketch, AndroidEditor.this);
|
||||
androidMode.handleRunEmulator(sketch, AndroidEditor.this);
|
||||
} catch (SketchException e) {
|
||||
statusError(e);
|
||||
} catch (IOException e) {
|
||||
@@ -363,7 +364,7 @@ public class AndroidEditor extends JavaEditor {
|
||||
startIndeterminate();
|
||||
prepareRun();
|
||||
try {
|
||||
amode.handleRunDevice(sketch, AndroidEditor.this);
|
||||
androidMode.handleRunDevice(sketch, AndroidEditor.this);
|
||||
} catch (SketchException e) {
|
||||
statusError(e);
|
||||
} catch (IOException e) {
|
||||
@@ -378,7 +379,7 @@ public class AndroidEditor extends JavaEditor {
|
||||
public void handleStop() {
|
||||
toolbar.deactivate(AndroidToolbar.RUN);
|
||||
stopIndeterminate();
|
||||
amode.handleStop(this);
|
||||
androidMode.handleStop(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -393,7 +394,7 @@ public class AndroidEditor extends JavaEditor {
|
||||
toolbar.activate(AndroidToolbar.EXPORT);
|
||||
startIndeterminate();
|
||||
statusNotice("Exporting a debug version of the sketch...");
|
||||
AndroidBuild build = new AndroidBuild(sketch, amode);
|
||||
AndroidBuild build = new AndroidBuild(sketch, androidMode);
|
||||
try {
|
||||
File exportFolder = build.exportProject();
|
||||
if (exportFolder != null) {
|
||||
|
||||
@@ -105,11 +105,33 @@ public class AndroidMode extends JavaMode {
|
||||
}
|
||||
|
||||
|
||||
public AndroidSDK loadSDK() throws BadSDKException, IOException {
|
||||
// public AndroidSDK loadSDK() throws BadSDKException, IOException {
|
||||
// if (sdk == null) {
|
||||
// sdk = AndroidSDK.load();
|
||||
// }
|
||||
// return sdk;
|
||||
// }
|
||||
|
||||
|
||||
public void checkSDK(Editor parent) {
|
||||
if (sdk == null) {
|
||||
sdk = AndroidSDK.load();
|
||||
try {
|
||||
sdk = AndroidSDK.load();
|
||||
if (sdk == null) {
|
||||
sdk = AndroidSDK.locate(parent);
|
||||
}
|
||||
} catch (BadSDKException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (sdk == null) {
|
||||
Base.showWarning("It's gonna be a bad day",
|
||||
"The Android SDK could not be loaded.\n" +
|
||||
"Use of Android mode will be all but disabled.",
|
||||
null);
|
||||
}
|
||||
return sdk;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package processing.mode.android;
|
||||
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.Frame;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -8,6 +9,7 @@ import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import processing.app.Base;
|
||||
@@ -245,11 +247,11 @@ class AndroidSDK {
|
||||
throw new BadSDKException("No SDK installed.");
|
||||
}
|
||||
while (true) {
|
||||
File folder = Base.selectFolder(SELECT_ANDROID_SDK_FOLDER, null, window);
|
||||
// TODO this is really a yucky way to do this stuff. fix it.
|
||||
File folder = selectFolder(SELECT_ANDROID_SDK_FOLDER, null, window);
|
||||
if (folder == null) {
|
||||
throw new BadSDKException("User canceled attempt to find SDK.");
|
||||
}
|
||||
|
||||
try {
|
||||
final AndroidSDK androidSDK = new AndroidSDK(folder);
|
||||
Preferences.set("android.sdk.path", folder.getAbsolutePath());
|
||||
@@ -262,6 +264,41 @@ class AndroidSDK {
|
||||
}
|
||||
|
||||
|
||||
// this was banished from Base because it encourages bad practice.
|
||||
// TODO figure out a better way to handle the above.
|
||||
static public File selectFolder(String prompt, File folder, Frame frame) {
|
||||
if (Base.isMacOS()) {
|
||||
if (frame == null) frame = new Frame(); //.pack();
|
||||
FileDialog fd = new FileDialog(frame, prompt, FileDialog.LOAD);
|
||||
if (folder != null) {
|
||||
fd.setDirectory(folder.getParent());
|
||||
//fd.setFile(folder.getName());
|
||||
}
|
||||
System.setProperty("apple.awt.fileDialogForDirectories", "true");
|
||||
fd.setVisible(true);
|
||||
System.setProperty("apple.awt.fileDialogForDirectories", "false");
|
||||
if (fd.getFile() == null) {
|
||||
return null;
|
||||
}
|
||||
return new File(fd.getDirectory(), fd.getFile());
|
||||
|
||||
} else {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
fc.setDialogTitle(prompt);
|
||||
if (folder != null) {
|
||||
fc.setSelectedFile(folder);
|
||||
}
|
||||
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
|
||||
int returned = fc.showOpenDialog(frame);
|
||||
if (returned == JFileChooser.APPROVE_OPTION) {
|
||||
return fc.getSelectedFile();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static final String ADB_DAEMON_MSG_1 = "daemon not running";
|
||||
private static final String ADB_DAEMON_MSG_2 = "daemon started successfully";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user