Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Implement launcher zoom callback #7206

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
@@ -1,6 +1,7 @@
[1.12.1]
- LWJGL3 Improvement: Audio device is automatically switched if it was changed in the operating system.
- Tiled Fix: TiledLayer parallax default values fix
- Android: Added AndroidWallpaperListener#zoomChange() for listening to launcher zoom changes on Android 11+.

[1.12.0]
- [BREAKING CHANGE] Added #touchCancelled to InputProcessor interface, see #6871.
Expand Down
Expand Up @@ -568,6 +568,51 @@ public void run () {
}
}

// zoom from last onZoomChanged
boolean zoomConsumed = true;
float zoom = 0.0f;

@Override
public void onZoomChanged (float zoom) {

// it spawns too frequent on some devices - its annoying!
// if (DEBUG)
// Log.d(TAG, " > AndroidWallpaperEngine - onZoomChanged(" + zoom + ") " + hashCode()
// + ", linkedApp: " + (linkedApp != null));

this.zoomConsumed = false;
this.zoom = zoom;

// can fail if linkedApp == null, so we repeat it in Engine.onResume
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is either outdated or wrong as this isn't repeated in Engine.onResume?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I indeed forgot some calls of the new method, now it should be all right!

notifyZoomChanged();
if (!Gdx.graphics.isContinuousRendering()) {
Gdx.graphics.requestRendering();
}

super.onZoomChanged(zoom);
}

protected void notifyZoomChanged () {
if (linkedEngine == this && app.listener instanceof AndroidWallpaperListener) {
if (!zoomConsumed) { // no need for more sophisticated synchronization - zoomChanged can be called multiple
// times and with various patterns on various devices - user application must be prepared for that
zoomConsumed = true;

app.postRunnable(new Runnable() {
@Override
public void run () {
boolean isCurrent = false;
synchronized (sync) {
isCurrent = (linkedEngine == AndroidWallpaperEngine.this); // without this app can crash when fast
// switching between engines (tested!)
}
if (isCurrent) ((AndroidWallpaperListener)app.listener).zoomChange(zoom);
}
});
}
}
}

protected void notifyPreviewState () {
// notify preview state to app listener
if (linkedEngine == this && app.listener instanceof AndroidWallpaperListener) {
Expand Down
Expand Up @@ -33,6 +33,10 @@ public interface AndroidWallpaperListener {
* @param yPixelOffset */
void offsetChange (float xOffset, float yOffset, float xOffsetStep, float yOffsetStep, int xPixelOffset, int yPixelOffset);

/** Called on the rendering thread after the live wallpaper's zoom had changed.
* @param zoom */
void zoomChange (float zoom);

/** Called after 'isPreview' state had changed. First time called just after application initialization.
* @param isPreview current status, save this value and update always when this method is called if you want track live
* wallpaper isPreview status. */
Expand Down
Expand Up @@ -47,6 +47,11 @@ public void offsetChange (float xOffset, float yOffset, float xOffsetStep, float
+ " yOffsetStep:" + yOffsetStep + " xPixelOffset:" + xPixelOffset + " yPixelOffset:" + yPixelOffset + ")");
}

@Override
public void zoomChange (float zoom) {
Log.i("LiveWallpaper test", "zoomChange(zoom:" + zoom + ")");
}

@Override
public void previewStateChange (boolean isPreview) {
Log.i("LiveWallpaper test", "previewStateChange(isPreview:" + isPreview + ")");
Expand Down