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

Commit e1070928 authored by Adam Powell's avatar Adam Powell Committed by Android Git Automerger
Browse files

am 50d7bfd8: DO NOT MERGE Refactoring of fitSystemWindows to applyWindowInsets for views

* commit '50d7bfd8':
  DO NOT MERGE Refactoring of fitSystemWindows to applyWindowInsets for views
parents 99c3605c 50d7bfd8
Loading
Loading
Loading
Loading
+31 −2
Original line number Diff line number Diff line
@@ -27751,6 +27751,7 @@ package android.view {
    method public android.view.accessibility.AccessibilityNodeInfo createAccessibilityNodeInfo();
    method public void createContextMenu(android.view.ContextMenu);
    method public void destroyDrawingCache();
    method public android.view.WindowInsets dispatchApplyWindowInsets(android.view.WindowInsets);
    method public void dispatchConfigurationChanged(android.content.res.Configuration);
    method public void dispatchDisplayHint(int);
    method public boolean dispatchDragEvent(android.view.DragEvent);
@@ -27782,7 +27783,7 @@ package android.view {
    method public final android.view.View findViewById(int);
    method public final android.view.View findViewWithTag(java.lang.Object);
    method public void findViewsWithText(java.util.ArrayList<android.view.View>, java.lang.CharSequence, int);
    method protected boolean fitSystemWindows(android.graphics.Rect);
    method protected deprecated boolean fitSystemWindows(android.graphics.Rect);
    method public android.view.View focusSearch(int);
    method public void forceLayout();
    method public static int generateViewId();
@@ -27964,6 +27965,7 @@ package android.view {
    method public void offsetTopAndBottom(int);
    method protected void onAnimationEnd();
    method protected void onAnimationStart();
    method public android.view.WindowInsets onApplyWindowInsets(android.view.WindowInsets);
    method protected void onAttachedToWindow();
    method public void onCancelPendingInputEvents();
    method public boolean onCheckIsTextEditor();
@@ -28030,7 +28032,8 @@ package android.view {
    method public boolean removeCallbacks(java.lang.Runnable);
    method public void removeOnAttachStateChangeListener(android.view.View.OnAttachStateChangeListener);
    method public void removeOnLayoutChangeListener(android.view.View.OnLayoutChangeListener);
    method public void requestFitSystemWindows();
    method public void requestApplyInsets();
    method public deprecated void requestFitSystemWindows();
    method public final boolean requestFocus();
    method public final boolean requestFocus(int);
    method public boolean requestFocus(int, android.graphics.Rect);
@@ -28094,6 +28097,7 @@ package android.view {
    method public void setNextFocusLeftId(int);
    method public void setNextFocusRightId(int);
    method public void setNextFocusUpId(int);
    method public void setOnApplyWindowInsetsListener(android.view.View.OnApplyWindowInsetsListener);
    method public void setOnClickListener(android.view.View.OnClickListener);
    method public void setOnCreateContextMenuListener(android.view.View.OnCreateContextMenuListener);
    method public void setOnDragListener(android.view.View.OnDragListener);
@@ -28312,6 +28316,10 @@ package android.view {
    field public static final int UNSPECIFIED = 0; // 0x0
  }
  public static abstract interface View.OnApplyWindowInsetsListener {
    method public abstract android.view.WindowInsets onApplyWindowInsets(android.view.View, android.view.WindowInsets);
  }
  public static abstract interface View.OnAttachStateChangeListener {
    method public abstract void onViewAttachedToWindow(android.view.View);
    method public abstract void onViewDetachedFromWindow(android.view.View);
@@ -28921,6 +28929,27 @@ package android.view {
    method public abstract void onFocusLost(android.view.WindowId);
  }
  public class WindowInsets {
    ctor public WindowInsets(android.view.WindowInsets);
    method public android.view.WindowInsets cloneWithSystemWindowInsets(int, int, int, int);
    method public android.view.WindowInsets cloneWithSystemWindowInsetsConsumed();
    method public android.view.WindowInsets cloneWithSystemWindowInsetsConsumed(boolean, boolean, boolean, boolean);
    method public android.view.WindowInsets cloneWithWindowDecorInsets(int, int, int, int);
    method public android.view.WindowInsets cloneWithWindowDecorInsetsConsumed();
    method public android.view.WindowInsets cloneWithWindowDecorInsetsConsumed(boolean, boolean, boolean, boolean);
    method public int getSystemWindowInsetBottom();
    method public int getSystemWindowInsetLeft();
    method public int getSystemWindowInsetRight();
    method public int getSystemWindowInsetTop();
    method public int getWindowDecorInsetBottom();
    method public int getWindowDecorInsetLeft();
    method public int getWindowDecorInsetRight();
    method public int getWindowDecorInsetTop();
    method public boolean hasInsets();
    method public boolean hasSystemWindowInsets();
    method public boolean hasWindowDecorInsets();
  }
  public abstract interface WindowManager implements android.view.ViewManager {
    method public abstract android.view.Display getDefaultDisplay();
    method public abstract void removeViewImmediate(android.view.View);
+159 −0
Original line number Diff line number Diff line
@@ -2269,6 +2269,16 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    static final int PFLAG3_CALLED_SUPER = 0x10;
    /**
     * Flag indicating that we're in the process of applying window insets.
     */
    static final int PFLAG3_APPLYING_INSETS = 0x40;
    /**
     * Flag indicating that we're in the process of fitting system windows using the old method.
     */
    static final int PFLAG3_FITTING_SYSTEM_WINDOWS = 0x80;
    /* End of masks for mPrivateFlags3 */
    static final int DRAG_MASK = PFLAG2_DRAG_CAN_ACCEPT | PFLAG2_DRAG_HOVERED;
@@ -3178,6 +3188,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        private OnDragListener mOnDragListener;
        private OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener;
        OnApplyWindowInsetsListener mOnApplyWindowInsetsListener;
    }
    ListenerInfo mListenerInfo;
@@ -5903,8 +5915,31 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * @see #getFitsSystemWindows()
     * @see #setFitsSystemWindows(boolean) 
     * @see #setSystemUiVisibility(int)
     *
     * @deprecated As of API XX use {@link #dispatchApplyWindowInsets(WindowInsets)} to apply
     * insets to views. Views should override {@link #onApplyWindowInsets(WindowInsets)} or use
     * {@link #setOnApplyWindowInsetsListener(android.view.View.OnApplyWindowInsetsListener)}
     * to implement handling their own insets.
     */
    protected boolean fitSystemWindows(Rect insets) {
        if ((mPrivateFlags3 & PFLAG3_APPLYING_INSETS) == 0) {
            // If we're not in the process of dispatching the newer apply insets call,
            // that means we're not in the compatibility path. Dispatch into the newer
            // apply insets path and take things from there.
            try {
                mPrivateFlags3 |= PFLAG3_FITTING_SYSTEM_WINDOWS;
                return !dispatchApplyWindowInsets(new WindowInsets(insets)).hasInsets();
            } finally {
                mPrivateFlags3 &= PFLAG3_FITTING_SYSTEM_WINDOWS;
            }
        } else {
            // We're being called from the newer apply insets path.
            // Perform the standard fallback behavior.
            return fitSystemWindowsInt(insets);
        }
    }
    private boolean fitSystemWindowsInt(Rect insets) {
        if ((mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS) {
            mUserPaddingStart = UNDEFINED_PADDING;
            mUserPaddingEnd = UNDEFINED_PADDING;
@@ -5923,6 +5958,97 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        return false;
    }
    /**
     * Called when the view should apply {@link WindowInsets} according to its internal policy.
     *
     * <p>This method should be overridden by views that wish to apply a policy different from or
     * in addition to the default behavior. Clients that wish to force a view subtree
     * to apply insets should call {@link #dispatchApplyWindowInsets(WindowInsets)}.</p>
     *
     * <p>Clients may supply an {@link OnApplyWindowInsetsListener} to a view. If one is set
     * it will be called during dispatch instead of this method. The listener may optionally
     * call this method from its own implementation if it wishes to apply the view's default
     * insets policy in addition to its own.</p>
     *
     * <p>Implementations of this method should either return the insets parameter unchanged
     * or a new {@link WindowInsets} cloned from the supplied insets with any insets consumed
     * that this view applied itself. This allows new inset types added in future platform
     * versions to pass through existing implementations unchanged without being erroneously
     * consumed.</p>
     *
     * <p>By default if a view's {@link #setFitsSystemWindows(boolean) fitsSystemWindows}
     * property is set then the view will consume the system window insets and apply them
     * as padding for the view.</p>
     *
     * @param insets Insets to apply
     * @return The supplied insets with any applied insets consumed
     */
    public WindowInsets onApplyWindowInsets(WindowInsets insets) {
        if ((mPrivateFlags3 & PFLAG3_FITTING_SYSTEM_WINDOWS) == 0) {
            // We weren't called from within a direct call to fitSystemWindows,
            // call into it as a fallback in case we're in a class that overrides it
            // and has logic to perform.
            if (fitSystemWindows(insets.getSystemWindowInsets())) {
                return insets.cloneWithSystemWindowInsetsConsumed();
            }
        } else {
            // We were called from within a direct call to fitSystemWindows.
            if (fitSystemWindowsInt(insets.getSystemWindowInsets())) {
                return insets.cloneWithSystemWindowInsetsConsumed();
            }
        }
        return insets;
    }
    /**
     * Set an {@link OnApplyWindowInsetsListener} to take over the policy for applying
     * window insets to this view. The listener's
     * {@link OnApplyWindowInsetsListener#onApplyWindowInsets(View, WindowInsets) onApplyWindowInsets}
     * method will be called instead of the view's
     * {@link #onApplyWindowInsets(WindowInsets) onApplyWindowInsets} method.
     *
     * @param listener Listener to set
     *
     * @see #onApplyWindowInsets(WindowInsets)
     */
    public void setOnApplyWindowInsetsListener(OnApplyWindowInsetsListener listener) {
        getListenerInfo().mOnApplyWindowInsetsListener = listener;
    }
    /**
     * Request to apply the given window insets to this view or another view in its subtree.
     *
     * <p>This method should be called by clients wishing to apply insets corresponding to areas
     * obscured by window decorations or overlays. This can include the status and navigation bars,
     * action bars, input methods and more. New inset categories may be added in the future.
     * The method returns the insets provided minus any that were applied by this view or its
     * children.</p>
     *
     * <p>Clients wishing to provide custom behavior should override the
     * {@link #onApplyWindowInsets(WindowInsets)} method or alternatively provide a
     * {@link OnApplyWindowInsetsListener} via the
     * {@link #setOnApplyWindowInsetsListener(View.OnApplyWindowInsetsListener) setOnApplyWindowInsetsListener}
     * method.</p>
     *
     * <p>This method replaces the older {@link #fitSystemWindows(Rect) fitSystemWindows} method.
     * </p>
     *
     * @param insets Insets to apply
     * @return The provided insets minus the insets that were consumed
     */
    public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) {
        try {
            mPrivateFlags3 |= PFLAG3_APPLYING_INSETS;
            if (mListenerInfo != null && mListenerInfo.mOnApplyWindowInsetsListener != null) {
                return mListenerInfo.mOnApplyWindowInsetsListener.onApplyWindowInsets(this, insets);
            } else {
                return onApplyWindowInsets(insets);
            }
        } finally {
            mPrivateFlags3 &= ~PFLAG3_APPLYING_INSETS;
        }
    }
    /**
     * @hide Compute the insets that should be consumed by this view and the ones
     * that should propagate to those under it.
@@ -5995,6 +6121,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    /**
     * Ask that a new dispatch of {@link #fitSystemWindows(Rect)} be performed.
     * @deprecated Use {@link #requestApplyInsets()} for newer platform versions.
     */
    public void requestFitSystemWindows() {
        if (mParent != null) {
@@ -6002,6 +6129,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        }
    }
    /**
     * Ask that a new dispatch of {@link #onApplyWindowInsets(WindowInsets)} be performed.
     */
    public void requestApplyInsets() {
        requestFitSystemWindows();
    }
    /**
     * For use by PhoneWindow to make its own system window fitting optional.
     * @hide
@@ -18668,6 +18802,31 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        public void onViewDetachedFromWindow(View v);
    }
    /**
     * Listener for applying window insets on a view in a custom way.
     *
     * <p>Apps may choose to implement this interface if they want to apply custom policy
     * to the way that window insets are treated for a view. If an OnApplyWindowInsetsListener
     * is set, its
     * {@link OnApplyWindowInsetsListener#onApplyWindowInsets(View, WindowInsets) onApplyWindowInsets}
     * method will be called instead of the View's own
     * {@link #onApplyWindowInsets(WindowInsets) onApplyWindowInsets} method. The listener
     * may optionally call the parameter View's <code>onApplyWindowInsets</code> method to apply
     * the View's normal behavior as part of its own.</p>
     */
    public interface OnApplyWindowInsetsListener {
        /**
         * When {@link View#setOnApplyWindowInsetsListener(View.OnApplyWindowInsetsListener) set}
         * on a View, this listener method will be called instead of the view's own
         * {@link View#onApplyWindowInsets(WindowInsets) onApplyWindowInsets} method.
         *
         * @param v The view applying window insets
         * @param insets The insets to apply
         * @return The insets supplied, minus any insets that were consumed
         */
        public WindowInsets onApplyWindowInsets(View v, WindowInsets insets);
    }
    private final class UnsetPressedState implements Runnable {
        public void run() {
            setPressed(false);
+7 −9
Original line number Diff line number Diff line
@@ -5429,21 +5429,19 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        }
    }


    @Override
    protected boolean fitSystemWindows(Rect insets) {
        boolean done = super.fitSystemWindows(insets);
        if (!done) {
            final int count = mChildrenCount;
            final View[] children = mChildren;
    public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) {
        insets = super.dispatchApplyWindowInsets(insets);
        if (insets.hasInsets()) {
            final int count = getChildCount();
            for (int i = 0; i < count; i++) {
                done = children[i].fitSystemWindows(insets);
                if (done) {
                insets = getChildAt(i).dispatchApplyWindowInsets(insets);
                if (!insets.hasInsets()) {
                    break;
                }
            }
        }
        return done;
        return insets;
    }

    /**
+278 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package android.view;

import android.graphics.Rect;

/**
 * Describes a set of insets for window content.
 *
 * <p>WindowInsets are immutable and may be expanded to include more inset types in the future.
 * To adjust insets, use one of the supplied clone methods to obtain a new WindowInsets instance
 * with the adjusted properties.</p>
 *
 * @see View.OnApplyWindowInsetsListener
 * @see View#onApplyWindowInsets(WindowInsets)
 */
public class WindowInsets {
    private Rect mSystemWindowInsets;
    private Rect mWindowDecorInsets;
    private Rect mTempRect;

    private static final Rect EMPTY_RECT = new Rect(0, 0, 0, 0);

    /**
     * Since new insets may be added in the future that existing apps couldn't
     * know about, this fully empty constant shouldn't be made available to apps
     * since it would allow them to inadvertently consume unknown insets by returning it.
     * @hide
     */
    public static final WindowInsets EMPTY = new WindowInsets(EMPTY_RECT, EMPTY_RECT);

    /** @hide */
    public WindowInsets(Rect systemWindowInsets, Rect windowDecorInsets) {
        mSystemWindowInsets = systemWindowInsets;
        mWindowDecorInsets = windowDecorInsets;
    }

    /**
     * Construct a new WindowInsets, copying all values from a source WindowInsets.
     *
     * @param src Source to copy insets from
     */
    public WindowInsets(WindowInsets src) {
        mSystemWindowInsets = src.mSystemWindowInsets;
        mWindowDecorInsets = src.mWindowDecorInsets;
    }

    /** @hide */
    public WindowInsets(Rect systemWindowInsets) {
        mSystemWindowInsets = systemWindowInsets;
        mWindowDecorInsets = EMPTY_RECT;
    }

    /**
     * Used to provide a safe copy of the system window insets to pass through
     * to the existing fitSystemWindows method and other similar internals.
     * @hide
     */
    public Rect getSystemWindowInsets() {
        if (mTempRect == null) {
            mTempRect = new Rect();
        }
        mTempRect.set(mSystemWindowInsets);
        return mTempRect;
    }

    /**
     * Returns the left system window inset in pixels.
     *
     * <p>The system window inset represents the area of a full-screen window that is
     * partially or fully obscured by the status bar, navigation bar, IME or other system windows.
     * </p>
     *
     * @return The left system window inset
     */
    public int getSystemWindowInsetLeft() {
        return mSystemWindowInsets.left;
    }

    /**
     * Returns the top system window inset in pixels.
     *
     * <p>The system window inset represents the area of a full-screen window that is
     * partially or fully obscured by the status bar, navigation bar, IME or other system windows.
     * </p>
     *
     * @return The top system window inset
     */
    public int getSystemWindowInsetTop() {
        return mSystemWindowInsets.top;
    }

    /**
     * Returns the right system window inset in pixels.
     *
     * <p>The system window inset represents the area of a full-screen window that is
     * partially or fully obscured by the status bar, navigation bar, IME or other system windows.
     * </p>
     *
     * @return The right system window inset
     */
    public int getSystemWindowInsetRight() {
        return mSystemWindowInsets.right;
    }

    /**
     * Returns the bottom system window inset in pixels.
     *
     * <p>The system window inset represents the area of a full-screen window that is
     * partially or fully obscured by the status bar, navigation bar, IME or other system windows.
     * </p>
     *
     * @return The bottom system window inset
     */
    public int getSystemWindowInsetBottom() {
        return mSystemWindowInsets.bottom;
    }

    /**
     * Returns the left window decor inset in pixels.
     *
     * <p>The window decor inset represents the area of the window content area that is
     * partially or fully obscured by decorations within the window provided by the framework.
     * This can include action bars, title bars, toolbars, etc.</p>
     *
     * @return The left window decor inset
     */
    public int getWindowDecorInsetLeft() {
        return mWindowDecorInsets.left;
    }

    /**
     * Returns the top window decor inset in pixels.
     *
     * <p>The window decor inset represents the area of the window content area that is
     * partially or fully obscured by decorations within the window provided by the framework.
     * This can include action bars, title bars, toolbars, etc.</p>
     *
     * @return The top window decor inset
     */
    public int getWindowDecorInsetTop() {
        return mWindowDecorInsets.top;
    }

    /**
     * Returns the right window decor inset in pixels.
     *
     * <p>The window decor inset represents the area of the window content area that is
     * partially or fully obscured by decorations within the window provided by the framework.
     * This can include action bars, title bars, toolbars, etc.</p>
     *
     * @return The right window decor inset
     */
    public int getWindowDecorInsetRight() {
        return mWindowDecorInsets.right;
    }

    /**
     * Returns the bottom window decor inset in pixels.
     *
     * <p>The window decor inset represents the area of the window content area that is
     * partially or fully obscured by decorations within the window provided by the framework.
     * This can include action bars, title bars, toolbars, etc.</p>
     *
     * @return The bottom window decor inset
     */
    public int getWindowDecorInsetBottom() {
        return mWindowDecorInsets.bottom;
    }

    /**
     * Returns true if this WindowInsets has nonzero system window insets.
     *
     * <p>The system window inset represents the area of a full-screen window that is
     * partially or fully obscured by the status bar, navigation bar, IME or other system windows.
     * </p>
     *
     * @return true if any of the system window inset values are nonzero
     */
    public boolean hasSystemWindowInsets() {
        return mSystemWindowInsets.left != 0 || mSystemWindowInsets.top != 0 ||
                mSystemWindowInsets.right != 0 || mSystemWindowInsets.bottom != 0;
    }

    /**
     * Returns true if this WindowInsets has nonzero window decor insets.
     *
     * <p>The window decor inset represents the area of the window content area that is
     * partially or fully obscured by decorations within the window provided by the framework.
     * This can include action bars, title bars, toolbars, etc.</p>
     *
     * @return true if any of the window decor inset values are nonzero
     */
    public boolean hasWindowDecorInsets() {
        return mWindowDecorInsets.left != 0 || mWindowDecorInsets.top != 0 ||
                mWindowDecorInsets.right != 0 || mWindowDecorInsets.bottom != 0;
    }

    /**
     * Returns true if this WindowInsets has any nonzero insets.
     *
     * @return true if any inset values are nonzero
     */
    public boolean hasInsets() {
        return hasSystemWindowInsets() || hasWindowDecorInsets();
    }

    public WindowInsets cloneWithSystemWindowInsetsConsumed() {
        final WindowInsets result = new WindowInsets(this);
        result.mSystemWindowInsets = new Rect(0, 0, 0, 0);
        return result;
    }

    public WindowInsets cloneWithSystemWindowInsetsConsumed(boolean left, boolean top,
            boolean right, boolean bottom) {
        if (left || top || right || bottom) {
            final WindowInsets result = new WindowInsets(this);
            result.mSystemWindowInsets = new Rect(left ? 0 : mSystemWindowInsets.left,
                    top ? 0 : mSystemWindowInsets.top,
                    right ? 0 : mSystemWindowInsets.right,
                    bottom ? 0 : mSystemWindowInsets.bottom);
            return result;
        }
        return this;
    }

    public WindowInsets cloneWithSystemWindowInsets(int left, int top, int right, int bottom) {
        final WindowInsets result = new WindowInsets(this);
        result.mSystemWindowInsets = new Rect(left, top, right, bottom);
        return result;
    }

    public WindowInsets cloneWithWindowDecorInsetsConsumed() {
        final WindowInsets result = new WindowInsets(this);
        result.mWindowDecorInsets.set(0, 0, 0, 0);
        return result;
    }

    public WindowInsets cloneWithWindowDecorInsetsConsumed(boolean left, boolean top,
            boolean right, boolean bottom) {
        if (left || top || right || bottom) {
            final WindowInsets result = new WindowInsets(this);
            result.mWindowDecorInsets = new Rect(left ? 0 : mWindowDecorInsets.left,
                    top ? 0 : mWindowDecorInsets.top,
                    right ? 0 : mWindowDecorInsets.right,
                    bottom ? 0 : mWindowDecorInsets.bottom);
            return result;
        }
        return this;
    }

    public WindowInsets cloneWithWindowDecorInsets(int left, int top, int right, int bottom) {
        final WindowInsets result = new WindowInsets(this);
        result.mWindowDecorInsets = new Rect(left, top, right, bottom);
        return result;
    }

    @Override
    public String toString() {
        return "WindowInsets{systemWindowInsets=" + mSystemWindowInsets + " windowDecorInsets=" +
                mWindowDecorInsets + "}";
    }
}
+11 −9

File changed.

Preview size limit exceeded, changes collapsed.