diff options
| -rw-r--r-- | api/current.txt | 2 | ||||
| -rw-r--r-- | core/java/android/view/GestureExclusionTracker.java | 20 | ||||
| -rw-r--r-- | core/java/android/view/ViewRootImpl.java | 18 | ||||
| -rw-r--r-- | core/java/android/view/Window.java | 48 | ||||
| -rw-r--r-- | core/java/com/android/internal/policy/PhoneWindow.java | 13 |
5 files changed, 99 insertions, 2 deletions
diff --git a/api/current.txt b/api/current.txt index 8ec7594773af..a16cf588ab8f 100644 --- a/api/current.txt +++ b/api/current.txt @@ -51509,6 +51509,7 @@ package android.view { method public android.transition.Transition getSharedElementReturnTransition(); method public boolean getSharedElementsUseOverlay(); method @ColorInt public abstract int getStatusBarColor(); + method @NonNull public java.util.List<android.graphics.Rect> getSystemGestureExclusionRects(); method public long getTransitionBackgroundFadeDuration(); method public android.transition.TransitionManager getTransitionManager(); method public abstract int getVolumeControlStream(); @@ -51587,6 +51588,7 @@ package android.view { method public void setSoftInputMode(int); method public abstract void setStatusBarColor(@ColorInt int); method public void setSustainedPerformanceMode(boolean); + method public void setSystemGestureExclusionRects(@NonNull java.util.List<android.graphics.Rect>); method public abstract void setTitle(CharSequence); method @Deprecated public abstract void setTitleColor(@ColorInt int); method public void setTransitionBackgroundFadeDuration(long); diff --git a/core/java/android/view/GestureExclusionTracker.java b/core/java/android/view/GestureExclusionTracker.java index 8eccc04fa647..6fcdd714f827 100644 --- a/core/java/android/view/GestureExclusionTracker.java +++ b/core/java/android/view/GestureExclusionTracker.java @@ -20,6 +20,8 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.graphics.Rect; +import com.android.internal.util.Preconditions; + import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collections; @@ -31,6 +33,8 @@ import java.util.List; */ class GestureExclusionTracker { private boolean mGestureExclusionViewsChanged = false; + private boolean mRootGestureExclusionRectsChanged = false; + private List<Rect> mRootGestureExclusionRects = Collections.emptyList(); private List<GestureExclusionViewInfo> mGestureExclusionViewInfos = new ArrayList<>(); private List<Rect> mGestureExclusionRects = Collections.emptyList(); @@ -59,9 +63,9 @@ class GestureExclusionTracker { @Nullable public List<Rect> computeChangedRects() { - boolean changed = false; + boolean changed = mRootGestureExclusionRectsChanged; final Iterator<GestureExclusionViewInfo> i = mGestureExclusionViewInfos.iterator(); - final List<Rect> rects = new ArrayList<>(); + final List<Rect> rects = new ArrayList<>(mRootGestureExclusionRects); while (i.hasNext()) { final GestureExclusionViewInfo info = i.next(); switch (info.update()) { @@ -79,6 +83,7 @@ class GestureExclusionTracker { } if (changed || mGestureExclusionViewsChanged) { mGestureExclusionViewsChanged = false; + mRootGestureExclusionRectsChanged = false; if (!mGestureExclusionRects.equals(rects)) { mGestureExclusionRects = rects; return rects; @@ -87,6 +92,17 @@ class GestureExclusionTracker { return null; } + public void setRootSystemGestureExclusionRects(@NonNull List<Rect> rects) { + Preconditions.checkNotNull(rects, "rects must not be null"); + mRootGestureExclusionRects = rects; + mRootGestureExclusionRectsChanged = true; + } + + @NonNull + public List<Rect> getRootSystemGestureExclusionRects() { + return mRootGestureExclusionRects; + } + private static class GestureExclusionViewInfo { public static final int CHANGED = 0; public static final int UNCHANGED = 1; diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 5ca70ba9a575..7ad118e760d8 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -3829,6 +3829,24 @@ public final class ViewRootImpl implements ViewParent, } /** + * Set the root-level system gesture exclusion rects. These are added to those provided by + * the root's view hierarchy. + */ + public void setRootSystemGestureExclusionRects(@NonNull List<Rect> rects) { + mGestureExclusionTracker.setRootSystemGestureExclusionRects(rects); + mHandler.sendEmptyMessage(MSG_SYSTEM_GESTURE_EXCLUSION_CHANGED); + } + + /** + * Returns the root-level system gesture exclusion rects. These do not include those provided by + * the root's view hierarchy. + */ + @NonNull + public List<Rect> getRootSystemGestureExclusionRects() { + return mGestureExclusionTracker.getRootSystemGestureExclusionRects(); + } + + /** * Requests that the root render node is invalidated next time we perform a draw, such that * {@link WindowCallbacks#onPostDraw} gets called. */ diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java index fc9d8c269538..b0ec6210d828 100644 --- a/core/java/android/view/Window.java +++ b/core/java/android/view/Window.java @@ -48,6 +48,7 @@ import android.transition.Transition; import android.transition.TransitionManager; import android.view.accessibility.AccessibilityEvent; +import java.util.Collections; import java.util.List; /** @@ -2397,6 +2398,53 @@ public abstract class Window { return false; } + /** + * Sets a list of areas within this window's coordinate space where the system should not + * intercept touch or other pointing device gestures. + * + * <p>This method should be used by apps that make use of + * {@link #takeSurface(SurfaceHolder.Callback2)} and do not have a view hierarchy available. + * Apps that do have a view hierarchy should use + * {@link View#setSystemGestureExclusionRects(List)} instead. This method does not modify or + * replace the gesture exclusion rects populated by individual views in this window's view + * hierarchy using {@link View#setSystemGestureExclusionRects(List)}.</p> + * + * <p>Use this to tell the system which specific sub-areas of a view need to receive gesture + * input in order to function correctly in the presence of global system gestures that may + * conflict. For example, if the system wishes to capture swipe-in-from-screen-edge gestures + * to provide system-level navigation functionality, a view such as a navigation drawer + * container can mark the left (or starting) edge of itself as requiring gesture capture + * priority using this API. The system may then choose to relax its own gesture recognition + * to allow the app to consume the user's gesture. It is not necessary for an app to register + * exclusion rects for broadly spanning regions such as the entirety of a + * <code>ScrollView</code> or for simple press and release click targets such as + * <code>Button</code>. Mark an exclusion rect when interacting with a view requires + * a precision touch gesture in a small area in either the X or Y dimension, such as + * an edge swipe or dragging a <code>SeekBar</code> thumb.</p> + * + * <p>Do not modify the provided list after this method is called.</p> + * + * @param rects A list of precision gesture regions that this window needs to function correctly + */ + @SuppressWarnings("unused") + public void setSystemGestureExclusionRects(@NonNull List<Rect> rects) { + throw new UnsupportedOperationException("window does not support gesture exclusion rects"); + } + + /** + * Retrieve the list of areas within this window's coordinate space where the system should not + * intercept touch or other pointing device gestures. This is the list as set by + * {@link #setSystemGestureExclusionRects(List)} or an empty list if + * {@link #setSystemGestureExclusionRects(List)} has not been called. It does not include + * exclusion rects set by this window's view hierarchy. + * + * @return a list of system gesture exclusion rects specific to this window + */ + @NonNull + public List<Rect> getSystemGestureExclusionRects() { + return Collections.emptyList(); + } + /** @hide */ public void setTheme(int resId) { } diff --git a/core/java/com/android/internal/policy/PhoneWindow.java b/core/java/com/android/internal/policy/PhoneWindow.java index fd75f4fa4567..21f8d87e7e8c 100644 --- a/core/java/com/android/internal/policy/PhoneWindow.java +++ b/core/java/com/android/internal/policy/PhoneWindow.java @@ -45,6 +45,7 @@ import android.content.res.Configuration; import android.content.res.Resources.Theme; import android.content.res.TypedArray; import android.graphics.Color; +import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.media.AudioManager; import android.media.session.MediaController; @@ -115,6 +116,7 @@ import com.android.internal.widget.SwipeDismissLayout; import java.lang.ref.WeakReference; import java.util.ArrayList; +import java.util.List; /** * Android-specific Window. @@ -3926,4 +3928,15 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { public WindowInsetsController getInsetsController() { return mDecor.getWindowInsetsController(); } + + @Override + public void setSystemGestureExclusionRects(@NonNull List<Rect> rects) { + getViewRootImpl().setRootSystemGestureExclusionRects(rects); + } + + @Override + @NonNull + public List<Rect> getSystemGestureExclusionRects() { + return getViewRootImpl().getRootSystemGestureExclusionRects(); + } } |