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

Commit 50eb3b9b authored by Jeff Brown's avatar Jeff Brown Committed by Android (Google) Code Review
Browse files

Merge "Encapsulate the ViewRootImpl's handler."

parents 101d5aad a175a5b7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -384,7 +384,7 @@ public class SurfaceView extends View {
        if (!mHaveFrame) {
            return;
        }
        ViewRootImpl viewRoot = (ViewRootImpl) getRootView().getParent();
        ViewRootImpl viewRoot = getViewRootImpl();
        if (viewRoot != null) {
            mTranslator = viewRoot.mTranslator;
        }
+36 −54
Original line number Diff line number Diff line
@@ -5442,12 +5442,6 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
        return true;
    }
    /** Gets the ViewAncestor, or null if not attached. */
    /*package*/ ViewRootImpl getViewRootImpl() {
        View root = getRootView();
        return root != null ? (ViewRootImpl)root.getParent() : null;
    }
    /**
     * Call this to try to give focus to a specific view or to one of its descendants. This is a
     * special variant of {@link #requestFocus() } that will allow views that are not focuable in
@@ -8684,6 +8678,18 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
        return null;
    }
    /**
     * Gets the view root associated with the View.
     * @return The view root, or null if none.
     * @hide
     */
    public ViewRootImpl getViewRootImpl() {
        if (mAttachInfo != null) {
            return mAttachInfo.mViewRootImpl;
        }
        return null;
    }
    /**
     * <p>Causes the Runnable to be added to the message queue.
     * The runnable will be run on the user interface thread.</p>
@@ -8698,19 +8704,15 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
     *         looper processing the message queue is exiting.
     */
    public boolean post(Runnable action) {
        Handler handler;
        AttachInfo attachInfo = mAttachInfo;
        final AttachInfo attachInfo = mAttachInfo;
        if (attachInfo != null) {
            handler = attachInfo.mHandler;
        } else {
            return attachInfo.mHandler.post(action);
        }
        // Assume that post will succeed later
        ViewRootImpl.getRunQueue().post(action);
        return true;
    }
        return handler.post(action);
    }
    /**
     * <p>Causes the Runnable to be added to the message queue, to be run
     * after the specified amount of time elapses.
@@ -8731,19 +8733,15 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
     *         occurs then the message will be dropped.
     */
    public boolean postDelayed(Runnable action, long delayMillis) {
        Handler handler;
        AttachInfo attachInfo = mAttachInfo;
        final AttachInfo attachInfo = mAttachInfo;
        if (attachInfo != null) {
            handler = attachInfo.mHandler;
        } else {
            return attachInfo.mHandler.postDelayed(action, delayMillis);
        }
        // Assume that post will succeed later
        ViewRootImpl.getRunQueue().postDelayed(action, delayMillis);
        return true;
    }
        return handler.postDelayed(action, delayMillis);
    }
    /**
     * <p>Removes the specified Runnable from the message queue.</p>
     * 
@@ -8758,17 +8756,13 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
     *         (for instance, if the Runnable was not in the queue already.)
     */
    public boolean removeCallbacks(Runnable action) {
        Handler handler;
        AttachInfo attachInfo = mAttachInfo;
        final AttachInfo attachInfo = mAttachInfo;
        if (attachInfo != null) {
            handler = attachInfo.mHandler;
            attachInfo.mHandler.removeCallbacks(action);
        } else {
            // Assume that post will succeed later
            ViewRootImpl.getRunQueue().removeCallbacks(action);
            return true;
        }
        handler.removeCallbacks(action);
        return true;
    }
@@ -8817,12 +8811,9 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
    public void postInvalidateDelayed(long delayMilliseconds) {
        // We try only with the AttachInfo because there's no point in invalidating
        // if we are not attached to our window
        AttachInfo attachInfo = mAttachInfo;
        final AttachInfo attachInfo = mAttachInfo;
        if (attachInfo != null) {
            Message msg = Message.obtain();
            msg.what = AttachInfo.INVALIDATE_MSG;
            msg.obj = this;
            attachInfo.mHandler.sendMessageDelayed(msg, delayMilliseconds);
            attachInfo.mViewRootImpl.dispatchInvalidateDelayed(this, delayMilliseconds);
        }
    }
@@ -8845,7 +8836,7 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
        // We try only with the AttachInfo because there's no point in invalidating
        // if we are not attached to our window
        AttachInfo attachInfo = mAttachInfo;
        final AttachInfo attachInfo = mAttachInfo;
        if (attachInfo != null) {
            final AttachInfo.InvalidateInfo info = AttachInfo.InvalidateInfo.acquire();
            info.target = this;
@@ -8854,10 +8845,7 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
            info.right = right;
            info.bottom = bottom;
            final Message msg = Message.obtain();
            msg.what = AttachInfo.INVALIDATE_RECT_MSG;
            msg.obj = info;
            attachInfo.mHandler.sendMessageDelayed(msg, delayMilliseconds);
            attachInfo.mViewRootImpl.dispatchInvalidateRectDelayed(info, delayMilliseconds);
        }
    }
@@ -9702,7 +9690,7 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
        }
        if (mAttachInfo != null) {
            mAttachInfo.mHandler.removeMessages(AttachInfo.INVALIDATE_MSG, this);
            mAttachInfo.mViewRootImpl.cancelInvalidate(this);
        }
        mCurrentAnimation = null;
@@ -14991,22 +14979,15 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
        Canvas mCanvas;
        /**
         * A Handler supplied by a view's {@link android.view.ViewRootImpl}. This
         * handler can be used to pump events in the UI events queue.
         */
        final Handler mHandler;
        /**
         * Identifier for messages requesting the view to be invalidated.
         * Such messages should be sent to {@link #mHandler}.
         * The view root impl.
         */
        static final int INVALIDATE_MSG = 0x1;
        final ViewRootImpl mViewRootImpl;
        /**
         * Identifier for messages requesting the view to invalidate a region.
         * Such messages should be sent to {@link #mHandler}.
         * A Handler supplied by a view's {@link android.view.ViewRootImpl}. This
         * handler can be used to pump events in the UI events queue.
         */
        static final int INVALIDATE_RECT_MSG = 0x2;
        final Handler mHandler;
        /**
         * Temporary for use in computing invalidate rectangles while
@@ -15036,10 +15017,11 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
         * @param handler the events handler the view must use
         */
        AttachInfo(IWindowSession session, IWindow window,
                Handler handler, Callbacks effectPlayer) {
                ViewRootImpl viewRootImpl, Handler handler, Callbacks effectPlayer) {
            mSession = session;
            mWindow = window;
            mWindowToken = window.asBinder();
            mViewRootImpl = viewRootImpl;
            mHandler = handler;
            mRootCallbacks = effectPlayer;
        }
+6 −6
Original line number Diff line number Diff line
@@ -375,7 +375,7 @@ public class ViewDebug {
    }

    private static BufferedWriter sHierarchyTraces;
    private static ViewRootImpl sHierarhcyRoot;
    private static ViewRootImpl sHierarchyRoot;
    private static String sHierarchyTracePrefix;

    /**
@@ -855,7 +855,7 @@ public class ViewDebug {
            return;
        }

        if (sHierarhcyRoot != null) {
        if (sHierarchyRoot != null) {
            throw new IllegalStateException("You must call stopHierarchyTracing() before running" +
                " a new trace!");
        }
@@ -874,7 +874,7 @@ public class ViewDebug {
            return;
        }

        sHierarhcyRoot = (ViewRootImpl) view.getRootView().getParent();
        sHierarchyRoot = view.getViewRootImpl();
    }

    /**
@@ -896,7 +896,7 @@ public class ViewDebug {
            return;
        }

        if (sHierarhcyRoot == null || sHierarchyTraces == null) {
        if (sHierarchyRoot == null || sHierarchyTraces == null) {
            throw new IllegalStateException("You must call startHierarchyTracing() before" +
                " stopHierarchyTracing()!");
        }
@@ -921,7 +921,7 @@ public class ViewDebug {
            return;
        }

        View view = sHierarhcyRoot.getView();
        View view = sHierarchyRoot.getView();
        if (view instanceof ViewGroup) {
            ViewGroup group = (ViewGroup) view;
            dumpViewHierarchy(group, out, 0);
@@ -932,7 +932,7 @@ public class ViewDebug {
            }
        }

        sHierarhcyRoot = null;
        sHierarchyRoot = null;
    }

    static void dispatchCommand(View view, String command, String parameters,
+339 −301

File changed.

Preview size limit exceeded, changes collapsed.

+5 −6
Original line number Diff line number Diff line
@@ -497,15 +497,14 @@ public class BaseInputConnection implements InputConnection {
     */
    public boolean sendKeyEvent(KeyEvent event) {
        synchronized (mIMM.mH) {
            Handler h = mTargetView != null ? mTargetView.getHandler() : null;
            if (h == null) {
            ViewRootImpl viewRootImpl = mTargetView != null ? mTargetView.getViewRootImpl() : null;
            if (viewRootImpl == null) {
                if (mIMM.mServedView != null) {
                    h = mIMM.mServedView.getHandler();
                    viewRootImpl = mIMM.mServedView.getViewRootImpl();
                }
            }
            if (h != null) {
                h.sendMessage(h.obtainMessage(ViewRootImpl.DISPATCH_KEY_FROM_IME,
                        event));
            if (viewRootImpl != null) {
                viewRootImpl.dispatchKeyFromIme(event);
            }
        }
        return false;
Loading