Skip to content

Commit 6cab600

Browse files
chethaaseAndroid (Google) Code Review
authored andcommitted
Merge "Make detachViewFromParent more robust" into jb-mr1-dev
2 parents b2fc49b + ca479d4 commit 6cab600

File tree

3 files changed

+60
-22
lines changed

3 files changed

+60
-22
lines changed

core/java/android/view/GLES20DisplayList.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525
* An implementation of display list for OpenGL ES 2.0.
2626
*/
2727
class GLES20DisplayList extends DisplayList {
28-
// These lists ensure that any Bitmaps recorded by a DisplayList are kept alive as long
29-
// as the DisplayList is alive. The Bitmaps are populated by the GLES20RecordingCanvas.
28+
// These lists ensure that any Bitmaps and DisplayLists recorded by a DisplayList are kept
29+
// alive as long as the DisplayList is alive. The Bitmap and DisplayList lists
30+
// are populated by the GLES20RecordingCanvas during appropriate drawing calls and are
31+
// cleared at the start of a new drawing frame or when the view is detached from the window.
3032
final ArrayList<Bitmap> mBitmaps = new ArrayList<Bitmap>(5);
33+
final ArrayList<DisplayList> mChildDisplayLists = new ArrayList<DisplayList>();
3134

3235
private GLES20RecordingCanvas mCanvas;
3336
private boolean mValid;
@@ -79,6 +82,7 @@ public void invalidate() {
7982
public void clear() {
8083
if (!mValid) {
8184
mBitmaps.clear();
85+
mChildDisplayLists.clear();
8286
}
8387
}
8488

core/java/android/view/GLES20RecordingCanvas.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ void recycle() {
7676

7777
void start() {
7878
mDisplayList.mBitmaps.clear();
79+
mDisplayList.mChildDisplayLists.clear();
7980
}
8081

8182
int end(int nativeDisplayList) {
@@ -155,6 +156,13 @@ public void drawCircle(float cx, float cy, float radius, Paint paint) {
155156
recordShaderBitmap(paint);
156157
}
157158

159+
@Override
160+
public int drawDisplayList(DisplayList displayList, Rect dirty, int flags) {
161+
int status = super.drawDisplayList(displayList, dirty, flags);
162+
mDisplayList.mChildDisplayLists.add(displayList);
163+
return status;
164+
}
165+
158166
@Override
159167
public void drawLine(float startX, float startY, float stopX, float stopY, Paint paint) {
160168
super.drawLine(startX, startY, stopX, stopY, paint);

core/java/android/view/ViewGroup.java

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3806,6 +3806,13 @@ public void removeAllViewsInLayout() {
38063806
/**
38073807
* Finishes the removal of a detached view. This method will dispatch the detached from
38083808
* window event and notify the hierarchy change listener.
3809+
* <p>
3810+
* This method is intended to be lightweight and makes no assumptions about whether the
3811+
* parent or child should be redrawn. Proper use of this method will include also making
3812+
* any appropriate {@link #requestLayout()} or {@link #invalidate()} calls.
3813+
* For example, callers can {@link #post(Runnable) post} a {@link Runnable}
3814+
* which performs a {@link #requestLayout()} on the next frame, after all detach/remove
3815+
* calls are finished, causing layout to be run prior to redrawing the view hierarchy.
38093816
*
38103817
* @param child the child to be definitely removed from the view hierarchy
38113818
* @param animate if true and the view has an animation, the view is placed in the
@@ -3846,10 +3853,17 @@ protected void removeDetachedView(View child, boolean animate) {
38463853

38473854
/**
38483855
* Attaches a view to this view group. Attaching a view assigns this group as the parent,
3849-
* sets the layout parameters and puts the view in the list of children so it can be retrieved
3850-
* by calling {@link #getChildAt(int)}.
3851-
*
3852-
* This method should be called only for view which were detached from their parent.
3856+
* sets the layout parameters and puts the view in the list of children so that
3857+
* it can be retrieved by calling {@link #getChildAt(int)}.
3858+
* <p>
3859+
* This method is intended to be lightweight and makes no assumptions about whether the
3860+
* parent or child should be redrawn. Proper use of this method will include also making
3861+
* any appropriate {@link #requestLayout()} or {@link #invalidate()} calls.
3862+
* For example, callers can {@link #post(Runnable) post} a {@link Runnable}
3863+
* which performs a {@link #requestLayout()} on the next frame, after all detach/attach
3864+
* calls are finished, causing layout to be run prior to redrawing the view hierarchy.
3865+
* <p>
3866+
* This method should be called only for views which were detached from their parent.
38533867
*
38543868
* @param child the child to attach
38553869
* @param index the index at which the child should be attached
@@ -3881,10 +3895,13 @@ protected void attachViewToParent(View child, int index, LayoutParams params) {
38813895
}
38823896

38833897
/**
3884-
* Detaches a view from its parent. Detaching a view should be temporary and followed
3885-
* either by a call to {@link #attachViewToParent(View, int, android.view.ViewGroup.LayoutParams)}
3886-
* or a call to {@link #removeDetachedView(View, boolean)}. When a view is detached,
3887-
* its parent is null and cannot be retrieved by a call to {@link #getChildAt(int)}.
3898+
* Detaches a view from its parent. Detaching a view should be followed
3899+
* either by a call to
3900+
* {@link #attachViewToParent(View, int, android.view.ViewGroup.LayoutParams)}
3901+
* or a call to {@link #removeDetachedView(View, boolean)}. Detachment should only be
3902+
* temporary; reattachment or removal should happen within the same drawing cycle as
3903+
* detachment. When a view is detached, its parent is null and cannot be retrieved by a
3904+
* call to {@link #getChildAt(int)}.
38883905
*
38893906
* @param child the child to detach
38903907
*
@@ -3899,10 +3916,13 @@ protected void detachViewFromParent(View child) {
38993916
}
39003917

39013918
/**
3902-
* Detaches a view from its parent. Detaching a view should be temporary and followed
3903-
* either by a call to {@link #attachViewToParent(View, int, android.view.ViewGroup.LayoutParams)}
3904-
* or a call to {@link #removeDetachedView(View, boolean)}. When a view is detached,
3905-
* its parent is null and cannot be retrieved by a call to {@link #getChildAt(int)}.
3919+
* Detaches a view from its parent. Detaching a view should be followed
3920+
* either by a call to
3921+
* {@link #attachViewToParent(View, int, android.view.ViewGroup.LayoutParams)}
3922+
* or a call to {@link #removeDetachedView(View, boolean)}. Detachment should only be
3923+
* temporary; reattachment or removal should happen within the same drawing cycle as
3924+
* detachment. When a view is detached, its parent is null and cannot be retrieved by a
3925+
* call to {@link #getChildAt(int)}.
39063926
*
39073927
* @param index the index of the child to detach
39083928
*
@@ -3917,10 +3937,13 @@ protected void detachViewFromParent(int index) {
39173937
}
39183938

39193939
/**
3920-
* Detaches a range of view from their parent. Detaching a view should be temporary and followed
3921-
* either by a call to {@link #attachViewToParent(View, int, android.view.ViewGroup.LayoutParams)}
3922-
* or a call to {@link #removeDetachedView(View, boolean)}. When a view is detached, its
3923-
* parent is null and cannot be retrieved by a call to {@link #getChildAt(int)}.
3940+
* Detaches a range of views from their parents. Detaching a view should be followed
3941+
* either by a call to
3942+
* {@link #attachViewToParent(View, int, android.view.ViewGroup.LayoutParams)}
3943+
* or a call to {@link #removeDetachedView(View, boolean)}. Detachment should only be
3944+
* temporary; reattachment or removal should happen within the same drawing cycle as
3945+
* detachment. When a view is detached, its parent is null and cannot be retrieved by a
3946+
* call to {@link #getChildAt(int)}.
39243947
*
39253948
* @param start the first index of the childrend range to detach
39263949
* @param count the number of children to detach
@@ -3936,10 +3959,13 @@ protected void detachViewsFromParent(int start, int count) {
39363959
}
39373960

39383961
/**
3939-
* Detaches all views from the parent. Detaching a view should be temporary and followed
3940-
* either by a call to {@link #attachViewToParent(View, int, android.view.ViewGroup.LayoutParams)}
3941-
* or a call to {@link #removeDetachedView(View, boolean)}. When a view is detached,
3942-
* its parent is null and cannot be retrieved by a call to {@link #getChildAt(int)}.
3962+
* Detaches all views from the parent. Detaching a view should be followed
3963+
* either by a call to
3964+
* {@link #attachViewToParent(View, int, android.view.ViewGroup.LayoutParams)}
3965+
* or a call to {@link #removeDetachedView(View, boolean)}. Detachment should only be
3966+
* temporary; reattachment or removal should happen within the same drawing cycle as
3967+
* detachment. When a view is detached, its parent is null and cannot be retrieved by a
3968+
* call to {@link #getChildAt(int)}.
39433969
*
39443970
* @see #detachViewFromParent(View)
39453971
* @see #detachViewFromParent(int)

0 commit comments

Comments
 (0)