diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2023-03-24 16:14:37 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2023-03-24 16:14:37 +0000 |
commit | 6e393258111e9a3c413347621f37f8c44ebc3dc0 (patch) | |
tree | df35b3265016994da28fa13d92a206ae12a503b8 | |
parent | c103b4ab38232a44f6f049fafd1e3edf8e44fa3c (diff) | |
parent | 551cdef08c3c29f59e37e0c41fb274bbcdc17c2d (diff) | |
download | WallpaperPicker2-6e393258111e9a3c413347621f37f8c44ebc3dc0.tar.gz |
Merge "Use the same cropping for outer screen and unfolded vertical hinge" into tm-qpr-dev
3 files changed, 46 insertions, 8 deletions
diff --git a/src/com/android/wallpaper/model/WallpaperSectionController.java b/src/com/android/wallpaper/model/WallpaperSectionController.java index 6bb2a152..649e79aa 100644 --- a/src/com/android/wallpaper/model/WallpaperSectionController.java +++ b/src/com/android/wallpaper/model/WallpaperSectionController.java @@ -184,7 +184,7 @@ public class WallpaperSectionController implements mHomeWallpaperSurface, colorFuture, () -> { if (mHomePreviewWallpaperInfo != null) { maybeLoadThumbnail(mHomePreviewWallpaperInfo, mHomeWallpaperSurfaceCallback, - mDisplayUtils.isOnWallpaperDisplay(mActivity)); + mDisplayUtils.isSingleDisplayOrUnfoldedHorizontalHinge(mActivity)); } }); @@ -199,7 +199,7 @@ public class WallpaperSectionController implements mLockscreenPreviewCard, mLockWallpaperSurface, colorFuture, () -> { if (mLockPreviewWallpaperInfo != null) { maybeLoadThumbnail(mLockPreviewWallpaperInfo, mLockWallpaperSurfaceCallback, - mDisplayUtils.isOnWallpaperDisplay(mActivity)); + mDisplayUtils.isSingleDisplayOrUnfoldedHorizontalHinge(mActivity)); } }); mLockPreviewContainer = mLockscreenPreviewCard.findViewById( @@ -422,7 +422,7 @@ public class WallpaperSectionController implements // Load thumb regardless of live wallpaper to make sure we have a placeholder while // the live wallpaper initializes in that case. maybeLoadThumbnail(wallpaperInfo, surfaceCallback, - mDisplayUtils.isOnWallpaperDisplay(mActivity)); + mDisplayUtils.isSingleDisplayOrUnfoldedHorizontalHinge(mActivity)); WallpaperManager wallpaperManager = WallpaperManager.getInstance(mActivity); if (wallpaperManager.isLockscreenLiveWallpaperEnabled()) { diff --git a/src/com/android/wallpaper/picker/customization/ui/section/ScreenPreviewSectionController.kt b/src/com/android/wallpaper/picker/customization/ui/section/ScreenPreviewSectionController.kt index 134dc042..821c5bd8 100644 --- a/src/com/android/wallpaper/picker/customization/ui/section/ScreenPreviewSectionController.kt +++ b/src/com/android/wallpaper/picker/customization/ui/section/ScreenPreviewSectionController.kt @@ -135,7 +135,7 @@ open class ScreenPreviewSectionController( wallpaperInteractor = wallpaperInteractor, ), lifecycleOwner = lifecycleOwner, - offsetToStart = displayUtils.isOnWallpaperDisplay(activity), + offsetToStart = displayUtils.isSingleDisplayOrUnfoldedHorizontalHinge(activity), screen = CustomizationSections.Screen.LOCK_SCREEN, onPreviewDirty = { // only the visible binding should recreate the activity so it's not done twice @@ -180,7 +180,7 @@ open class ScreenPreviewSectionController( wallpaperInteractor = wallpaperInteractor, ), lifecycleOwner = lifecycleOwner, - offsetToStart = displayUtils.isOnWallpaperDisplay(activity), + offsetToStart = displayUtils.isSingleDisplayOrUnfoldedHorizontalHinge(activity), screen = CustomizationSections.Screen.HOME_SCREEN, onPreviewDirty = { // only the visible binding should recreate the activity so it's not done twice diff --git a/src/com/android/wallpaper/util/DisplayUtils.kt b/src/com/android/wallpaper/util/DisplayUtils.kt index 55bd8b7a..cd364dbe 100644 --- a/src/com/android/wallpaper/util/DisplayUtils.kt +++ b/src/com/android/wallpaper/util/DisplayUtils.kt @@ -21,6 +21,8 @@ import android.graphics.Point import android.hardware.display.DisplayManager import android.util.Log import android.view.Display +import android.view.Surface.ROTATION_270 +import android.view.Surface.ROTATION_90 /** * Utility class to provide methods to find and obtain information about displays via {@link @@ -29,6 +31,7 @@ import android.view.Display class DisplayUtils(private val context: Context) { companion object { private const val TAG = "DisplayUtils" + private val ROTATION_HORIZONTAL_HINGE = setOf(ROTATION_90, ROTATION_270) } private val displayManager: DisplayManager by lazy { @@ -39,14 +42,43 @@ class DisplayUtils(private val context: Context) { return getInternalDisplays().size > 1 } - /** Returns the {@link Display} to be used to calculate wallpaper size and cropping. */ + /** + * Returns the internal {@link Display} with tthe largest area to be used to calculate wallpaper + * size and cropping. + */ fun getWallpaperDisplay(): Display { val internalDisplays = getInternalDisplays() - return internalDisplays.maxWithOrNull { a, b -> getRealSize(a) - getRealSize(b) } + return internalDisplays.maxWithOrNull { a, b -> getRealArea(a) - getRealArea(b) } ?: internalDisplays[0] } /** + * Checks if the device only has one display or unfolded screen in horizontal hinge orientation. + */ + fun isSingleDisplayOrUnfoldedHorizontalHinge(activity: Activity): Boolean { + return !hasMultiInternalDisplays() || isUnfoldedHorizontalHinge(activity) + } + + /** + * Checks if the device is a foldable and it's unfolded and in horizontal hinge orientation + * (portrait). + */ + fun isUnfoldedHorizontalHinge(activity: Activity): Boolean { + return activity.display.rotation in ROTATION_HORIZONTAL_HINGE && + isOnWallpaperDisplay(activity) && + hasMultiInternalDisplays() + } + + fun getMaxDisplaysDimension(): Point { + val dimen = Point() + getInternalDisplays().let { displays -> + dimen.x = displays.maxOf { getRealSize(it).x } + dimen.y = displays.maxOf { getRealSize(it).y } + } + return dimen + } + + /** * Returns `true` if the current display is the wallpaper display on a multi-display device. * * On a multi-display device the wallpaper display is the largest display while on a single @@ -56,12 +88,18 @@ class DisplayUtils(private val context: Context) { return activity.display.uniqueId == getWallpaperDisplay().uniqueId } - private fun getRealSize(display: Display): Int { + private fun getRealArea(display: Display): Int { val p = Point() display.getRealSize(p) return p.x * p.y } + private fun getRealSize(display: Display): Point { + val p = Point() + display.getRealSize(p) + return p + } + private fun getInternalDisplays(): List<Display> { val allDisplays: Array<out Display> = displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_ALL_INCLUDING_DISABLED) |