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

Commit 8df8b2b4 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Allow wallpapers to get touch events.

parent 948ee251
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -144050,6 +144050,19 @@
<parameter name="o" type="android.view.MotionEvent">
</parameter>
</method>
<method name="obtainNoHistory"
 return="android.view.MotionEvent"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="o" type="android.view.MotionEvent">
</parameter>
</method>
<method name="offsetLocation"
 return="void"
 abstract="false"
+73 −9
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.os.RemoteException;
import android.util.Log;
import android.view.Gravity;
import android.view.IWindowSession;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.View;
import android.view.ViewGroup;
@@ -59,6 +60,7 @@ public abstract class WallpaperService extends Service {
    private static final int MSG_VISIBILITY_CHANGED = 10010;
    private static final int MSG_WALLPAPER_OFFSETS = 10020;
    private static final int MSG_WINDOW_RESIZED = 10030;
    private static final int MSG_TOUCH_EVENT = 10040;
    
    /**
     * The actual implementation of a wallpaper.  A wallpaper service may
@@ -87,6 +89,8 @@ public abstract class WallpaperService extends Service {
        int mType;
        int mCurWidth;
        int mCurHeight;
        int mWindowFlags = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
        int mCurWindowFlags = mWindowFlags;
        boolean mDestroyReportNeeded;
        final Rect mVisibleInsets = new Rect();
        final Rect mWinFrame = new Rect();
@@ -100,6 +104,7 @@ public abstract class WallpaperService extends Service {
        boolean mOffsetMessageEnqueued;
        float mPendingXOffset;
        float mPendingYOffset;
        MotionEvent mPendingMove;
        
        final BaseSurfaceHolder mSurfaceHolder = new BaseSurfaceHolder() {

@@ -131,6 +136,27 @@ public abstract class WallpaperService extends Service {
        };
        
        final BaseIWindow mWindow = new BaseIWindow() {
            @Override
            public boolean onDispatchPointer(MotionEvent event, long eventTime,
                    boolean callWhenDone) {
                synchronized (mLock) {
                    if (event.getAction() == MotionEvent.ACTION_MOVE) {
                        if (mPendingMove != null) {
                            mCaller.removeMessages(MSG_TOUCH_EVENT, mPendingMove);
                            mPendingMove.recycle();
                        }
                        mPendingMove = event;
                    } else {
                        mPendingMove = null;
                    }
                    Message msg = mCaller.obtainMessageO(MSG_TOUCH_EVENT,
                            event);
                    mCaller.sendMessage(msg);
                }
                return false;
            }
            
            @Override
            public void resized(int w, int h, Rect coveredInsets,
                    Rect visibleInsets, boolean reportDraw) {
                Message msg = mCaller.obtainMessageI(MSG_WINDOW_RESIZED,
@@ -138,6 +164,7 @@ public abstract class WallpaperService extends Service {
                mCaller.sendMessage(msg);
            }
            
            @Override
            public void dispatchAppVisibility(boolean visible) {
                Message msg = mCaller.obtainMessageI(MSG_VISIBILITY_CHANGED,
                        visible ? 1 : 0);
@@ -184,6 +211,22 @@ public abstract class WallpaperService extends Service {
            return mIWallpaperEngine.mReqHeight;
        }
        
        /**
         * Control whether this wallpaper will receive raw touch events
         * from the window manager as the user interacts with the window
         * that is currently displaying the wallpaper.  By default they
         * are turned off.  If enabled, the events will be received in
         * {@link #onTouchEvent(MotionEvent)}.
         */
        public void setTouchEventsEnabled(boolean enabled) {
            mWindowFlags = enabled
                    ? (mWindowFlags&~WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
                    : (mWindowFlags|WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
            if (mCreated) {
                updateSurface(false);
            }
        }
        
        /**
         * Called once to initialize the engine.  After returning, the
         * engine's surface will be created by the framework.
@@ -207,6 +250,16 @@ public abstract class WallpaperService extends Service {
        public void onVisibilityChanged(boolean visible) {
        }
        
        /**
         * Called as the user performs touch-screen interaction with the
         * window that is currently showing this wallpaper.  Note that the
         * events you receive here are driven by the actual application the
         * user is interacting with, so if it is slow you will get viewer
         * move events.
         */
        public void onTouchEvent(MotionEvent event) {
        }
        
        /**
         * Called to inform you of the wallpaper's offsets changing
         * within its contain, corresponding to the container's
@@ -248,7 +301,9 @@ public abstract class WallpaperService extends Service {
            final boolean formatChanged = mFormat != mSurfaceHolder.getRequestedFormat();
            boolean sizeChanged = mWidth != myWidth || mHeight != myHeight;
            final boolean typeChanged = mType != mSurfaceHolder.getRequestedType();
            if (force || creating || formatChanged || sizeChanged || typeChanged) {
            final boolean flagsChanged = mCurWindowFlags != mWindowFlags;
            if (force || creating || formatChanged || sizeChanged || typeChanged
                    || flagsChanged) {

                if (DEBUG) Log.i(TAG, "Changes: creating=" + creating
                        + " format=" + formatChanged + " size=" + sizeChanged);
@@ -259,19 +314,18 @@ public abstract class WallpaperService extends Service {
                    mFormat = mSurfaceHolder.getRequestedFormat();
                    mType = mSurfaceHolder.getRequestedType();

                    // Scaling/Translate window's layout here because mLayout is not used elsewhere.
                    
                    // Places the window relative
                    mLayout.x = 0;
                    mLayout.y = 0;
                    mLayout.width = myWidth;
                    mLayout.height = myHeight;
                    
                    mLayout.format = mFormat;
                    mLayout.flags |=WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
                    
                    mCurWindowFlags = mWindowFlags;
                    mLayout.flags = mWindowFlags
                            | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
                            | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                            | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                                  | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                            ;

                    mLayout.memoryType = mType;
@@ -478,6 +532,16 @@ public abstract class WallpaperService extends Service {
                        }
                    }
                } break;
                case MSG_TOUCH_EVENT: {
                    MotionEvent ev = (MotionEvent)message.obj;
                    synchronized (mEngine.mLock) {
                        if (mEngine.mPendingMove == ev) {
                            mEngine.mPendingMove = null;
                        }
                    }
                    mEngine.onTouchEvent(ev);
                    ev.recycle();
                } break;
                default :
                    Log.w(TAG, "Unknown message type " + message.what);
            }
+2 −2
Original line number Diff line number Diff line
@@ -46,8 +46,8 @@ oneway interface IWindow {
    void resized(int w, int h, in Rect coveredInsets, in Rect visibleInsets,
            boolean reportDraw);
    void dispatchKey(in KeyEvent event);
    void dispatchPointer(in MotionEvent event, long eventTime);
    void dispatchTrackball(in MotionEvent event, long eventTime);
    void dispatchPointer(in MotionEvent event, long eventTime, boolean callWhenDone);
    void dispatchTrackball(in MotionEvent event, long eventTime, boolean callWhenDone);
    void dispatchAppVisibility(boolean visible);
    void dispatchGetNewSurface();

+38 −0
Original line number Diff line number Diff line
@@ -551,6 +551,44 @@ public final class MotionEvent implements Parcelable {
        return ev;
    }

    /**
     * Create a new MotionEvent, copying from an existing one, but not including
     * any historical point information.
     */
    static public MotionEvent obtainNoHistory(MotionEvent o) {
        MotionEvent ev = obtain();
        ev.mDeviceId = o.mDeviceId;
        ev.mEdgeFlags = o.mEdgeFlags;
        ev.mDownTime = o.mDownTime;
        ev.mEventTimeNano = o.mEventTimeNano;
        ev.mAction = o.mAction;
        ev.mNumPointers = o.mNumPointers;
        ev.mRawX = o.mRawX;
        ev.mRawY = o.mRawY;
        ev.mMetaState = o.mMetaState;
        ev.mXPrecision = o.mXPrecision;
        ev.mYPrecision = o.mYPrecision;
        
        ev.mNumSamples = 1;
        ev.mTimeSamples[0] = o.mTimeSamples[0];
        
        final int NP = (ev.mNumPointers=o.mNumPointers);
        if (ev.mPointerIdentifiers.length >= NP) {
            System.arraycopy(o.mPointerIdentifiers, 0, ev.mPointerIdentifiers, 0, NP);
        } else {
            ev.mPointerIdentifiers = (int[])o.mPointerIdentifiers.clone();
        }
        
        final int ND = NP * NUM_SAMPLE_DATA;
        if (ev.mDataSamples.length >= ND) {
            System.arraycopy(o.mDataSamples, 0, ev.mDataSamples, 0, ND);
        } else {
            ev.mDataSamples = (float[])o.mDataSamples.clone();
        }
        
        return ev;
    }

    /**
     * Recycle the MotionEvent, to be re-used by a later caller.  After calling
     * this function you must not ever touch the event again.
+4 −2
Original line number Diff line number Diff line
@@ -481,7 +481,8 @@ public class SurfaceView extends View {
            }
        }

        public void dispatchPointer(MotionEvent event, long eventTime) {
        public void dispatchPointer(MotionEvent event, long eventTime,
                boolean callWhenDone) {
            Log.w("SurfaceView", "Unexpected pointer event in surface: " + event);
            //if (mSession != null && mSurface != null) {
            //    try {
@@ -491,7 +492,8 @@ public class SurfaceView extends View {
            //}
        }

        public void dispatchTrackball(MotionEvent event, long eventTime) {
        public void dispatchTrackball(MotionEvent event, long eventTime,
                boolean callWhenDone) {
            Log.w("SurfaceView", "Unexpected trackball event in surface: " + event);
            //if (mSession != null && mSurface != null) {
            //    try {
Loading