Skip to content

Commit 53b4cfe

Browse files
committed
large code refactoring, regular, VR, and wallpaper apps work
1 parent 283191e commit 53b4cfe

26 files changed

+421
-1276
lines changed

core/src/processing/android/PFragment.java

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
Part of the Processing project - http://processing.org
55
6-
Copyright (c) 2016 The Processing Foundation
6+
Copyright (c) 2016-17 The Processing Foundation
77
88
This library is free software; you can redistribute it and/or
99
modify it under the terms of the GNU Lesser General Public
@@ -33,7 +33,6 @@
3333
import android.content.pm.ActivityInfo;
3434
import android.content.res.Configuration;
3535
import android.graphics.Point;
36-
import android.os.Build;
3736
import android.os.Bundle;
3837
import android.view.ContextMenu;
3938
import android.view.Display;
@@ -68,36 +67,22 @@ public PFragment(PApplet sketch) {
6867
public void initDimensions() {
6968
WindowManager wm = getActivity().getWindowManager();
7069
Display display = wm.getDefaultDisplay();
71-
metrics = new DisplayMetrics();
72-
display.getMetrics(metrics);
7370

74-
// display.getRealMetrics(metrics); // API 17 or higher
75-
// display.getRealSize(size);
71+
metrics = new DisplayMetrics();
72+
display.getRealMetrics(metrics);
7673

7774
size = new Point();
78-
if (Build.VERSION.SDK_INT >= 17) {
79-
display.getRealSize(size);
80-
} else if (Build.VERSION.SDK_INT >= 14) {
81-
// Use undocumented methods getRawWidth, getRawHeight
82-
try {
83-
size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display);
84-
size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display);
85-
} catch (Exception e) {
86-
display.getSize(size);
87-
}
88-
}
75+
display.getRealSize(size);
8976
}
9077

9178

9279
public int getDisplayWidth() {
9380
return size.x;
94-
// return metrics.widthPixels;
9581
}
9682

9783

9884
public int getDisplayHeight() {
9985
return size.y;
100-
// return metrics.heightPixels;
10186
}
10287

10388

core/src/processing/android/PWallpaper.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import android.view.WindowManager;
2929
import processing.core.PApplet;
3030
import android.util.DisplayMetrics;
31-
import android.os.Build;
3231
import android.view.Display;
3332
import android.graphics.Point;
3433
import android.graphics.Rect;
@@ -42,36 +41,22 @@ public class PWallpaper extends WallpaperService implements AppComponent {
4241
public void initDimensions() {
4342
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
4443
Display display = wm.getDefaultDisplay();
45-
metrics = new DisplayMetrics();
46-
display.getMetrics(metrics);
4744

48-
// display.getRealMetrics(metrics); // API 17 or higher
49-
// display.getRealSize(size);
45+
metrics = new DisplayMetrics();
46+
display.getRealMetrics(metrics);
5047

5148
size = new Point();
52-
if (Build.VERSION.SDK_INT >= 17) {
53-
display.getRealSize(size);
54-
} else if (Build.VERSION.SDK_INT >= 14) {
55-
// Use undocumented methods getRawWidth, getRawHeight
56-
try {
57-
size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display);
58-
size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display);
59-
} catch (Exception e) {
60-
display.getSize(size);
61-
}
62-
}
49+
display.getRealSize(size);
6350
}
6451

6552

6653
public int getDisplayWidth() {
6754
return size.x;
68-
// return metrics.widthPixels;
6955
}
7056

7157

7258
public int getDisplayHeight() {
7359
return size.y;
74-
// return metrics.heightPixels;
7560
}
7661

7762

core/src/processing/android/PWatchFaceCanvas.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import android.graphics.Canvas;
2828
import android.graphics.Point;
29-
import android.os.Build;
3029
import android.os.Bundle;
3130
import android.graphics.Rect;
3231
import android.support.wearable.complications.ComplicationData;
@@ -52,36 +51,22 @@ public class PWatchFaceCanvas extends CanvasWatchFaceService implements AppCompo
5251
public void initDimensions() {
5352
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
5453
Display display = wm.getDefaultDisplay();
55-
metrics = new DisplayMetrics();
56-
display.getMetrics(metrics);
5754

58-
// display.getRealMetrics(metrics); // API 17 or higher
59-
// display.getRealSize(size);
55+
metrics = new DisplayMetrics();
56+
display.getRealMetrics(metrics);
6057

6158
size = new Point();
62-
if (Build.VERSION.SDK_INT >= 17) {
63-
display.getRealSize(size);
64-
} else if (Build.VERSION.SDK_INT >= 14) {
65-
// Use undocumented methods getRawWidth, getRawHeight
66-
try {
67-
size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display);
68-
size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display);
69-
} catch (Exception e) {
70-
display.getSize(size);
71-
}
72-
}
59+
display.getRealSize(size);
7360
}
7461

7562

7663
public int getDisplayWidth() {
7764
return size.x;
78-
// return metrics.widthPixels;
7965
}
8066

8167

8268
public int getDisplayHeight() {
8369
return size.y;
84-
// return metrics.heightPixels;
8570
}
8671

8772

core/src/processing/android/PWatchFaceGLES.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
package processing.android;
2424

2525
import android.graphics.Point;
26-
import android.os.Build;
2726
import android.os.Bundle;
2827
import android.view.Display;
2928
import android.view.WindowInsets;
@@ -50,36 +49,22 @@ public class PWatchFaceGLES extends Gles2WatchFaceService implements AppComponen
5049
public void initDimensions() {
5150
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
5251
Display display = wm.getDefaultDisplay();
53-
metrics = new DisplayMetrics();
54-
display.getMetrics(metrics);
5552

56-
// display.getRealMetrics(metrics); // API 17 or higher
57-
// display.getRealSize(size);
53+
metrics = new DisplayMetrics();
54+
display.getRealMetrics(metrics);
5855

5956
size = new Point();
60-
if (Build.VERSION.SDK_INT >= 17) {
61-
display.getRealSize(size);
62-
} else if (Build.VERSION.SDK_INT >= 14) {
63-
// Use undocumented methods getRawWidth, getRawHeight
64-
try {
65-
size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display);
66-
size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display);
67-
} catch (Exception e) {
68-
display.getSize(size);
69-
}
70-
}
57+
display.getRealSize(size);
7158
}
7259

7360

7461
public int getDisplayWidth() {
7562
return size.x;
76-
// return metrics.widthPixels;
7763
}
7864

7965

8066
public int getDisplayHeight() {
8167
return size.y;
82-
// return metrics.heightPixels;
8368
}
8469

8570

src/processing/mode/android/AVD.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ public class AVD {
8888
/** Default virtual device used by Processing. */
8989
static public final AVD mobileAVD =
9090
new AVD("Processing-0" + Base.getRevision(),
91-
AndroidBuild.target_platform, SysImageDownloader.SYSTEM_IMAGE_TAG, DEFAULT_SKIN);
91+
AndroidBuild.TARGET_PLATFORM, SysImageDownloader.SYSTEM_IMAGE_TAG, DEFAULT_SKIN);
9292
// "Google Inc.:Google APIs:" + AndroidBuild.sdkVersion);
9393

9494
/** Default virtual wear device used by Processing. */
9595
static public final AVD wearAVD =
9696
new AVD("Processing-Wear-0" + Base.getRevision(),
97-
AndroidBuild.target_platform, SysImageDownloader.SYSTEM_IMAGE_WEAR_TAG, WEAR_SKIN);
97+
AndroidBuild.TARGET_PLATFORM, SysImageDownloader.SYSTEM_IMAGE_WEAR_TAG, WEAR_SKIN);
9898

9999
public AVD(final String name, final String target,
100100
final String tag, final String skin) {
@@ -243,7 +243,7 @@ protected void initTargets(final AndroidSDK sdk) throws IOException {
243243
protected boolean noTargets(final AndroidSDK sdk) throws IOException {
244244
initTargets(sdk);
245245
// return preferredAbi.size() == 0;
246-
return preferredAbi.get(AndroidBuild.target_sdk) == null;
246+
return preferredAbi.get(AndroidBuild.TARGET_SDK) == null;
247247
}
248248

249249

@@ -257,7 +257,7 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
257257
"-t", target,
258258
"-c", DEFAULT_SDCARD_SIZE,
259259
"-s", skin,
260-
"--abi", preferredAbi.get(AndroidBuild.target_sdk)
260+
"--abi", preferredAbi.get(AndroidBuild.TARGET_SDK)
261261
};
262262

263263
// sdk/tools/android create avd -n "Wear-Processing-0254" -t android-23 -c 64M -s AndroidWearSquare --abi android-wear/x86
@@ -279,7 +279,7 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
279279
} else {
280280
// Just generally not working
281281
AndroidUtil.showMessage(AVD_CREATE_TITLE,
282-
String.format(AVD_CREATE_MESSAGE, AndroidBuild.target_sdk));
282+
String.format(AVD_CREATE_MESSAGE, AndroidBuild.TARGET_SDK));
283283
System.out.println(createAvdResult);
284284
}
285285
//System.err.println(createAvdResult);
@@ -339,7 +339,7 @@ static public boolean ensureProperAVD(final Frame window, final AndroidMode mode
339339
} catch (final Exception e) {
340340
e.printStackTrace();
341341
AndroidUtil.showMessage(AVD_CREATE_TITLE,
342-
String.format(AVD_CREATE_MESSAGE, AndroidBuild.target_sdk));
342+
String.format(AVD_CREATE_MESSAGE, AndroidBuild.TARGET_SDK));
343343
}
344344
return false;
345345
}

0 commit comments

Comments
 (0)