Loading core/java/android/service/wallpaper/WallpaperService.java +5 −2 Original line number Diff line number Diff line Loading @@ -784,8 +784,11 @@ public abstract class WallpaperService extends Service { // only internal implementations like ImageWallpaper DisplayInfo displayInfo = new DisplayInfo(); mDisplay.getDisplayInfo(displayInfo); mLayout.width = Math.max(displayInfo.logicalWidth, myWidth); mLayout.height = Math.max(displayInfo.logicalHeight, myHeight); final float layoutScale = Math.max( (float) displayInfo.logicalHeight / (float) myHeight, (float) displayInfo.logicalWidth / (float) myWidth); mLayout.height = (int) (myHeight * layoutScale); mLayout.width = (int) (myWidth * layoutScale); mWindowFlags |= WindowManager.LayoutParams.FLAG_SCALED; } Loading packages/SystemUI/src/com/android/systemui/ImageWallpaper.java +41 −11 Original line number Diff line number Diff line Loading @@ -16,14 +16,18 @@ package com.android.systemui; import static android.view.Display.DEFAULT_DISPLAY; import android.app.WallpaperManager; import android.content.ComponentCallbacks2; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.RecordingCanvas; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Region.Op; import android.hardware.display.DisplayManager; import android.os.AsyncTask; import android.os.Handler; import android.os.Trace; Loading @@ -33,7 +37,6 @@ import android.view.Display; import android.view.DisplayInfo; import android.view.Surface; import android.view.SurfaceHolder; import android.view.WindowManager; import com.android.internal.annotations.VisibleForTesting; Loading Loading @@ -94,7 +97,7 @@ public class ImageWallpaper extends WallpaperService { float mYOffset = 0f; float mScale = 1f; private Display mDefaultDisplay; private Display mDisplay; private final DisplayInfo mTmpDisplayInfo = new DisplayInfo(); boolean mVisible = true; Loading Loading @@ -138,10 +141,20 @@ public class ImageWallpaper extends WallpaperService { super.onCreate(surfaceHolder); //noinspection ConstantConditions mDefaultDisplay = getSystemService(WindowManager.class).getDefaultDisplay(); final Context displayContext = getDisplayContext(); final int displayId = displayContext == null ? DEFAULT_DISPLAY : displayContext.getDisplayId(); DisplayManager dm = getSystemService(DisplayManager.class); if (dm != null) { mDisplay = dm.getDisplay(displayId); if (mDisplay == null) { Log.e(TAG, "Cannot find display! Fallback to default."); mDisplay = dm.getDisplay(DEFAULT_DISPLAY); } } setOffsetNotificationsEnabled(false); updateSurfaceSize(surfaceHolder, getDefaultDisplayInfo(), false /* forDraw */); updateSurfaceSize(surfaceHolder, getDisplayInfo(), false /* forDraw */); } @Override Loading @@ -165,9 +178,26 @@ public class ImageWallpaper extends WallpaperService { hasWallpaper = false; } // Set surface size equal to bitmap size, prevent memory waste int surfaceWidth = Math.max(MIN_BACKGROUND_WIDTH, mBackgroundWidth); int surfaceHeight = Math.max(MIN_BACKGROUND_HEIGHT, mBackgroundHeight); // Expected surface size. int surfaceWidth = Math.max(displayInfo.logicalWidth, mBackgroundWidth); int surfaceHeight = Math.max(displayInfo.logicalHeight, mBackgroundHeight); // Calculate the minimum drawing area of the surface, which saves memory and does not // distort the image. final float scale = Math.min( (float) mBackgroundHeight / (float) surfaceHeight, (float) mBackgroundWidth / (float) surfaceWidth); surfaceHeight = (int) (scale * surfaceHeight); surfaceWidth = (int) (scale * surfaceWidth); // Set surface size to at least MIN size. if (surfaceWidth < MIN_BACKGROUND_WIDTH || surfaceHeight < MIN_BACKGROUND_HEIGHT) { final float scaleUp = Math.max( (float) MIN_BACKGROUND_WIDTH / (float) surfaceWidth, (float) MIN_BACKGROUND_HEIGHT / (float) surfaceHeight); surfaceWidth = (int) ((float) surfaceWidth * scaleUp); surfaceHeight = (int) ((float) surfaceHeight * scaleUp); } // Used a fixed size surface, because we are special. We can do // this because we know the current design of window animations doesn't Loading Loading @@ -267,8 +297,8 @@ public class ImageWallpaper extends WallpaperService { } @VisibleForTesting DisplayInfo getDefaultDisplayInfo() { mDefaultDisplay.getDisplayInfo(mTmpDisplayInfo); DisplayInfo getDisplayInfo() { mDisplay.getDisplayInfo(mTmpDisplayInfo); return mTmpDisplayInfo; } Loading @@ -278,7 +308,7 @@ public class ImageWallpaper extends WallpaperService { } try { Trace.traceBegin(Trace.TRACE_TAG_VIEW, "drawWallpaper"); DisplayInfo displayInfo = getDefaultDisplayInfo(); DisplayInfo displayInfo = getDisplayInfo(); int newRotation = displayInfo.rotation; // Sometimes a wallpaper is not large enough to cover the screen in one dimension. Loading Loading @@ -445,7 +475,7 @@ public class ImageWallpaper extends WallpaperService { if (DEBUG) { Log.d(TAG, "Wallpaper loaded: " + mBackground); } updateSurfaceSize(getSurfaceHolder(), getDefaultDisplayInfo(), updateSurfaceSize(getSurfaceHolder(), getDisplayInfo(), false /* forDraw */); } Loading packages/SystemUI/tests/src/com/android/systemui/ImageWallpaperTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ public class ImageWallpaperTest extends SysuiTestCase { public Engine onCreateEngine() { return new DrawableEngine() { @Override DisplayInfo getDefaultDisplayInfo() { DisplayInfo getDisplayInfo() { return mDisplayInfo; } Loading Loading
core/java/android/service/wallpaper/WallpaperService.java +5 −2 Original line number Diff line number Diff line Loading @@ -784,8 +784,11 @@ public abstract class WallpaperService extends Service { // only internal implementations like ImageWallpaper DisplayInfo displayInfo = new DisplayInfo(); mDisplay.getDisplayInfo(displayInfo); mLayout.width = Math.max(displayInfo.logicalWidth, myWidth); mLayout.height = Math.max(displayInfo.logicalHeight, myHeight); final float layoutScale = Math.max( (float) displayInfo.logicalHeight / (float) myHeight, (float) displayInfo.logicalWidth / (float) myWidth); mLayout.height = (int) (myHeight * layoutScale); mLayout.width = (int) (myWidth * layoutScale); mWindowFlags |= WindowManager.LayoutParams.FLAG_SCALED; } Loading
packages/SystemUI/src/com/android/systemui/ImageWallpaper.java +41 −11 Original line number Diff line number Diff line Loading @@ -16,14 +16,18 @@ package com.android.systemui; import static android.view.Display.DEFAULT_DISPLAY; import android.app.WallpaperManager; import android.content.ComponentCallbacks2; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.RecordingCanvas; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Region.Op; import android.hardware.display.DisplayManager; import android.os.AsyncTask; import android.os.Handler; import android.os.Trace; Loading @@ -33,7 +37,6 @@ import android.view.Display; import android.view.DisplayInfo; import android.view.Surface; import android.view.SurfaceHolder; import android.view.WindowManager; import com.android.internal.annotations.VisibleForTesting; Loading Loading @@ -94,7 +97,7 @@ public class ImageWallpaper extends WallpaperService { float mYOffset = 0f; float mScale = 1f; private Display mDefaultDisplay; private Display mDisplay; private final DisplayInfo mTmpDisplayInfo = new DisplayInfo(); boolean mVisible = true; Loading Loading @@ -138,10 +141,20 @@ public class ImageWallpaper extends WallpaperService { super.onCreate(surfaceHolder); //noinspection ConstantConditions mDefaultDisplay = getSystemService(WindowManager.class).getDefaultDisplay(); final Context displayContext = getDisplayContext(); final int displayId = displayContext == null ? DEFAULT_DISPLAY : displayContext.getDisplayId(); DisplayManager dm = getSystemService(DisplayManager.class); if (dm != null) { mDisplay = dm.getDisplay(displayId); if (mDisplay == null) { Log.e(TAG, "Cannot find display! Fallback to default."); mDisplay = dm.getDisplay(DEFAULT_DISPLAY); } } setOffsetNotificationsEnabled(false); updateSurfaceSize(surfaceHolder, getDefaultDisplayInfo(), false /* forDraw */); updateSurfaceSize(surfaceHolder, getDisplayInfo(), false /* forDraw */); } @Override Loading @@ -165,9 +178,26 @@ public class ImageWallpaper extends WallpaperService { hasWallpaper = false; } // Set surface size equal to bitmap size, prevent memory waste int surfaceWidth = Math.max(MIN_BACKGROUND_WIDTH, mBackgroundWidth); int surfaceHeight = Math.max(MIN_BACKGROUND_HEIGHT, mBackgroundHeight); // Expected surface size. int surfaceWidth = Math.max(displayInfo.logicalWidth, mBackgroundWidth); int surfaceHeight = Math.max(displayInfo.logicalHeight, mBackgroundHeight); // Calculate the minimum drawing area of the surface, which saves memory and does not // distort the image. final float scale = Math.min( (float) mBackgroundHeight / (float) surfaceHeight, (float) mBackgroundWidth / (float) surfaceWidth); surfaceHeight = (int) (scale * surfaceHeight); surfaceWidth = (int) (scale * surfaceWidth); // Set surface size to at least MIN size. if (surfaceWidth < MIN_BACKGROUND_WIDTH || surfaceHeight < MIN_BACKGROUND_HEIGHT) { final float scaleUp = Math.max( (float) MIN_BACKGROUND_WIDTH / (float) surfaceWidth, (float) MIN_BACKGROUND_HEIGHT / (float) surfaceHeight); surfaceWidth = (int) ((float) surfaceWidth * scaleUp); surfaceHeight = (int) ((float) surfaceHeight * scaleUp); } // Used a fixed size surface, because we are special. We can do // this because we know the current design of window animations doesn't Loading Loading @@ -267,8 +297,8 @@ public class ImageWallpaper extends WallpaperService { } @VisibleForTesting DisplayInfo getDefaultDisplayInfo() { mDefaultDisplay.getDisplayInfo(mTmpDisplayInfo); DisplayInfo getDisplayInfo() { mDisplay.getDisplayInfo(mTmpDisplayInfo); return mTmpDisplayInfo; } Loading @@ -278,7 +308,7 @@ public class ImageWallpaper extends WallpaperService { } try { Trace.traceBegin(Trace.TRACE_TAG_VIEW, "drawWallpaper"); DisplayInfo displayInfo = getDefaultDisplayInfo(); DisplayInfo displayInfo = getDisplayInfo(); int newRotation = displayInfo.rotation; // Sometimes a wallpaper is not large enough to cover the screen in one dimension. Loading Loading @@ -445,7 +475,7 @@ public class ImageWallpaper extends WallpaperService { if (DEBUG) { Log.d(TAG, "Wallpaper loaded: " + mBackground); } updateSurfaceSize(getSurfaceHolder(), getDefaultDisplayInfo(), updateSurfaceSize(getSurfaceHolder(), getDisplayInfo(), false /* forDraw */); } Loading
packages/SystemUI/tests/src/com/android/systemui/ImageWallpaperTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ public class ImageWallpaperTest extends SysuiTestCase { public Engine onCreateEngine() { return new DrawableEngine() { @Override DisplayInfo getDefaultDisplayInfo() { DisplayInfo getDisplayInfo() { return mDisplayInfo; } Loading