diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java b/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java
index 7aa2123..7b24c26 100644
--- a/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java
+++ b/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java
@@ -69,7 +69,6 @@
 import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
 
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.List;
 
 /**
@@ -110,29 +109,9 @@
     private boolean mIsRtl;
     private int mArrowHorizontalOffset;
 
-    /**
-     * Sorts shortcuts in rank order, with manifest shortcuts coming before dynamic shortcuts.
-     */
-    private static final Comparator<ShortcutInfoCompat> sShortcutsComparator
-            = new Comparator<ShortcutInfoCompat>() {
-        @Override
-        public int compare(ShortcutInfoCompat a, ShortcutInfoCompat b) {
-            if (a.isDeclaredInManifest() && !b.isDeclaredInManifest()) {
-                return -1;
-            }
-            if (!a.isDeclaredInManifest() && b.isDeclaredInManifest()) {
-                return 1;
-            }
-            return Integer.compare(a.getRank(), b.getRank());
-        }
-    };
-
-    private static final Comparator<ShortcutInfoCompat> sShortcutsComparatorReversed
-            = Collections.reverseOrder(sShortcutsComparator);
-
     public DeepShortcutsContainer(Context context, AttributeSet attrs, int defStyleAttr) {
         super(context, attrs, defStyleAttr);
-        mLauncher = (Launcher) context;
+        mLauncher = Launcher.getLauncher(context);
         mDeepShortcutsManager = LauncherAppState.getInstance().getShortcutManager();
 
         mDragDeadzone = ViewConfiguration.get(context).getScaledTouchSlop();
@@ -154,10 +133,11 @@
         // Add dummy views first, and populate with real shortcut info when ready.
         final int spacing = getResources().getDimensionPixelSize(R.dimen.deep_shortcuts_spacing);
         final LayoutInflater inflater = mLauncher.getLayoutInflater();
-        for (int i = 0; i < ids.size(); i++) {
+        int numShortcuts = Math.min(ids.size(), ShortcutFilter.MAX_SHORTCUTS);
+        for (int i = 0; i < numShortcuts; i++) {
             final DeepShortcutView shortcut =
                     (DeepShortcutView) inflater.inflate(R.layout.deep_shortcut, this, false);
-            if (i < ids.size() - 1) {
+            if (i < numShortcuts - 1) {
                 ((LayoutParams) shortcut.getLayoutParams()).bottomMargin = spacing;
             }
             shortcut.getBubbleText().setAccessibilityDelegate(mAccessibilityDelegate);
@@ -190,12 +170,12 @@
         new Handler(workerLooper).postAtFrontOfQueue(new Runnable() {
             @Override
             public void run() {
-                final List<ShortcutInfoCompat> shortcuts = mDeepShortcutsManager
-                        .queryForShortcutsContainer(activity, ids, user);
+                final List<ShortcutInfoCompat> shortcuts = ShortcutFilter.sortAndFilterShortcuts(
+                        mDeepShortcutsManager.queryForShortcutsContainer(activity, ids, user));
                 // We want the lowest rank to be closest to the user's finger.
-                final Comparator<ShortcutInfoCompat> shortcutsComparator = mIsAboveIcon ?
-                        sShortcutsComparatorReversed : sShortcutsComparator;
-                Collections.sort(shortcuts, shortcutsComparator);
+                if (mIsAboveIcon) {
+                    Collections.reverse(shortcuts);
+                }
                 for (int i = 0; i < shortcuts.size(); i++) {
                     final ShortcutInfoCompat shortcut = shortcuts.get(i);
                     final ShortcutInfo launcherShortcutInfo =
diff --git a/src/com/android/launcher3/shortcuts/ShortcutFilter.java b/src/com/android/launcher3/shortcuts/ShortcutFilter.java
new file mode 100644
index 0000000..ec68817
--- /dev/null
+++ b/src/com/android/launcher3/shortcuts/ShortcutFilter.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2016 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.shortcuts;
+
+import android.support.annotation.VisibleForTesting;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * Sorts and filters shortcuts.
+ */
+public class ShortcutFilter {
+
+    public static final int MAX_SHORTCUTS = 4;
+    @VisibleForTesting static final int NUM_DYNAMIC = 2;
+
+    /**
+     * Sorts shortcuts in rank order, with manifest shortcuts coming before dynamic shortcuts.
+     */
+    private static final Comparator<ShortcutInfoCompat> RANK_COMPARATOR
+            = new Comparator<ShortcutInfoCompat>() {
+        @Override
+        public int compare(ShortcutInfoCompat a, ShortcutInfoCompat b) {
+            if (a.isDeclaredInManifest() && !b.isDeclaredInManifest()) {
+                return -1;
+            }
+            if (!a.isDeclaredInManifest() && b.isDeclaredInManifest()) {
+                return 1;
+            }
+            return Integer.compare(a.getRank(), b.getRank());
+        }
+    };
+
+    /**
+     * Filters the shortcuts so that only MAX_SHORTCUTS or fewer shortcuts are retained.
+     * We want the filter to include both static and dynamic shortcuts, so we always
+     * include NUM_DYNAMIC dynamic shortcuts, if at least that many are present.
+     *
+     * @return a subset of shortcuts, in sorted order, with size <= MAX_SHORTCUTS.
+     */
+    public static List<ShortcutInfoCompat> sortAndFilterShortcuts(
+            List<ShortcutInfoCompat> shortcuts) {
+        Collections.sort(shortcuts, RANK_COMPARATOR);
+        if (shortcuts.size() <= MAX_SHORTCUTS) {
+            return shortcuts;
+        }
+
+        // The list of shortcuts is now sorted with static shortcuts followed by dynamic
+        // shortcuts. We want to preserve this order, but only keep MAX_SHORTCUTS.
+        List<ShortcutInfoCompat> filteredShortcuts = new ArrayList<>(MAX_SHORTCUTS);
+        int numDynamic = 0;
+        int size = shortcuts.size();
+        for (int i = 0; i < size; i++) {
+            ShortcutInfoCompat shortcut = shortcuts.get(i);
+            int filteredSize = filteredShortcuts.size();
+            if (filteredSize < MAX_SHORTCUTS) {
+                // Always add the first MAX_SHORTCUTS to the filtered list.
+                filteredShortcuts.add(shortcut);
+                if (shortcut.isDynamic()) {
+                    numDynamic++;
+                }
+                continue;
+            }
+            // At this point, we have MAX_SHORTCUTS already, but they may all be static.
+            // If there are dynamic shortcuts, remove static shortcuts to add them.
+            if (shortcut.isDynamic() && numDynamic < NUM_DYNAMIC) {
+                numDynamic++;
+                int lastStaticIndex = filteredSize - numDynamic;
+                filteredShortcuts.remove(lastStaticIndex);
+                filteredShortcuts.add(shortcut);
+            }
+        }
+        return filteredShortcuts;
+    }
+}
diff --git a/tests/src/com/android/launcher3/shortcuts/ShortcutFilterTest.java b/tests/src/com/android/launcher3/shortcuts/ShortcutFilterTest.java
new file mode 100644
index 0000000..05d0ffb
--- /dev/null
+++ b/tests/src/com/android/launcher3/shortcuts/ShortcutFilterTest.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2016 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.shortcuts;
+
+import android.content.pm.ShortcutInfo;
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static com.android.launcher3.shortcuts.ShortcutFilter.MAX_SHORTCUTS;
+import static com.android.launcher3.shortcuts.ShortcutFilter.NUM_DYNAMIC;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests the sorting and filtering of shortcuts in {@link ShortcutFilter}.
+ */
+@RunWith(AndroidJUnit4.class)
+public class ShortcutFilterTest {
+
+    @Test
+    public void testSortAndFilterShortcuts() {
+        filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(3, 0), 3, 0);
+        filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(0, 3), 0, 3);
+        filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(5, 0), MAX_SHORTCUTS, 0);
+        filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(0, 5), 0, MAX_SHORTCUTS);
+        filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(3, 3),
+                MAX_SHORTCUTS - NUM_DYNAMIC, NUM_DYNAMIC);
+        filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(5, 5),
+                MAX_SHORTCUTS - NUM_DYNAMIC, NUM_DYNAMIC);
+        filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(5, 1), MAX_SHORTCUTS - 1, 1);
+        filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(1, 5), 1, MAX_SHORTCUTS - 1);
+        filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(5, 3),
+                MAX_SHORTCUTS - NUM_DYNAMIC, NUM_DYNAMIC);
+        filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(3, 5),
+                MAX_SHORTCUTS - NUM_DYNAMIC, NUM_DYNAMIC);
+    }
+
+    private void filterShortcutsAndAssertNumStaticAndDynamic(
+            List<ShortcutInfoCompat> shortcuts, int expectedStatic, int expectedDynamic) {
+        Collections.shuffle(shortcuts);
+        List<ShortcutInfoCompat> filteredShortcuts = ShortcutFilter.sortAndFilterShortcuts(shortcuts);
+        assertIsSorted(filteredShortcuts);
+
+        int numStatic = 0;
+        int numDynamic = 0;
+        for (ShortcutInfoCompat shortcut : filteredShortcuts) {
+            if (shortcut.isDeclaredInManifest()) {
+                numStatic++;
+            }
+            if (shortcut.isDynamic()) {
+                numDynamic++;
+            }
+        }
+        assertEquals(expectedStatic, numStatic);
+        assertEquals(expectedDynamic, numDynamic);
+    }
+
+    private void assertIsSorted(List<ShortcutInfoCompat> shortcuts) {
+        int lastStaticRank = -1;
+        int lastDynamicRank = -1;
+        boolean hasSeenDynamic = false;
+        for (ShortcutInfoCompat shortcut : shortcuts) {
+            int rank = shortcut.getRank();
+            if (shortcut.isDeclaredInManifest()) {
+                assertFalse("Static shortcuts should come before all dynamic shortcuts.",
+                        hasSeenDynamic);
+                assertTrue(rank > lastStaticRank);
+                lastStaticRank = rank;
+            }
+            if (shortcut.isDynamic()) {
+                hasSeenDynamic = true;
+                assertTrue(rank > lastDynamicRank);
+                lastDynamicRank = rank;
+            }
+        }
+    }
+
+    private List<ShortcutInfoCompat> createShortcutsList(int numStatic, int numDynamic) {
+        List<ShortcutInfoCompat> shortcuts = new ArrayList<>();
+        for (int i = 0; i < numStatic; i++) {
+            shortcuts.add(new Shortcut(true, i));
+        }
+        for (int i = 0; i < numDynamic; i++) {
+            shortcuts.add(new Shortcut(false, i));
+        }
+        return shortcuts;
+    }
+
+    private class Shortcut extends ShortcutInfoCompat {
+        private boolean mIsStatic;
+        private int mRank;
+
+        public Shortcut(ShortcutInfo shortcutInfo) {
+            super(shortcutInfo);
+        }
+
+        public Shortcut(boolean isStatic, int rank) {
+            this(null);
+            mIsStatic = isStatic;
+            mRank = rank;
+        }
+
+        @Override
+        public boolean isDeclaredInManifest() {
+            return mIsStatic;
+        }
+
+        @Override
+        public boolean isDynamic() {
+            return !mIsStatic;
+        }
+
+        @Override
+        public int getRank() {
+            return mRank;
+        }
+    }
+}
\ No newline at end of file
