Skip to content

Commit 3776e19

Browse files
committed
add getContext() method, fixes #227
1 parent 9321a04 commit 3776e19

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

core/src/processing/core/PSurface.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.io.InputStream;
2727

2828
import android.app.Activity;
29+
import android.content.Context;
2930
import android.content.Intent;
3031
import android.content.res.AssetManager;
3132
import android.view.SurfaceView;
@@ -37,6 +38,7 @@
3738
* handling
3839
*/
3940
public interface PSurface {
41+
public Context getContext();
4042
public Activity getActivity();
4143
public AppComponent getComponent();
4244

core/src/processing/core/PSurfaceNone.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package processing.core;
2424

2525
import android.app.Activity;
26+
import android.content.Context;
2627
import android.content.Intent;
2728
import android.content.pm.ActivityInfo;
2829
import android.content.res.AssetManager;
@@ -61,6 +62,18 @@ public class PSurfaceNone implements PSurface, PConstants {
6162
protected float frameRateTarget = 60;
6263
protected long frameRatePeriod = 1000000000L / 60L;
6364

65+
@Override
66+
public Context getContext() {
67+
if (component.getKind() == AppComponent.FRAGMENT) {
68+
return activity;
69+
} else if (component.getKind() == AppComponent.WALLPAPER) {
70+
return wallpaper;
71+
} else if (component.getKind() == AppComponent.WATCHFACE) {
72+
return watchface;
73+
}
74+
return null;
75+
}
76+
6477
@Override
6578
public Activity getActivity() {
6679
return activity;

0 commit comments

Comments
 (0)