Skip to content

Commit ff8bcef

Browse files
committed
some refactoring, moved getSurfaceHolder() to PSurface
1 parent 6d339b6 commit ff8bcef

File tree

13 files changed

+79
-92
lines changed

13 files changed

+79
-92
lines changed

core/src/processing/a2d/PGraphicsAndroid2D.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public void endDraw() {
232232
// }
233233

234234
if (primaryGraphics) {
235-
SurfaceHolder holder = parent.getSurfaceHolder();
235+
SurfaceHolder holder = parent.surface.getSurfaceHolder();
236236
if (holder != null) {
237237
Canvas screen = null;
238238
try {
@@ -243,7 +243,7 @@ public void endDraw() {
243243
} finally {
244244
if (screen != null) {
245245
try {
246-
parent.getSurfaceHolder().unlockCanvasAndPost(screen);
246+
holder.unlockCanvasAndPost(screen);
247247
} catch (IllegalStateException ex) {
248248
}
249249
}

core/src/processing/a2d/PSurfaceAndroid2D.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ public PSurfaceAndroid2D(PGraphics graphics, AppComponent component, SurfaceHold
4646
if (component.getKind() == AppComponent.FRAGMENT) {
4747
PFragment frag = (PFragment)component;
4848
activity = frag.getActivity();
49-
surface = new SketchSurfaceView(activity, null);
49+
surfaceView = new SketchSurfaceView(activity, null);
5050
} else if (component.getKind() == AppComponent.WALLPAPER) {
5151
wallpaper = (WallpaperService)component;
52-
surface = new SketchSurfaceView(wallpaper, holder);
52+
surfaceView = new SketchSurfaceView(wallpaper, holder);
5353
} else if (component.getKind() == AppComponent.WATCHFACE) {
5454
watchface = (CanvasWatchFaceService)component;
55-
surface = null;
55+
surfaceView = null;
5656
}
5757
}
5858

core/src/processing/android/PFragment.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
110110
Bundle savedInstanceState) {
111111
if (sketch != null) {
112112
sketch.initSurface(inflater, container, savedInstanceState, this, null);
113-
sketch.startSurface();
114-
return sketch.getRootView();
113+
return sketch.surface.getRootView();
115114
} else {
116115
return null;
117116
}

core/src/processing/android/PWallpaper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ public void onCreate(SurfaceHolder surfaceHolder) {
149149
super.onCreate(surfaceHolder);
150150
sketch = createSketch();
151151
sketch.initSurface(PWallpaper.this, getSurfaceHolder());
152-
sketch.startSurface();
153152
sketch.preview = isPreview();
154153
if (isPreview()) requestPermissions();
155154
setTouchEventsEnabled(true);

core/src/processing/android/PWatchFaceCanvas.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ public void onCreate(SurfaceHolder surfaceHolder) {
172172
sketch = createSketch();
173173
PGraphicsAndroid2D.useBitmap = false;
174174
sketch.initSurface(PWatchFaceCanvas.this, null);
175-
sketch.startSurface();
176175
initComplications();
177176
requestPermissions();
178177
}

core/src/processing/android/PWatchFaceGLES.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ public void onCreate(SurfaceHolder surfaceHolder) {
170170
.build());
171171
sketch = createSketch();
172172
sketch.initSurface(PWatchFaceGLES.this, null);
173-
sketch.startSurface();
174173
initComplications();
175174
requestPermissions();
176175
}

core/src/processing/core/PApplet.java

Lines changed: 11 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -263,49 +263,20 @@ public class PApplet extends Object implements PConstants {
263263
*/
264264
public boolean focused = false;
265265

266-
/**
267-
* Use in watch faces to check if the device in in ambient mode or interactive mode.
268-
*/
266+
///////////////////////////////////////////////////////////////
267+
// Wallpaper and watchface variables: these will go away soon...
269268
public boolean ambientMode = false;
270-
271-
/**
272-
* Indicates whether the watch face is round or not.
273-
*/
274269
public boolean isRound = false;
275-
276-
/**
277-
* Watch face insets
278-
*/
279-
public int insetLeft, insetRight = 0;
280-
public int insetTop, insetBottom = 0;
281-
282-
/**
283-
* Use in watch faces to store information abou the device screen
284-
* https://developer.android.com/training/wearables/watch-faces/drawing.html#Screen
285-
*/
270+
public int insetLeft = 0;
271+
public int insetRight = 0;
272+
public int insetTop = 0;
273+
public int insetBottom = 0;
286274
public boolean lowBitAmbient = false;
287275
public boolean burnInProtection = false;
288-
289-
/**
290-
* Offset for wallpapers, when user swipes across home screens.
291-
*/
276+
public boolean preview = false;
292277
public float homeScreenOffset = 0;
293-
// public float offsetY = 0;
294-
295278
public int homeScreenCount = 1;
296-
297-
/**
298-
* Indicates if the wallpaper is in preview mode.
299-
*/
300-
public boolean preview = false;
301-
302-
/**
303-
* true if the applet is online.
304-
* <P>
305-
* This can be used to test how the applet should behave
306-
* since online situations are different (no file writing, etc).
307-
*/
308-
// public boolean online = false;
279+
///////////////////////////////////////////////////////////////
309280

310281
/**
311282
* Time in milliseconds when the applet was started.
@@ -480,6 +451,7 @@ public void initSurface(AppComponent component, SurfaceHolder holder) {
480451
initSurface(null, null, null, component, holder);
481452
}
482453

454+
483455
public void initSurface(LayoutInflater inflater, ViewGroup container,
484456
Bundle savedInstanceState,
485457
AppComponent component, SurfaceHolder holder) {
@@ -554,18 +526,12 @@ public void onGlobalLayout() {
554526

555527
sketchPath = surface.getFilesDir().getAbsolutePath();
556528

557-
if (DEBUG) println("Done with init surface");
558-
}
559-
560-
561-
public void startSurface() {
562529
surface.startThread();
563-
}
564530

565-
public View getRootView() {
566-
return surface.getRootView();
531+
if (DEBUG) println("Done with init surface");
567532
}
568533

534+
569535
private void setFullScreenVisibility() {
570536
if (fullScreen) {
571537
int visibility;
@@ -689,30 +655,6 @@ public void settings() {
689655
}
690656

691657

692-
//////////////////////////////////////////////////////////////
693-
694-
// ANDROID SURFACE VIEW
695-
696-
697-
// TODO this is only used by A2D, when finishing up a draw. but if the
698-
// surfaceview has changed, then it might belong to an a3d surfaceview. hrm.
699-
public SurfaceHolder getSurfaceHolder() {
700-
SurfaceView view = surface.getSurfaceView();
701-
if (view == null) {
702-
// Watch faces don't have a surface view associated to them.
703-
return null;
704-
} else {
705-
return view.getHolder();
706-
}
707-
}
708-
709-
710-
/** Not official API, not guaranteed to work in the future. */
711-
public SurfaceView getSurfaceView() {
712-
return surface.getSurfaceView();
713-
}
714-
715-
716658
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
717659

718660

core/src/processing/core/PSurface.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import android.graphics.Rect;
3333
import android.os.Bundle;
3434
import android.view.LayoutInflater;
35+
import android.view.SurfaceHolder;
3536
import android.view.SurfaceView;
3637
import android.view.View;
3738
import android.view.ViewGroup;
@@ -57,6 +58,7 @@ public interface PSurface {
5758
public Rect getVisibleFrame();
5859

5960
public SurfaceView getSurfaceView();
61+
public SurfaceHolder getSurfaceHolder();
6062

6163
public View getRootView();
6264
public void setRootView(View view);

0 commit comments

Comments
 (0)