Skip to content

Commit 55cfecd

Browse files
committed
create wear emulator
1 parent 5b19ffa commit 55cfecd

File tree

6 files changed

+82
-44
lines changed

6 files changed

+82
-44
lines changed

src/processing/mode/android/AVD.java

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ public class AVD {
5959
static private final String AVD_TARGET_SECONDARY =
6060
"Please re-read the installation instructions for Processing<br>" +
6161
"found at http://android.processing.org and try again.";
62-
63-
static final String DEFAULT_SKIN = "WVGA800";
62+
6463
static final String DEFAULT_SDCARD_SIZE = "64M";
65-
64+
65+
static final String DEFAULT_SKIN = "WVGA800";
66+
static final String WEAR_SKIN = "AndroidWearSquare";
67+
6668
/** Name of this avd. */
6769
protected String name;
6870

@@ -74,30 +76,37 @@ public class AVD {
7476
// static ArrayList<String> skinList;
7577

7678
private Map<String, String> preferredAbi = new HashMap<>(30);
77-
private static List<String> abiList = new ArrayList<>();
79+
private List<String> abiList = new ArrayList<>();
80+
private String skin;
7881

7982
/** Default virtual device used by Processing. */
8083
static public final AVD defaultAVD =
8184
new AVD("Processing-0" + Base.getRevision(),
82-
AndroidBuild.target_platform);
85+
AndroidBuild.target_platform, "default", DEFAULT_SKIN);
8386
// "Google Inc.:Google APIs:" + AndroidBuild.sdkVersion);
8487

85-
public AVD(final String name, final String target) {
88+
/** Default virtual wear device used by Processing. */
89+
static public final AVD wearAVD =
90+
new AVD("Wear-Processing-0" + Base.getRevision(),
91+
AndroidBuild.target_platform, "android-wear", WEAR_SKIN);
92+
93+
public AVD(final String name, final String target,
94+
final String tag, final String skin) {
8695
this.name = name;
8796
this.target = target;
88-
89-
initializeAbiList();
97+
this.skin = skin;
98+
initializeAbiList(tag);
9099
}
91100

92-
private void initializeAbiList() {
101+
private void initializeAbiList(String tag) {
93102
if (abiList.size() == 0) {
94103
// The order in this list determines the preference of one abi over the other
95-
abiList.add("default/x86");
96-
abiList.add("google_apis/x86");
97-
abiList.add("default/x86_64");
98-
abiList.add("google_apis/x86_64");
99-
abiList.add("default/armeabi-v7a");
100-
abiList.add("google_apis/armeabi-v7a");
104+
abiList.add(tag + "/x86");
105+
abiList.add(tag + "/x86_64");
106+
abiList.add(tag + "/armeabi-v7a");
107+
// abiList.add("google_apis/x86");
108+
// abiList.add("google_apis/x86_64");
109+
// abiList.add("google_apis/armeabi-v7a");
101110
}
102111
}
103112

@@ -241,10 +250,13 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
241250
"-n", name,
242251
"-t", target,
243252
"-c", DEFAULT_SDCARD_SIZE,
244-
"-s", DEFAULT_SKIN,
253+
"-s", skin,
245254
"--abi", preferredAbi.get(AndroidBuild.target_sdk)
246255
};
247256

257+
//sdk/tools/android create avd -n "Wear-Processing-0254" -t android-23 -c 64M -s AndroidWearSquare --abi android-wear/x86
258+
259+
248260
// Set the list to null so that exists() will check again
249261
avdList = null;
250262

@@ -273,22 +285,32 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
273285

274286
static public boolean ensureProperAVD(final AndroidSDK sdk) {
275287
try {
276-
if (defaultAVD.exists(sdk)) {
277-
// System.out.println("the avd exists");
278-
return true;
279-
}
280-
// if (badList.contains(defaultAVD)) {
281-
if (defaultAVD.badness()) {
282-
// Base.showWarning("Android Error", AVD_CANNOT_LOAD, null);
283-
Messages.showWarningTiered("Android Error", AVD_LOAD_PRIMARY, AVD_LOAD_SECONDARY, null);
284-
return false;
285-
}
286-
if (defaultAVD.create(sdk)) {
287-
// System.out.println("the avd was created");
288-
return true;
288+
289+
if (AndroidBuild.appComponent == AndroidBuild.WATCHFACE) {
290+
if (wearAVD.exists(sdk)) {
291+
return true;
292+
}
293+
if (wearAVD.badness()) {
294+
Messages.showWarningTiered("Android Error", AVD_LOAD_PRIMARY, AVD_LOAD_SECONDARY, null);
295+
return false;
296+
}
297+
if (wearAVD.create(sdk)) {
298+
return true;
299+
}
300+
} else {
301+
if (defaultAVD.exists(sdk)) {
302+
return true;
303+
}
304+
if (defaultAVD.badness()) {
305+
Messages.showWarningTiered("Android Error", AVD_LOAD_PRIMARY, AVD_LOAD_SECONDARY, null);
306+
return false;
307+
}
308+
if (defaultAVD.create(sdk)) {
309+
return true;
310+
}
289311
}
312+
290313
} catch (final Exception e) {
291-
// Base.showWarning("Android Error", AVD_CREATE_ERROR, e);
292314
Messages.showWarningTiered("Android Error", AVD_CREATE_PRIMARY,
293315
String.format(AVD_CREATE_SECONDARY,
294316
AndroidBuild.target_sdk), null);

src/processing/mode/android/AndroidBuild.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class AndroidBuild extends JavaBuild {
7272
static public int appComponent = FRAGMENT;
7373
static boolean forceNewManifest = false;
7474

75+
private String renderer = "";
76+
7577
private final AndroidSDK sdk;
7678
private final File coreZipFile;
7779

@@ -200,7 +202,8 @@ public File createProject() throws IOException, SketchException {
200202

201203
// TODO: it would be great if we can just get the renderer from the SurfaceInfo
202204
// object returned by initSketchSize()
203-
writeMainClass(srcFolder, preproc.getRenderer(sketch.getMainProgram()));
205+
renderer = preproc.getRenderer(sketch.getMainProgram());
206+
writeMainClass(srcFolder, renderer);
204207

205208
final File libsFolder = mkdirs(tmpFolder, "libs");
206209
final File assetsFolder = mkdirs(tmpFolder, "assets");
@@ -406,6 +409,11 @@ private File createTempBuildFolder(final Sketch sketch) throws IOException {
406409
}
407410
return tmp;
408411
}
412+
413+
414+
protected boolean usesGPU() {
415+
return renderer != null && (renderer.equals("P2D") || renderer.equals("P3D"));
416+
}
409417

410418

411419
protected File createExportFolder() throws IOException {
@@ -1150,7 +1158,7 @@ private void writeMainClass(final File srcDirectory, String renderer) {
11501158
} else if (appComponent == WALLPAPER) {
11511159
writeWallpaperService(srcDirectory);
11521160
} else if (appComponent == WATCHFACE) {
1153-
if (renderer != null && (renderer.equals("P2D") || renderer.equals("P3D"))) {
1161+
if (usesGPU()) {
11541162
writeWatchFaceGLESService(srcDirectory);
11551163
} else {
11561164
writeWatchFaceCanvasService(srcDirectory);

src/processing/mode/android/AndroidMode.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
import java.io.BufferedInputStream;
4040
import java.io.BufferedOutputStream;
4141
import java.io.File;
42-
//import java.nio.file.Path;
43-
//import java.nio.file.Paths;
4442
import java.io.FileOutputStream;
4543
import java.io.IOException;
4644
import java.text.SimpleDateFormat;
@@ -265,7 +263,7 @@ public void handleRunEmulator(Sketch sketch, RunnerListener listener) throws Ske
265263

266264
listener.statusNotice("Building Android project...");
267265
build.build("debug");
268-
266+
269267
boolean avd = AVD.ensureProperAVD(sdk);
270268
if (!avd) {
271269
SketchException se =
@@ -276,7 +274,7 @@ public void handleRunEmulator(Sketch sketch, RunnerListener listener) throws Ske
276274

277275
listener.statusNotice("Running sketch on emulator...");
278276
runner = new AndroidRunner(build, listener);
279-
runner.launch(Devices.getInstance().getEmulator());
277+
runner.launch(Devices.getInstance().getEmulator(build.usesGPU()));
280278
}
281279

282280

src/processing/mode/android/Commander.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private void execute() {
219219
if (task == RUN) {
220220
AndroidRunner runner = new AndroidRunner(build, this);
221221
runner.launch(runArg_EMULATOR.equals(device) ?
222-
Devices.getInstance().getEmulator() :
222+
Devices.getInstance().getEmulator(build.usesGPU()) :
223223
Devices.getInstance().getHardware());
224224
}
225225

src/processing/mode/android/Devices.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ public void run() {
111111
}
112112

113113

114-
public Future<Device> getEmulator() {
114+
public Future<Device> getEmulator(final boolean gpu) {
115115
final Callable<Device> androidFinder = new Callable<Device>() {
116116
public Device call() throws Exception {
117-
return blockingGetEmulator();
117+
return blockingGetEmulator(gpu);
118118
}
119119
};
120120
final FutureTask<Device> task =
@@ -124,7 +124,7 @@ public Device call() throws Exception {
124124
}
125125

126126

127-
private final Device blockingGetEmulator() {
127+
private final Device blockingGetEmulator(final boolean gpu) {
128128
// System.out.println("going looking for emulator");
129129
Device emu = find(true);
130130
if (emu != null) {
@@ -138,7 +138,7 @@ private final Device blockingGetEmulator() {
138138
if (emuController.getState() == State.NOT_RUNNING) {
139139
try {
140140
// System.out.println("not running, gonna launch");
141-
emuController.launch(); // this blocks until emulator boots
141+
emuController.launch(gpu); // this blocks until emulator boots
142142
// System.out.println("not just gonna, we've done the launch");
143143
} catch (final IOException e) {
144144
System.err.println("Problem while launching emulator.");

src/processing/mode/android/EmulatorController.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private void setState(final State state) {
5757
* Blocks until emulator is running, or some catastrophe happens.
5858
* @throws IOException
5959
*/
60-
synchronized public void launch() throws IOException {
60+
synchronized public void launch(boolean gpu) throws IOException {
6161
if (state != State.NOT_RUNNING) {
6262
String illegal = "You can't launch an emulator whose state is " + state;
6363
throw new IllegalStateException(illegal);
@@ -70,14 +70,24 @@ synchronized public void launch() throws IOException {
7070
}
7171

7272
// See http://developer.android.com/guide/developing/tools/emulator.html
73+
String avdName;
74+
if (AndroidBuild.appComponent == AndroidBuild.WATCHFACE) {
75+
avdName = AVD.wearAVD.name;
76+
} else {
77+
avdName = AVD.defaultAVD.name;
78+
}
79+
80+
String gpuFlag = gpu ? "on" : "off";
7381
final String[] cmd = new String[] {
7482
"emulator",
75-
"-avd", AVD.defaultAVD.name,
83+
"-avd", avdName,
7684
"-port", portString,
7785
// "-no-boot-anim", // does this do anything?
7886
// http://code.google.com/p/processing/issues/detail?id=1059
79-
// "-gpu", "on" // enable OpenGL
87+
"-gpu", gpuFlag // enable OpenGL
8088
};
89+
90+
8191
//System.err.println("EmulatorController: Launching emulator");
8292
if (Base.DEBUG) {
8393
System.out.println(processing.core.PApplet.join(cmd, " "));

0 commit comments

Comments
 (0)