diff options
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/launcher3/BubbleTextView.java | 2 | ||||
-rw-r--r-- | src/com/android/launcher3/DeleteDropTarget.java | 6 | ||||
-rw-r--r-- | src/com/android/launcher3/Hotseat.java | 41 | ||||
-rw-r--r-- | src/com/android/launcher3/InfoDropTarget.java | 17 | ||||
-rw-r--r-- | src/com/android/launcher3/Launcher.java | 80 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherModel.java | 132 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherSettings.java | 5 | ||||
-rw-r--r-- | src/com/android/launcher3/ShortcutInfo.java | 2 | ||||
-rw-r--r-- | src/com/android/launcher3/Workspace.java | 11 |
9 files changed, 176 insertions, 120 deletions
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index 8dab9432a..659b2b9d9 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -105,10 +105,10 @@ public class BubbleTextView extends TextView { } public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache) { - Bitmap b = info.getIcon(iconCache); LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); + Bitmap b = info.getIcon(iconCache); setCompoundDrawables(null, Utilities.createIconDrawable(b), null, null); setCompoundDrawablePadding((int) ((grid.folderIconSizePx - grid.iconSizePx) / 2f)); diff --git a/src/com/android/launcher3/DeleteDropTarget.java b/src/com/android/launcher3/DeleteDropTarget.java index 4023dafb6..150d958a8 100644 --- a/src/com/android/launcher3/DeleteDropTarget.java +++ b/src/com/android/launcher3/DeleteDropTarget.java @@ -104,6 +104,7 @@ public class DeleteDropTarget extends ButtonDropTarget { switch (addInfo.itemType) { case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: + case LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS: return true; } } @@ -145,6 +146,11 @@ public class DeleteDropTarget extends ButtonDropTarget { return true; } + if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS && + LauncherModel.hasMultipleAllAppsShortcuts()) { + return true; + } + if (!AppsCustomizePagedView.DISABLE_ALL_APPS && item.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) { return true; diff --git a/src/com/android/launcher3/Hotseat.java b/src/com/android/launcher3/Hotseat.java index c88cd1da5..2812b4129 100644 --- a/src/com/android/launcher3/Hotseat.java +++ b/src/com/android/launcher3/Hotseat.java @@ -94,13 +94,6 @@ public class Hotseat extends FrameLayout { int getCellYFromOrder(int rank) { return hasVerticalHotseat() ? (mContent.getCountY() - (rank + 1)) : 0; } - public boolean isAllAppsButtonRank(int rank) { - if (AppsCustomizePagedView.DISABLE_ALL_APPS) { - return false; - } else { - return rank == mAllAppsButtonRank; - } - } /** This returns the coordinates of an app in a given cell, relative to the DragLayer */ Rect getCellCoordinates(int cellX, int cellY) { @@ -141,40 +134,6 @@ public class Hotseat extends FrameLayout { void resetLayout() { mContent.removeAllViewsInLayout(); - - if (!AppsCustomizePagedView.DISABLE_ALL_APPS) { - // Add the Apps button - Context context = getContext(); - - LayoutInflater inflater = LayoutInflater.from(context); - TextView allAppsButton = (TextView) - inflater.inflate(R.layout.all_apps_button, mContent, false); - Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon); - Utilities.resizeIconDrawable(d); - Utilities.applyTypeface(allAppsButton); - allAppsButton.setCompoundDrawables(null, d, null, null); - - allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label)); - if (mLauncher != null) { - allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener()); - } - allAppsButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(android.view.View v) { - if (mLauncher != null) { - mLauncher.onClickAllAppsButton(v); - } - } - }); - - // Note: We do this to ensure that the hotseat is always laid out in the orientation of - // the hotseat in order regardless of which orientation they were added - int x = getCellXFromOrder(mAllAppsButtonRank); - int y = getCellYFromOrder(mAllAppsButtonRank); - CellLayout.LayoutParams lp = new CellLayout.LayoutParams(x,y,1,1); - lp.canReorder = false; - mContent.addViewToCellLayout(allAppsButton, -1, 0, lp, true); - } } @Override diff --git a/src/com/android/launcher3/InfoDropTarget.java b/src/com/android/launcher3/InfoDropTarget.java index d27ddd958..73cda08a9 100644 --- a/src/com/android/launcher3/InfoDropTarget.java +++ b/src/com/android/launcher3/InfoDropTarget.java @@ -63,12 +63,17 @@ public class InfoDropTarget extends ButtonDropTarget { } private ComponentName dragItemComponentName(Object dragInfo) { - if (dragInfo instanceof AppInfo) { - return ((AppInfo) dragInfo).componentName; - } else if (dragInfo instanceof ShortcutInfo) { - return ((ShortcutInfo) dragInfo).intent.getComponent(); - } else if (dragInfo instanceof PendingAddItemInfo) { - return ((PendingAddItemInfo) dragInfo).componentName; + if (dragInfo instanceof ItemInfo) { + if (((ItemInfo) dragInfo).itemType == LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS) { + return null; + } + if (dragInfo instanceof AppInfo) { + return ((AppInfo) dragInfo).componentName; + } else if (dragInfo instanceof ShortcutInfo) { + return ((ShortcutInfo) dragInfo).intent.getComponent(); + } else if (dragInfo instanceof PendingAddItemInfo) { + return ((PendingAddItemInfo) dragInfo).componentName; + } } return null; } diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 6347324ed..bfd5271df 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -111,6 +111,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; +import java.lang.reflect.Array; import java.text.DateFormat; import java.util.ArrayList; import java.util.Collection; @@ -1321,6 +1322,13 @@ public class Launcher extends Activity BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false); favorite.applyFromShortcutInfo(info, mIconCache); favorite.setOnClickListener(this); + if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS && info.getIcon(mIconCache) == null) { + // All apps icon + Drawable d = getResources().getDrawable(R.drawable.all_apps_button_icon); + Utilities.resizeIconDrawable(d); + favorite.setCompoundDrawables(null, d, null, null); + favorite.setOnTouchListener(getHapticFeedbackTouchListener()); + } Utilities.applyTypeface(favorite); return favorite; } @@ -2257,37 +2265,41 @@ public class Launcher extends Activity if (tag instanceof ShortcutInfo) { // Open shortcut final ShortcutInfo shortcut = (ShortcutInfo) tag; - final Intent intent = shortcut.intent; - - // Check for special shortcuts - if (intent.getComponent() != null) { - final String shortcutClass = intent.getComponent().getClassName(); - - if (shortcutClass.equals(WidgetAdder.class.getName())) { - showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true); - return; - } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) { - MemoryDumpActivity.startDump(this); - return; - } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) { - toggleShowWeightWatcher(); - return; + if (shortcut.itemType == LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS) { + showAllApps(true, AppsCustomizePagedView.ContentType.Applications, true); + } else { + final Intent intent = shortcut.intent; + + // Check for special shortcuts + if (intent.getComponent() != null) { + final String shortcutClass = intent.getComponent().getClassName(); + + if (shortcutClass.equals(WidgetAdder.class.getName())) { + showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true); + return; + } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) { + MemoryDumpActivity.startDump(this); + return; + } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) { + toggleShowWeightWatcher(); + return; + } } - } - // Start activities - int[] pos = new int[2]; - v.getLocationOnScreen(pos); - intent.setSourceBounds(new Rect(pos[0], pos[1], - pos[0] + v.getWidth(), pos[1] + v.getHeight())); + // Start activities + int[] pos = new int[2]; + v.getLocationOnScreen(pos); + intent.setSourceBounds(new Rect(pos[0], pos[1], + pos[0] + v.getWidth(), pos[1] + v.getHeight())); - boolean success = startActivitySafely(v, intent, tag); + boolean success = startActivitySafely(v, intent, tag); - mStats.recordLaunch(intent, shortcut); + mStats.recordLaunch(intent, shortcut); - if (success && v instanceof BubbleTextView) { - mWaitingForResume = (BubbleTextView) v; - mWaitingForResume.setStayPressed(true); + if (success && v instanceof BubbleTextView) { + mWaitingForResume = (BubbleTextView) v; + mWaitingForResume.setStayPressed(true); + } } } else if (tag instanceof FolderInfo) { if (v instanceof FolderIcon) { @@ -3742,17 +3754,21 @@ public class Launcher extends Activity * * Implementation of the method from LauncherModel.Callbacks. */ - public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end, + public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end, final boolean forceAnimateIcons) { + final ArrayList<ItemInfo> items = shortcuts; + final int s = start; + final int e = end; Runnable r = new Runnable() { public void run() { - bindItems(shortcuts, start, end, forceAnimateIcons); + bindItems(items, s, e, forceAnimateIcons); } }; if (waitUntilResume(r)) { return; } + // Get the list of added shortcuts and intersect them with the set of shortcuts here final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet(); final Collection<Animator> bounceAnims = new ArrayList<Animator>(); @@ -3771,6 +3787,7 @@ public class Launcher extends Activity switch (item.itemType) { case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: + case LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS: ShortcutInfo info = (ShortcutInfo) item; View shortcut = createShortcut(info); @@ -3944,13 +3961,6 @@ public class Launcher extends Activity }); } - public boolean isAllAppsButtonRank(int rank) { - if (mHotseat != null) { - return mHotseat.isAllAppsButtonRank(rank); - } - return false; - } - private boolean canRunNewAppsAnimation() { long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime(); return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000); diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index e26d405bc..00b6fbb8e 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -169,7 +169,6 @@ public class LauncherModel extends BroadcastReceiver { boolean matchPackageNamesOnly); public void bindPackagesUpdated(ArrayList<Object> widgetsAndShortcuts); public void bindSearchablesChanged(); - public boolean isAllAppsButtonRank(int rank); public void onPageBoundSynchronously(int page); public void dumpLogsToLocalData(); } @@ -586,6 +585,7 @@ public class LauncherModel extends BroadcastReceiver { case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: + case LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS: if (!sBgWorkspaceItems.contains(modelItem)) { sBgWorkspaceItems.add(modelItem); } @@ -874,6 +874,7 @@ public class LauncherModel extends BroadcastReceiver { // Fall through case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: + case LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS: if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP || item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { sBgWorkspaceItems.add(item); @@ -897,6 +898,56 @@ public class LauncherModel extends BroadcastReceiver { } /** + * Checks whether there is an all apps shortcut in the database + */ + static boolean hasAllAppsShortcut() { + for (ItemInfo info : sBgWorkspaceItems) { + if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS) { + return true; + } + } + return false; + } + + /** + * Checks whether there is more than 1 all apps shortcut in the database + */ + static boolean hasMultipleAllAppsShortcuts() { + boolean foundOne = false; + for (ItemInfo info : sBgWorkspaceItems) { + if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS) { + if (!foundOne) { + foundOne = true; + } else { + return true; + } + } + } + return false; + } + + /** + * Add an all apps shortcut to the database if there aren't any already + */ + private ItemInfo addAllAppsShortcutIfNecessary() { + if (hasAllAppsShortcut()) return null; + + DeviceProfile grid = mApp.getDynamicGrid().getDeviceProfile(); + int allAppsIndex = grid.hotseatAllAppsRank; + + ShortcutInfo allAppsShortcut = new ShortcutInfo(); + allAppsShortcut.itemType = LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS; + allAppsShortcut.title = mApp.getContext().getResources().getString(R.string.all_apps_button_label); + allAppsShortcut.container = ItemInfo.NO_ID; + allAppsShortcut.spanX = 1; + allAppsShortcut.spanY = 1; + LauncherModel.addOrMoveItemInDatabase(mApp.getContext(), allAppsShortcut, LauncherSettings.Favorites.CONTAINER_HOTSEAT, + allAppsIndex, allAppsIndex, 0); + + return allAppsShortcut; + } + + /** * Creates a new unique child id, for a given cell span across all layouts. */ static int getCellLayoutChildId( @@ -936,6 +987,7 @@ public class LauncherModel extends BroadcastReceiver { break; case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: + case LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS: sBgWorkspaceItems.remove(item); break; case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: @@ -1529,13 +1581,6 @@ public class LauncherModel extends BroadcastReceiver { long containerIndex = item.screenId; if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { - // Return early if we detect that an item is under the hotseat button - if (mCallbacks == null || - mCallbacks.get().isAllAppsButtonRank((int) item.screenId)) { - deleteOnItemOverlap.set(true); - return false; - } - if (occupied.containsKey(LauncherSettings.Favorites.CONTAINER_HOTSEAT)) { if (occupied.get(LauncherSettings.Favorites.CONTAINER_HOTSEAT) [(int) item.screenId][0] != null) { @@ -1544,7 +1589,11 @@ public class LauncherModel extends BroadcastReceiver { + item.cellY + ") occupied by " + occupied.get(LauncherSettings.Favorites.CONTAINER_HOTSEAT) [(int) item.screenId][0]); - return false; + if (occupied.get(LauncherSettings.Favorites.CONTAINER_HOTSEAT) + [(int) item.screenId][0].itemType == LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS) { + deleteOnItemOverlap.set(true); + } + return false; } } else { ItemInfo[][] items = new ItemInfo[countX + 1][countY + 1]; @@ -1671,7 +1720,7 @@ public class LauncherModel extends BroadcastReceiver { LauncherAppWidgetInfo appWidgetInfo; int container; long id; - Intent intent; + Intent intent = null; while (!mStopped && c.moveToNext()) { AtomicBoolean deleteOnItemOverlap = new AtomicBoolean(false); @@ -1681,32 +1730,38 @@ public class LauncherModel extends BroadcastReceiver { switch (itemType) { case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: + case LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS: id = c.getLong(idIndex); intentDescription = c.getString(intentIndex); - try { - intent = Intent.parseUri(intentDescription, 0); - ComponentName cn = intent.getComponent(); - if (cn != null && !isValidPackageComponent(manager, cn)) { - if (!mAppsCanBeOnRemoveableStorage) { - // Log the invalid package, and remove it from the db - Launcher.addDumpLog(TAG, "Invalid package removed: " + cn, true); - itemsToRemove.add(id); - } else { - // If apps can be on external storage, then we just - // leave them for the user to remove (maybe add - // visual treatment to it) - Launcher.addDumpLog(TAG, "Invalid package found: " + cn, true); + if (itemType != LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS) { + try { + intent = Intent.parseUri(intentDescription, 0); + ComponentName cn = intent.getComponent(); + if (cn != null && !isValidPackageComponent(manager, cn)) { + if (!mAppsCanBeOnRemoveableStorage) { + // Log the invalid package, and remove it from the db + Launcher.addDumpLog(TAG, "Invalid package removed: " + cn, true); + itemsToRemove.add(id); + } else { + // If apps can be on external storage, then we just + // leave them for the user to remove (maybe add + // visual treatment to it) + Launcher.addDumpLog(TAG, "Invalid package found: " + cn, true); + } + continue; } + } catch (URISyntaxException e) { + Launcher.addDumpLog(TAG, "Invalid uri: " + intentDescription, true); continue; } - } catch (URISyntaxException e) { - Launcher.addDumpLog(TAG, "Invalid uri: " + intentDescription, true); - continue; } if (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) { info = getShortcutInfo(manager, intent, context, c, iconIndex, titleIndex, mLabelCache); + } else if (itemType == LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS) { + info = getShortcutInfo(c, context, + titleIndex); } else { info = getShortcutInfo(c, context, iconTypeIndex, iconPackageIndex, iconResourceIndex, iconIndex, @@ -1901,6 +1956,19 @@ public class LauncherModel extends BroadcastReceiver { return false; } + // Add an all apps button to the database if there isn't one already + ItemInfo allAppsButton = addAllAppsShortcutIfNecessary(); + if (allAppsButton != null) { + // Check if there was an icon occupying the default position and remove + if (occupied.containsKey(allAppsButton.container)) { + if (occupied.get(allAppsButton.container) + [(int) allAppsButton.screenId][0] != null) { + itemsToRemove.add(occupied.get(allAppsButton.container) + [(int) allAppsButton.screenId][0].id); + } + } + } + if (itemsToRemove.size() > 0) { ContentProviderClient client = contentResolver.acquireContentProviderClient( LauncherSettings.Favorites.CONTENT_URI); @@ -2817,6 +2885,18 @@ public class LauncherModel extends BroadcastReceiver { * Make an ShortcutInfo object for a shortcut that isn't an application. */ private ShortcutInfo getShortcutInfo(Cursor c, Context context, + int titleIndex) { + final ShortcutInfo info = new ShortcutInfo(); + info.itemType = LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS; + + info.title = c.getString(titleIndex); + return info; + } + + /** + * Make an ShortcutInfo object for a shortcut that isn't an application. + */ + private ShortcutInfo getShortcutInfo(Cursor c, Context context, int iconTypeIndex, int iconPackageIndex, int iconResourceIndex, int iconIndex, int titleIndex) { diff --git a/src/com/android/launcher3/LauncherSettings.java b/src/com/android/launcher3/LauncherSettings.java index 988e5efca..1d161d097 100644 --- a/src/com/android/launcher3/LauncherSettings.java +++ b/src/com/android/launcher3/LauncherSettings.java @@ -223,6 +223,11 @@ class LauncherSettings { static final int ITEM_TYPE_APPWIDGET = 4; /** + * The favorite is the all apps button + */ + static final int ITEM_TYPE_ALLAPPS = 5; + + /** * The favorite is a clock */ static final int ITEM_TYPE_WIDGET_CLOCK = 1000; diff --git a/src/com/android/launcher3/ShortcutInfo.java b/src/com/android/launcher3/ShortcutInfo.java index dafabb8d9..0998eec2b 100644 --- a/src/com/android/launcher3/ShortcutInfo.java +++ b/src/com/android/launcher3/ShortcutInfo.java @@ -118,7 +118,7 @@ class ShortcutInfo extends ItemInfo { } public Bitmap getIcon(IconCache iconCache) { - if (mIcon == null) { + if (mIcon == null && itemType != LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS) { updateIcon(iconCache); } return mIcon; diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 7dc228925..84a5996df 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -2618,16 +2618,7 @@ public class Workspace extends SmoothPagedView // Don't accept the drop if there's no room for the item if (!foundCell) { - // Don't show the message if we are dropping on the AllApps button and the hotseat - // is full boolean isHotseat = mLauncher.isHotseatLayout(dropTargetLayout); - if (mTargetCell != null && isHotseat) { - Hotseat hotseat = mLauncher.getHotseat(); - if (hotseat.isAllAppsButtonRank( - hotseat.getOrderInHotseat(mTargetCell[0], mTargetCell[1]))) { - return false; - } - } mLauncher.showOutOfSpaceMessage(isHotseat); return false; @@ -4026,7 +4017,7 @@ public class Workspace extends SmoothPagedView View v = children.get(i); ItemInfo info = (ItemInfo) v.getTag(); // Null check required as the AllApps button doesn't have an item info - if (info instanceof ShortcutInfo) { + if (info instanceof ShortcutInfo && info.itemType != LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS) { ShortcutInfo si = (ShortcutInfo) info; ComponentName cn = si.intent.getComponent(); |