diff options
author | Chris Poultney <poultney@google.com> | 2023-03-03 22:37:20 +0000 |
---|---|---|
committer | Chris Poultney <poultney@google.com> | 2023-03-08 17:30:25 +0000 |
commit | e258e822887270b392b1c80ebe50f6e9c7ac3d00 (patch) | |
tree | 53e7f54d2a3524304c2b7a010f98d31755d74cd5 | |
parent | e84806c791baefddf845f3d095a8b09a284a84d8 (diff) | |
download | WallpaperPicker2-e258e822887270b392b1c80ebe50f6e9c7ac3d00.tar.gz |
Shows lock screen live wallpaper preview
Shows a proper lock screen preview image when the lock screen has a
separate live wallpaper set.
This is behind flag WallpaperManager#isLockscreenLiveWallpaperEnabled().
Tests will be added as follow-ups because test architecture changes are
needed.
Bug: 267479837
Test: added as follow-ups
Change-Id: Ic8be571f37f63e5e46672b562e4ee8be26d6e1b7
-rw-r--r-- | src/com/android/wallpaper/model/WallpaperSectionController.java | 118 |
1 files changed, 97 insertions, 21 deletions
diff --git a/src/com/android/wallpaper/model/WallpaperSectionController.java b/src/com/android/wallpaper/model/WallpaperSectionController.java index 68ec5ed1..4b28b59c 100644 --- a/src/com/android/wallpaper/model/WallpaperSectionController.java +++ b/src/com/android/wallpaper/model/WallpaperSectionController.java @@ -91,7 +91,8 @@ public class WallpaperSectionController implements private CardView mLockscreenPreviewCard; private ViewGroup mLockPreviewContainer; private ContentLoadingProgressBar mLockscreenPreviewProgress; - private WallpaperConnection mWallpaperConnection; + private WallpaperConnection mHomeWallpaperConnection; + private WallpaperConnection mLockWallpaperConnection; // The wallpaper information which is currently shown on the home preview. private WallpaperInfo mHomePreviewWallpaperInfo; @@ -134,26 +135,20 @@ public class WallpaperSectionController implements @MainThread public void onResume() { refreshCurrentWallpapers(/* forceRefresh= */ mSavedInstanceState == null); - if (mWallpaperConnection != null) { - mWallpaperConnection.setVisibility(true); - } + updateLivePreviewVisibility(true); } @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) @MainThread public void onPause() { - if (mWallpaperConnection != null) { - mWallpaperConnection.setVisibility(false); - } + updateLivePreviewVisibility(false); } @OnLifecycleEvent(Lifecycle.Event.ON_STOP) @MainThread public void onStop() { - if (mWallpaperConnection != null) { - mWallpaperConnection.disconnect(); - mWallpaperConnection = null; - } + disconnectHomeLiveWallpaper(); + disconnectLockLiveWallpaper(); } @Override @@ -234,6 +229,29 @@ public class WallpaperSectionController implements return wallpaperSectionView; } + private void updateLivePreviewVisibility(boolean visible) { + if (mHomeWallpaperConnection != null) { + mHomeWallpaperConnection.setVisibility(visible); + } + if (mLockWallpaperConnection != null) { + mLockWallpaperConnection.setVisibility(visible); + } + } + + private void disconnectHomeLiveWallpaper() { + if (mHomeWallpaperConnection != null) { + mHomeWallpaperConnection.disconnect(); + mHomeWallpaperConnection = null; + } + } + + private void disconnectLockLiveWallpaper() { + if (mLockWallpaperConnection != null) { + mLockWallpaperConnection.disconnect(); + mLockWallpaperConnection = null; + } + } + private void updateWorkspacePreview(SurfaceView workspaceSurface, WorkspaceSurfaceHolderCallback callback, @Nullable WallpaperColors colors) { // Reattach SurfaceView to trigger #surfaceCreated to update preview for different option. @@ -404,13 +422,22 @@ public class WallpaperSectionController implements maybeLoadThumbnail(wallpaperInfo, surfaceCallback, mDisplayUtils.isOnWallpaperDisplay(mActivity)); - if (isHomeWallpaper) { - if (mWallpaperConnection != null) { - mWallpaperConnection.disconnect(); - mWallpaperConnection = null; + WallpaperManager wallpaperManager = WallpaperManager.getInstance(mActivity); + if (wallpaperManager.isLockscreenLiveWallpaperEnabled()) { + if (isHomeWallpaper) { + disconnectHomeLiveWallpaper(); + } else { + disconnectLockLiveWallpaper(); } if (wallpaperInfo instanceof LiveWallpaperInfo) { - setUpLiveWallpaperPreview(wallpaperInfo); + setUpLiveWallpaperPreview(wallpaperInfo, isHomeWallpaper); + } + } else { + if (isHomeWallpaper) { + disconnectHomeLiveWallpaper(); + if (wallpaperInfo instanceof LiveWallpaperInfo) { + setUpLiveWallpaperPreviewLegacy(wallpaperInfo); + } } } @@ -456,14 +483,63 @@ public class WallpaperSectionController implements } } - private void setUpLiveWallpaperPreview(WallpaperInfo homeWallpaper) { + private void setUpLiveWallpaperPreview(WallpaperInfo wallpaper, boolean isHomeWallpaper) { + if (!isActivityAlive() || !WallpaperConnection.isPreviewAvailable()) { + return; + } + + final boolean isHomeBoth = (mHomePreviewWallpaperInfo == mLockPreviewWallpaperInfo); + if (isHomeBoth && !isHomeWallpaper) { + // If home and lock are the same the preview is handled by mirroring the home preview, + // so the lock preview is a no-op. + return; + } + + final SurfaceView mainSurface = + isHomeWallpaper ? mHomeWallpaperSurface : mLockWallpaperSurface; + final SurfaceView mirrorSurface = isHomeBoth ? mLockWallpaperSurface : null; + final WallpaperConnection connection = new WallpaperConnection( + getWallpaperIntent(wallpaper.getWallpaperComponent()), mActivity, + new WallpaperConnection.WallpaperConnectionListener() { + @Override + public void onWallpaperColorsChanged(WallpaperColors colors, int displayId) { + if (isHomeWallpaper) { + onHomeWallpaperColorsChanged(colors); + if (isHomeBoth && mLockScreenPreviewer != null) { + mLockScreenPreviewer.setColor(colors); + onLockWallpaperColorsChanged(colors); + } + } else { + onLockWallpaperColorsChanged(colors); + } + } + }, + mainSurface, mirrorSurface); + + connection.setVisibility(true); + if (isHomeWallpaper) { + mHomeWallpaperConnection = connection; + } else { + mLockWallpaperConnection = connection; + } + mainSurface.post(() -> { + if (mHomeWallpaperConnection != null && !mHomeWallpaperConnection.connect()) { + mHomeWallpaperConnection = null; + } + if (mLockWallpaperConnection != null && !mLockWallpaperConnection.connect()) { + mLockWallpaperConnection = null; + } + }); + } + + private void setUpLiveWallpaperPreviewLegacy(WallpaperInfo homeWallpaper) { if (!isActivityAlive()) { return; } if (WallpaperConnection.isPreviewAvailable()) { final boolean isLockLive = mLockPreviewWallpaperInfo instanceof LiveWallpaperInfo; - mWallpaperConnection = new WallpaperConnection( + mHomeWallpaperConnection = new WallpaperConnection( getWallpaperIntent(homeWallpaper.getWallpaperComponent()), mActivity, new WallpaperConnection.WallpaperConnectionListener() { @Override @@ -478,10 +554,10 @@ public class WallpaperSectionController implements }, mHomeWallpaperSurface, isLockLive ? mLockWallpaperSurface : null); - mWallpaperConnection.setVisibility(true); + mHomeWallpaperConnection.setVisibility(true); mHomeWallpaperSurface.post(() -> { - if (mWallpaperConnection != null && !mWallpaperConnection.connect()) { - mWallpaperConnection = null; + if (mHomeWallpaperConnection != null && !mHomeWallpaperConnection.connect()) { + mHomeWallpaperConnection = null; } }); } |