Merge "Fix LockscreenWallpaper panning" into nyc-dev

This commit is contained in:
Adrian Roos
2016-04-15 00:04:55 +00:00
committed by Android (Google) Code Review
2 changed files with 71 additions and 5 deletions

View File

@@ -21,8 +21,12 @@ import android.app.IWallpaperManager;
import android.app.IWallpaperManagerCallback; import android.app.IWallpaperManagerCallback;
import android.app.WallpaperManager; import android.app.WallpaperManager;
import android.content.Context; import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.DrawableWrapper;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
@@ -151,4 +155,57 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen
getBitmap(); getBitmap();
mBar.updateMediaMetaData(true /* metaDataChanged */, true /* allowEnterAnimation */); mBar.updateMediaMetaData(true /* metaDataChanged */, true /* allowEnterAnimation */);
} }
/**
* Drawable that aligns left horizontally and center vertically (like ImageWallpaper).
*/
public static class WallpaperDrawable extends DrawableWrapper {
private Bitmap mBackground;
private Rect mTmpRect = new Rect();
public WallpaperDrawable(Resources r, Bitmap b) {
super(new BitmapDrawable(r, b));
mBackground = b;
}
@Override
public int getIntrinsicWidth() {
return -1;
}
@Override
public int getIntrinsicHeight() {
return -1;
}
@Override
protected void onBoundsChange(Rect bounds) {
int vwidth = getBounds().width();
int vheight = getBounds().height();
int dwidth = mBackground.getWidth();
int dheight = mBackground.getHeight();
float scale;
float dx = 0, dy = 0;
if (dwidth * vheight > vwidth * dheight) {
scale = (float) vheight / (float) dheight;
} else {
scale = (float) vwidth / (float) dwidth;
}
if (scale <= 1f) {
scale = 1f;
}
dy = (vheight - dheight * scale) * 0.5f;
mTmpRect.set(
bounds.left,
bounds.top + Math.round(dy),
bounds.left + Math.round(dwidth * scale),
bounds.top + Math.round(dheight * scale + dy));
super.onBoundsChange(mTmpRect);
}
}
} }

View File

@@ -46,6 +46,7 @@ import android.graphics.PointF;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode; import android.graphics.PorterDuffXfermode;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.inputmethodservice.InputMethodService; import android.inputmethodservice.InputMethodService;
@@ -1928,19 +1929,27 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
+ " state=" + mState); + " state=" + mState);
} }
Bitmap artworkBitmap = null; Drawable artworkDrawable = null;
if (mMediaMetadata != null) { if (mMediaMetadata != null) {
Bitmap artworkBitmap = null;
artworkBitmap = mMediaMetadata.getBitmap(MediaMetadata.METADATA_KEY_ART); artworkBitmap = mMediaMetadata.getBitmap(MediaMetadata.METADATA_KEY_ART);
if (artworkBitmap == null) { if (artworkBitmap == null) {
artworkBitmap = mMediaMetadata.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART); artworkBitmap = mMediaMetadata.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART);
// might still be null // might still be null
} }
if (artworkBitmap != null) {
artworkDrawable = new BitmapDrawable(mBackdropBack.getResources(), artworkBitmap);
}
} }
if (ENABLE_LOCKSCREEN_WALLPAPER && artworkBitmap == null) { if (ENABLE_LOCKSCREEN_WALLPAPER && artworkDrawable == null) {
artworkBitmap = mLockscreenWallpaper.getBitmap(); Bitmap lockWallpaper = mLockscreenWallpaper.getBitmap();
if (lockWallpaper != null) {
artworkDrawable = new LockscreenWallpaper.WallpaperDrawable(
mBackdropBack.getResources(), lockWallpaper);
}
} }
final boolean hasArtwork = artworkBitmap != null; final boolean hasArtwork = artworkDrawable != null;
if ((hasArtwork || DEBUG_MEDIA_FAKE_ARTWORK) && mState != StatusBarState.SHADE if ((hasArtwork || DEBUG_MEDIA_FAKE_ARTWORK) && mState != StatusBarState.SHADE
&& mFingerprintUnlockController.getMode() && mFingerprintUnlockController.getMode()
@@ -1985,7 +1994,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
mBackdropBack.setBackgroundColor(0xFFFFFFFF); mBackdropBack.setBackgroundColor(0xFFFFFFFF);
mBackdropBack.setImageDrawable(new ColorDrawable(c)); mBackdropBack.setImageDrawable(new ColorDrawable(c));
} else { } else {
mBackdropBack.setImageBitmap(artworkBitmap); mBackdropBack.setImageDrawable(artworkDrawable);
} }
if (mScrimSrcModeEnabled) { if (mScrimSrcModeEnabled) {
mBackdropBack.getDrawable().mutate().setXfermode(mSrcXferMode); mBackdropBack.getDrawable().mutate().setXfermode(mSrcXferMode);