From 71b3d1c38e028d7c1f625543a30993af1193b321 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Wed, 20 Jul 2016 17:42:05 -0700 Subject: [PATCH] Optimizing open shortcuts container lookep findviewById does a DFS, inseat only looking at the first level children Change-Id: Idc028a56648ca026c6022425e3a6e7453fa91986 --- src/com/android/launcher3/Launcher.java | 10 +++++++++- src/com/android/launcher3/Workspace.java | 5 +++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 73cd800ca..0571787c8 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -3128,7 +3128,15 @@ public class Launcher extends Activity * @return The open shortcuts container, or null if there is none */ public DeepShortcutsContainer getOpenShortcutsContainer() { - return (DeepShortcutsContainer) mDragLayer.findViewById(R.id.deep_shortcuts_container); + // Iterate in reverse order. Shortcuts container is added later to the dragLayer, + // and will be one of the last views. + for (int i = mDragLayer.getChildCount() - 1; i >= 0; i--) { + View child = mDragLayer.getChildAt(i); + if (child instanceof DeepShortcutsContainer) { + return (DeepShortcutsContainer) child; + } + } + return null; } @Override diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 75d4a8d3d..7d7324d0b 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -532,8 +532,9 @@ public class Workspace extends PagedView */ public Folder getOpenFolder() { DragLayer dragLayer = mLauncher.getDragLayer(); - int count = dragLayer.getChildCount(); - for (int i = 0; i < count; i++) { + // Iterate in reverse order. Folder is added later to the dragLayer, + // and will be one of the last views. + for (int i = dragLayer.getChildCount() - 1; i >= 0; i--) { View child = dragLayer.getChildAt(i); if (child instanceof Folder) { Folder folder = (Folder) child; -- 2.11.0