Skip to content

Commit 0e13224

Browse files
committed
cleanup phone/wear AVD logic, removed gpu option
1 parent 3db759d commit 0e13224

File tree

5 files changed

+405
-422
lines changed

5 files changed

+405
-422
lines changed

src/processing/mode/android/AVD.java

Lines changed: 45 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import processing.app.Preferences;
2727
import processing.app.exec.LineProcessor;
2828
import processing.app.exec.StreamPump;
29+
import processing.app.ui.Toolkit;
2930
import processing.core.PApplet;
3031

3132
import java.awt.Frame;
@@ -35,6 +36,9 @@
3536

3637

3738
public class AVD {
39+
final static private int PHONE = 0;
40+
final static private int WEAR = 1;
41+
3842
static private final String AVD_CREATE_TITLE =
3943
"Could not create the AVD";
4044

@@ -79,10 +83,10 @@ public class AVD {
7983

8084
protected String device;
8185
protected String skin;
86+
protected int type;
8287

8388
static ArrayList<String> avdList;
8489
static ArrayList<String> badList;
85-
// static ArrayList<String> skinList;
8690

8791
/** "system-images;android-25;google_apis;x86" */
8892
static ArrayList<String> wearImages;
@@ -91,20 +95,21 @@ public class AVD {
9195
private static Process process;
9296

9397
/** Default virtual device used by Processing. */
94-
static public final AVD mobileAVD =
98+
static public final AVD phoneAVD =
9599
new AVD("processing-phone",
96-
DEVICE_DEFINITION, DEVICE_SKIN);
100+
DEVICE_DEFINITION, DEVICE_SKIN, PHONE);
97101

98102
/** Default virtual wear device used by Processing. */
99-
static public final AVD wearAVD =
103+
static public final AVD watchAVD =
100104
new AVD("processing-watch",
101-
DEVICE_WEAR_DEFINITION, DEVICE_WEAR_SKIN);
105+
DEVICE_WEAR_DEFINITION, DEVICE_WEAR_SKIN, WEAR);
102106

103107

104-
public AVD(final String name, final String device, final String skin) {
108+
public AVD(final String name, final String device, final String skin, int type) {
105109
this.name = name;
106110
this.device = device;
107111
this.skin = skin;
112+
this.type = type;
108113
}
109114

110115

@@ -194,32 +199,30 @@ protected boolean badness() {
194199

195200

196201
protected boolean hasImages(final AndroidSDK sdk) throws IOException {
197-
if (phoneImages == null) {
198-
phoneImages = new ArrayList<String>();
199-
getImages(phoneImages, sdk, SysImageDownloader.SYSTEM_IMAGE_TAG);
202+
if (type == PHONE) {
203+
if (phoneImages == null) {
204+
phoneImages = new ArrayList<String>();
205+
getImages(phoneImages, sdk, SysImageDownloader.SYSTEM_IMAGE_TAG);
206+
}
207+
return !phoneImages.isEmpty();
208+
} else {
209+
if (wearImages == null) {
210+
wearImages = new ArrayList<String>();
211+
getImages(wearImages, sdk, SysImageDownloader.SYSTEM_IMAGE_WEAR_TAG);
212+
}
213+
return !wearImages.isEmpty();
200214
}
201-
return !phoneImages.isEmpty();
202215
}
203216

204217

205218
protected void refreshImages(final AndroidSDK sdk) throws IOException {
206-
phoneImages = new ArrayList<String>();
207-
getImages(phoneImages, sdk, SysImageDownloader.SYSTEM_IMAGE_TAG);
208-
}
209-
210-
211-
protected boolean hasWearImages(final AndroidSDK sdk) throws IOException {
212-
if (wearImages == null) {
219+
if (type == PHONE) {
220+
phoneImages = new ArrayList<String>();
221+
getImages(phoneImages, sdk, SysImageDownloader.SYSTEM_IMAGE_TAG);
222+
} else {
213223
wearImages = new ArrayList<String>();
214224
getImages(wearImages, sdk, SysImageDownloader.SYSTEM_IMAGE_WEAR_TAG);
215225
}
216-
return !wearImages.isEmpty();
217-
}
218-
219-
220-
protected void refreshWearImages(final AndroidSDK sdk) throws IOException {
221-
wearImages = new ArrayList<String>();
222-
getImages(wearImages, sdk, SysImageDownloader.SYSTEM_IMAGE_WEAR_TAG);
223226
}
224227

225228

@@ -273,7 +276,7 @@ protected String getSdkId() throws IOException {
273276
if (Preferences.get("android.system.image.type") == null)
274277
Preferences.set("android.system.image.type", "x86"); // Prefer x86
275278

276-
if (this.name.contains("phone")) {
279+
if (type == PHONE) {
277280
for (String image : phoneImages) {
278281
if (image.contains(Preferences.get("android.system.image.type")))
279282
return image;
@@ -384,45 +387,25 @@ static public String getPort(boolean wear) {
384387

385388
static public boolean ensureProperAVD(final Frame window, final AndroidMode mode,
386389
final AndroidSDK sdk, boolean wear) {
387-
try {
388-
if (wear) {
389-
if (wearAVD.exists(sdk)) {
390-
return true;
391-
}
392-
if (wearAVD.badness()) {
393-
AndroidUtil.showMessage(AVD_LOAD_TITLE, AVD_LOAD_MESSAGE);
394-
return false;
395-
}
396-
if (!wearAVD.hasWearImages(sdk)) {
397-
boolean res = AndroidSDK.locateSysImage(window, mode, true);
398-
if (!res) {
399-
return false;
400-
} else {
401-
wearAVD.refreshWearImages(sdk);
402-
}
403-
}
404-
if (wearAVD.create(sdk)) {
405-
return true;
406-
}
407-
} else {
408-
if (mobileAVD.exists(sdk)) {
409-
return true;
410-
}
411-
if (mobileAVD.badness()) {
412-
AndroidUtil.showMessage(AVD_LOAD_TITLE, AVD_LOAD_MESSAGE);
390+
try {
391+
AVD avd = wear ? watchAVD : phoneAVD;
392+
if (avd.exists(sdk)) {
393+
return true;
394+
}
395+
if (avd.badness()) {
396+
AndroidUtil.showMessage(AVD_LOAD_TITLE, AVD_LOAD_MESSAGE);
397+
return false;
398+
}
399+
if (!avd.hasImages(sdk)) {
400+
boolean res = AndroidSDK.locateSysImage(window, mode, wear);
401+
if (!res) {
413402
return false;
403+
} else {
404+
avd.refreshImages(sdk);
414405
}
415-
if (!mobileAVD.hasImages(sdk)) {
416-
boolean res = AndroidSDK.locateSysImage(window, mode, false);
417-
if (!res) {
418-
return false;
419-
} else {
420-
mobileAVD.refreshImages(sdk);
421-
}
422-
}
423-
if (mobileAVD.create(sdk)) {
424-
return true;
425-
}
406+
}
407+
if (avd.create(sdk)) {
408+
return true;
426409
}
427410
} catch (final Exception e) {
428411
e.printStackTrace();

src/processing/mode/android/AndroidMode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public void handleRunEmulator(Sketch sketch, AndroidEditor editor,
298298
}
299299

300300
int comp = build.getAppComponent();
301-
Future<Device> emu = Devices.getInstance().getEmulator(sdk.getToolsFolder(), build.isWear(), build.usesOpenGL());
301+
Future<Device> emu = Devices.getInstance().getEmulator(sdk.getToolsFolder(), build.isWear());
302302
runner = new AndroidRunner(build, listener);
303303
runner.launch(emu, comp, true);
304304
}

src/processing/mode/android/Commander.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ private void execute() {
239239
if (task == RUN) {
240240
AndroidRunner runner = new AndroidRunner(build, this);
241241
runner.launch(runOnEmu ?
242-
Devices.getInstance().getEmulator(androidMode.getSDK().getToolsFolder(), build.isWear(), build.usesOpenGL()) :
242+
Devices.getInstance().getEmulator(androidMode.getSDK().getToolsFolder(), build.isWear()) :
243243
Devices.getInstance().getHardware(), build.getAppComponent(), runOnEmu);
244244
}
245245

0 commit comments

Comments
 (0)