diff options
author | Dake Gu <dake@google.com> | 2014-08-12 14:54:53 -0700 |
---|---|---|
committer | George Mount <mount@google.com> | 2014-08-12 16:10:40 -0700 |
commit | 0017ef9ee1ca342863a76fd44d1cce4709a7ce67 (patch) | |
tree | e044b479517dd7b83388190760fa61ccd3468167 /core/java/android/view/GhostView.java | |
parent | 7036cb6bacdb1a805ff24e793c502abbc5c66473 (diff) | |
download | frameworks_base-0017ef9ee1ca342863a76fd44d1cce4709a7ce67.zip frameworks_base-0017ef9ee1ca342863a76fd44d1cce4709a7ce67.tar.gz frameworks_base-0017ef9ee1ca342863a76fd44d1cce4709a7ce67.tar.bz2 |
fix ghost clipBounds problem
OverlayViewGroup clipChildren=true, so that RenderNode
of GhostView will be forced clip its content to its bounds.
Because GhostView is transformed to a different location
other than (0,0), the content left/up to the bounds
is clipped out.
Introduce another clipChildren=false view between
OverlayViewGroup and GhostView.
b/16982904
Change-Id: Ia11926c78e19bffe80c3d4584a59b83b2fbee6df
Diffstat (limited to 'core/java/android/view/GhostView.java')
-rw-r--r-- | core/java/android/view/GhostView.java | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/core/java/android/view/GhostView.java b/core/java/android/view/GhostView.java index a79838f..3cbaf60 100644 --- a/core/java/android/view/GhostView.java +++ b/core/java/android/view/GhostView.java @@ -17,6 +17,7 @@ package android.view; import android.graphics.Canvas; import android.graphics.Matrix; +import android.widget.FrameLayout; /** * This view draws another View in an Overlay without changing the parent. It will not be drawn @@ -28,17 +29,13 @@ import android.graphics.Matrix; */ public class GhostView extends View { private final View mView; + private int mReferences; - private GhostView(View view, ViewGroup host, Matrix matrix) { + private GhostView(View view) { super(view.getContext()); mView = view; mView.mGhostView = this; - mRenderNode.setAnimationMatrix(matrix); final ViewGroup parent = (ViewGroup) mView.getParent(); - setLeft(0); - setTop(0); - setRight(host.getWidth()); - setBottom(host.getHeight()); setGhostedVisibility(View.INVISIBLE); parent.mRecreateDisplayList = true; parent.getDisplayList(); @@ -100,10 +97,13 @@ public class GhostView extends View { ViewGroupOverlay overlay = viewGroup.getOverlay(); ViewOverlay.OverlayViewGroup overlayViewGroup = overlay.mOverlayViewGroup; GhostView ghostView = view.mGhostView; + int previousRefCount = 0; if (ghostView != null) { - ViewGroup oldParent = (ViewGroup) ghostView.getParent(); - if (oldParent != overlayViewGroup) { - oldParent.removeView(ghostView); + View oldParent = (View) ghostView.getParent(); + ViewGroup oldGrandParent = (ViewGroup) oldParent.getParent(); + if (oldGrandParent != overlayViewGroup) { + previousRefCount = ghostView.mReferences; + oldGrandParent.removeView(oldParent); ghostView = null; } } @@ -112,9 +112,19 @@ public class GhostView extends View { matrix = new Matrix(); calculateMatrix(view, viewGroup, matrix); } - ghostView = new GhostView(view, (ViewGroup) overlayViewGroup.mHostView, matrix); - overlay.add(ghostView); + ghostView = new GhostView(view); + ghostView.setMatrix(matrix); + FrameLayout parent = new FrameLayout(view.getContext()); + parent.setClipChildren(false); + copySize(viewGroup, parent); + copySize(viewGroup, ghostView); + parent.addView(ghostView); + overlay.add(parent); + ghostView.mReferences = previousRefCount; + } else if (matrix != null) { + ghostView.setMatrix(matrix); } + ghostView.mReferences++; return ghostView; } @@ -125,12 +135,23 @@ public class GhostView extends View { public static void removeGhost(View view) { GhostView ghostView = view.mGhostView; if (ghostView != null) { - ViewGroup parent = (ViewGroup) ghostView.getParent(); - parent.removeView(ghostView); + ghostView.mReferences--; + if (ghostView.mReferences == 0) { + ViewGroup parent = (ViewGroup) ghostView.getParent(); + ViewGroup grandParent = (ViewGroup) parent.getParent(); + grandParent.removeView(parent); + } } } public static GhostView getGhost(View view) { return view.mGhostView; } + + private static void copySize(View from, View to) { + to.setLeft(0); + to.setTop(0); + to.setRight(from.getWidth()); + to.setBottom(from.getHeight()); + } } |