Skip to content

Commit e8fd81c

Browse files
committed
new threading, watch face fixes
1 parent d85ca24 commit e8fd81c

File tree

10 files changed

+501
-670
lines changed

10 files changed

+501
-670
lines changed

core/src/processing/android/AppComponent.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
abstract public interface AppComponent extends PConstants {
3030
static public final int FRAGMENT = 0;
3131
static public final int WALLPAPER = 1;
32-
static public final int WATCHFACE_CANVAS = 2;
33-
static public final int WATCHFACE_GLES = 3;
32+
static public final int WATCHFACE = 2;
3433

3534
public void initDimensions();
3635
public int getWidth();

core/src/processing/android/PFragment.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ public void setSketch(PApplet sketch) {
6565
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
6666
if (sketch != null) {
6767
sketch.initSurface(this, null);
68-
sketch.start();
69-
return sketch.surface.getRootView();
68+
sketch.startSurface();
69+
return sketch.getRootView();
7070
} else {
7171
return null;
7272
}
@@ -96,7 +96,6 @@ public void onDestroy() {
9696
@Override
9797
public void onStart() {
9898
super.onStart();
99-
// System.err.println("----> ON START: " + sketch);
10099
sketch.onStart();
101100
}
102101

@@ -116,7 +115,7 @@ public void onConfigurationChanged(Configuration newConfig) {
116115

117116

118117
public void onBackPressed() {
119-
sketch.onBackPressed();
118+
sketch.exit();
120119
}
121120

122121

@@ -133,6 +132,6 @@ public void requestDraw() {
133132
}
134133

135134
public boolean canDraw() {
136-
return true;
135+
return sketch.isLooping();
137136
}
138137
}

core/src/processing/android/PWallpaper.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,13 @@ public class PEngine extends Engine {
9393
@Override
9494
public void onCreate(SurfaceHolder surfaceHolder) {
9595
super.onCreate(surfaceHolder);
96-
Log.d(TAG, "onCreate(SurfaceHolder)");
97-
98-
9996
sketch = createSketch();
100-
System.out.println("initializing sketch " + sketch);
101-
102-
sketch.initSurface(PWallpaper.this, getSurfaceHolder());
103-
104-
// By default we don't get touch events, so enable them.
105-
setTouchEventsEnabled(true);
106-
107-
sketch.start();
97+
if (sketch != null) {
98+
sketch.initSurface(PWallpaper.this, getSurfaceHolder());
99+
sketch.startSurface();
100+
// By default we don't get touch events, so enable them.
101+
setTouchEventsEnabled(true);
102+
}
108103
}
109104

110105
@Override

core/src/processing/android/PWatchFaceCanvas.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424

2525
import android.content.Intent;
2626
import android.graphics.Canvas;
27+
import android.os.Bundle;
2728
import android.graphics.Rect;
2829
import android.support.wearable.watchface.CanvasWatchFaceService;
2930
import android.support.wearable.watchface.WatchFaceService;
3031
import android.support.wearable.watchface.WatchFaceStyle;
3132
import android.util.DisplayMetrics;
3233
import android.view.MotionEvent;
3334
import android.view.SurfaceHolder;
35+
import android.view.WindowInsets;
3436
import android.view.WindowManager;
3537
import processing.core.PApplet;
3638
import processing.core.PGraphicsAndroid2D;
@@ -57,7 +59,7 @@ public int getHeight() {
5759
}
5860

5961
public int getKind() {
60-
return WATCHFACE_CANVAS;
62+
return WATCHFACE;
6163
}
6264

6365
@Override
@@ -79,10 +81,11 @@ public void requestDraw() {
7981
}
8082

8183
public boolean canDraw() {
82-
return engine.isVisible() && !engine.isInAmbientMode();
84+
// The rendering loop should never call handleDraw() directly, it only needs to invalidate the
85+
// screen
86+
return false;
8387
}
8488

85-
8689
private class CEngine extends CanvasWatchFaceService.Engine {
8790
@Override
8891
public void onCreate(SurfaceHolder surfaceHolder) {
@@ -97,7 +100,7 @@ public void onCreate(SurfaceHolder surfaceHolder) {
97100
if (sketch != null) {
98101
PGraphicsAndroid2D.useBitmap = false;
99102
sketch.initSurface(PWatchFaceCanvas.this, null);
100-
sketch.start();
103+
sketch.startSurface();
101104
}
102105
}
103106

@@ -111,9 +114,26 @@ private void invalidateIfNecessary() {
111114
public void onAmbientModeChanged(boolean inAmbientMode) {
112115
super.onAmbientModeChanged(inAmbientMode);
113116
invalidateIfNecessary();
117+
sketch.ambientMode = inAmbientMode;
114118
// call new event handlers in sketch (?)
115119
}
116120

121+
@Override
122+
public void onPropertiesChanged(Bundle properties) {
123+
super.onPropertiesChanged(properties);
124+
sketch.lowBitAmbient = properties.getBoolean(PROPERTY_LOW_BIT_AMBIENT, false);
125+
sketch.burnInProtection = properties.getBoolean(PROPERTY_BURN_IN_PROTECTION, false);
126+
}
127+
128+
@Override
129+
public void onApplyWindowInsets(WindowInsets insets) {
130+
super.onApplyWindowInsets(insets);
131+
sketch.isRound = insets.isRound();
132+
sketch.insetLeft = insets.getSystemWindowInsetLeft();
133+
sketch.insetRight = insets.getSystemWindowInsetRight();
134+
sketch.insetTop = insets.getSystemWindowInsetTop();
135+
sketch.insetBottom = insets.getSystemWindowInsetBottom();
136+
}
117137

118138
@Override
119139
public void onVisibilityChanged(boolean visible) {

core/src/processing/android/PWatchFaceGLES.java

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

2525
import android.content.Intent;
26+
import android.os.Bundle;
27+
import android.view.WindowInsets;
2628
import android.support.wearable.watchface.Gles2WatchFaceService;
2729
import android.support.wearable.watchface.WatchFaceService;
2830
import android.support.wearable.watchface.WatchFaceStyle;
@@ -55,7 +57,7 @@ public int getHeight() {
5557
}
5658

5759
public int getKind() {
58-
return WATCHFACE_GLES;
60+
return WATCHFACE;
5961
}
6062

6163
@Override
@@ -77,7 +79,9 @@ public void requestDraw() {
7779
}
7880

7981
public boolean canDraw() {
80-
return engine.isVisible() && !engine.isInAmbientMode();
82+
// The rendering loop should never call handleDraw() directly, it only needs to invalidate the
83+
// screen
84+
return false;
8185
}
8286

8387
private class GLEngine extends Gles2WatchFaceService.Engine {
@@ -94,7 +98,7 @@ public void onCreate(SurfaceHolder surfaceHolder) {
9498
.build());
9599
if (sketch != null) {
96100
sketch.initSurface(PWatchFaceGLES.this, null);
97-
sketch.start();
101+
sketch.startSurface();
98102
}
99103
}
100104

@@ -126,9 +130,26 @@ public void onGlSurfaceCreated(int width, int height) {
126130
public void onAmbientModeChanged(boolean inAmbientMode) {
127131
super.onAmbientModeChanged(inAmbientMode);
128132
invalidateIfNecessary();
133+
sketch.ambientMode = inAmbientMode;
129134
// call new event handlers in sketch (?)
130135
}
131136

137+
@Override
138+
public void onPropertiesChanged(Bundle properties) {
139+
super.onPropertiesChanged(properties);
140+
sketch.lowBitAmbient = properties.getBoolean(PROPERTY_LOW_BIT_AMBIENT, false);
141+
sketch.burnInProtection = properties.getBoolean(PROPERTY_BURN_IN_PROTECTION, false);
142+
}
143+
144+
@Override
145+
public void onApplyWindowInsets(WindowInsets insets) {
146+
super.onApplyWindowInsets(insets);
147+
sketch.isRound = insets.isRound();
148+
sketch.insetLeft = insets.getSystemWindowInsetLeft();
149+
sketch.insetRight = insets.getSystemWindowInsetRight();
150+
sketch.insetTop = insets.getSystemWindowInsetTop();
151+
sketch.insetBottom = insets.getSystemWindowInsetBottom();
152+
}
132153

133154
@Override
134155
public void onVisibilityChanged(boolean visible) {

0 commit comments

Comments
 (0)