diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2019-01-04 00:30:34 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-01-04 00:30:34 +0000 |
commit | e0c927a50b7dc5c15dfc740ec43d5161fa6fbc92 (patch) | |
tree | 9c8e9f1c4c7bce0eedebaecdb0e0566ea76da074 /src/com/android | |
parent | 5115de84155e780afcbf45e62d2c03b5d7d4c689 (diff) | |
parent | 9dbdd7249882f7181e1116e57668af076ba03573 (diff) | |
download | packages_apps_Trebuchet-e0c927a50b7dc5c15dfc740ec43d5161fa6fbc92.tar.gz packages_apps_Trebuchet-e0c927a50b7dc5c15dfc740ec43d5161fa6fbc92.tar.bz2 packages_apps_Trebuchet-e0c927a50b7dc5c15dfc740ec43d5161fa6fbc92.zip |
Merge "Migrating some runnables to lambda operations" into ub-launcher3-master
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/launcher3/model/BaseLoaderResults.java | 121 |
1 files changed, 35 insertions, 86 deletions
diff --git a/src/com/android/launcher3/model/BaseLoaderResults.java b/src/com/android/launcher3/model/BaseLoaderResults.java index d9d0a4fd0..f6e220f94 100644 --- a/src/com/android/launcher3/model/BaseLoaderResults.java +++ b/src/com/android/launcher3/model/BaseLoaderResults.java @@ -25,6 +25,7 @@ import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.ItemInfo; import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherAppWidgetInfo; +import com.android.launcher3.LauncherModel.CallbackTask; import com.android.launcher3.LauncherModel.Callbacks; import com.android.launcher3.LauncherSettings; import com.android.launcher3.MainThreadExecutor; @@ -74,8 +75,6 @@ public abstract class BaseLoaderResults { * Binds all loaded data to actual views on the main thread. */ public void bindWorkspace() { - Runnable r; - Callbacks callbacks = mCallbacks.get(); // Don't use these two variables in any of the callback runnables. // Otherwise we hold a reference to them. @@ -125,27 +124,13 @@ public abstract class BaseLoaderResults { sortWorkspaceItemsSpatially(otherWorkspaceItems); // Tell the workspace that we're about to start binding items - r = new Runnable() { - public void run() { - Callbacks callbacks = mCallbacks.get(); - if (callbacks != null) { - callbacks.clearPendingBinds(); - callbacks.startBinding(); - } - } - }; - mUiExecutor.execute(r); + executeCallbacksTask(c -> { + c.clearPendingBinds(); + c.startBinding(); + }, mUiExecutor); // Bind workspace screens - mUiExecutor.execute(new Runnable() { - @Override - public void run() { - Callbacks callbacks = mCallbacks.get(); - if (callbacks != null) { - callbacks.bindScreens(orderedScreenIds); - } - } - }); + executeCallbacksTask(c -> c.bindScreens(orderedScreenIds), mUiExecutor); Executor mainExecutor = mUiExecutor; // Load items on the current page. @@ -159,46 +144,25 @@ public abstract class BaseLoaderResults { final Executor deferredExecutor = validFirstPage ? new ViewOnDrawExecutor() : mainExecutor; - mainExecutor.execute(new Runnable() { - @Override - public void run() { - Callbacks callbacks = mCallbacks.get(); - if (callbacks != null) { - callbacks.finishFirstPageBind( - validFirstPage ? (ViewOnDrawExecutor) deferredExecutor : null); - } - } - }); + executeCallbacksTask(c -> c.finishFirstPageBind( + validFirstPage ? (ViewOnDrawExecutor) deferredExecutor : null), mainExecutor); bindWorkspaceItems(otherWorkspaceItems, deferredExecutor); bindAppWidgets(otherAppWidgets, deferredExecutor); // Tell the workspace that we're done binding items - r = new Runnable() { - public void run() { - Callbacks callbacks = mCallbacks.get(); - if (callbacks != null) { - callbacks.finishBindingItems(mPageToBindFirst); - } - } - }; - deferredExecutor.execute(r); + executeCallbacksTask(c -> c.finishBindingItems(mPageToBindFirst), deferredExecutor); if (validFirstPage) { - r = new Runnable() { - public void run() { - Callbacks callbacks = mCallbacks.get(); - if (callbacks != null) { - // We are loading synchronously, which means, some of the pages will be - // bound after first draw. Inform the callbacks that page binding is - // not complete, and schedule the remaining pages. - if (currentScreen != PagedView.INVALID_RESTORE_PAGE) { - callbacks.onPageBoundSynchronously(currentScreen); - } - callbacks.executeOnNextDraw((ViewOnDrawExecutor) deferredExecutor); - } + executeCallbacksTask(c -> { + // We are loading synchronously, which means, some of the pages will be + // bound after first draw. Inform the callbacks that page binding is + // not complete, and schedule the remaining pages. + if (currentScreen != PagedView.INVALID_RESTORE_PAGE) { + c.onPageBoundSynchronously(currentScreen); } - }; - mUiExecutor.execute(r); + c.executeOnNextDraw((ViewOnDrawExecutor) deferredExecutor); + + }, mUiExecutor); } } @@ -258,7 +222,7 @@ public abstract class BaseLoaderResults { public int compare(ItemInfo lhs, ItemInfo rhs) { if (lhs.container == rhs.container) { // Within containers, order by their spatial position in that container - switch ((int) lhs.container) { + switch (lhs.container) { case LauncherSettings.Favorites.CONTAINER_DESKTOP: { int lr = (lhs.screenId * screenCellCount + lhs.cellY * screenCols + lhs.cellX); @@ -297,17 +261,9 @@ public abstract class BaseLoaderResults { for (int i = 0; i < N; i += ITEMS_CHUNK) { final int start = i; final int chunkSize = (i+ITEMS_CHUNK <= N) ? ITEMS_CHUNK : (N-i); - final Runnable r = new Runnable() { - @Override - public void run() { - Callbacks callbacks = mCallbacks.get(); - if (callbacks != null) { - callbacks.bindItems(workspaceItems.subList(start, start + chunkSize), - false); - } - } - }; - executor.execute(r); + executeCallbacksTask( + c -> c.bindItems(workspaceItems.subList(start, start + chunkSize), false), + executor); } } @@ -316,15 +272,8 @@ public abstract class BaseLoaderResults { N = appWidgets.size(); for (int i = 0; i < N; i++) { final ItemInfo widget = appWidgets.get(i); - final Runnable r = new Runnable() { - public void run() { - Callbacks callbacks = mCallbacks.get(); - if (callbacks != null) { - callbacks.bindItems(Collections.singletonList(widget), false); - } - } - }; - executor.execute(r); + executeCallbacksTask( + c -> c.bindItems(Collections.singletonList(widget), false), executor); } } @@ -333,21 +282,21 @@ public abstract class BaseLoaderResults { public void bindAllApps() { // shallow copy @SuppressWarnings("unchecked") - final ArrayList<AppInfo> list = (ArrayList<AppInfo>) mBgAllAppsList.data.clone(); - - Runnable r = new Runnable() { - public void run() { - Callbacks callbacks = mCallbacks.get(); - if (callbacks != null) { - callbacks.bindAllApplications(list); - } - } - }; - mUiExecutor.execute(r); + ArrayList<AppInfo> list = (ArrayList<AppInfo>) mBgAllAppsList.data.clone(); + executeCallbacksTask(c -> c.bindAllApplications(list), mUiExecutor); } public abstract void bindWidgets(); + protected void executeCallbacksTask(CallbackTask task, Executor executor) { + executor.execute(() -> { + Callbacks callbacks = mCallbacks.get(); + if (callbacks != null) { + task.execute(callbacks); + } + }); + } + public LooperIdleLock newIdleLock(Object lock) { LooperIdleLock idleLock = new LooperIdleLock(lock, Looper.getMainLooper()); // If we are not binding, there is no reason to wait for idle. |