From 99894d9bb73fdc4bf9bba8423b5c5d5715a4f5d5 Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Fri, 14 Jun 2013 11:22:59 -0700 Subject: Fixing up handling of shortcuts Change-Id: I70dd044b608f4ef18a9c436964a11122168305d0 --- src/com/android/launcher3/Launcher.java | 31 ++++++++++++++++++++++++++----- src/com/android/launcher3/Workspace.java | 32 ++++++++++++++++++++++++++------ 2 files changed, 52 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 46943b510..db7a2ba76 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -44,6 +44,7 @@ import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Configuration; import android.content.res.Resources; @@ -2042,7 +2043,8 @@ public class Launcher extends Activity final Intent intent = ((ShortcutInfo) tag).intent; ComponentName widgetComp = new ComponentName(this, WidgetAdder.class); - if (intent.getComponent().getClassName().equals(widgetComp.getClassName())) { + if (intent.getComponent() != null && + intent.getComponent().getClassName().equals(widgetComp.getClassName())) { showAllApps(true); return; } @@ -3641,11 +3643,11 @@ public class Launcher extends Activity mWorkspaceLoading = false; if (upgradePath) { mWorkspace.saveWorkspaceToDb(); - - // Run through this twice... a little hackleberry, but the right solution is complex. - mWorkspace.stripDuplicateApps(); - mIntentsOnWorkspaceFromUpgradePath = mWorkspace.stripDuplicateApps(); + ArrayList allApps = constructAllAppsComponents(); + mWorkspace.stripDuplicateApps(allApps); + mIntentsOnWorkspaceFromUpgradePath = mWorkspace.stripDuplicateApps(allApps); } + mWorkspace.post(new Runnable() { @Override public void run() { @@ -3654,6 +3656,25 @@ public class Launcher extends Activity }); } + private ArrayList constructAllAppsComponents() { + // Run through this twice... a little hackleberry, but the right solution is complex. + final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); + mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); + + List apps = getPackageManager().queryIntentActivities(mainIntent, 0); + ArrayList allApps = new ArrayList(); + + int count = apps.size(); + for (int i = 0; i < count; i++) { + ActivityInfo ai = apps.get(i).activityInfo; + + ComponentName cn = + new ComponentName(ai.applicationInfo.packageName, ai.name); + allApps.add(cn); + } + return allApps; + } + 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/Workspace.java b/src/com/android/launcher3/Workspace.java index abf3b9832..dc784ee93 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -29,6 +29,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Bitmap; @@ -39,6 +40,7 @@ import android.graphics.PointF; import android.graphics.Rect; import android.graphics.Region.Op; import android.graphics.drawable.Drawable; +import android.net.Uri; import android.os.IBinder; import android.os.Parcelable; import android.util.AttributeSet; @@ -60,6 +62,7 @@ import java.net.URISyntaxException; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Set; /** @@ -3427,18 +3430,19 @@ public class Workspace extends SmoothPagedView } } - ArrayList stripDuplicateApps() { + ArrayList stripDuplicateApps(ArrayList allApps) { ArrayList uniqueIntents = new ArrayList(); - stripDuplicateApps((CellLayout) mLauncher.getHotseat().getLayout(), uniqueIntents); + stripDuplicateApps((CellLayout) mLauncher.getHotseat().getLayout(), uniqueIntents, allApps); int count = getChildCount(); for (int i = 0; i < count; i++) { CellLayout cl = (CellLayout) getChildAt(i); - stripDuplicateApps(cl, uniqueIntents); + stripDuplicateApps(cl, uniqueIntents, allApps); } return uniqueIntents; } - void stripDuplicateApps(CellLayout cl, ArrayList uniqueIntents) { + void stripDuplicateApps(CellLayout cl, ArrayList uniqueIntents, + ArrayList allApps) { int count = cl.getShortcutsAndWidgets().getChildCount(); ArrayList children = new ArrayList(); @@ -3454,7 +3458,15 @@ public class Workspace extends SmoothPagedView if (info instanceof ShortcutInfo) { ShortcutInfo si = (ShortcutInfo) info; ComponentName cn = si.intent.getComponent(); - + Uri dataUri = si.intent.getData(); + + // If dataUri is not null / empty or if this component isn't one that would + // have previously showed up in the AllApps list, then this is a widget-type + // shortcut, so ignore it. + if ((dataUri != null && !dataUri.equals(Uri.EMPTY)) + || !allApps.contains(cn)) { + continue; + } if (!uniqueIntents.contains(cn)) { uniqueIntents.add(cn); } else { @@ -3469,7 +3481,15 @@ public class Workspace extends SmoothPagedView if (items.get(j).getTag() instanceof ShortcutInfo) { ShortcutInfo si = (ShortcutInfo) items.get(j).getTag(); ComponentName cn = si.intent.getComponent(); - + Uri dataUri = si.intent.getData(); + + // If dataUri is not null / empty or if this component isn't one that would + // have previously showed up in the AllApps list, then this is a widget-type + // shortcut, so ignore it. + if (dataUri != null && !dataUri.equals(Uri.EMPTY) + || !allApps.contains(cn)) { + continue; + } if (!uniqueIntents.contains(cn)) { uniqueIntents.add(cn); } else { -- cgit v1.2.3