mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-28 15:56:49 +00:00
Ensuring that all the pending tasks are run
before marking the ViewOnDrawExecutor as completed. Also fixing model writer not updated on rotation Change-Id: I5ecd7ac865b939ffa4c02afe892bd773d9f275c3
This commit is contained in:
@@ -34,20 +34,14 @@ public class ViewOnDrawExecutor implements Executor, OnDrawListener, Runnable,
|
||||
OnAttachStateChangeListener {
|
||||
|
||||
private final ArrayList<Runnable> mTasks = new ArrayList<>();
|
||||
private final Executor mExecutor;
|
||||
|
||||
private Launcher mLauncher;
|
||||
private View mAttachedView;
|
||||
private boolean mCompleted;
|
||||
private boolean mIsExecuting;
|
||||
|
||||
private boolean mLoadAnimationCompleted;
|
||||
private boolean mFirstDrawCompleted;
|
||||
|
||||
public ViewOnDrawExecutor(Executor executor) {
|
||||
mExecutor = executor;
|
||||
}
|
||||
|
||||
public void attachTo(Launcher launcher) {
|
||||
attachTo(launcher, launcher.getWorkspace(), true /* waitForLoadAnimation */);
|
||||
}
|
||||
@@ -89,13 +83,6 @@ public class ViewOnDrawExecutor implements Executor, OnDrawListener, Runnable,
|
||||
mAttachedView.post(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the executor is still queuing tasks and hasn't yet executed them.
|
||||
*/
|
||||
public boolean canQueue() {
|
||||
return !mIsExecuting && !mCompleted;
|
||||
}
|
||||
|
||||
public void onLoadAnimationCompleted() {
|
||||
mLoadAnimationCompleted = true;
|
||||
if (mAttachedView != null) {
|
||||
@@ -107,7 +94,6 @@ public class ViewOnDrawExecutor implements Executor, OnDrawListener, Runnable,
|
||||
public void run() {
|
||||
// Post the pending tasks after both onDraw and onLoadAnimationCompleted have been called.
|
||||
if (mLoadAnimationCompleted && mFirstDrawCompleted && !mCompleted) {
|
||||
mIsExecuting = true;
|
||||
runAllTasks();
|
||||
}
|
||||
}
|
||||
@@ -115,7 +101,6 @@ public class ViewOnDrawExecutor implements Executor, OnDrawListener, Runnable,
|
||||
public void markCompleted() {
|
||||
mTasks.clear();
|
||||
mCompleted = true;
|
||||
mIsExecuting = false;
|
||||
if (mAttachedView != null) {
|
||||
mAttachedView.getViewTreeObserver().removeOnDrawListener(this);
|
||||
mAttachedView.removeOnAttachStateChangeListener(this);
|
||||
@@ -132,7 +117,7 @@ public class ViewOnDrawExecutor implements Executor, OnDrawListener, Runnable,
|
||||
|
||||
protected void runAllTasks() {
|
||||
for (final Runnable r : mTasks) {
|
||||
mExecutor.execute(r);
|
||||
r.run();
|
||||
}
|
||||
markCompleted();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user