26
26
import processing .app .Preferences ;
27
27
import processing .app .exec .LineProcessor ;
28
28
import processing .app .exec .StreamPump ;
29
+ import processing .app .ui .Toolkit ;
29
30
import processing .core .PApplet ;
30
31
31
32
import java .awt .Frame ;
35
36
36
37
37
38
public class AVD {
39
+ final static private int PHONE = 0 ;
40
+ final static private int WEAR = 1 ;
41
+
38
42
static private final String AVD_CREATE_TITLE =
39
43
"Could not create the AVD" ;
40
44
@@ -79,10 +83,10 @@ public class AVD {
79
83
80
84
protected String device ;
81
85
protected String skin ;
86
+ protected int type ;
82
87
83
88
static ArrayList <String > avdList ;
84
89
static ArrayList <String > badList ;
85
- // static ArrayList<String> skinList;
86
90
87
91
/** "system-images;android-25;google_apis;x86" */
88
92
static ArrayList <String > wearImages ;
@@ -91,20 +95,21 @@ public class AVD {
91
95
private static Process process ;
92
96
93
97
/** Default virtual device used by Processing. */
94
- static public final AVD mobileAVD =
98
+ static public final AVD phoneAVD =
95
99
new AVD ("processing-phone" ,
96
- DEVICE_DEFINITION , DEVICE_SKIN );
100
+ DEVICE_DEFINITION , DEVICE_SKIN , PHONE );
97
101
98
102
/** Default virtual wear device used by Processing. */
99
- static public final AVD wearAVD =
103
+ static public final AVD watchAVD =
100
104
new AVD ("processing-watch" ,
101
- DEVICE_WEAR_DEFINITION , DEVICE_WEAR_SKIN );
105
+ DEVICE_WEAR_DEFINITION , DEVICE_WEAR_SKIN , WEAR );
102
106
103
107
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 ) {
105
109
this .name = name ;
106
110
this .device = device ;
107
111
this .skin = skin ;
112
+ this .type = type ;
108
113
}
109
114
110
115
@@ -194,32 +199,30 @@ protected boolean badness() {
194
199
195
200
196
201
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 ();
200
214
}
201
- return !phoneImages .isEmpty ();
202
215
}
203
216
204
217
205
218
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 {
213
223
wearImages = new ArrayList <String >();
214
224
getImages (wearImages , sdk , SysImageDownloader .SYSTEM_IMAGE_WEAR_TAG );
215
225
}
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 );
223
226
}
224
227
225
228
@@ -273,7 +276,7 @@ protected String getSdkId() throws IOException {
273
276
if (Preferences .get ("android.system.image.type" ) == null )
274
277
Preferences .set ("android.system.image.type" , "x86" ); // Prefer x86
275
278
276
- if (this . name . contains ( "phone" ) ) {
279
+ if (type == PHONE ) {
277
280
for (String image : phoneImages ) {
278
281
if (image .contains (Preferences .get ("android.system.image.type" )))
279
282
return image ;
@@ -384,45 +387,25 @@ static public String getPort(boolean wear) {
384
387
385
388
static public boolean ensureProperAVD (final Frame window , final AndroidMode mode ,
386
389
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 ) {
413
402
return false ;
403
+ } else {
404
+ avd .refreshImages (sdk );
414
405
}
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 ;
426
409
}
427
410
} catch (final Exception e ) {
428
411
e .printStackTrace ();
0 commit comments