Skip to content

Commit 79b38d1

Browse files
committed
handle back press event in the animation thread
1 parent a06c203 commit 79b38d1

File tree

10 files changed

+28
-29
lines changed

10 files changed

+28
-29
lines changed

core/src/processing/android/PWallpaper.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,26 +154,18 @@ public void onSurfaceCreated(SurfaceHolder surfaceHolder) {
154154
@Override
155155
public void onSurfaceChanged(final SurfaceHolder holder, final int format,
156156
final int width, final int height) {
157-
// if (sketch != null) {
158-
//// sketch.g.setSize(width, height);
159-
// sketch.surfaceChanged();
160-
// sketch.setSize(width, height);
161-
// }
162-
163157
// When the surface of a live wallpaper changes (eg: after a screen rotation) the same sketch
164158
// continues to run (unlike the case of regular apps, where its re-created) so we need to
165159
// force a reset of the renderer so the backing FBOs (in the case of the OpenGL renderers)
166160
// get reinitalized with the correct size.
167161
sketch.g.reset();
168-
System.out.println("===================> ON SURFACE CHANGED!!!!!!!!!!!!!!!");
169162
super.onSurfaceChanged(holder, format, width, height);
170163
}
171164

172165

173166
@Override
174167
public void onVisibilityChanged(boolean visible) {
175168
if (sketch != null) {
176-
System.out.println("============> CHANGING WALLPAPER VISIBILITY TO " + visible);
177169
if (visible) {
178170
sketch.onResume();
179171
} else {

core/src/processing/android/PWatchFaceCanvas.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,6 @@ public void onVisibilityChanged(boolean visible) {
230230
public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
231231
super.onSurfaceChanged(holder, format, width, height);
232232
if (sketch != null) {
233-
// sketch.displayWidth = width;
234-
// sketch.displayHeight = height;
235-
// sketch.g.setSize(sketch.sketchWidth(), sketch.sketchHeight());
236-
// sketch.surfaceChanged();
237233
sketch.surfaceChanged();
238234
sketch.setSize(width, height);
239235
}

core/src/processing/android/PWatchFaceGLES.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,6 @@ public void onGlContextCreated() {
191191
public void onGlSurfaceCreated(int width, int height) {
192192
super.onGlSurfaceCreated(width, height);
193193
if (sketch != null) {
194-
// sketch.displayWidth = width;
195-
// sketch.displayHeight = height;
196-
// sketch.g.setSize(sketch.sketchWidth(), sketch.sketchHeight());
197-
// sketch.surfaceChanged();
198194
sketch.surfaceChanged();
199195
sketch.setSize(width, height);
200196
}

core/src/processing/core/PApplet.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,11 @@ public class PApplet extends Object implements ActivityAPI, PConstants {
260260
*/
261261
boolean keyboardIsOpen = false;
262262

263+
/**
264+
* Flag to determine if the back key was pressed.
265+
*/
266+
private boolean requestedBackPress = false;
267+
263268
/**
264269
* Flag to determine if the user handled the back press.
265270
*/
@@ -648,8 +653,8 @@ public void setHasOptionsMenu(boolean hasMenu) {
648653
}
649654

650655

651-
public void onBackPressed() {
652-
handledBackPressed = false;
656+
synchronized public void onBackPressed() {
657+
requestedBackPress = true;
653658
}
654659

655660
public void startActivity(Intent intent) {
@@ -729,6 +734,19 @@ private void handlePermissions() {
729734
}
730735
}
731736

737+
synchronized private void handleBackPressed() {
738+
if (requestedBackPress) {
739+
requestedBackPress = false;
740+
backPressed();
741+
if (!handledBackPressed) {
742+
if (getActivity() != null) {
743+
// Services don't have an activity associated to them, but back press could not be triggered for those anyways
744+
getActivity().finish();
745+
}
746+
handledBackPressed = false;
747+
}
748+
}
749+
}
732750

733751
/**
734752
* @param method "size" or "fullScreen"
@@ -904,6 +922,10 @@ public void resume() {
904922
}
905923

906924

925+
public void backPressed() {
926+
handledBackPressed = false;
927+
}
928+
907929
//////////////////////////////////////////////////////////////
908930

909931

@@ -1844,6 +1866,7 @@ public void handleDraw() {
18441866

18451867
handleMethods("draw");
18461868
handlePermissions();
1869+
handleBackPressed();
18471870

18481871
redraw = false; // unset 'redraw' flag in case it was set
18491872
// (only do this once draw() has run, not just setup())

mode/libraries/vr/src/processing/vr/PVR.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
195195
public void onBackPressed() {
196196
if (sketch != null) {
197197
sketch.onBackPressed();
198-
if (sketch.handledBackPressed) return;
199198
}
200-
super.onBackPressed();
201199
}
202200
}

mode/templates/AppActivity.java.tmpl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ public class MainActivity extends AppCompatActivity {
5252
public void onBackPressed() {
5353
if (sketch != null) {
5454
sketch.onBackPressed();
55-
if (sketch.handledBackPressed) return;
5655
}
57-
super.onBackPressed();
58-
}
56+
}
5957
}

studio/apps/fast2d/src/main/java/fast2d/MainActivity.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
5252
public void onBackPressed() {
5353
if (sketch != null) {
5454
sketch.onBackPressed();
55-
if (sketch.handledBackPressed) return;
5655
}
57-
super.onBackPressed();
5856
}
5957
}

studio/apps/simple/src/main/java/simple/MainActivity.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
5252
public void onBackPressed() {
5353
if (sketch != null) {
5454
sketch.onBackPressed();
55-
if (sketch.handledBackPressed) return;
5655
}
57-
super.onBackPressed();
5856
}
5957
}

studio/apps/simple/src/main/java/simple/Sketch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ public void draw() {
2020
background(9);
2121
image(leaf, mouseX, mouseY);
2222
}
23-
}
23+
}

studio/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
google()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.1.3'
9+
classpath 'com.android.tools.build:gradle:3.1.4'
1010

1111
// NOTE: Do not place your application dependencies here; they belong
1212
// in the individual module build.gradle files

0 commit comments

Comments
 (0)