Skip to content

Commit ad004ee

Browse files
committed
added ServiceEngine interface
It encapsulates getters specific to wallpapers and watch faces
1 parent d9e790a commit ad004ee

File tree

6 files changed

+297
-32
lines changed

6 files changed

+297
-32
lines changed

core/src/processing/android/AppComponent.java

Lines changed: 1 addition & 1 deletion
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

core/src/processing/android/PWallpaper.java

Lines changed: 73 additions & 5 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,9 +33,9 @@
3333
import android.graphics.Point;
3434

3535
public class PWallpaper extends WallpaperService implements AppComponent {
36-
protected Point size;
36+
private Point size;
3737
private DisplayMetrics metrics;
38-
protected WallpaperEngine engine;
38+
private WallpaperEngine engine;
3939

4040

4141
public void initDimensions() {
@@ -140,8 +140,9 @@ public void onDestroy() {
140140
}
141141

142142

143-
public class WallpaperEngine extends Engine {
144-
protected PApplet sketch;
143+
public class WallpaperEngine extends Engine implements ServiceEngine {
144+
private PApplet sketch;
145+
private float xOffset, xOffsetStep;
145146

146147

147148
@Override
@@ -210,6 +211,9 @@ public void onOffsetsChanged(float xOffset, float yOffset,
210211
int xPixelOffset, int yPixelOffset) {
211212

212213
if (sketch != null) {
214+
this.xOffset = xOffset;
215+
this.xOffsetStep = xOffsetStep;
216+
213217
sketch.homeScreenOffset = xOffset;
214218
if (0 < xOffsetStep) {
215219
sketch.homeScreenCount = (int)(1 + 1 / xOffsetStep);
@@ -238,5 +242,69 @@ public void onDestroy() {
238242
sketch.onDestroy();
239243
}
240244
}
245+
246+
247+
@Override
248+
public float homeScreenOffset() {
249+
return xOffset;
250+
}
251+
252+
253+
@Override
254+
public int homeScreenCount() {
255+
if (0 < xOffsetStep) {
256+
return (int)(1 + 1 / xOffsetStep);
257+
} else {
258+
return 1;
259+
}
260+
}
261+
262+
263+
@Override
264+
public boolean ambientMode() {
265+
return false;
266+
}
267+
268+
269+
@Override
270+
public boolean isRound() {
271+
return false;
272+
}
273+
274+
275+
@Override
276+
public int insetLeft() {
277+
return 0;
278+
}
279+
280+
281+
@Override
282+
public int insetRight() {
283+
return 0;
284+
}
285+
286+
287+
@Override
288+
public int insetTop() {
289+
return 0;
290+
}
291+
292+
293+
@Override
294+
public int insetBottom() {
295+
return 0;
296+
}
297+
298+
299+
@Override
300+
public boolean lowBitAmbient() {
301+
return false;
302+
}
303+
304+
305+
@Override
306+
public boolean burnInProtection() {
307+
return false;
308+
}
241309
}
242310
}

core/src/processing/android/PWatchFaceCanvas.java

Lines changed: 78 additions & 4 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
@@ -44,9 +44,9 @@
4444
import processing.event.MouseEvent;
4545

4646
public class PWatchFaceCanvas extends CanvasWatchFaceService implements AppComponent {
47-
protected Point size;
47+
private Point size;
4848
private DisplayMetrics metrics;
49-
protected CanvasEngine engine;
49+
private CanvasEngine engine;
5050

5151

5252
public void initDimensions() {
@@ -154,9 +154,16 @@ public void onDestroy() {
154154
}
155155

156156

157-
private class CanvasEngine extends CanvasWatchFaceService.Engine {
157+
private class CanvasEngine extends CanvasWatchFaceService.Engine implements ServiceEngine {
158158
private PApplet sketch;
159159
private Method compUpdatedMethod;
160+
private boolean isRound = false;
161+
private int insetLeft = 0;
162+
private int insetRight = 0;
163+
private int insetTop = 0;
164+
private int insetBottom = 0;
165+
private boolean lowBitAmbient = false;
166+
private boolean burnInProtection = false;
160167

161168
@SuppressWarnings("deprecation")
162169
@Override
@@ -213,6 +220,8 @@ public void onAmbientModeChanged(boolean inAmbientMode) {
213220
@Override
214221
public void onPropertiesChanged(Bundle properties) {
215222
super.onPropertiesChanged(properties);
223+
lowBitAmbient = properties.getBoolean(PROPERTY_LOW_BIT_AMBIENT, false);
224+
burnInProtection = properties.getBoolean(PROPERTY_BURN_IN_PROTECTION, false);
216225
if (sketch != null) {
217226
sketch.lowBitAmbient = properties.getBoolean(PROPERTY_LOW_BIT_AMBIENT, false);
218227
sketch.burnInProtection = properties.getBoolean(PROPERTY_BURN_IN_PROTECTION, false);
@@ -223,6 +232,11 @@ public void onPropertiesChanged(Bundle properties) {
223232
@Override
224233
public void onApplyWindowInsets(WindowInsets insets) {
225234
super.onApplyWindowInsets(insets);
235+
isRound = insets.isRound();
236+
insetLeft = insets.getSystemWindowInsetLeft();
237+
insetRight = insets.getSystemWindowInsetRight();
238+
insetTop = insets.getSystemWindowInsetTop();
239+
insetBottom = insets.getSystemWindowInsetBottom();
226240
if (sketch != null) {
227241
sketch.isRound = insets.isRound();
228242
sketch.insetLeft = insets.getSystemWindowInsetLeft();
@@ -362,5 +376,65 @@ public void onDestroy() {
362376
super.onDestroy();
363377
if (sketch != null) sketch.onDestroy();
364378
}
379+
380+
381+
@Override
382+
public float homeScreenOffset() {
383+
return 0;
384+
}
385+
386+
387+
@Override
388+
public int homeScreenCount() {
389+
return 0;
390+
}
391+
392+
393+
@Override
394+
public boolean ambientMode() {
395+
return isInAmbientMode();
396+
}
397+
398+
399+
@Override
400+
public boolean isRound() {
401+
return isRound;
402+
}
403+
404+
405+
@Override
406+
public int insetLeft() {
407+
return insetLeft;
408+
}
409+
410+
411+
@Override
412+
public int insetRight() {
413+
return insetRight;
414+
}
415+
416+
417+
@Override
418+
public int insetTop() {
419+
return insetTop;
420+
}
421+
422+
423+
@Override
424+
public int insetBottom() {
425+
return insetBottom;
426+
}
427+
428+
429+
@Override
430+
public boolean lowBitAmbient() {
431+
return lowBitAmbient;
432+
}
433+
434+
435+
@Override
436+
public boolean burnInProtection() {
437+
return burnInProtection;
438+
}
365439
}
366440
}

0 commit comments

Comments
 (0)