processing-android
processing-android copied to clipboard
getContext() is not working properly when running a Wallpaper
getContext() seems to be null when using the sketch as a Wallpaper. Maybe the context could be the Service used for the wallpaper itself.
I can also confirm this, so there is no way to use sensors in wallpapers basically.
Wallpapers were broken by commit 71bdb3
; I believe that reverting the change from there to PSurfaceNone
would fix the issue. For the time being, I have been using a very hacky solution - you can add the following file to your project:
PWallpaperSurface.java
package processing.core;
import android.service.wallpaper.WallpaperService;
public class PWallpaperSurface extends PSurfaceNone {
public PWallpaperSurface (PSurfaceNone _super) {
sketch = _super.sketch;
graphics = _super.graphics;
component = _super.component;
surfaceReady = _super.surfaceReady;
surfaceView = _super.surfaceView;
view = _super.view;
wallpaper = _super.wallpaper;
requestedThreadStart = _super.requestedThreadStart;
thread = _super.thread;
paused = _super.paused;
pauseObject = _super.pauseObject;
frameRateTarget = _super.frameRateTarget;
frameRatePeriod = _super.frameRatePeriod;
}
public WallpaperService getWallpaper() {
return wallpaper;
}
}
Then, where you were using getContext()
previously, you can do (new PWallpaperSurface((PSurfaceNone)surface)).getWallpaper()
. (I tend to overwrite the surface
object with the PWallpaperService
version)