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

Commit b36e4f94 authored by Adam Powell's avatar Adam Powell
Browse files

Add support for hiding action bars on scroll.

Also tweak the nested scrolling API around nested flings and fix a bug
where recursive nested scrolling would stop prematurely.

Change-Id: I561226db878b2493970440a6af3e2332c56a1913
parent b6ea9db4
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -598,6 +598,7 @@ package android {
    field public static final int headerBackground = 16843055; // 0x101012f
    field public static final int headerDividersEnabled = 16843310; // 0x101022e
    field public static final int height = 16843093; // 0x1010155
    field public static final int hideOnContentScroll = 16843855; // 0x101044f
    field public static final int hint = 16843088; // 0x1010150
    field public static final int homeAsUpIndicator = 16843531; // 0x101030b
    field public static final int homeLayout = 16843549; // 0x101031d
@@ -3064,6 +3065,7 @@ package android.app {
    method public abstract android.view.View getCustomView();
    method public abstract int getDisplayOptions();
    method public abstract int getHeight();
    method public int getHideOffset();
    method public abstract deprecated int getNavigationItemCount();
    method public abstract deprecated int getNavigationMode();
    method public abstract deprecated int getSelectedNavigationIndex();
@@ -3074,6 +3076,7 @@ package android.app {
    method public android.content.Context getThemedContext();
    method public abstract java.lang.CharSequence getTitle();
    method public abstract void hide();
    method public boolean isHideOnContentScrollEnabled();
    method public abstract boolean isShowing();
    method public abstract deprecated android.app.ActionBar.Tab newTab();
    method public abstract deprecated void removeAllTabs();
@@ -3092,6 +3095,8 @@ package android.app {
    method public abstract void setDisplayShowHomeEnabled(boolean);
    method public abstract void setDisplayShowTitleEnabled(boolean);
    method public abstract void setDisplayUseLogoEnabled(boolean);
    method public void setHideOffset(int);
    method public void setHideOnContentScrollEnabled(boolean);
    method public void setHomeActionContentDescription(java.lang.CharSequence);
    method public void setHomeActionContentDescription(int);
    method public void setHomeAsUpIndicator(android.graphics.drawable.Drawable);
@@ -30185,7 +30190,7 @@ package android.view {
    method public boolean dispatchKeyEvent(android.view.KeyEvent);
    method public boolean dispatchKeyEventPreIme(android.view.KeyEvent);
    method public boolean dispatchKeyShortcutEvent(android.view.KeyEvent);
    method public boolean dispatchNestedFling(float, float);
    method public boolean dispatchNestedFling(float, float, boolean);
    method public boolean dispatchNestedPreScroll(int, int, int[], int[]);
    method public boolean dispatchNestedScroll(int, int, int, int, int[]);
    method public boolean dispatchPopulateAccessibilityEvent(android.view.accessibility.AccessibilityEvent);
@@ -30978,7 +30983,7 @@ package android.view {
    method public boolean onInterceptHoverEvent(android.view.MotionEvent);
    method public boolean onInterceptTouchEvent(android.view.MotionEvent);
    method protected abstract void onLayout(boolean, int, int, int, int);
    method public boolean onNestedFling(android.view.View, float, float);
    method public boolean onNestedFling(android.view.View, float, float, boolean);
    method public void onNestedPreScroll(android.view.View, int, int, int[]);
    method public void onNestedScroll(android.view.View, int, int, int, int);
    method public void onNestedScrollAccepted(android.view.View, android.view.View, int);
@@ -31116,7 +31121,7 @@ package android.view {
    method public abstract boolean isTextAlignmentResolved();
    method public abstract boolean isTextDirectionResolved();
    method public abstract void notifySubtreeAccessibilityStateChanged(android.view.View, android.view.View, int);
    method public abstract boolean onNestedFling(android.view.View, float, float);
    method public abstract boolean onNestedFling(android.view.View, float, float, boolean);
    method public abstract void onNestedPreScroll(android.view.View, int, int, int[]);
    method public abstract void onNestedScroll(android.view.View, int, int, int, int);
    method public abstract void onNestedScrollAccepted(android.view.View, android.view.View, int);
+60 −0
Original line number Diff line number Diff line
@@ -932,6 +932,66 @@ public abstract class ActionBar {
     */
    public void setHomeActionContentDescription(int resId) { }

    /**
     * Enable hiding the action bar on content scroll.
     *
     * <p>If enabled, the action bar will scroll out of sight along with a
     * {@link View#setNestedScrollingEnabled(boolean) nested scrolling child} view's content.
     * The action bar must be in {@link Window#FEATURE_ACTION_BAR_OVERLAY overlay mode}
     * to enable hiding on content scroll.</p>
     *
     * <p>When partially scrolled off screen the action bar is considered
     * {@link #hide() hidden}. A call to {@link #show() show} will cause it to return to full view.
     * </p>
     * @param hideOnContentScroll true to enable hiding on content scroll.
     */
    public void setHideOnContentScrollEnabled(boolean hideOnContentScroll) {
        if (hideOnContentScroll) {
            throw new UnsupportedOperationException("Hide on content scroll is not supported in " +
                    "this action bar configuration.");
        }
    }

    /**
     * Return whether the action bar is configured to scroll out of sight along with
     * a {@link View#setNestedScrollingEnabled(boolean) nested scrolling child}.
     *
     * @return true if hide-on-content-scroll is enabled
     * @see #setHideOnContentScrollEnabled(boolean)
     */
    public boolean isHideOnContentScrollEnabled() {
        return false;
    }

    /**
     * Return the current vertical offset of the action bar.
     *
     * <p>The action bar's current hide offset is the distance that the action bar is currently
     * scrolled offscreen in pixels. The valid range is 0 (fully visible) to the action bar's
     * current measured {@link #getHeight() height} (fully invisible).</p>
     *
     * @return The action bar's offset toward its fully hidden state in pixels
     */
    public int getHideOffset() {
        return 0;
    }

    /**
     * Set the current hide offset of the action bar.
     *
     * <p>The action bar's current hide offset is the distance that the action bar is currently
     * scrolled offscreen in pixels. The valid range is 0 (fully visible) to the action bar's
     * current measured {@link #getHeight() height} (fully invisible).</p>
     *
     * @param offset The action bar's offset toward its fully hidden state in pixels.
     */
    public void setHideOffset(int offset) {
        if (offset != 0) {
            throw new UnsupportedOperationException("Setting an explicit action bar hide offset " +
                    "is not supported in this action bar configuration.");
        }
    }

    /** @hide */
    public void setDefaultDisplayHomeAsUpEnabled(boolean enabled) {
    }
+63 −43
Original line number Diff line number Diff line
@@ -17989,7 +17989,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     *
     * <p>If this property is set to true the view will be permitted to initiate nested
     * scrolling operations with a compatible parent view in the current hierarchy. If this
     * view does not implement nested scrolling this will have no effect.</p>
     * view does not implement nested scrolling this will have no effect. Disabling nested scrolling
     * while a nested scroll is in progress has the effect of {@link #stopNestedScroll() stopping}
     * the nested scroll.</p>
     *
     * @param enabled true to enable nested scrolling, false to disable
     *
@@ -17999,6 +18001,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        if (enabled) {
            mPrivateFlags3 |= PFLAG3_NESTED_SCROLLING_ENABLED;
        } else {
            stopNestedScroll();
            mPrivateFlags3 &= ~PFLAG3_NESTED_SCROLLING_ENABLED;
        }
    }
@@ -18138,6 +18141,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed,
            int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow) {
        if (isNestedScrollingEnabled() && mNestedScrollingParent != null) {
            if (dxConsumed != 0 || dyConsumed != 0 || dxUnconsumed != 0 || dyUnconsumed != 0) {
                int startX = 0;
                int startY = 0;
                if (offsetInWindow != null) {
@@ -18155,6 +18159,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                    offsetInWindow[1] -= startY;
                }
                return true;
            } else if (offsetInWindow != null) {
                // No motion, no dispatch. Keep offsetInWindow up to date.
                offsetInWindow[0] = 0;
                offsetInWindow[1] = 0;
            }
        }
        return false;
    }
@@ -18180,6 +18189,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow) {
        if (isNestedScrollingEnabled() && mNestedScrollingParent != null) {
            if (dx != 0 || dy != 0) {
                int startX = 0;
                int startY = 0;
                if (offsetInWindow != null) {
@@ -18204,6 +18214,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                    offsetInWindow[1] -= startY;
                }
                return consumed[0] != 0 || consumed[1] != 0;
            } else if (offsetInWindow != null) {
                offsetInWindow[0] = 0;
                offsetInWindow[1] = 0;
            }
        }
        return false;
    }
@@ -18211,18 +18225,24 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    /**
     * Dispatch a fling to a nested scrolling parent.
     *
     * <p>If a nested scrolling child view would normally fling but it is at the edge of its
     * own content it should use this method to delegate the fling to its nested scrolling parent.
     * The view implementation can use a {@link VelocityTracker} to obtain the velocity values
     * to pass.</p>
     * <p>This method should be used to indicate that a nested scrolling child has detected
     * suitable conditions for a fling. Generally this means that a touch scroll has ended with a
     * {@link VelocityTracker velocity} in the direction of scrolling that meets or exceeds
     * the {@link ViewConfiguration#getScaledMinimumFlingVelocity() minimum fling velocity}
     * along a scrollable axis.</p>
     *
     * <p>If a nested scrolling child view would normally fling but it is at the edge of
     * its own content, it can use this method to delegate the fling to its nested scrolling
     * parent instead. The parent may optionally consume the fling or observe a child fling.</p>
     *
     * @param velocityX Horizontal fling velocity in pixels per second
     * @param velocityY Vertical fling velocity in pixels per second
     * @return true if the nested scrolling parent consumed the fling
     * @param consumed true if the child consumed the fling, false otherwise
     * @return true if the nested scrolling parent consumed or otherwise reacted to the fling
     */
    public boolean dispatchNestedFling(float velocityX, float velocityY) {
    public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed) {
        if (isNestedScrollingEnabled() && mNestedScrollingParent != null) {
            return mNestedScrollingParent.onNestedFling(this, velocityX, velocityY);
            return mNestedScrollingParent.onNestedFling(this, velocityX, velocityY, consumed);
        }
        return false;
    }
+1 −2
Original line number Diff line number Diff line
@@ -2342,7 +2342,6 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager

        if (disallowIntercept) {
            mGroupFlags |= FLAG_DISALLOW_INTERCEPT;
            stopNestedScroll();
        } else {
            mGroupFlags &= ~FLAG_DISALLOW_INTERCEPT;
        }
@@ -5914,7 +5913,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
     * @inheritDoc
     */
    @Override
    public boolean onNestedFling(View target, float velocityX, float velocityY) {
    public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed) {
        return false;
    }

+11 −4
Original line number Diff line number Diff line
@@ -512,14 +512,21 @@ public interface ViewParent {
    /**
     * Request a fling from a nested scroll.
     *
     * <p>This method signifies that a nested scrolling child has detected suitable conditions
     * for a fling. Generally this means that a touch scroll has ended with a
     * {@link VelocityTracker velocity} in the direction of scrolling that meets or exceeds
     * the {@link ViewConfiguration#getScaledMinimumFlingVelocity() minimum fling velocity}
     * along a scrollable axis.</p>
     *
     * <p>If a nested scrolling child view would normally fling but it is at the edge of
     * its own content, it can delegate the fling to its nested scrolling parent instead.
     * This method allows the parent to optionally consume the fling.</p>
     * its own content, it can use this method to delegate the fling to its nested scrolling
     * parent instead. The parent may optionally consume the fling or observe a child fling.</p>
     *
     * @param target View that initiated the nested scroll
     * @param velocityX Horizontal velocity in pixels per second.
     * @param velocityY Vertical velocity in pixels per second
     * @return true if this parent consumed the fling
     * @param consumed true if the child consumed the fling, false otherwise
     * @return true if this parent consumed or otherwise reacted to the fling
     */
    public boolean onNestedFling(View target, float velocityX, float velocityY);
    public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed);
}
Loading