Skip to content

Commit d66d4e6

Browse files
committed
implementing new wallpaper/wear API, addressing #313
1 parent 8a6933f commit d66d4e6

File tree

5 files changed

+77
-161
lines changed

5 files changed

+77
-161
lines changed

core/src/processing/android/PWallpaper.java

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import android.os.Build;
3232
import android.view.Display;
3333
import android.graphics.Point;
34+
import android.graphics.Rect;
3435

3536
public class PWallpaper extends WallpaperService implements AppComponent {
3637
private Point size;
@@ -286,61 +287,21 @@ public int getYPixelOffset() {
286287
}
287288

288289

289-
@Override
290-
public int getHomeScreenCount() {
291-
if (0 < xOffsetStep) {
292-
return (int)(1 + 1 / xOffsetStep);
293-
} else {
294-
return 1;
295-
}
296-
}
297-
298-
299290
@Override
300291
public boolean isInAmbientMode() {
301292
return false;
302293
}
303294

304295

305-
@Override
306-
public boolean isInInteractiveMode() {
307-
return false;
308-
}
309-
310-
311296
@Override
312297
public boolean isRound() {
313298
return false;
314299
}
315300

316301

317302
@Override
318-
public boolean isSquare() {
319-
return false;
320-
}
321-
322-
323-
@Override
324-
public int getInsetLeft() {
325-
return 0;
326-
}
327-
328-
329-
@Override
330-
public int getInsetRight() {
331-
return 0;
332-
}
333-
334-
335-
@Override
336-
public int getInsetTop() {
337-
return 0;
338-
}
339-
340-
341-
@Override
342-
public int getInsetBottom() {
343-
return 0;
303+
public Rect getInsets() {
304+
return null;
344305
}
345306

346307

core/src/processing/android/PWatchFaceCanvas.java

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,7 @@ private class CanvasEngine extends CanvasWatchFaceService.Engine implements Serv
158158
private PApplet sketch;
159159
private Method compUpdatedMethod;
160160
private boolean isRound = false;
161-
private int insetLeft = 0;
162-
private int insetRight = 0;
163-
private int insetTop = 0;
164-
private int insetBottom = 0;
161+
private Rect insets = new Rect();
165162
private boolean lowBitAmbient = false;
166163
private boolean burnInProtection = false;
167164

@@ -233,10 +230,10 @@ public void onPropertiesChanged(Bundle properties) {
233230
public void onApplyWindowInsets(WindowInsets insets) {
234231
super.onApplyWindowInsets(insets);
235232
isRound = insets.isRound();
236-
insetLeft = insets.getSystemWindowInsetLeft();
237-
insetRight = insets.getSystemWindowInsetRight();
238-
insetTop = insets.getSystemWindowInsetTop();
239-
insetBottom = insets.getSystemWindowInsetBottom();
233+
this.insets.set(insets.getSystemWindowInsetLeft(),
234+
insets.getSystemWindowInsetTop(),
235+
insets.getSystemWindowInsetRight(),
236+
insets.getSystemWindowInsetBottom());
240237
if (sketch != null) {
241238
sketch.isRound = insets.isRound();
242239
sketch.insetLeft = insets.getSystemWindowInsetLeft();
@@ -414,51 +411,15 @@ public int getYPixelOffset() {
414411
}
415412

416413

417-
@Override
418-
public int getHomeScreenCount() {
419-
return 0;
420-
}
421-
422-
423-
@Override
424-
public boolean isInInteractiveMode() {
425-
return !isInAmbientMode();
426-
}
427-
428-
429414
@Override
430415
public boolean isRound() {
431416
return isRound;
432417
}
433418

434419

435420
@Override
436-
public boolean isSquare() {
437-
return !isRound;
438-
}
439-
440-
441-
@Override
442-
public int getInsetLeft() {
443-
return insetLeft;
444-
}
445-
446-
447-
@Override
448-
public int getInsetRight() {
449-
return insetRight;
450-
}
451-
452-
453-
@Override
454-
public int getInsetTop() {
455-
return insetTop;
456-
}
457-
458-
459-
@Override
460-
public int getInsetBottom() {
461-
return insetBottom;
421+
public Rect getInsets() {
422+
return insets;
462423
}
463424

464425

core/src/processing/android/PWatchFaceGLES.java

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,7 @@ private class GLES2Engine extends Gles2WatchFaceService.Engine implements
157157
private PApplet sketch;
158158
private Method compUpdatedMethod;
159159
private boolean isRound = false;
160-
private int insetLeft = 0;
161-
private int insetRight = 0;
162-
private int insetTop = 0;
163-
private int insetBottom = 0;
160+
private Rect insets = new Rect();
164161
private boolean lowBitAmbient = false;
165162
private boolean burnInProtection = false;
166163

@@ -237,6 +234,8 @@ public void onAmbientModeChanged(boolean inAmbientMode) {
237234
@Override
238235
public void onPropertiesChanged(Bundle properties) {
239236
super.onPropertiesChanged(properties);
237+
lowBitAmbient = properties.getBoolean(PROPERTY_LOW_BIT_AMBIENT, false);
238+
burnInProtection = properties.getBoolean(PROPERTY_BURN_IN_PROTECTION, false);
240239
if (sketch != null) {
241240
sketch.lowBitAmbient = properties.getBoolean(PROPERTY_LOW_BIT_AMBIENT, false);
242241
sketch.burnInProtection = properties.getBoolean(PROPERTY_BURN_IN_PROTECTION, false);
@@ -247,6 +246,10 @@ public void onPropertiesChanged(Bundle properties) {
247246
@Override
248247
public void onApplyWindowInsets(WindowInsets insets) {
249248
super.onApplyWindowInsets(insets);
249+
this.insets.set(insets.getSystemWindowInsetLeft(),
250+
insets.getSystemWindowInsetTop(),
251+
insets.getSystemWindowInsetRight(),
252+
insets.getSystemWindowInsetBottom());
250253
if (sketch != null) {
251254
sketch.isRound = insets.isRound();
252255
sketch.insetLeft = insets.getSystemWindowInsetLeft();
@@ -409,51 +412,15 @@ public int getYPixelOffset() {
409412
}
410413

411414

412-
@Override
413-
public int getHomeScreenCount() {
414-
return 0;
415-
}
416-
417-
418-
@Override
419-
public boolean isInInteractiveMode() {
420-
return !isInAmbientMode();
421-
}
422-
423-
424415
@Override
425416
public boolean isRound() {
426417
return isRound;
427418
}
428419

429420

430421
@Override
431-
public boolean isSquare() {
432-
return !isRound;
433-
}
434-
435-
436-
@Override
437-
public int getInsetLeft() {
438-
return insetLeft;
439-
}
440-
441-
442-
@Override
443-
public int getInsetRight() {
444-
return insetRight;
445-
}
446-
447-
448-
@Override
449-
public int getInsetTop() {
450-
return insetTop;
451-
}
452-
453-
454-
@Override
455-
public int getInsetBottom() {
456-
return insetBottom;
422+
public Rect getInsets() {
423+
return insets;
457424
}
458425

459426

core/src/processing/android/ServiceEngine.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,23 @@
2222

2323
package processing.android;
2424

25+
import android.graphics.Rect;
2526
import processing.core.PConstants;
2627

2728
public interface ServiceEngine extends PConstants {
28-
// Live wallpapers
29+
// wwallpapers
2930
public boolean isPreview();
3031
public float getXOffset();
3132
public float getYOffset();
3233
public float getXOffsetStep();
3334
public float getYOffsetStep();
3435
public int getXPixelOffset();
3536
public int getYPixelOffset();
36-
public int getHomeScreenCount();
3737

38-
// Watch faces
38+
// wear
3939
public boolean isInAmbientMode();
40-
public boolean isInInteractiveMode();
4140
public boolean isRound();
42-
public boolean isSquare();
43-
44-
public int getInsetLeft();
45-
public int getInsetRight();
46-
public int getInsetTop();
47-
public int getInsetBottom();
48-
41+
public Rect getInsets();
4942
public boolean useLowBitAmbient();
5043
public boolean requireBurnInProtection();
5144
}

core/src/processing/core/PApplet.java

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import android.view.SurfaceHolder;
5050
import android.view.View;
5151
import android.view.ViewGroup;
52-
import android.view.inputmethod.InputMethodManager;
5352
import processing.a2d.PGraphicsAndroid2D;
5453
import processing.android.AppComponent;
5554
import processing.android.ServiceEngine;
@@ -464,11 +463,6 @@ public Activity getActivity() {
464463
}
465464

466465

467-
public ServiceEngine getEngine() {
468-
return surface.getEngine();
469-
}
470-
471-
472466
public void initSurface(AppComponent component, SurfaceHolder holder) {
473467
parentLayout = -1;
474468
initSurface(null, null, null, component, holder);
@@ -2297,22 +2291,62 @@ public void touchCancelled(TouchEvent event) {
22972291

22982292
//////////////////////////////////////////////////////////////
22992293

2300-
// unfinished API, do not use
2294+
// Wallpaper and wear API
23012295

23022296

2303-
// protected void pressEvent() { }
2304-
//
2305-
// protected void dragEvent() { }
2306-
//
2307-
// protected void moveEvent() { }
2308-
//
2309-
// protected void releaseEvent() { }
2310-
//
2311-
// protected void zoomEvent(float x, float y, float d0, float d1) { }
2312-
//
2313-
// protected void tapEvent(float x, float y) { }
2314-
//
2315-
// protected void swipeEvent(float x0, float y0, float x1, float y1) { }
2297+
public boolean wallpaperPreview() {
2298+
return surface.getEngine().isPreview();
2299+
}
2300+
2301+
2302+
public float wallpaperOffset() {
2303+
return surface.getEngine().getXOffset();
2304+
}
2305+
2306+
2307+
public int wallpaperHomeCount() {
2308+
float step = surface.getEngine().getXOffsetStep();
2309+
if (0 < step) {
2310+
return (int)(1 + 1 / step);
2311+
} else {
2312+
return 1;
2313+
}
2314+
}
2315+
2316+
2317+
public boolean wearAmbient() {
2318+
return surface.getEngine().isInAmbientMode();
2319+
}
2320+
2321+
2322+
public boolean wearInteractive() {
2323+
return !surface.getEngine().isInAmbientMode();
2324+
}
2325+
2326+
2327+
public boolean wearRound() {
2328+
return surface.getEngine().isRound();
2329+
}
2330+
2331+
2332+
public boolean wearSquare() {
2333+
return !surface.getEngine().isRound();
2334+
}
2335+
2336+
2337+
public Rect wearInsets() {
2338+
return surface.getEngine().getInsets();
2339+
}
2340+
2341+
2342+
boolean wearLowBit() {
2343+
return surface.getEngine().useLowBitAmbient();
2344+
}
2345+
2346+
2347+
boolean wearBurnProtection() {
2348+
return surface.getEngine().requireBurnInProtection();
2349+
}
23162350

23172351

23182352
//////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)