diff options
author | 2019-02-28 21:11:59 +0000 | |
---|---|---|
committer | 2019-02-28 21:11:59 +0000 | |
commit | b10113347d1c008a3ccbb02b86722a6c02ab0e18 (patch) | |
tree | a454c300e06a7606d9fa4436e70601f7e0aaafd7 /graphics/java | |
parent | 357f00384986fa0120752d4b3b97e071fc4643e7 (diff) | |
parent | 769b8638f970c6cf62abb7ac46f80211b7c3afb6 (diff) |
Merge "System gesture exclusion rects for Views"
Diffstat (limited to 'graphics/java')
-rw-r--r-- | graphics/java/android/graphics/RenderNode.java | 67 |
1 files changed, 64 insertions, 3 deletions
diff --git a/graphics/java/android/graphics/RenderNode.java b/graphics/java/android/graphics/RenderNode.java index e98879d0c5bd..42b6acd3b25a 100644 --- a/graphics/java/android/graphics/RenderNode.java +++ b/graphics/java/android/graphics/RenderNode.java @@ -27,6 +27,8 @@ import android.view.RenderNodeAnimator; import android.view.Surface; import android.view.View; +import com.android.internal.util.ArrayUtils; + import dalvik.annotation.optimization.CriticalNative; import dalvik.annotation.optimization.FastNative; @@ -179,6 +181,10 @@ public final class RenderNode { private final AnimationHost mAnimationHost; private RecordingCanvas mCurrentRecordingCanvas; + // Will be null if not currently registered + @Nullable + private CompositePositionUpdateListener mCompositePositionUpdateListener; + /** * Creates a new RenderNode that can be used to record batches of * drawing operations, and store / apply render properties when drawn. @@ -248,15 +254,70 @@ public final class RenderNode { } + private static final class CompositePositionUpdateListener implements PositionUpdateListener { + private final PositionUpdateListener[] mListeners; + + CompositePositionUpdateListener(PositionUpdateListener... listeners) { + mListeners = listeners; + } + + public CompositePositionUpdateListener with(PositionUpdateListener listener) { + return new CompositePositionUpdateListener( + ArrayUtils.appendElement(PositionUpdateListener.class, mListeners, listener)); + } + + public CompositePositionUpdateListener without(PositionUpdateListener listener) { + return new CompositePositionUpdateListener( + ArrayUtils.removeElement(PositionUpdateListener.class, mListeners, listener)); + } + + @Override + public void positionChanged(long frameNumber, int left, int top, int right, int bottom) { + for (PositionUpdateListener pul : mListeners) { + pul.positionChanged(frameNumber, left, top, right, bottom); + } + } + + @Override + public void positionLost(long frameNumber) { + for (PositionUpdateListener pul : mListeners) { + pul.positionLost(frameNumber); + } + } + } + /** - * Enable callbacks for position changes. + * Enable callbacks for position changes. Call only from the UI thread or with + * external synchronization. * * @hide */ - public void requestPositionUpdates(PositionUpdateListener listener) { - nRequestPositionUpdates(mNativeRenderNode, listener); + public void addPositionUpdateListener(@NonNull PositionUpdateListener listener) { + CompositePositionUpdateListener comp = mCompositePositionUpdateListener; + if (comp == null) { + comp = new CompositePositionUpdateListener(listener); + } else { + comp = comp.with(listener); + } + mCompositePositionUpdateListener = comp; + nRequestPositionUpdates(mNativeRenderNode, comp); } + /** + * Disable a callback for position changes. Call only from the UI thread or with + * external synchronization. + * + * @param listener Callback to remove + * @hide + */ + public void removePositionUpdateListener(@NonNull PositionUpdateListener listener) { + CompositePositionUpdateListener comp = mCompositePositionUpdateListener; + if (comp != null) { + comp = comp.without(listener); + mCompositePositionUpdateListener = comp; + nRequestPositionUpdates(mNativeRenderNode, comp); + } + } /** * Starts recording a display list for the render node. All |