Merge "Fix NPE in WallpaperDrawable" into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
75db0392b8
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.systemui.statusbar.phone;
|
package com.android.systemui.statusbar.phone;
|
||||||
|
|
||||||
|
import android.annotation.Nullable;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.IWallpaperManager;
|
import android.app.IWallpaperManager;
|
||||||
import android.app.IWallpaperManagerCallback;
|
import android.app.IWallpaperManagerCallback;
|
||||||
@@ -26,6 +27,7 @@ import android.graphics.Bitmap;
|
|||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.DrawableWrapper;
|
import android.graphics.drawable.DrawableWrapper;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -209,12 +211,16 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen
|
|||||||
*/
|
*/
|
||||||
public static class WallpaperDrawable extends DrawableWrapper {
|
public static class WallpaperDrawable extends DrawableWrapper {
|
||||||
|
|
||||||
private Bitmap mBackground;
|
private final ConstantState mState;
|
||||||
private Rect mTmpRect = new Rect();
|
private final Rect mTmpRect = new Rect();
|
||||||
|
|
||||||
public WallpaperDrawable(Resources r, Bitmap b) {
|
public WallpaperDrawable(Resources r, Bitmap b) {
|
||||||
super(new BitmapDrawable(r, b));
|
this(r, new ConstantState(b));
|
||||||
mBackground = b;
|
}
|
||||||
|
|
||||||
|
private WallpaperDrawable(Resources r, ConstantState state) {
|
||||||
|
super(new BitmapDrawable(r, state.mBackground));
|
||||||
|
mState = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -231,8 +237,8 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen
|
|||||||
protected void onBoundsChange(Rect bounds) {
|
protected void onBoundsChange(Rect bounds) {
|
||||||
int vwidth = getBounds().width();
|
int vwidth = getBounds().width();
|
||||||
int vheight = getBounds().height();
|
int vheight = getBounds().height();
|
||||||
int dwidth = mBackground.getWidth();
|
int dwidth = mState.mBackground.getWidth();
|
||||||
int dheight = mBackground.getHeight();
|
int dheight = mState.mBackground.getHeight();
|
||||||
float scale;
|
float scale;
|
||||||
float dx = 0, dy = 0;
|
float dx = 0, dy = 0;
|
||||||
|
|
||||||
@@ -255,5 +261,35 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen
|
|||||||
|
|
||||||
super.onBoundsChange(mTmpRect);
|
super.onBoundsChange(mTmpRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConstantState getConstantState() {
|
||||||
|
return mState;
|
||||||
|
}
|
||||||
|
|
||||||
|
static class ConstantState extends Drawable.ConstantState {
|
||||||
|
|
||||||
|
private final Bitmap mBackground;
|
||||||
|
|
||||||
|
ConstantState(Bitmap background) {
|
||||||
|
mBackground = background;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Drawable newDrawable() {
|
||||||
|
return newDrawable(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Drawable newDrawable(@Nullable Resources res) {
|
||||||
|
return new WallpaperDrawable(res, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getChangingConfigurations() {
|
||||||
|
// DrawableWrapper already handles this for us.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2021,7 +2021,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
|
|||||||
if (metaDataChanged) {
|
if (metaDataChanged) {
|
||||||
if (mBackdropBack.getDrawable() != null) {
|
if (mBackdropBack.getDrawable() != null) {
|
||||||
Drawable drawable =
|
Drawable drawable =
|
||||||
mBackdropBack.getDrawable().getConstantState().newDrawable().mutate();
|
mBackdropBack.getDrawable().getConstantState()
|
||||||
|
.newDrawable(mBackdropFront.getResources()).mutate();
|
||||||
mBackdropFront.setImageDrawable(drawable);
|
mBackdropFront.setImageDrawable(drawable);
|
||||||
if (mScrimSrcModeEnabled) {
|
if (mScrimSrcModeEnabled) {
|
||||||
mBackdropFront.getDrawable().mutate().setXfermode(mSrcOverXferMode);
|
mBackdropFront.getDrawable().mutate().setXfermode(mSrcOverXferMode);
|
||||||
|
|||||||
Reference in New Issue
Block a user