am 1a797546: Merge change 21380 into eclair

Merge commit '1a797546d75d2c85d6fefeefdc55de051aa66018'

* commit '1a797546d75d2c85d6fefeefdc55de051aa66018':
  More work on wallpapers.
This commit is contained in:
Dianne Hackborn
2009-08-17 11:52:06 -07:00
committed by Android Git Automerger
9 changed files with 160 additions and 46 deletions

View File

@@ -28,6 +28,7 @@ import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;
import android.view.ViewRoot;
import java.io.FileOutputStream;
@@ -82,7 +83,8 @@ public class WallpaperManager {
try {
ParcelFileDescriptor fd = mService.getWallpaper(this);
if (fd != null) {
Bitmap bm = BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
Bitmap bm = BitmapFactory.decodeFileDescriptor(
fd.getFileDescriptor(), null, null);
if (bm != null) {
// For now clear the density until we figure out how
// to deal with it for wallpapers.

View File

@@ -23,6 +23,7 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import android.content.pm.ApplicationInfo;
import android.graphics.BitmapFactory;
import android.graphics.Movie;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ColorDrawable;
@@ -1707,7 +1708,8 @@ public class Resources {
InputStream is = mAssets.openNonAsset(
value.assetCookie, file, AssetManager.ACCESS_BUFFER);
// System.out.println("Opened file " + file + ": " + is);
dr = Drawable.createFromResourceStream(this, value, is, file);
dr = Drawable.createFromResourceStream(this, value, is,
file, null);
is.close();
// System.out.println("Created stream: " + dr);
} catch (Exception e) {

View File

@@ -58,6 +58,7 @@ public abstract class WallpaperService extends Service {
private static final int MSG_UPDATE_SURFACE = 10000;
private static final int MSG_VISIBILITY_CHANGED = 10010;
private static final int MSG_WALLPAPER_OFFSETS = 10020;
private static final int MSG_WINDOW_RESIZED = 10030;
/**
* The actual implementation of a wallpaper. A wallpaper service may
@@ -130,6 +131,13 @@ public abstract class WallpaperService extends Service {
};
final BaseIWindow mWindow = new BaseIWindow() {
public void resized(int w, int h, Rect coveredInsets,
Rect visibleInsets, boolean reportDraw) {
Message msg = mCaller.obtainMessageI(MSG_WINDOW_RESIZED,
reportDraw ? 1 : 0);
mCaller.sendMessage(msg);
}
public void dispatchAppVisibility(boolean visible) {
Message msg = mCaller.obtainMessageI(MSG_VISIBILITY_CHANGED,
visible ? 1 : 0);
@@ -238,7 +246,7 @@ public abstract class WallpaperService extends Service {
final boolean creating = !mCreated;
final boolean formatChanged = mFormat != mSurfaceHolder.getRequestedFormat();
final boolean sizeChanged = mWidth != myWidth || mHeight != myHeight;
boolean sizeChanged = mWidth != myWidth || mHeight != myHeight;
final boolean typeChanged = mType != mSurfaceHolder.getRequestedType();
if (force || creating || formatChanged || sizeChanged || typeChanged) {
@@ -286,8 +294,16 @@ public abstract class WallpaperService extends Service {
if (DEBUG) Log.i(TAG, "New surface: " + mSurfaceHolder.mSurface
+ ", frame=" + mWinFrame);
mCurWidth = mWinFrame.width();
mCurHeight = mWinFrame.height();
int w = mWinFrame.width();
if (mCurWidth != w) {
sizeChanged = true;
mCurWidth = w;
}
int h = mWinFrame.height();
if (mCurHeight != h) {
sizeChanged = true;
mCurHeight = h;
}
mSurfaceHolder.mSurfaceLock.unlock();
@@ -312,7 +328,7 @@ public abstract class WallpaperService extends Service {
}
}
}
if (creating || formatChanged || sizeChanged) {
if (force || creating || formatChanged || sizeChanged) {
onSurfaceChanged(mSurfaceHolder, mFormat,
mCurWidth, mCurHeight);
if (callbacks != null) {
@@ -452,6 +468,16 @@ public abstract class WallpaperService extends Service {
final int yPixels = availh > 0 ? -(int)(availh*yOffset+.5f) : 0;
mEngine.onOffsetsChanged(xOffset, yOffset, xPixels, yPixels);
} break;
case MSG_WINDOW_RESIZED: {
final boolean reportDraw = message.arg1 != 0;
mEngine.updateSurface(true);
if (reportDraw) {
try {
mEngine.mSession.finishDrawing(mEngine.mWindow);
} catch (RemoteException e) {
}
}
} break;
default :
Log.w(TAG, "Unknown message type " + message.what);
}

View File

@@ -67,8 +67,8 @@ public class ImageWallpaper extends WallpaperService {
private final Object mLock = new Object();
private final Rect mBounds = new Rect();
Drawable mBackground;
int mXOffset;
int mYOffset;
float mXOffset;
float mYOffset;
@Override
public void onCreate(SurfaceHolder surfaceHolder) {
@@ -85,8 +85,8 @@ public class ImageWallpaper extends WallpaperService {
@Override
public void onOffsetsChanged(float xOffset, float yOffset,
int xPixels, int yPixels) {
mXOffset = xPixels;
mYOffset = yPixels;
mXOffset = xOffset;
mYOffset = xOffset;
drawFrame();
}
@@ -110,11 +110,20 @@ public class ImageWallpaper extends WallpaperService {
SurfaceHolder sh = getSurfaceHolder();
Canvas c = sh.lockCanvas();
if (c != null) {
//final Rect frame = sh.getSurfaceFrame();
final Rect frame = sh.getSurfaceFrame();
synchronized (mLock) {
final Drawable background = mBackground;
//background.setBounds(frame);
c.translate(mXOffset, mYOffset);
final int dw = frame.width();
final int dh = frame.height();
final int bw = mBackground.getIntrinsicWidth();
final int bh = mBackground.getIntrinsicHeight();
final int availw = bw-dw;
final int availh = bh-dh;
int xPixels = availw > 0
? -(int)(availw*mXOffset+.5f) : -(int)(availw/2);
int yPixels = availh > 0
? -(int)(availh*mYOffset+.5f) : -(int)(availh/2);
c.translate(xPixels, yPixels);
c.drawColor(0xff000000);
background.draw(c);
}
@@ -128,9 +137,6 @@ public class ImageWallpaper extends WallpaperService {
mBounds.left = mBounds.top = 0;
mBounds.right = mBackground.getIntrinsicWidth();
mBounds.bottom = mBackground.getIntrinsicHeight();
int offx = (getDesiredMinimumWidth() - mBounds.right) / 2;
int offy = (getDesiredMinimumHeight() - mBounds.bottom) / 2;
mBounds.offset(offx, offy);
mBackground.setBounds(mBounds);
}
}