Skip to content

Commit 6200b58

Browse files
Calling open(), close(), or toggle() before SlideHolder is layouted now delays execution of this methods (it crashed before)
1 parent 5a49374 commit 6200b58

3 files changed

Lines changed: 76 additions & 0 deletions

File tree

example/src/com/agimind/widget/SlideHolder.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package com.agimind.widget;
1818

19+
import java.util.LinkedList;
20+
import java.util.Queue;
21+
1922
import android.content.Context;
2023
import android.graphics.Bitmap;
2124
import android.graphics.Canvas;
@@ -55,6 +58,8 @@ public class SlideHolder extends FrameLayout {
5558
private boolean mInterceptTouch = true;
5659
private boolean mAlwaysOpened = false;
5760

61+
private Queue<Runnable> mWhenReady = new LinkedList<Runnable>();
62+
5863
private OnSlideListener mListener;
5964

6065
public SlideHolder(Context context) {
@@ -150,6 +155,18 @@ public boolean open() {
150155
return false;
151156
}
152157

158+
if(!isReadyForSlide()) {
159+
mWhenReady.add(new Runnable() {
160+
161+
@Override
162+
public void run() {
163+
open();
164+
}
165+
});
166+
167+
return true;
168+
}
169+
153170
initSlideMode();
154171

155172
Animation anim = new SlideAnimation(mOffset, mEndOffset);
@@ -182,6 +199,18 @@ public boolean close() {
182199
return false;
183200
}
184201

202+
if(!isReadyForSlide()) {
203+
mWhenReady.add(new Runnable() {
204+
205+
@Override
206+
public void run() {
207+
close();
208+
}
209+
});
210+
211+
return true;
212+
}
213+
185214
initSlideMode();
186215

187216
Animation anim = new SlideAnimation(mOffset, mEndOffset);
@@ -246,6 +275,15 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
246275
);
247276

248277
invalidate();
278+
279+
Runnable rn;
280+
while((rn = mWhenReady.poll()) != null) {
281+
rn.run();
282+
}
283+
}
284+
285+
private boolean isReadyForSlide() {
286+
return (getWidth() > 0 && getHeight() > 0);
249287
}
250288

251289
@Override

sidemenu.jar

1.4 KB
Binary file not shown.

src/com/agimind/widget/SlideHolder.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package com.agimind.widget;
1818

19+
import java.util.LinkedList;
20+
import java.util.Queue;
21+
1922
import android.content.Context;
2023
import android.graphics.Bitmap;
2124
import android.graphics.Canvas;
@@ -55,6 +58,8 @@ public class SlideHolder extends FrameLayout {
5558
private boolean mInterceptTouch = true;
5659
private boolean mAlwaysOpened = false;
5760

61+
private Queue<Runnable> mWhenReady = new LinkedList<Runnable>();
62+
5863
private OnSlideListener mListener;
5964

6065
public SlideHolder(Context context) {
@@ -150,6 +155,18 @@ public boolean open() {
150155
return false;
151156
}
152157

158+
if(!isReadyForSlide()) {
159+
mWhenReady.add(new Runnable() {
160+
161+
@Override
162+
public void run() {
163+
open();
164+
}
165+
});
166+
167+
return true;
168+
}
169+
153170
initSlideMode();
154171

155172
Animation anim = new SlideAnimation(mOffset, mEndOffset);
@@ -182,6 +199,18 @@ public boolean close() {
182199
return false;
183200
}
184201

202+
if(!isReadyForSlide()) {
203+
mWhenReady.add(new Runnable() {
204+
205+
@Override
206+
public void run() {
207+
close();
208+
}
209+
});
210+
211+
return true;
212+
}
213+
185214
initSlideMode();
186215

187216
Animation anim = new SlideAnimation(mOffset, mEndOffset);
@@ -246,6 +275,15 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
246275
);
247276

248277
invalidate();
278+
279+
Runnable rn;
280+
while((rn = mWhenReady.poll()) != null) {
281+
rn.run();
282+
}
283+
}
284+
285+
private boolean isReadyForSlide() {
286+
return (getWidth() > 0 && getHeight() > 0);
249287
}
250288

251289
@Override

0 commit comments

Comments
 (0)