@@ -80,17 +80,17 @@ public WallpaperBackupHelper(Context context, String[] files, String[] keys) {
8080 mFiles = files ;
8181 mKeys = keys ;
8282
83- WallpaperManager wpm ;
84- wpm = (WallpaperManager ) context .getSystemService (Context .WALLPAPER_SERVICE );
85- mDesiredMinWidth = (double ) wpm .getDesiredMinimumWidth ();
83+ final WindowManager wm =
84+ (WindowManager ) context .getSystemService (Context .WINDOW_SERVICE );
85+ final WallpaperManager wpm =
86+ (WallpaperManager ) context .getSystemService (Context .WALLPAPER_SERVICE );
87+ final Display d = wm .getDefaultDisplay ();
88+ final Point size = new Point ();
89+ d .getSize (size );
90+ mDesiredMinWidth = size .x ;
8691 mDesiredMinHeight = (double ) wpm .getDesiredMinimumHeight ();
8792
88- if (mDesiredMinWidth <= 0 || mDesiredMinHeight <= 0 ) {
89- WindowManager wm = (WindowManager ) context .getSystemService (Context .WINDOW_SERVICE );
90- Display d = wm .getDefaultDisplay ();
91- Point size = new Point ();
92- d .getSize (size );
93- mDesiredMinWidth = size .x ;
93+ if (mDesiredMinHeight <= 0 ) {
9494 mDesiredMinHeight = size .y ;
9595 }
9696
@@ -130,15 +130,12 @@ public void restoreEntity(BackupDataInputStream data) {
130130 if (DEBUG ) Slog .d (TAG , "Restoring wallpaper image w=" + options .outWidth
131131 + " h=" + options .outHeight );
132132
133- // How much does the image differ from our preference? The threshold
134- // here is set to accept any image larger than our target, because
135- // scaling down is acceptable; but to reject images that are deemed
136- // "too small" to scale up attractively. The value 1.33 is just barely
137- // too low to pass Nexus 1 or Droid wallpapers for use on a Xoom, but
138- // will pass anything relatively larger.
139- double widthRatio = mDesiredMinWidth / options .outWidth ;
140- double heightRatio = mDesiredMinHeight / options .outHeight ;
141- if (widthRatio > 0 && widthRatio < 1.33
133+ // We accept any wallpaper that is at least as wide as our preference
134+ // (i.e. wide enough to fill the screen), and is within a comfortable
135+ // factor of the target height, to avoid significant clipping/scaling/
136+ // letterboxing.
137+ final double heightRatio = mDesiredMinHeight / options .outHeight ;
138+ if (options .outWidth >= mDesiredMinWidth
142139 && heightRatio > 0 && heightRatio < 1.33 ) {
143140 // sufficiently close to our resolution; go ahead and use it
144141 Slog .d (TAG , "Applying restored wallpaper image." );
@@ -147,8 +144,11 @@ public void restoreEntity(BackupDataInputStream data) {
147144 // since it does not exist anywhere other than the private wallpaper
148145 // file.
149146 } else {
150- Slog .i (TAG , "Dimensions too far off; using default wallpaper. wr=" + widthRatio
151- + " hr=" + heightRatio );
147+ Slog .i (TAG , "Restored image dimensions (w="
148+ + options .outWidth + ", h=" + options .outHeight
149+ + ") too far off target (tw="
150+ + mDesiredMinWidth + ", th=" + mDesiredMinHeight
151+ + "); falling back to default wallpaper." );
152152 f .delete ();
153153 }
154154 }
0 commit comments