Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7341d7a1 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

More work on wallpapers.

- Do better about figuring out when to stop them and other related window
  management.
- Fix problem where we were not redrawing the surface when the orientation
  changed.  This was the cause of the device hang.
parent 56e7ba29
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -60831,6 +60831,27 @@
<parameter name="srcName" type="java.lang.String">
</parameter>
</method>
<method name="createFromResourceStream"
 return="android.graphics.drawable.Drawable"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="res" type="android.content.res.Resources">
</parameter>
<parameter name="value" type="android.util.TypedValue">
</parameter>
<parameter name="is" type="java.io.InputStream">
</parameter>
<parameter name="srcName" type="java.lang.String">
</parameter>
<parameter name="opts" type="android.graphics.BitmapFactory.Options">
</parameter>
</method>
<method name="createFromStream"
 return="android.graphics.drawable.Drawable"
 abstract="false"
+3 −1
Original line number Diff line number Diff line
@@ -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.
+3 −1
Original line number Diff line number Diff line
@@ -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) {
+30 −4
Original line number Diff line number Diff line
@@ -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);
            }
+16 −10
Original line number Diff line number Diff line
@@ -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);
            }
        }
Loading