Loading src/com/android/launcher3/Launcher.java +9 −45 Original line number Diff line number Diff line Loading @@ -383,9 +383,6 @@ public class Launcher extends StatefulActivity<LauncherState> private PopupDataProvider mPopupDataProvider; private IntSet mSynchronouslyBoundPages = new IntSet(); @NonNull private IntSet mPagesToBindSynchronously = new IntSet(); // We only want to get the SharedPreferences once since it does an FS stat each time we get // it from the context. private SharedPreferences mSharedPrefs; Loading Loading @@ -560,7 +557,7 @@ public class Launcher extends StatefulActivity<LauncherState> if (savedInstanceState != null) { int[] pageIds = savedInstanceState.getIntArray(RUNTIME_STATE_CURRENT_SCREEN_IDS); if (pageIds != null) { mPagesToBindSynchronously = IntSet.wrap(pageIds); mModelCallbacks.setPagesToBindSynchronously(IntSet.wrap(pageIds)); } } Loading Loading @@ -1648,8 +1645,9 @@ public class Launcher extends StatefulActivity<LauncherState> @Override public void onRestoreInstanceState(Bundle state) { super.onRestoreInstanceState(state); if (mSynchronouslyBoundPages != null) { mSynchronouslyBoundPages.forEach(screenId -> { IntSet synchronouslyBoundPages = mModelCallbacks.getSynchronouslyBoundPages(); if (synchronouslyBoundPages != null) { synchronouslyBoundPages.forEach(screenId -> { int pageIndex = mWorkspace.getPageIndexForScreenId(screenId); if (pageIndex != PagedView.INVALID_PAGE) { mWorkspace.restoreInstanceStateForChild(pageIndex); Loading Loading @@ -2072,41 +2070,7 @@ public class Launcher extends StatefulActivity<LauncherState> @Override public IntSet getPagesToBindSynchronously(IntArray orderedScreenIds) { IntSet visibleIds; if (!mPagesToBindSynchronously.isEmpty()) { visibleIds = mPagesToBindSynchronously; } else if (!mWorkspaceLoading) { visibleIds = mWorkspace.getCurrentPageScreenIds(); } else { // If workspace binding is still in progress, getCurrentPageScreenIds won't be accurate, // and we should use mSynchronouslyBoundPages that's set during initial binding. visibleIds = mSynchronouslyBoundPages; } IntArray actualIds = new IntArray(); IntSet result = new IntSet(); if (visibleIds.isEmpty()) { return result; } for (int id : orderedScreenIds.toArray()) { actualIds.add(id); } int firstId = visibleIds.getArray().get(0); int pairId = mWorkspace.getScreenPair(firstId); // Double check that actual screenIds contains the visibleId, as empty screens are hidden // in single panel. if (actualIds.contains(firstId)) { result.add(firstId); if (mDeviceProfile.isTwoPanels && actualIds.contains(pairId)) { result.add(pairId); } } else if (LauncherAppState.getIDP(this).supportedProfiles.stream().anyMatch( deviceProfile -> deviceProfile.isTwoPanels) && actualIds.contains(pairId)) { // Add the right panel if left panel is hidden when switching display, due to empty // pages being hidden in single panel. result.add(pairId); } return result; return mModelCallbacks.getPagesToBindSynchronously(orderedScreenIds); } /** Loading Loading @@ -2608,8 +2572,8 @@ public class Launcher extends StatefulActivity<LauncherState> @TargetApi(Build.VERSION_CODES.S) public void onInitialBindComplete(IntSet boundPages, RunnableList pendingTasks, int workspaceItemCount, boolean isBindSync) { mSynchronouslyBoundPages = boundPages; mPagesToBindSynchronously = new IntSet(); mModelCallbacks.setSynchronouslyBoundPages(boundPages); mModelCallbacks.setPagesToBindSynchronously(new IntSet()); clearPendingBinds(); ViewOnDrawExecutor executor = new ViewOnDrawExecutor(pendingTasks); Loading Loading @@ -2682,7 +2646,7 @@ public class Launcher extends StatefulActivity<LauncherState> // Since we are just resetting the current page without user interaction, // override the previous page so we don't log the page switch. mWorkspace.setCurrentPage(currentPage, currentPage /* overridePrevPage */); mPagesToBindSynchronously = new IntSet(); mModelCallbacks.setPagesToBindSynchronously(new IntSet()); // Cache one page worth of icons getViewCache().setCacheSize(R.layout.folder_application, Loading Loading @@ -3259,7 +3223,7 @@ public class Launcher extends StatefulActivity<LauncherState> * @param pages should not be null. */ public void setPagesToBindSynchronously(@NonNull IntSet pages) { mPagesToBindSynchronously = pages; mModelCallbacks.setPagesToBindSynchronously(pages); } @Override Loading src/com/android/launcher3/ModelCallbacks.kt +42 −0 Original line number Diff line number Diff line Loading @@ -8,12 +8,18 @@ import com.android.launcher3.model.data.LauncherAppWidgetInfo import com.android.launcher3.model.data.WorkspaceItemInfo import com.android.launcher3.popup.PopupContainerWithArrow import com.android.launcher3.util.ComponentKey import com.android.launcher3.util.IntArray as LIntArray import com.android.launcher3.util.IntSet as LIntSet import com.android.launcher3.util.PackageUserKey import com.android.launcher3.util.Preconditions import com.android.launcher3.widget.model.WidgetsListBaseEntry import java.util.function.Predicate class ModelCallbacks(private var launcher: Launcher) : BgDataModel.Callbacks { var synchronouslyBoundPages = LIntSet() var pagesToBindSynchronously = LIntSet() override fun preAddApps() { // If there's an undo snackbar, force it to complete to ensure empty screens are removed // before trying to add new items. Loading Loading @@ -93,4 +99,40 @@ class ModelCallbacks(private var launcher: Launcher) : BgDataModel.Callbacks { override fun bindAllWidgets(allWidgets: List<WidgetsListBaseEntry?>?) { launcher.popupDataProvider.allWidgets = allWidgets } /** Returns the ids of the workspaces to bind. */ override fun getPagesToBindSynchronously(orderedScreenIds: LIntArray): LIntSet { // If workspace binding is still in progress, getCurrentPageScreenIds won't be // accurate, and we should use mSynchronouslyBoundPages that's set during initial binding. val visibleIds = when { !pagesToBindSynchronously.isEmpty -> pagesToBindSynchronously !launcher.isWorkspaceLoading -> launcher.workspace.currentPageScreenIds else -> synchronouslyBoundPages } // Launcher IntArray has the same name as Kotlin IntArray val result = LIntSet() if (visibleIds.isEmpty) { return result } val actualIds = orderedScreenIds.clone() val firstId = visibleIds.first() val pairId = launcher.workspace.getScreenPair(firstId) // Double check that actual screenIds contains the visibleId, as empty screens are hidden // in single panel. if (actualIds.contains(firstId)) { result.add(firstId) if (launcher.deviceProfile.isTwoPanels && actualIds.contains(pairId)) { result.add(pairId) } } else if ( LauncherAppState.getIDP(launcher).supportedProfiles.any(DeviceProfile::isTwoPanels) && actualIds.contains(pairId) ) { // Add the right panel if left panel is hidden when switching display, due to empty // pages being hidden in single panel. result.add(pairId) } return result } } Loading
src/com/android/launcher3/Launcher.java +9 −45 Original line number Diff line number Diff line Loading @@ -383,9 +383,6 @@ public class Launcher extends StatefulActivity<LauncherState> private PopupDataProvider mPopupDataProvider; private IntSet mSynchronouslyBoundPages = new IntSet(); @NonNull private IntSet mPagesToBindSynchronously = new IntSet(); // We only want to get the SharedPreferences once since it does an FS stat each time we get // it from the context. private SharedPreferences mSharedPrefs; Loading Loading @@ -560,7 +557,7 @@ public class Launcher extends StatefulActivity<LauncherState> if (savedInstanceState != null) { int[] pageIds = savedInstanceState.getIntArray(RUNTIME_STATE_CURRENT_SCREEN_IDS); if (pageIds != null) { mPagesToBindSynchronously = IntSet.wrap(pageIds); mModelCallbacks.setPagesToBindSynchronously(IntSet.wrap(pageIds)); } } Loading Loading @@ -1648,8 +1645,9 @@ public class Launcher extends StatefulActivity<LauncherState> @Override public void onRestoreInstanceState(Bundle state) { super.onRestoreInstanceState(state); if (mSynchronouslyBoundPages != null) { mSynchronouslyBoundPages.forEach(screenId -> { IntSet synchronouslyBoundPages = mModelCallbacks.getSynchronouslyBoundPages(); if (synchronouslyBoundPages != null) { synchronouslyBoundPages.forEach(screenId -> { int pageIndex = mWorkspace.getPageIndexForScreenId(screenId); if (pageIndex != PagedView.INVALID_PAGE) { mWorkspace.restoreInstanceStateForChild(pageIndex); Loading Loading @@ -2072,41 +2070,7 @@ public class Launcher extends StatefulActivity<LauncherState> @Override public IntSet getPagesToBindSynchronously(IntArray orderedScreenIds) { IntSet visibleIds; if (!mPagesToBindSynchronously.isEmpty()) { visibleIds = mPagesToBindSynchronously; } else if (!mWorkspaceLoading) { visibleIds = mWorkspace.getCurrentPageScreenIds(); } else { // If workspace binding is still in progress, getCurrentPageScreenIds won't be accurate, // and we should use mSynchronouslyBoundPages that's set during initial binding. visibleIds = mSynchronouslyBoundPages; } IntArray actualIds = new IntArray(); IntSet result = new IntSet(); if (visibleIds.isEmpty()) { return result; } for (int id : orderedScreenIds.toArray()) { actualIds.add(id); } int firstId = visibleIds.getArray().get(0); int pairId = mWorkspace.getScreenPair(firstId); // Double check that actual screenIds contains the visibleId, as empty screens are hidden // in single panel. if (actualIds.contains(firstId)) { result.add(firstId); if (mDeviceProfile.isTwoPanels && actualIds.contains(pairId)) { result.add(pairId); } } else if (LauncherAppState.getIDP(this).supportedProfiles.stream().anyMatch( deviceProfile -> deviceProfile.isTwoPanels) && actualIds.contains(pairId)) { // Add the right panel if left panel is hidden when switching display, due to empty // pages being hidden in single panel. result.add(pairId); } return result; return mModelCallbacks.getPagesToBindSynchronously(orderedScreenIds); } /** Loading Loading @@ -2608,8 +2572,8 @@ public class Launcher extends StatefulActivity<LauncherState> @TargetApi(Build.VERSION_CODES.S) public void onInitialBindComplete(IntSet boundPages, RunnableList pendingTasks, int workspaceItemCount, boolean isBindSync) { mSynchronouslyBoundPages = boundPages; mPagesToBindSynchronously = new IntSet(); mModelCallbacks.setSynchronouslyBoundPages(boundPages); mModelCallbacks.setPagesToBindSynchronously(new IntSet()); clearPendingBinds(); ViewOnDrawExecutor executor = new ViewOnDrawExecutor(pendingTasks); Loading Loading @@ -2682,7 +2646,7 @@ public class Launcher extends StatefulActivity<LauncherState> // Since we are just resetting the current page without user interaction, // override the previous page so we don't log the page switch. mWorkspace.setCurrentPage(currentPage, currentPage /* overridePrevPage */); mPagesToBindSynchronously = new IntSet(); mModelCallbacks.setPagesToBindSynchronously(new IntSet()); // Cache one page worth of icons getViewCache().setCacheSize(R.layout.folder_application, Loading Loading @@ -3259,7 +3223,7 @@ public class Launcher extends StatefulActivity<LauncherState> * @param pages should not be null. */ public void setPagesToBindSynchronously(@NonNull IntSet pages) { mPagesToBindSynchronously = pages; mModelCallbacks.setPagesToBindSynchronously(pages); } @Override Loading
src/com/android/launcher3/ModelCallbacks.kt +42 −0 Original line number Diff line number Diff line Loading @@ -8,12 +8,18 @@ import com.android.launcher3.model.data.LauncherAppWidgetInfo import com.android.launcher3.model.data.WorkspaceItemInfo import com.android.launcher3.popup.PopupContainerWithArrow import com.android.launcher3.util.ComponentKey import com.android.launcher3.util.IntArray as LIntArray import com.android.launcher3.util.IntSet as LIntSet import com.android.launcher3.util.PackageUserKey import com.android.launcher3.util.Preconditions import com.android.launcher3.widget.model.WidgetsListBaseEntry import java.util.function.Predicate class ModelCallbacks(private var launcher: Launcher) : BgDataModel.Callbacks { var synchronouslyBoundPages = LIntSet() var pagesToBindSynchronously = LIntSet() override fun preAddApps() { // If there's an undo snackbar, force it to complete to ensure empty screens are removed // before trying to add new items. Loading Loading @@ -93,4 +99,40 @@ class ModelCallbacks(private var launcher: Launcher) : BgDataModel.Callbacks { override fun bindAllWidgets(allWidgets: List<WidgetsListBaseEntry?>?) { launcher.popupDataProvider.allWidgets = allWidgets } /** Returns the ids of the workspaces to bind. */ override fun getPagesToBindSynchronously(orderedScreenIds: LIntArray): LIntSet { // If workspace binding is still in progress, getCurrentPageScreenIds won't be // accurate, and we should use mSynchronouslyBoundPages that's set during initial binding. val visibleIds = when { !pagesToBindSynchronously.isEmpty -> pagesToBindSynchronously !launcher.isWorkspaceLoading -> launcher.workspace.currentPageScreenIds else -> synchronouslyBoundPages } // Launcher IntArray has the same name as Kotlin IntArray val result = LIntSet() if (visibleIds.isEmpty) { return result } val actualIds = orderedScreenIds.clone() val firstId = visibleIds.first() val pairId = launcher.workspace.getScreenPair(firstId) // Double check that actual screenIds contains the visibleId, as empty screens are hidden // in single panel. if (actualIds.contains(firstId)) { result.add(firstId) if (launcher.deviceProfile.isTwoPanels && actualIds.contains(pairId)) { result.add(pairId) } } else if ( LauncherAppState.getIDP(launcher).supportedProfiles.any(DeviceProfile::isTwoPanels) && actualIds.contains(pairId) ) { // Add the right panel if left panel is hidden when switching display, due to empty // pages being hidden in single panel. result.add(pairId) } return result } }