diff --git a/go/src/com/android/launcher3/model/LoaderResults.java b/go/src/com/android/launcher3/model/LoaderResults.java new file mode 100644 index 0000000000..b82f362496 --- /dev/null +++ b/go/src/com/android/launcher3/model/LoaderResults.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.model; + +import com.android.launcher3.AllAppsList; +import com.android.launcher3.LauncherAppState; +import com.android.launcher3.LauncherModel.Callbacks; + +import java.lang.ref.WeakReference; + +/** + * Helper class to handle results of {@link com.android.launcher3.model.LoaderTask}. + */ +public class LoaderResults extends BaseLoaderResults { + + public LoaderResults(LauncherAppState app, BgDataModel dataModel, + AllAppsList allAppsList, int pageToBindFirst, WeakReference callbacks) { + super(app, dataModel, allAppsList, pageToBindFirst, callbacks); + } + + @Override + public void bindDeepShortcuts() { + } + + @Override + public void bindWidgets() { + } +} diff --git a/src/com/android/launcher3/model/LoaderResults.java b/src/com/android/launcher3/model/BaseLoaderResults.java similarity index 85% rename from src/com/android/launcher3/model/LoaderResults.java rename to src/com/android/launcher3/model/BaseLoaderResults.java index 1d18e7667b..d3dc91f3be 100644 --- a/src/com/android/launcher3/model/LoaderResults.java +++ b/src/com/android/launcher3/model/BaseLoaderResults.java @@ -30,47 +30,44 @@ import com.android.launcher3.LauncherSettings; import com.android.launcher3.MainThreadExecutor; import com.android.launcher3.PagedView; import com.android.launcher3.config.FeatureFlags; -import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.IntArray; import com.android.launcher3.util.IntSet; import com.android.launcher3.util.LooperIdleLock; import com.android.launcher3.util.ViewOnDrawExecutor; -import com.android.launcher3.widget.WidgetListRowEntry; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; -import java.util.HashMap; import java.util.Iterator; import java.util.concurrent.Executor; /** - * Helper class to handle results of {@link com.android.launcher3.model.LoaderTask}. + * Base Helper class to handle results of {@link com.android.launcher3.model.LoaderTask}. */ -public class LoaderResults { +public abstract class BaseLoaderResults { - private static final String TAG = "LoaderResults"; - private static final int INVALID_SCREEN_ID = -1; + protected static final String TAG = "LoaderResults"; + protected static final int INVALID_SCREEN_ID = -1; private static final int ITEMS_CHUNK = 6; // batch size for the workspace icons - private final Executor mUiExecutor; + protected final Executor mUiExecutor; - private final LauncherAppState mApp; - private final BgDataModel mBgDataModel; + protected final LauncherAppState mApp; + protected final BgDataModel mBgDataModel; private final AllAppsList mBgAllAppsList; - private final int mPageToBindFirst; + protected final int mPageToBindFirst; - private final WeakReference mCallbacks; + protected final WeakReference mCallbacks; - public LoaderResults(LauncherAppState app, BgDataModel dataModel, + public BaseLoaderResults(LauncherAppState app, BgDataModel dataModel, AllAppsList allAppsList, int pageToBindFirst, WeakReference callbacks) { mUiExecutor = new MainThreadExecutor(); mApp = app; mBgDataModel = dataModel; mBgAllAppsList = allAppsList; mPageToBindFirst = pageToBindFirst; - mCallbacks = callbacks == null ? new WeakReference(null) : callbacks; + mCallbacks = callbacks == null ? new WeakReference<>(null) : callbacks; } /** @@ -152,8 +149,8 @@ public class LoaderResults { Executor mainExecutor = mUiExecutor; // Load items on the current page. - bindWorkspaceItems(currentWorkspaceItems, currentAppWidgets, mainExecutor); - + bindWorkspaceItems(currentWorkspaceItems, mainExecutor); + bindAppWidgets(currentAppWidgets, mainExecutor); // In case of validFirstPage, only bind the first screen, and defer binding the // remaining screens after first onDraw (and an optional the fade animation whichever // happens later). @@ -173,8 +170,8 @@ public class LoaderResults { } }); - bindWorkspaceItems(otherWorkspaceItems, otherAppWidgets, deferredExecutor); - + bindWorkspaceItems(otherWorkspaceItems, deferredExecutor); + bindAppWidgets(otherAppWidgets, deferredExecutor); // Tell the workspace that we're done binding items r = new Runnable() { public void run() { @@ -252,7 +249,7 @@ public class LoaderResults { /** Sorts the set of items by hotseat, workspace (spatially from top to bottom, left to * right) */ - private void sortWorkspaceItemsSpatially(ArrayList workspaceItems) { + protected void sortWorkspaceItemsSpatially(ArrayList workspaceItems) { final InvariantDeviceProfile profile = mApp.getInvariantDeviceProfile(); final int screenCols = profile.numColumns; final int screenCellCount = profile.numColumns * profile.numRows; @@ -288,14 +285,12 @@ public class LoaderResults { }); } - private void bindWorkspaceItems(final ArrayList workspaceItems, - final ArrayList appWidgets, + protected void bindWorkspaceItems(final ArrayList workspaceItems, final Executor executor) { if (com.android.launcher3.Utilities.IS_RUNNING_IN_TEST_HARNESS && com.android.launcher3.Utilities.IS_DEBUG_DEVICE) { - android.util.Log.d("b/117332845", - android.util.Log.getStackTraceString(new Throwable())); + Log.d("b/117332845", Log.getStackTraceString(new Throwable())); } // Bind the workspace items int N = workspaceItems.size(); @@ -307,22 +302,25 @@ public class LoaderResults { public void run() { Callbacks callbacks = mCallbacks.get(); if (callbacks != null) { - callbacks.bindItems(workspaceItems.subList(start, start+chunkSize), false); + callbacks.bindItems(workspaceItems.subList(start, start + chunkSize), + false); } } }; executor.execute(r); } + } - // Bind the widgets, one at a time + private void bindAppWidgets(ArrayList appWidgets, Executor executor) { + int N;// Bind the widgets, one at a time 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); + Callbacks callbacks = mCallbacks.get(); + if (callbacks != null) { + callbacks.bindItems(Collections.singletonList(widget), false); } } }; @@ -330,18 +328,7 @@ public class LoaderResults { } } - public void bindDeepShortcuts() { - final HashMap shortcutMapCopy; - synchronized (mBgDataModel) { - shortcutMapCopy = new HashMap<>(mBgDataModel.deepShortcutMap); - } - mUiExecutor.execute(() -> { - Callbacks callbacks = mCallbacks.get(); - if (callbacks != null) { - callbacks.bindDeepShortcutMap(shortcutMapCopy); - } - }); - } + public abstract void bindDeepShortcuts(); public void bindAllApps() { // shallow copy @@ -359,19 +346,7 @@ public class LoaderResults { mUiExecutor.execute(r); } - public void bindWidgets() { - final ArrayList widgets = - mBgDataModel.widgetsModel.getWidgetsList(mApp.getContext()); - Runnable r = new Runnable() { - public void run() { - Callbacks callbacks = mCallbacks.get(); - if (callbacks != null) { - callbacks.bindAllWidgets(widgets); - } - } - }; - mUiExecutor.execute(r); - } + public abstract void bindWidgets(); public LooperIdleLock newIdleLock(Object lock) { LooperIdleLock idleLock = new LooperIdleLock(lock, Looper.getMainLooper()); diff --git a/src_shortcuts_overrides/com/android/launcher3/model/LoaderResults.java b/src_shortcuts_overrides/com/android/launcher3/model/LoaderResults.java new file mode 100644 index 0000000000..9785887ac7 --- /dev/null +++ b/src_shortcuts_overrides/com/android/launcher3/model/LoaderResults.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.model; + +import com.android.launcher3.AllAppsList; +import com.android.launcher3.LauncherAppState; +import com.android.launcher3.LauncherModel.Callbacks; +import com.android.launcher3.util.ComponentKey; +import com.android.launcher3.widget.WidgetListRowEntry; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.HashMap; + +/** + * Helper class to handle results of {@link com.android.launcher3.model.LoaderTask}. + */ +public class LoaderResults extends BaseLoaderResults { + + public LoaderResults(LauncherAppState app, BgDataModel dataModel, + AllAppsList allAppsList, int pageToBindFirst, WeakReference callbacks) { + super(app, dataModel, allAppsList, pageToBindFirst, callbacks); + } + + @Override + public void bindDeepShortcuts() { + final HashMap shortcutMapCopy; + synchronized (mBgDataModel) { + shortcutMapCopy = new HashMap<>(mBgDataModel.deepShortcutMap); + } + mUiExecutor.execute(() -> { + Callbacks callbacks = mCallbacks.get(); + if (callbacks != null) { + callbacks.bindDeepShortcutMap(shortcutMapCopy); + } + }); + } + + @Override + public void bindWidgets() { + final ArrayList widgets = + mBgDataModel.widgetsModel.getWidgetsList(mApp.getContext()); + Runnable r = new Runnable() { + public void run() { + Callbacks callbacks = mCallbacks.get(); + if (callbacks != null) { + callbacks.bindAllWidgets(widgets); + } + } + }; + mUiExecutor.execute(r); + } +}