summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAustin Wang <wangaustin@google.com>2023-03-06 15:28:29 +0800
committerAustin Wang <wangaustin@google.com>2023-03-24 02:25:05 +0000
commit551cdef08c3c29f59e37e0c41fb274bbcdc17c2d (patch)
tree851df2296bf33e11c45f93a8eb07490c068deb9d
parentd83706f73143b89ae2ecbda621a57eafaf2664e4 (diff)
downloadWallpaperPicker2-551cdef08c3c29f59e37e0c41fb274bbcdc17c2d.tar.gz
Use the same cropping for outer screen and unfolded vertical hinge
Offset the preview to start if on handheld or unfolded horizontal hinge. Bug: 266436682 Test: set wallpaper on tablets, foldables w/ different screen config. Change-Id: I8d787eaa3981fbf2c4916a69c5468e97f7131322
-rw-r--r--src/com/android/wallpaper/model/WallpaperSectionController.java6
-rw-r--r--src/com/android/wallpaper/picker/customization/ui/section/ScreenPreviewSectionController.kt4
-rw-r--r--src/com/android/wallpaper/util/DisplayUtils.kt44
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 4b28b59c..fe80493d 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(
@@ -420,7 +420,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)