fixing up the device check

This commit is contained in:
benfry
2010-01-11 00:00:48 +00:00
parent 3092f6135a
commit e75042e664
3 changed files with 80 additions and 64 deletions

View File

@@ -135,14 +135,20 @@ public class Android implements Tool {
File folder =
Base.selectFolder(SELECT_ANDROID_SDK_FOLDER, null, editor);
if (folder != null) {
boolean basicCheck = Base.isWindows() ?
new File(folder, "tools/android.exe").exists() :
new File(folder, "tools/android").exists();
boolean basicCheck = false;
if (Base.isWindows()) {
basicCheck = (new File(folder, "tools/android.exe").exists() ||
new File(folder, "tools/android.bat").exists());
} else {
basicCheck = new File(folder, "tools/android").exists();
}
if (basicCheck) {
sdkPath = folder.getAbsolutePath();
Preferences.set("android.sdk.path", sdkPath);
} else {
// tools/android not found in the selected folder
System.err.println("Could not find the android executable at " +
folder.getAbsolutePath() + "/tools/android");
JOptionPane.showMessageDialog(editor, NOT_ANDROID_SDK);
return false;
}

View File

@@ -28,12 +28,12 @@ import processing.core.PApplet;
public class Device {
/** Name of this device. */
String name;
/** "android-4" or "Google Inc.:Google APIs:4" */
String target;
String target;
/** Width of the skin used in the emulator. */
int width;
@@ -41,53 +41,53 @@ public class Device {
/** Height of the skin used in the emulator. */
int height;
/**
* Default virtual device used by Processing, intended to be similar to
/**
* Default virtual device used by Processing, intended to be similar to
* a device like a T-Mobile G1 or myTouch 3G. Uses Android 1.6 (Donut) APIs,
* and the screen is 480x320 pixels, or HVGA (Half VGA).
* and the screen is 480x320 pixels, or HVGA (Half VGA).
*/
static Device avdDonut =
// Using the generic AVD causes a prompt to show up on the console,
// Using the generic AVD causes a prompt to show up on the console,
// so using the Google version instead which doesn't ask for a profile.
new Device("Processing-Donut", "Google Inc.:Google APIs:4", 480, 320);
/**
* Default virtual device used by Processing, designed to be similar to
/**
* Default virtual device used by Processing, designed to be similar to
* a device like the Moto Droid. Uses Android 2.0 APIs, and the screen
* is set to WVGA854 (854x480), the same aspect ratio (with rounding),
* is set to WVGA854 (854x480), the same aspect ratio (with rounding),
* as 1920x1080, or 16:9.
*/
static Device avdEclair =
new Device("Processing-Eclair", "Google Inc.:Google APIs:5", 854, 480);
static final String AVD_CREATE_ERROR =
"An error occurred while running “android create avd”\n" +
"to set up the default Android emulator. Make sure that the\n" +
static final String AVD_CREATE_ERROR =
"An error occurred while running “android create avd”\n" +
"to set up the default Android emulator. Make sure that the\n" +
"Android SDK is installed properly, and that the Android\n" +
"and Google APIs are installed for levels 4 and 5.";
static final String ADB_DEVICES_ERROR =
static final String ADB_DEVICES_ERROR =
"Received unfamiliar output from “adb devices”.\n" +
"The device list may have errors.";
"The device list may have errors.";
static final int DEFAULT_WIDTH = 320;
static final int DEFAULT_HEIGHT = 480;
Device(String name, String target, int width, int height) {
this.name = name;
this.target = target;
this.width = width;
this.height = height;
}
static boolean checkDefaults() {
try {
if (!avdDonut.exists()) {
if (!avdDonut.create()) {
Base.showWarning("Android Error",
"An error occurred while running “android create avd”\n" +
Base.showWarning("Android Error",
"An error occurred while running “android create avd”\n" +
"to set up the default Android emulator.", null);
}
}
@@ -97,14 +97,14 @@ public class Device {
}
}
return true;
} catch (Exception e) {
} catch (Exception e) {
Base.showWarning("Android Error", AVD_CREATE_ERROR, null);
}
}
return false;
}
protected boolean exists() throws IOException {
String[] cmd = { "android", "list", "avds" };
// Process p = Runtime.getRuntime().exec(cmd);
@@ -130,7 +130,7 @@ public class Device {
p.printLines();
}
} catch (InterruptedException ie) { }
return false;
}
@@ -138,12 +138,11 @@ public class Device {
protected boolean create() throws IOException {
// not using "-s", width + "x" + height, because that can be specified
// on startup, which will be easier to do for Processing apps anyway.
String[] cmd = { "android", "create", "avd",
String[] cmd = { "android", "create", "avd",
"-n", name,
"-t", target,
"-t", target,
"-c", "64M"
};
//System.out.println(PApplet.join(cmd, " "));
Process p = Runtime.getRuntime().exec(cmd);
StringRedirectThread error = new StringRedirectThread(p.getErrorStream());
StringRedirectThread output = new StringRedirectThread(p.getInputStream());
@@ -152,28 +151,33 @@ public class Device {
int result = p.waitFor();
//System.out.println("res is " + res);
if (result == 0) {
//String[] lines = output.getLines();
//PApplet.println(lines);
// mumble the result into the console
//PApplet.println(output.getLines());
for (String s : output.getLines()) {
// mumble the result into the console
System.out.println(s);
}
return true;
} else {
System.out.println("Attempted: '" + PApplet.join(cmd, " ") + "'");
// Include the stdout stuff since lots of these tools die with an
// error, but use stdout to print their sadness instead of stderr
for (String s : output.getLines()) {
System.out.println(s);
}
for (String s : error.getLines()) {
System.err.println(s);
}
}
} catch (InterruptedException ie) { }
return false;
}
static void sendMenuButton(String device) throws IOException {
// adb -s emulator-5566 shell getevent
// back on G1
// /dev/input/event3: 0001 008b 00000001
// /dev/input/event3: 0001 008b 00000000
@@ -181,15 +185,15 @@ public class Device {
// back on the emulator
// /dev/input/event0: 0001 00e5 00000001
// /dev/input/event0: 0001 00e5 00000000
if (device.startsWith("emulator-")) {
sendKey(device, 0x00e5);
} else {
sendKey(device, 0x008b);
}
}
static void sendHomeButton(String device) throws IOException {
sendKey(device, 0x0066); // 102
@@ -202,16 +206,16 @@ public class Device {
// /dev/input/event0: 0001 0066 00000000
}
static void sendKey(String device, int key) throws IOException {
String inputDevice =
device.startsWith("emulator") ? "/dev/input/event0" : "/dev/input/event3";
String[] cmd = new String[] {
"adb",
String inputDevice =
device.startsWith("emulator") ? "/dev/input/event0" : "/dev/input/event3";
String[] cmd = new String[] {
"adb",
"-s", device,
"shell", "sendevent",
inputDevice, "1", String.valueOf(key),
"shell", "sendevent",
inputDevice, "1", String.valueOf(key),
"1" // start with key down
};
try {
@@ -221,20 +225,20 @@ public class Device {
result = Runtime.getRuntime().exec(cmd).waitFor();
attempts++;
} while (result != 0 && attempts < 5);
attempts = 0;
cmd[cmd.length - 1] = "0"; // send key up
do {
result = Runtime.getRuntime().exec(cmd).waitFor();
attempts++;
} while (result != 0 && attempts < 5);
} catch (InterruptedException ie) { }
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
static protected String[] list() throws IOException {
String[] cmd = { "adb", "devices" };
@@ -249,21 +253,21 @@ public class Device {
String[] lines = p.getOutputLines();
// First line starts "List of devices", last line is blank.
// when an emulator is started with a debug port, then it shows up
// when an emulator is started with a debug port, then it shows up
// in the list of devices.
// List of devices attached
// List of devices attached
// HT91MLC00031 device
// emulator-5554 offline
// List of devices attached
// List of devices attached
// HT91MLC00031 device
// emulator-5554 device
// for (String s : lines) {
// System.out.println("Device.list(): '" + s + ".");
// }
if (lines == null || lines.length == 0) {
// result was 0, so we're ok, but this is odd.
System.out.println("No devices found.");
@@ -274,7 +278,7 @@ public class Device {
// just pretend he didn't say that.
lines = PApplet.subset(lines, 1);
}
if (lines[0].startsWith("* daemon started successfully *")) {
// ignore that too
lines = PApplet.subset(lines, 1);
@@ -303,8 +307,8 @@ public class Device {
System.err.println(s);
}
}
} catch (InterruptedException ie) {
// ignored, just other thread fun
} catch (InterruptedException ie) {
// ignored, just other thread fun
}
return null;
}

View File

@@ -1,6 +1,12 @@
0176 pde (private)
_ remove SurfaceView2D/SurfaceView3D separation, or clean up
_ what is resetLights() in PGraphics?
_ remove drawCube() method from PApplet
_ remove model() method from end of PApplet (make it shape(PShape))
_ add a check to make sure that people aren't running from the dmg